program a
  implicit none
  integer :: N,i,ale,ue,dif
  integer,allocatable :: W(:)
  read(*,*) N
  allocate(W(N))
  read(*,*) W
  ale=sum(W)
  dif=ale
  do i=1,N
     ue=sum(W(1:i))
     if(dif.gt.abs(ale-2*ue)) then
        dif=abs(ale-2*ue)
     endif
  enddo
  write(*,'(i0)') dif

  deallocate(W)
end program a


