import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    W = LI()

    W_cum = [0] * (N + 1)
    for i in range(N):
        W_cum[i+1] = W_cum[i] + W[i]

    sum_W = sum(W)
    ans = INF
    for i in W_cum:
        ans = min(abs(sum_W - 2 * i), ans)

    print(ans)

if __name__ == '__main__':
    resolve() import bisect, collections, copy, heapq, itertools, math, string, sys bisect collections copy heapq itertools math string sys input = lambda: sys.stdin.readline().rstrip() input lambda: sys.stdin.readline().rstrip() sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip sys.setrecursionlimit(10**7) sys.setrecursionlimit sys setrecursionlimit 10**7 10 7 INF = float('inf') INF float('inf') float 'inf' def I(): return int(input()) I def F(): return float(input()) F def SS(): return input() SS int(x) for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x) int x def LI(): return [int(x) for x in input().split()] LI int(x)-1 for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x)-1 int(x) int x 1 def LI_(): return [int(x)-1 for x in input().split()] LI_ float(x) for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() float(x) float x def LF(): return [float(x) for x in input().split()] LF def LSS(): return input().split() LSS def resolve():
    N = I()
    W = LI()

    W_cum = [0] * (N + 1)
    for i in range(N):
        W_cum[i+1] = W_cum[i] + W[i]

    sum_W = sum(W)
    ans = INF
    for i in W_cum:
        ans = min(abs(sum_W - 2 * i), ans)

    print(ans) resolve N = I() N I() I W = LI() W LI() LI W_cum = [0] * (N + 1) W_cum [0] * (N + 1) [0] 0 N + 1 N 1 for i in range(N):
        W_cum[i+1] = W_cum[i] + W[i]

     i range(N) range N W_cum[i+1] = W_cum[i] + W[i] W_cum[i+1] W_cum i+1 i 1 W_cum[i] + W[i] W_cum[i] W_cum i W[i] W i sum_W = sum(W) sum_W sum(W) sum W ans = INF ans INF for i in W_cum:
        ans = min(abs(sum_W - 2 * i), ans)

     i W_cum ans = min(abs(sum_W - 2 * i), ans) ans min(abs(sum_W - 2 * i), ans) min abs(sum_W - 2 * i) abs sum_W - 2 * i sum_W 2 * i 2 i ans print(ans) print ans if __name__ == '__main__':
    resolve() __name__ == '__main__' __name__ '__main__' resolve() resolve def LI(): return [int(x) for x in input().split()] def LI(): return [int(x) for x in input().split()] LI def LF(): return [float(x) for x in input().split()] def LF(): return [float(x) for x in input().split()] LF def LI_(): return [int(x)-1 for x in input().split()] def LI_(): return [int(x)-1 for x in input().split()] LI_ input = lambda: sys.stdin.readline().rstrip() lambda: sys.stdin.readline().rstrip() input def SS(): return input() def SS(): return input() SS INF = float('inf') float('inf') INF def LSS(): return input().split() def LSS(): return input().split() LSS def resolve():
    N = I()
    W = LI()

    W_cum = [0] * (N + 1)
    for i in range(N):
        W_cum[i+1] = W_cum[i] + W[i]

    sum_W = sum(W)
    ans = INF
    for i in W_cum:
        ans = min(abs(sum_W - 2 * i), ans)

    print(ans) def resolve():
    N = I()
    W = LI()

    W_cum = [0] * (N + 1)
    for i in range(N):
        W_cum[i+1] = W_cum[i] + W[i]

    sum_W = sum(W)
    ans = INF
    for i in W_cum:
        ans = min(abs(sum_W - 2 * i), ans)

    print(ans) resolve def F(): return float(input()) def F(): return float(input()) F def I(): return int(input()) def I(): return int(input()) I
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    W = LI()

    W_cum = [0] * (N + 1)
    for i in range(N):
        W_cum[i+1] = W_cum[i] + W[i]

    sum_W = sum(W)
    ans = INF
    for i in W_cum:
        ans = min(abs(sum_W - 2 * i), ans)

    print(ans)

if __name__ == '__main__':
    resolve()
