program balance
  implicit none
  integer :: n, w(100), s1, s2, m, i
  w = 0
  read(*,*) n
  read(*,*) w(1:n)
  s1 = 0
  s2 = sum(w(1:n))
  m = 10000000
  do i = 1, n
    s1 = s1+w(i)
    s2 = s2-w(i)
    m = min(m,abs(s2-s1))
  end do
  write(*,'(i0)') m
  stop
end program balance