program weight
  implicit none
  integer :: n, allsum,partsum, ans, i
  integer,allocatable :: w(:)

  partsum = 0
  read *, n 
  allocate(w(n))
  read *, w
  allsum = sum(w)
  do i = 1, n
    partsum = partsum + w(i)
    if (partsum < allsum-partsum) then
      ans = allsum - 2*partsum
    else
      ans = min(ans, 2*partsum - allsum)
      exit
    end if
  end do
  print '(i0)', ans
end program weight
