read N
read W

sum=$(echo $W | tr ' ' '\n' | awk '{sum+=$1} END {print sum}')

acc=0
ans=''
for x in $W
do
    acc=$(($acc+$x))
    rest=$(($sum-$acc))
    if [ $acc -gt $rest ]; then
        V=$(($acc-$rest))
    else
        V=$(($rest-$acc))
    fi
    ans=$(echo $ans $V)
done

echo $ans | tr ' ' '\n' | sort -n | head -n1