LI = lambda: list(map(int, input().split()))

N = int(input())
W = LI()


def main():
    s = sum(W)
    ans = s
    x = 0
    for w in W:
        x += w
        ans = min(ans, abs(2 * x - s))
    print(ans)


if __name__ == "__main__":
    main() LI = lambda: list(map(int, input().split())) LI lambda: list(map(int, input().split())) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split N = int(input()) N int(input()) int input() input W = LI() W LI() LI def main():
    s = sum(W)
    ans = s
    x = 0
    for w in W:
        x += w
        ans = min(ans, abs(2 * x - s))
    print(ans) main s = sum(W) s sum(W) sum W ans = s ans s x = 0 x 0 for w in W:
        x += w
        ans = min(ans, abs(2 * x - s))
     w W x += w x w ans = min(ans, abs(2 * x - s)) ans min(ans, abs(2 * x - s)) min ans abs(2 * x - s) abs 2 * x - s 2 * x 2 x s print(ans) print ans if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main W = LI() LI() W N = int(input()) int(input()) N def main():
    s = sum(W)
    ans = s
    x = 0
    for w in W:
        x += w
        ans = min(ans, abs(2 * x - s))
    print(ans) def main():
    s = sum(W)
    ans = s
    x = 0
    for w in W:
        x += w
        ans = min(ans, abs(2 * x - s))
    print(ans) main LI = lambda: list(map(int, input().split())) lambda: list(map(int, input().split())) LI
LI = lambda: list(map(int, input().split()))

N = int(input())
W = LI()


def main():
    s = sum(W)
    ans = s
    x = 0
    for w in W:
        x += w
        ans = min(ans, abs(2 * x - s))
    print(ans)


if __name__ == "__main__":
    main()
