
url = "https://atcoder.jp//contests/abc129/tasks/abc129_b"

def main():
    n = int(input())
    t = list(map(int, input().split()))
    ans = 1000000000
    sums = sum(t)
    for v in t:
        sums -= v
        ans = min(abs((sum(t)-sums)-sums), ans)
    print(ans)


if __name__ == '__main__':
    main() url = "https://atcoder.jp//contests/abc129/tasks/abc129_b" url "https://atcoder.jp//contests/abc129/tasks/abc129_b" def main():
    n = int(input())
    t = list(map(int, input().split()))
    ans = 1000000000
    sums = sum(t)
    for v in t:
        sums -= v
        ans = min(abs((sum(t)-sums)-sums), ans)
    print(ans) main n = int(input()) n int(input()) int input() input t = list(map(int, input().split())) t list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split ans = 1000000000 ans 1000000000 sums = sum(t) sums sum(t) sum t for v in t:
        sums -= v
        ans = min(abs((sum(t)-sums)-sums), ans)
     v t sums -= v sums v ans = min(abs((sum(t)-sums)-sums), ans) ans min(abs((sum(t)-sums)-sums), ans) min abs((sum(t)-sums)-sums) abs (sum(t)-sums)-sums sum(t)-sums sum(t) sum t sums sums ans print(ans) print ans if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main url = "https://atcoder.jp//contests/abc129/tasks/abc129_b" "https://atcoder.jp//contests/abc129/tasks/abc129_b" url def main():
    n = int(input())
    t = list(map(int, input().split()))
    ans = 1000000000
    sums = sum(t)
    for v in t:
        sums -= v
        ans = min(abs((sum(t)-sums)-sums), ans)
    print(ans) def main():
    n = int(input())
    t = list(map(int, input().split()))
    ans = 1000000000
    sums = sum(t)
    for v in t:
        sums -= v
        ans = min(abs((sum(t)-sums)-sums), ans)
    print(ans) main

url = "https://atcoder.jp//contests/abc129/tasks/abc129_b"

def main():
    n = int(input())
    t = list(map(int, input().split()))
    ans = 1000000000
    sums = sum(t)
    for v in t:
        sums -= v
        ans = min(abs((sum(t)-sums)-sums), ans)
    print(ans)


if __name__ == '__main__':
    main()
