program balance

 implicit none
 integer::n,answer,i,j,k
 integer,allocatable::w(:),s1(:),s2(:),ans(:)

 read*,n
 allocate(w(n),s1(n),s2(n),ans(n))
 read*,w
 
 s1=0
 s2=0
 do i=1,n
  do j=1,i
   s1(i)=s1(i)+w(j)
  end do
  do k=n,i+1,-1
   s2(i)=s2(i)+w(k)
  end do
   ans(i)=abs(s1(i)-s2(i))
 end do

 answer=minval(ans)
 print*,answer

end program balance