integer N
integer,allocatable,dimension(:)::P
integer mae,ushiro
integer ans
read*,N
allocate(P(N))
read*,P
mae=0
ushiro=sum(P)
ans=huge(ans)
do i=1,N
  mae=mae+p(i)
  ushiro=ushiro-p(i)
  ans=min(ans,abs(mae-ushiro))
end do
print"(I0)",ans
end