read N
read -a W

sum=$(printf "%s\n" ${W[@]} | awk '{sum+=$1} END {print sum}')
arr=()

for ((i=0; i<$N; i++)); do
    left=${W[@]:0:$i}
    X=$(printf "%s\n" ${left[@]} | awk '{sum+=$1} END {print sum}')
    ((Y=sum-X))
    
    if (($X > $Y)); then
        ((V=X-Y))
    else
        ((V=Y-X))
    fi
    arr+=($V)
done

printf "%s\n" ${arr[@]} | sort -n | head -n 1
