program balance
implicit none
integer n, s, t, i
integer,allocatable,dimension(:) :: w, z
read*, n
allocate(w(n))
allocate(z(n))
read*, w
s=0
 do i=1,n
 t=t+w(i)
 end do
 do i=1, n
 s=s+w(i)
 t=t-w(i)
 z(i)=abs(s-t)
 end do
print*, minval(z)
end program