import sys

def main():
    N = int(input())
    W = list(map(int, input().split()))
    min_diff = sys.maxsize
    for i in range(1, N+1):
        diff = abs(sum(W[:i]) - sum(W[i:]))
        if diff < min_diff:
            min_diff = diff
    print(min_diff)


if __name__ == '__main__':
    main() import sys sys def main():
    N = int(input())
    W = list(map(int, input().split()))
    min_diff = sys.maxsize
    for i in range(1, N+1):
        diff = abs(sum(W[:i]) - sum(W[i:]))
        if diff < min_diff:
            min_diff = diff
    print(min_diff) 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 min_diff = sys.maxsize min_diff sys.maxsize sys maxsize for i in range(1, N+1):
        diff = abs(sum(W[:i]) - sum(W[i:]))
        if diff < min_diff:
            min_diff = diff
     i range(1, N+1) range 1 N+1 N 1 diff = abs(sum(W[:i]) - sum(W[i:])) diff abs(sum(W[:i]) - sum(W[i:])) abs sum(W[:i]) - sum(W[i:]) sum(W[:i]) sum W[:i] W :i i sum(W[i:]) sum W[i:] W i: i if diff < min_diff:
            min_diff = diff
     diff < min_diff diff min_diff min_diff = diff min_diff diff print(min_diff) print min_diff if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    N = int(input())
    W = list(map(int, input().split()))
    min_diff = sys.maxsize
    for i in range(1, N+1):
        diff = abs(sum(W[:i]) - sum(W[i:]))
        if diff < min_diff:
            min_diff = diff
    print(min_diff) def main():
    N = int(input())
    W = list(map(int, input().split()))
    min_diff = sys.maxsize
    for i in range(1, N+1):
        diff = abs(sum(W[:i]) - sum(W[i:]))
        if diff < min_diff:
            min_diff = diff
    print(min_diff) main
import sys

def main():
    N = int(input())
    W = list(map(int, input().split()))
    min_diff = sys.maxsize
    for i in range(1, N+1):
        diff = abs(sum(W[:i]) - sum(W[i:]))
        if diff < min_diff:
            min_diff = diff
    print(min_diff)


if __name__ == '__main__':
    main()
