#import sys

#import math

import numpy as np

'''a,b= map(int,input().split())'''

#a, b, c = [list(map(int, input().split())) for _ in range(3)]

#li0= [int(x) for x in input().split()]

#n,l= map(int, input().split())

#x = [list(map(int, input().split())) for _ in range(n)] 

a=int(eval(input()))

li0=[int(x) for x in input().split()]

count=0

ju=ans=mis=0

half=0

count=sum(li0)//2

for i in range(len(li0)):

  ju+=li0[i]

  if ju>=count:

    half=i

    break

if sum(li0[0:half])>=sum(li0[half+1:]):

  print((np.absolute(sum(li0[0:half])-sum(li0[half:]))))

else:

  print((np.absolute(sum(li0[0:half+1])-sum(li0[half+1:]))))



#import sys

#import math

#import numpy as np

'''a,b= map(int,input().split())'''

#a, b, c = [list(map(int, input().split())) for _ in range(3)]

#li0= [int(x) for x in input().split()]

#n,l= map(int, input().split())

#x = [list(map(int, input().split())) for _ in range(n)] 

a=int(eval(input()))

li=[int(x) for x in input().split()]

count=10**9



for i in range(len(li)):

  count=min(count,abs(sum(li[:i])-sum(li[i:])))

print(count)
# import sys
# import math
import numpy as np

"""a,b= map(int,input().split())"""
# a, b, c = [list(map(int, input().split())) for _ in range(3)]
# li0= [int(x) for x in input().split()]
# n,l= map(int, input().split())
# x = [list(map(int, input().split())) for _ in range(n)]
a = int(eval(input()))
li0 = [int(x) for x in input().split()]
count = 0
ju = ans = mis = 0
half = 0
count = sum(li0) // 2
for i in range(len(li0)):
    ju += li0[i]
    if ju >= count:
        half = i
        break
if sum(li0[0:half]) >= sum(li0[half + 1 :]):
    print((np.absolute(sum(li0[0:half]) - sum(li0[half:]))))
else:
    print((np.absolute(sum(li0[0 : half + 1]) - sum(li0[half + 1 :]))))

# import sys
# import math
# import numpy as np
"""a,b= map(int,input().split())"""
# a, b, c = [list(map(int, input().split())) for _ in range(3)]
# li0= [int(x) for x in input().split()]
# n,l= map(int, input().split())
# x = [list(map(int, input().split())) for _ in range(n)]
a = int(eval(input()))
li = [int(x) for x in input().split()]
count = 10**9
for i in range(len(li)):
    count = min(count, abs(sum(li[:i]) - sum(li[i:])))
print(count)

-import numpy as np - +# import numpy as np -li0 = [int(x) for x in input().split()] -count = 0 -ju = ans = mis = 0 -half = 0 -count = sum(li0) // 2 -for i in range(len(li0)): -    ju += li0[i] -    if ju >= count: -        half = i -        break -if sum(li0[0:half]) >= sum(li0[half + 1 :]): -    print((np.absolute(sum(li0[0:half]) - sum(li0[half:])))) -else: -    print((np.absolute(sum(li0[0 : half + 1]) - sum(li0[half + 1 :])))) +li = [int(x) for x in input().split()] +count = 10**9 +for i in range(len(li)): +    count = min(count, abs(sum(li[:i]) - sum(li[i:]))) +print(count)