import sys
input = sys.stdin.readline

n = int(input())
w = list(map(int, input().split()))
ruiseki = [0]
for i in range(len(w)):
    ruiseki.append(ruiseki[i] + w[i])
result = []
for i in range(1, len(w)):
    result.append(abs(ruiseki[i]-(ruiseki[-1]-ruiseki[i])))
# print(ruiseki)
print(min(result))

a699812dc638017a69c8f9eb6707fb93df674528
<mask token>

<mask token>
for i in range(len(w)):
    ruiseki.append(ruiseki[i] + w[i])
<mask token>
for i in range(1, len(w)):
    result.append(abs(ruiseki[i] - (ruiseki[-1] - ruiseki[i])))
print(min(result))

<mask token>
input = sys.stdin.readline
n = int(input())
w = list(map(int, input().split()))
ruiseki = [0]
for i in range(len(w)):
    ruiseki.append(ruiseki[i] + w[i])
result = []
for i in range(1, len(w)):
    result.append(abs(ruiseki[i] - (ruiseki[-1] - ruiseki[i])))
print(min(result))

import sys
input = sys.stdin.readline
n = int(input())
w = list(map(int, input().split()))
ruiseki = [0]
for i in range(len(w)):
    ruiseki.append(ruiseki[i] + w[i])
result = []
for i in range(1, len(w)):
    result.append(abs(ruiseki[i] - (ruiseki[-1] - ruiseki[i])))
print(min(result))

import sys
input = sys.stdin.readline

n = int(input())
w = list(map(int, input().split()))
ruiseki = [0]
for i in range(len(w)):
    ruiseki.append(ruiseki[i] + w[i])
result = []
for i in range(1, len(w)):
    result.append(abs(ruiseki[i]-(ruiseki[-1]-ruiseki[i])))
# print(ruiseki)
print(min(result))
