import sys

input = sys.stdin.readline


def main():
    N = int(input())
    W = list(map(int, input().split()))

    S1 = 0
    S2 = sum(W)
    ans = 10 ** 18
    for i in range(N - 1):
        S1 += W[i]
        S2 -= W[i]
        diff = abs(S1 - S2)
        ans = min(ans, diff)

    print(ans)


if __name__ == "__main__":
    main() import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline def main():
    N = int(input())
    W = list(map(int, input().split()))

    S1 = 0
    S2 = sum(W)
    ans = 10 ** 18
    for i in range(N - 1):
        S1 += W[i]
        S2 -= W[i]
        diff = abs(S1 - S2)
        ans = min(ans, diff)

    print(ans) main 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 S1 = 0 S1 0 S2 = sum(W) S2 sum(W) sum W ans = 10 ** 18 ans 10 ** 18 10 18 for i in range(N - 1):
        S1 += W[i]
        S2 -= W[i]
        diff = abs(S1 - S2)
        ans = min(ans, diff)

     i range(N - 1) range N - 1 N 1 S1 += W[i] S1 W[i] W i S2 -= W[i] S2 W[i] W i diff = abs(S1 - S2) diff abs(S1 - S2) abs S1 - S2 S1 S2 ans = min(ans, diff) ans min(ans, diff) min ans diff print(ans) print ans if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main input = sys.stdin.readline sys.stdin.readline input def main():
    N = int(input())
    W = list(map(int, input().split()))

    S1 = 0
    S2 = sum(W)
    ans = 10 ** 18
    for i in range(N - 1):
        S1 += W[i]
        S2 -= W[i]
        diff = abs(S1 - S2)
        ans = min(ans, diff)

    print(ans) def main():
    N = int(input())
    W = list(map(int, input().split()))

    S1 = 0
    S2 = sum(W)
    ans = 10 ** 18
    for i in range(N - 1):
        S1 += W[i]
        S2 -= W[i]
        diff = abs(S1 - S2)
        ans = min(ans, diff)

    print(ans) main
import sys

input = sys.stdin.readline


def main():
    N = int(input())
    W = list(map(int, input().split()))

    S1 = 0
    S2 = sum(W)
    ans = 10 ** 18
    for i in range(N - 1):
        S1 += W[i]
        S2 -= W[i]
        diff = abs(S1 - S2)
        ans = min(ans, diff)

    print(ans)


if __name__ == "__main__":
    main()
