"""abc129_b"""
N = int(input())
W = list(map(int, input().split()))

W_SUM = sum(W)

W_TOTAL = 0
W_ABS = []
for w in W :
    W_TOTAL += w
    W_ABS.append(abs(W_SUM - W_TOTAL * 2))

    if W_TOTAL > W_SUM/2:
        break

print(min(W_ABS)) """abc129_b""" N = int(input()) N int(input()) int input() input W = list(map(int, input().split())) W list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split W_SUM = sum(W) W_SUM sum(W) sum W W_TOTAL = 0 W_TOTAL 0 W_ABS = [] W_ABS [] for w in W :
    W_TOTAL += w
    W_ABS.append(abs(W_SUM - W_TOTAL * 2))

    if W_TOTAL > W_SUM/2:
        break w W W_TOTAL += w W_TOTAL w W_ABS.append(abs(W_SUM - W_TOTAL * 2)) W_ABS.append W_ABS append abs(W_SUM - W_TOTAL * 2) abs W_SUM - W_TOTAL * 2 W_SUM W_TOTAL * 2 W_TOTAL 2 if W_TOTAL > W_SUM/2:
        break W_TOTAL > W_SUM/2 W_TOTAL W_SUM/2 W_SUM 2 break print(min(W_ABS)) print min(W_ABS) min W_ABS W_SUM = sum(W) sum(W) W_SUM W = list(map(int, input().split())) list(map(int, input().split())) W N = int(input()) int(input()) N W_TOTAL = 0 0 W_TOTAL W_ABS = [] [] W_ABS W_TOTAL += w w W_TOTAL
"""abc129_b"""
N = int(input())
W = list(map(int, input().split()))

W_SUM = sum(W)

W_TOTAL = 0
W_ABS = []
for w in W :
    W_TOTAL += w
    W_ABS.append(abs(W_SUM - W_TOTAL * 2))

    if W_TOTAL > W_SUM/2:
        break

print(min(W_ABS))
