Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut into n pieces. The i-th piece is a sector of angle equal to a_{i}. Vasya and Petya want to divide all pieces of pizza into two continuous sectors in such way that the difference between angles of these sectors is minimal. Sector angle is sum of angles of all pieces in it. Pay attention, that one of sectors can be empty.


-----Input-----

The first line contains one integer n (1 ≤ n ≤ 360)  — the number of pieces into which the delivered pizza was cut.

The second line contains n integers a_{i} (1 ≤ a_{i} ≤ 360)  — the angles of the sectors into which the pizza was cut. The sum of all a_{i} is 360.


-----Output-----

Print one integer  — the minimal difference between angles of sectors that will go to Vasya and Petya.


-----Examples-----
Input
4
90 90 90 90

Output
0

Input
3
100 100 160

Output
40

Input
1
360

Output
360

Input
4
170 30 150 10

Output
0



-----Note-----

In first sample Vasya can take 1 and 2 pieces, Petya can take 3 and 4 pieces. Then the answer is |(90 + 90) - (90 + 90)| = 0.

In third sample there is only one piece of pizza that can be taken by only one from Vasya and Petya. So the answer is |360 - 0| = 360.

In fourth sample Vasya can take 1 and 4 pieces, then Petya will take 2 and 3 pieces. So the answer is |(170 + 10) - (30 + 150)| = 0.

Picture explaning fourth sample:

[Image]

Both red and green sectors consist of two adjacent pieces of pizza. So Vasya can take green sector, then Petya will take red sector.

Difficulty: EASY
Tags: Implementation

Complete search
Skill types: Complete search

Starter code:

Solutions:
def diff(val):
	return 2 * abs(180 - val)
n = int(input())
arr = input().split(' ')
arr = [int(x) for x in arr]
sum = 0
min_diff = 360
last_idx = 0
for a in arr:
	sum += a
	min_diff = min(min_diff, diff(sum))
	while sum > 180:
		sum -= arr[last_idx]
		last_idx += 1
		min_diff = min(min_diff, diff(sum))
	if sum == 180:
		min_diff = 0
		break
print(min_diff)


n = int(input())
lst = list(map(int, input().split()))
ans = 360
for i in range(n):
	t = 0
	for j in range(n):
		t += lst[(i + j) % n]
		ans = min(ans, abs(t - (360 - t)))
print(ans)


def main():
	n = int(input())
	angles = [int(c) for c in input().split()]
	if n == 1:
		print(360)
		return
	angles = angles * 2
	angles.pop()
	ans = 360
	for k in range(n - 1):
		_sum = 0
		for i in range(k, k + n - 1):
			_sum += angles[i]
			(a, b) = (_sum, 360 - _sum)
			diff = max(a, b) - min(a, b)
			if diff < ans:
				ans = diff
	print(ans)
main()


n = int(input())
L = input().split()
for k in range(n):
	L[k] = int(L[k])

def difference(L, i, j):
	a = sum(L[i:j + 1])
	return abs(360 - 2 * a)
outpt = []
for i in range(n):
	for j in range(i, n):
		outpt.append(difference(L, i, j))
print(min(outpt))


n = int(input())
a = list(map(int, input().split()))
ans = 360
for i in range(n):
	for j in range(i, n):
		ans = min(ans, abs(180 - sum(a[i:j])) * 2)
print(ans)


n = int(input())
a = list(map(int, input().split()))
pr = [0] * (n + 1)
mn = 10 ** 10
for i in range(1, n + 1):
	pr[i] = pr[i - 1] + a[i - 1]
for i in range(1, n + 1):
	for j in range(i, n + 1):
		p = pr[j] - pr[i - 1]
		if abs(360 - 2 * p) < mn:
			mn = abs(360 - 2 * p)
print(mn)


n = int(input())
l = input().split()
a = []
c = 0
lv = []
for i in range(n):
	a.append(int(l[i]))
for i in range(n):
	for g in range(n):
		lv.append(abs(180 - sum(a[i:g + 1])))
print(min(lv) * 2)


(_, l) = (input(), [])
for a in map(int, input().split()):
	l += range(a)
print(min((l[i] for (i, a) in enumerate(l, -180) if not a)) * 2)


n = int(input())
a = list(map(int, input().split()))
mn = sum(a)
for i in range(len(a)):
	for j in range(i, len(a)):
		mn = min(mn, abs(sum(a[i + 1:j + 1]) - sum(a[0:i + 1] + a[j + 1:len(a)])))
print(mn)


n = int(input())
a = list(map(int, input().split()))
mi = 361
for i in range(n):
	for j in range(i, n):
		mi = min(mi, abs(sum(a[:]) - sum(a[i:j]) * 2))
print(mi)


n = int(input())
vals = list(map(int, input().split()))
print(min([360] + [abs(360 - 2 * sum(vals[j:j + i])) for i in range(n + 1) for j in range(n)]))


import math
a = int(input())
b = list(map(int, input().split()))
e = 361
if b[0] == 360:
	print(360)
else:
	for c in range(a - 1):
		for d in range(a - 1):
			if math.fabs(180 - sum(b[c:-(a - 1 - d)])) * 2 < e:
				e = math.fabs(180 - sum(b[c:-(a - 1 - d)])) * 2
	print(int(e))


(z, zz, dgraphs) = (input, lambda : list(map(int, z().split())), {})
from string import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0 and x != 2:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = True
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
n = int(z())
ll = zz()
lx = [360]
for l in range(n):
	for r in range(l + 1, n + 1):
		ans = abs(2 * sum(ll[l:r]) - 360)
		lx.append(ans)
print(min(lx))


input()
angs = [int(x) for x in input().split()]
result = 99999
for i in range(len(angs)):
	curr = 0
	for j in range(i, i + len(angs)):
		curr += angs[j % len(angs)]
		result = abs(180 - curr) if abs(180 - curr) < result else result
print(2 * result)


n = int(input())
pieces = [int(x) for x in input().split()]
sm = 360
curs = 0
ans = []
for i in range(n):
	for elem in pieces:
		ans.append(abs(sm - 2 * curs))
		curs += elem
		if curs >= 360:
			curs = 0
	pieces.append(pieces.pop(0))
print(min(ans))


n = int(input())
from itertools import permutations
a = list(map(int, input().split()))
b = 361
for i in range(n):
	for j in range(i, n):
		b = min(b, abs(sum(a[:]) - sum(a[i:j]) * 2))
print(b)


class CodeforcesTask895ASolution:

	def __init__(self):
		self.result = ''
		self.n = 0
		self.sectors = []

	def read_input(self):
		self.n = int(input())
		self.sectors = [int(x) for x in input().split(' ')]

	def process_task(self):
		mn = 360
		for a in range(self.n):
			for b in range(a, self.n):
				mn = min(mn, abs(2 * sum(self.sectors[a:b]) - 360))
		self.result = str(mn)

	def get_result(self):
		return self.result
Solution = CodeforcesTask895ASolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


n = int(input())
e = input()
a = e.split(' ')
(sum2, sum1) = (0, 0)
k = 0
for t in range(n):
	i = k
	k += 1
	while sum2 < 180:
		sum2 += int(a[i % n])
		i += 1
	if sum2 < sum1 or sum1 == 0:
		sum1 = sum2
	sum2 = 0
print(sum1 - (360 - sum1))


a = int(input())
l1 = [int(j) for j in input().split()]
r = 180
l2 = []
for j in range(len(l1)):
	l2.append(l1[j:] + l1[:j])
o1 = []
for j in l2:
	o = []
	r1 = 0
	for i in j:
		r1 += i
		if r1 > 180:
			o.append(r1)
			o.append(r1 - i)
			break
	u = [abs(o[0] - 180), abs(o[1] - 180)]
	o1.append(2 * min(u))
print(min(o1))


n = int(input())
a = list(map(int, input().split()))
m = abs(2 * a[0] - 360)
for i in range(n):
	for j in range(i + 1, n + 1):
		s = 0
		if i == 0 and j == n:
			continue
		for k in range(i, j):
			s += a[k]
		m = min(m, abs(2 * s - 360))
print(m)


n = int(input())
a = [int(i) for i in input().split()]
best = 360
for i in range(n):
	for j in range(i + 1, n + 1):
		if abs(sum(a[i:j]) - (360 - sum(a[i:j]))) < best:
			best = abs(sum(a[i:j]) - (360 - sum(a[i:j])))
print(best)


import sys
n = int(sys.stdin.readline())
a = list(map(int, sys.stdin.readline().split()))
a += a
ans = 360
for i in range(n):
	cur = 0
	for len in range(n):
		ans = min(ans, abs(cur - (360 - cur)))
		cur += a[i + len]
print(ans)


nP = int(input())
secs = [int(k) for k in input().split()]
total = sum(secs)
result = total
for left in range(nP):
	curS = 0
	for right in range(left, nP):
		curS += secs[right]
		result = min(result, abs(total - curS - curS))
print(result)


import os
import sys
from io import BytesIO, IOBase

def main():
	n = int(input())
	a = [int(x) for x in input().split()]
	a = a + a
	ans = 360
	cnt = 0
	for i in range(2 * n):
		cnt += a[i]
		a[i] = cnt
	for i in range(n):
		for j in range(n):
			x = a[i + j + 1] - a[i]
			ans = min(ans, abs(360 - 2 * x))
	print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


n = int(input())
a = list(map(int, input().split()))
ans = 360
for l in range(n):
	for r in range(l + 1, n + 1):
		ans = min(ans, abs(2 * sum(a[l:r]) - 360))
print(ans)


n = int(input())
l = list(map(int, input().split()))
ans = 180
for i in range(0, n):
	sum = 0
	for j in range(i, n):
		sum += l[j]
		if ans > abs(180 - sum):
			ans = abs(180 - sum)
print(ans * 2)


a = int(input())
b = list(map(int, input().split())) * 2
pizza = 360
for i in range(2 * a):
	t = 0
	for j in range(i, min(i + a, 2 * a)):
		t += b[j]
		pizza = min(pizza, abs(2 * t - 360))
print(pizza)


n = int(input())
A = list(map(int, input().split()))
if n == 1:
	print(A[0])
	exit()
t = float('inf')
gs = sum(A)
(fs, ss) = (A[0], abs(A[0] - gs))
for l in range(-n, n):
	for r in range(l, n):
		fs = sum(A[l:r])
		ss = gs - fs
		if abs(ss - fs) < t:
			t = abs(ss - fs)
print(t)


n = int(input())
sectors = list(map(int, input().split()))
sectors.extend(sectors)
min_diff = 360
for i in range(n):
	total = 0
	for j in range(i, i + n):
		total += sectors[j]
		min_diff = min(min_diff, abs(total - (360 - total)))
print(min_diff)


R = lambda : map(int, input().split())
n = int(input())
a = list(R())
ans = abs(2 * a[0] - 360)
for i in range(n):
	sum = a[i]
	if abs(2 * sum - 360) < ans:
		ans = sum
	for j in range(1, n):
		sum += a[(i + j) % n]
		temp = abs(2 * sum - 360)
		if temp < ans:
			ans = temp
print(ans)


import sys
sys.setrecursionlimit(100000000)

def iin():
	return int(input())

def impin():
	return map(int, input().split())

def irrin():
	return [int(x) for x in input().split()]

def imrin(n):
	return [int(input()) for _ in range(n)]
n = iin()
arr = irrin()
sa = sum(arr)
mn = 100000000
for i in range(n):
	for j in range(i, n + 1):
		s = sum(arr[i:j])
		k = sa - s
		mn = min(mn, abs(s - k))
print(mn)


n = int(input())
ai = list(map(int, input().split()))
ai2 = [0] * n
summ = sum(ai)
ai2[0] = ai[0]
minim = 360
for i in range(1, n):
	ai2[i] = ai2[i - 1] + ai[i]
	minim = min(minim, abs(180 - ai2[i]) * 2)
for i in range(n - 1, 0, -1):
	for j in range(i):
		minim = min(minim, abs((180 - (ai2[i] - ai2[j])) * 2))
print(minim)


N = int(input())
pizzaList = list(map(int, input().split()))

def checkMinSum(minDiff, currDiff):
	if abs(currDiff) < minDiff:
		return abs(currDiff)
	return minDiff
sum0 = 0
minDiff = 180
currDiff = 180
for i in range(0, N):
	sum0 = 0
	for j in range(0, N):
		sum0 += pizzaList[(i + j) % N]
		currDiff = 180 - sum0
		minDiff = checkMinSum(minDiff, currDiff)
		if currDiff <= 0:
			break
print(minDiff * 2)


N = int(input())
raw = input()
numbers = [int(token) for token in raw.split(' ')]
total = sum(numbers)
smallest = 1000
for i in range(N):
	for j in range(i, N):
		sum1 = sum(numbers[i:j])
		sum2 = total - sum1
		smallest = min(smallest, abs(sum1 - sum2))
print(smallest)


n = int(input())
a = list(map(int, input().split()))
(j, s, m) = (0, 0, 360)
for ai in a:
	while s < 180:
		s += a[j]
		j = (j + 1) % n
	m = min(m, s)
	s -= ai
print(2 * m - 360)


n = int(input())
a = list(map(int, input().split()))
res = 360
for qq in range(n):
	sm = 0
	for i in range(n - 1):
		sm += a[i]
		q = 360 - sm
		res = min(res, abs(sm - q))
	a = [a[-1]] + a[:-1]
print(res)


n = int(input())
a = [int(i) for i in input().split()]
ans = 360
for i in range(-len(a), len(a)):
	s = 0
	for j in range(i, len(a)):
		s += a[j]
		if j - i + 1 > len(a):
			break
		elif j < 0:
			continue
		elif j >= 0 and ans > 2 * abs(180 - s):
			ans = 2 * abs(180 - s)
print(ans)


n = int(input())
lst = list(map(int, input().strip().split(' ')))
if n == 1:
	print(lst[0])
elif n == 2:
	print(abs(lst[1] - lst[0]))
else:
	s = 360
	m = 360
	lst = lst * 2
	for i in range(n):
		p = 0
		for j in range(i, i + n - 1):
			p += lst[j]
			if abs(s - 2 * p) < m:
				m = abs(s - 2 * p)
	print(m)


n = int(input())
l = [int(i) for i in input().split()]
o = []
if n == 1:
	print('360')
elif n == 2:
	print(abs(l[0] - l[1]))
else:
	for i in range(n):
		for j in range(i, n):
			k = sum(l[i:j + 1])
			o.append(abs(k - 180))
	print(2 * min(o))


n = int(input())
lst = [int(i) for i in input().split()]
print(min([abs(360 - 2 * sum(lst[j:j + i])) for i in range(n + 1) for j in range(n)]))


input()
a = list(map(int, input().split(' '))) * 2
min = 512
for i in range(len(a)):
	sum = 0
	for j in range(i, len(a)):
		sum = a[j] + sum
		if abs(sum - 180) < min:
			min = abs(sum - 180)
print(2 * min)


import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys
N = int(input())
A = [int(x) for x in input().split()]
ans = float('inf')
total = sum(A or [0])
for i in range(N):
	for j in range(i, N):
		a = sum(A[i:j] or [0])
		b = total - a
		ans = min(ans, abs(a - b))
print(ans)


n = int(input())
s = [int(i) for i in input().split()]
ans = 10 ** 9 + 7
for i in range(n):
	a = 0
	ans = min(ans, abs(180 - a))
	for j in range(i, n):
		a += s[j]
		ans = min(ans, abs(180 - a))
print(ans * 2)


n = int(input())
mas = list(map(int, input().split()))
delta = 100000000000000000000
for a in range(n):
	for b in range(a + 1, n):
		s1 = sum(mas[a:b])
		s2 = sum(mas) - s1
		if abs(s1 - s2) < delta:
			delta = abs(s1 - s2)
if delta == 100000000000000000000:
	delta = sum(mas)
print(delta)


n = int(input())
a = list(map(int, input().split()))

def pizza(i, summ, n):
	if i == n:
		return abs(2 * summ - 360)
	return min(abs(2 * summ - 360), pizza(i + 1, summ + a[i], n))
minn = float('INF')
for i in range(n):
	tmp = pizza(i, 0, n)
	if tmp < minn:
		minn = tmp
print(minn)


n = int(input())
ar = [int(i) for i in input().split(' ')]
sum = 0
s_a = 1000
for i in range(n):
	k = 0
	sum = 0
	while sum < 180:
		sum += ar[i - k]
		k += 1
	if s_a > sum - (360 - sum):
		s_a = sum - (360 - sum)
print(s_a)


kolichestvoKuskov = int(input())
spisokUglov = list(map(int, input().split()))
raznica = 180
for a in range(0, kolichestvoKuskov):
	sum = 0
	for i in range(a, kolichestvoKuskov):
		sum += spisokUglov[i]
		if raznica > abs(180 - sum):
			raznica = abs(180 - sum)
print(raznica * 2)


n = int(input())
a = list(map(int, input().split()))
l = []
for i in range(n):
	for j in range(n):
		l.append(abs(180 - sum(a[i:j + 1])))
print(min(l) * 2)


from math import *
from collections import *
from operator import itemgetter
import bisect
ii = lambda : int(input())
iia = lambda : list(map(int, input().split()))
isa = lambda : list(input().split())
I = lambda : list(map(int, input().split()))
chrIdx = lambda x: ord(x) - 96
idxChr = lambda x: chr(96 + x)
n = ii()
a = iia()
x = 0
y = 0
i = 0
s = [0] * n
s[0] = a[0]
for i in range(1, n):
	s[i] = s[i - 1] + a[i]
mini = 360
for i in range(n):
	for j in range(n):
		mini = min(mini, abs(sum(a[i:j + 1]) - (360 - sum(a[i:j + 1]))))
print(mini)


n = int(input())
arr = list(map(int, input().split()))
sum = 0
l = 0
i = 0
ans = 360
while i < n:
	sum += arr[i]
	while sum >= 180:
		ans = min(ans, 2 * abs(sum - 180))
		sum -= arr[l]
		l += 1
	i += 1
	ans = min(ans, 2 * abs(sum - 180))
print(ans)


n = int(input())
a = list(map(int, input().split()))
a += a
rt = 360
for i in range(n):
	cur = 0
	j = i
	while cur < 180:
		cur += a[j]
		j += 1
	rt = min(rt, 2 * cur - 360)
print(rt)


def main():
	n = int(input())
	a = list(map(int, input().split()))
	s = sum(a)
	res = 100 ** 10
	for l in range(n):
		for r in range(l, n):
			s1 = sum(a[l:r])
			res = min(res, abs(s1 - (s - s1)))
	print(res)
main()


n = int(input())
a = list(map(int, input().split()))
a = a + a
ans = 360
for i in range(n):
	for j in range(n):
		v = sum(a[i:i + j + 1])
		ans = min(ans, abs(360 - v - v))
print(ans)


n = int(input())
p = list(map(int, input().split()))
r = [0] * n
mn = 360
for i in range(n):
	q = []
	q.extend(p[i:])
	if i > 0:
		q.extend(p[0:i])
	sm = 0
	for i in range(len(q)):
		sm += q[i]
		r[i] = sm
	for i in r:
		if abs(360 - 2 * i) < mn:
			mn = abs(360 - 2 * i)
print(mn)


n = int(input())
a = list(map(int, input().split()))
r = 180
for i in range(n):
	s = 0
	for j in range(i, n):
		s += a[j]
		r = min(abs(s - 180), r)
print(2 * r)


n = int(input())
a = list(map(int, input().split()))
mn = 360
for i in range(n):
	x = 0
	for j in range(i, n):
		x += a[j]
		mn = min(mn, abs(x - (360 - x)))
print(mn)


n = int(input())
lista = list(map(int, input().split(' ')))
ans = 1000
for i in range(0, n):
	sum = 0
	cont = i
	while cont < i + n:
		sum += lista[cont % n]
		ans = min(abs(sum - (360 - sum)), ans)
		cont += 1
print(ans)


n = int(input())
a = [int(i) for i in input().split()]
min = 361
for i in range(n):
	for j in range(i, n):
		if -min < sum(a[0:i]) + sum(a[j:]) - sum(a[i:j]) < min:
			min = sum(a[0:i]) + sum(a[j:]) - sum(a[i:j])
			if min < 0:
				min *= -1
print(min)


n = int(input())
l = list(map(int, input().split()))
m = 360
if n == 1:
	print(360)
else:
	for i in range(len(l)):
		a = l[i]
		m = min(m, abs(180 - a))
		for j in range(i + 1, len(l)):
			a += l[j]
			m = min(m, abs(180 - a))
			if m == 0:
				break
		if m == 0:
			break
	print(2 * m)


import sys
data = sys.stdin.readlines()
n = int(data[0])
m = [int(x) for x in data[1].split()]
res = []
for k in range(n):
	for i in range(n):
		a = abs(sum(m[:i]) - sum(m[i:]))
		res.append(a)
	m.append(m[0])
	m = m[1:]
print(min(res))


import math
import sys
import getpass

def ria():
	return [int(i) for i in input().split()]
files = True
if getpass.getuser().lower() == 'frohenk' and files:
	sys.stdin = open('test.in')
n = ria()[0]
ar = ria()
suma = sum(ar)
ar += ar
mini = 1000
for i in range(n):
	for j in range(i, i + n + 1):
		sums = sum(ar[i:j])
		cura = abs(suma - sums - sums)
		mini = min(mini, cura)
print(mini)
sys.stdout.close()


n = int(input())
l = list(map(int, input().split()))
k = 360
for i in range(n):
	for j in range(i, n):
		k = min(k, 2 * abs(180 - sum(l[i:j])))
print(k)


n = int(input())
a = [int(i) for i in input().split()]
ans = 1000000000.0
for j in range(n):
	pref = [0] * (n + 1)
	for i in range(1, n + 1):
		pref[i] = pref[i - 1] + a[i - 1]
	for i in range(n):
		ans = min(ans, abs(pref[-1] - 2 * pref[i]))
	a = [a[-1]] + a[:-1]
print(ans)


n = int(input())
s = list(map(int, input().split()))
m = 360
for i in range(n):
	sub = 0
	for j in range(i, n):
		sub += s[j]
		m = min(m, abs(sub - (360 - sub)))
print(m)


n = int(input())
l = [int(x) for x in input().split()]
ans = 360
sum = 0
j = 0
i = 0
while i < n:
	sum += l[i]
	while sum >= 180:
		ans = min(ans, 2 * abs(180 - sum))
		sum -= l[j]
		j += 1
	ans = min(ans, 2 * abs(180 - sum))
	i += 1
print(ans)


n = int(input())
a = [int(z) for z in input().split()]
ans = 360
for i in range(n):
	tmp = 0
	for j in range(i, n):
		tmp += a[j]
		ans = min(ans, abs(360 - tmp - tmp))
print(ans)


(n, mn) = (int(input()), 1000)
a = list(map(int, input().split()))
for i in range(n):
	m3lsh = 0
	for j in range(i, n):
		m3lsh += a[j]
		mn = min(mn, abs(360 - 2 * m3lsh))
print(mn)


n = int(input()) + 1
line = input()
arr = [0]
ans = -1
d = [0]
for l in line.split(' '):
	arr.append(int(l))
	d.append(d[-1] + int(l))
for i in range(1, n):
	for j in range(1, n):
		x = 360 - 2 * (d[j] - d[i - 1] if i <= j else d[-1] - d[i - 1] + d[j])
		if x < 0:
			x = -x
		if ans == -1 or ans > x:
			ans = x
print(ans)


n = int(input())
a = list(map(int, input().split()))
num = float('inf')
for i in range(n):
	for j in range(i, n):
		num = min(num, 2 * abs(180 - sum(a[i:j + 1])))
print(num)


from itertools import cycle
n = int(input())
a = list(map(int, input().split()))
(s, m) = (0, 360)
j = cycle(a)
for ai in a:
	while s < 180:
		s += next(j)
	m = min(m, s)
	s -= ai
print(2 * m - 360)


n = int(input())
a = [int(i) for i in input().split()]
c = sum(a)
m = c
for i in range(n):
	for k in range(i, n + 1):
		m = min(m, abs(c - 2 * sum(a[i:k + 1])))
print(m)


n = int(input())
a = list(map(int, input().split()))
ans = 10 ** 10
for l in range(n):
	for r in range(l, n):
		k1 = sum(a[l:r])
		k2 = 360 - k1
		ans = min(ans, abs(k1 - k2))
print(ans)


n = int(input())
l = []
l = input().split()
for i in range(n):
	l[i] = int(l[i])
l.extend(l)
otv = 400
for i in range(n):
	s = 0
	j = i
	while s < 180:
		s += l[j]
		j += 1
	if abs(s - 180) * 2 < otv:
		otv = abs(s - 180) * 2
print(otv)


n = int(input())
angles = list(map(int, input().split()))
angles = angles + angles
sum_ = 0
from_ = 0
best = 360
for to in range(n):
	sum_ += angles[to]
	while sum_ >= 180:
		best = min(best, abs(360 - 2 * sum_))
		sum_ -= angles[from_]
		from_ += 1
	best = min(best, abs(360 - 2 * sum_))
print(best)


n = int(input())
a = list(map(int, input().split()))
l = 0
ans = 360
sum1 = 0
for k in a:
	sum1 = sum1 + k
	while sum1 >= 180:
		ans = min(ans, 2 * abs(180 - sum1))
		sum1 = sum1 - a[l]
		l = l + 1
	ans = min(ans, 2 * abs(180 - sum1))
print(ans)


n = int(input())
a = [int(x) for x in input().split()]
ans = 180
for i in range(n):
	t = 0
	for j in range(i, n):
		t += a[j]
		c = abs(t - 180)
		ans = min(ans, c)
print(2 * ans)


n = int(input())
a = list(map(int, input().split()))
res = float('inf')
for i in range(len(a)):
	(l, r) = (0, 360)
	for i in a[i:] + a[:i]:
		res = min(res, abs(l - r))
		l += i
		r -= i
	res = min(res, abs(l - r))
print(res)


n = int(input())
a = list(map(int, input().split()))
if n == 1:
	print(360)
	exit(0)
r = 360
for i in range(len(a)):
	for j in range(1, len(a) + 1):
		k = (i + j) % n
		if i == k:
			s1 = sum(a)
		elif i < k:
			s1 = sum(a[i:k])
		else:
			s1 = sum(a[k:i])
		ss = abs(360 - s1 - s1)
		if ss < r:
			r = ss
print(r)


def solution(sectors):
	n = len(sectors)
	if n == 1:
		return sectors[0]
	else:
		min_diff = 360
		for i in range(n):
			j = i
			sum_sector = 0
			prev = sum_sector
			while sum_sector <= 180:
				prev = sum_sector
				sum_sector += sectors[j]
				j += 1
				j %= n
			if abs(360 - 2 * sum_sector) < min_diff:
				min_diff = abs(360 - 2 * sum_sector)
			if abs(360 - 2 * prev) < min_diff:
				min_diff = abs(360 - 2 * prev)
		return min_diff
n = int(input())
sectors = []
sectors_str = input().split()
for s in sectors_str:
	sectors.append(int(s))
print(solution(sectors))


N = int(input())
angles = list(map(int, input().split()))
total = sum(angles)
min_diff = total
start = total
for i in range(N, -1, -1):
	if i < N:
		start -= angles[i]
	count = start
	if count > total // 2:
		for j in range(0, i):
			count -= angles[j]
			min_diff = min(min_diff, abs(total - count * 2))
print(min_diff)


n = int(input())
l = list(map(int, input().split()))
mi = 360
f = 0
for i in range(n):
	f = l[i]
	f1 = f
	mi = min(mi, max(f, 360 - f))
	for j in range(i + 1, n):
		f1 += l[j]
		mi = min(mi, max(f1, 360 - f1))
print(abs(180 - mi) * 2)


n = int(input())
a = list(map(int, input().split()))
print(2 * min((abs(180 - sum(a[l:r])) for l in range(n) for r in range(l, n))))


n = int(input())
a = list(map(int, input().split()))
a = a + a
mid = n // 2
best = 99999999999999999999999
for i in range(n):
	sub = a[i:i + n]
	d = sum(sub)
	best = min(best, d)
	s = 0
	for j in range(n):
		s += sub[j]
		d -= sub[j]
		diff = abs(s - d)
		best = min(best, diff)
print(best)


n = int(input())
a = list(map(int, input().split()))
ans = 360
for i in range(0, n):
	s = 0
	for j in range(i, n):
		s = s + a[j]
		ans = min(ans, abs(360 - 2 * s))
print(ans)


n = int(input())
a = list(map(int, input().split()))
sumspref = [a[0]]
for i in range(1, n):
	sumspref.append(sumspref[-1] + a[i])
sums = []
for i in range(n):
	for j in range(i, n):
		sums.append(abs(180 - (sumspref[j] - sumspref[i])))
print(min(sums) * 2)


def solve(n, arr):
	summ = 360
	minn = 360
	for i in range(n):
		ans = 0
		tempN = n if i > 0 else n - 1
		for j in range(i, tempN):
			ans += arr[j]
			temp = abs(summ - ans - ans)
			if temp < minn:
				minn = temp
	print(minn)

def main():
	n = int(input())
	arr = list(map(int, input().split()))
	solve(n, arr)
main()


n = int(input())
a = list(map(int, input().split()))
(j, s, m) = (0, 0, 360)
for i in range(n):
	while s < 180:
		s += a[j]
		j += 1
		if j == n:
			j = 0
	m = min(m, s)
	s -= a[i]
print(2 * m - 360)


n = int(input())
b = input()
a = b.split(' ')
sum = 0
ans = 365
for i in range(0, n):
	sum = 0
	for j in range(i, n):
		sum += int(a[j])
		ans = min(ans, abs(360 - sum * 2))
print(ans)


x = int(input())
a = list(map(int, input().split()))
b = list(a)
for i in b:
	a.append(i)
mind = 360
for i in range(len(b)):
	ns = 0
	c = []
	q = i
	for k in range(x):
		c.append(a[q + k])
	for j in range(x):
		ns = ns + c[0]
		c.pop(0)
		s = sum(c)
		diff = abs(ns - s)
		if mind > diff:
			mind = diff
print(mind)


n = int(input())
slices = list(map(int, input().split()))
answer = 360
for i in range(n):
	for j in range(i + 1, n):
		cur_s = abs(sum(slices[:i]) + sum(slices[j:]) - sum(slices[i:j]))
		answer = min(cur_s, answer)
print(answer)


n = int(input())
lst = input().split()
for i in range(n):
	lst[i] = int(lst[i])
ans = 360
for begin in range(n):
	i = 0
	a = 0
	while a < 180:
		a += lst[(begin + i) % n]
		ans = min(ans, 2 * abs(180 - a))
		i += 1
	ans = min(ans, 2 * abs(180 - a))
print(ans)


n = int(input())
a = [int(s) for s in input().split()]
x2 = []
for i in range(n):
	x1 = []
	for j in range(i, i + n):
		if j % n >= i:
			x1.append(abs(sum(a) - 2 * sum(a[i:j % n])))
		else:
			x1.append(abs(sum(a) - 2 * sum(a[i:] + a[:j % n])))
	x2.append(min(x1))
print(min(x2))


n = int(input())
arr = list(map(int, input().split()))
ans = 360
sum = []
temp_sum = 0
for i in arr:
	temp_sum += i
	sum.append(temp_sum)
for i in range(len(arr)):
	for j in range(i, len(arr)):
		if i == 0:
			ans = min(ans, abs(2 * (sum[j] - 0) - 360))
		else:
			ans = min(ans, abs(2 * (sum[j] - sum[i - 1]) - 360))
print(ans)


def list_output(s):
	print(' '.join(map(str, s)))

def list_input(s='int'):
	if s == 'int':
		return list(map(int, input().split()))
	elif s == 'float':
		return list(map(float, input().split()))
	return list(map(str, input().split()))
n = int(input())
a = list(map(int, input().split()))
res = 360
for i in range(n):
	for j in range(n):
		j2 = j
		if j < i:
			j2 += n
		sum = 0
		for k in range(i, j2):
			idx = k % n
			sum += a[idx]
		res = min(res, abs(360 - sum - sum))
print(res)


n = int(input())
best = 360
tab = list(map(int, input().split()))
pre_sum = [0]
for i in range(1, len(tab) + 1):
	pre_sum += [tab[i - 1] + pre_sum[-1]]
for i in range(n + 1):
	for j in range(i, n + 1):
		best = min([best, 2 * abs(180 - (pre_sum[j] - pre_sum[i - 1]))])
print(best)


def read():
	return tuple((int(x) for x in input().split()))

def main():
	n = int(input())
	ns = list(read())
	ss = []
	s = []
	ss.append(s)
	for i in ns:
		if len(s) == 0:
			s.append(i)
		else:
			s.append(i + s[-1])
	for i in range(n):
		s[i] = s[i] * 2 - s[-1]
	for i in range(n - 1):
		s = []
		ss.append(s)
		for j in range(n):
			s.append(ss[-2][j] - 2 * ns[i])
	m = 9999999
	for s in ss:
		for n in s:
			if abs(n) < m:
				m = abs(n)
	return m
print(main())


n = int(input())
arr = list(map(int, input().split()))
sum1 = sum(arr)
sum2 = 360
i = 1
while i < n:
	j = 0
	while i + j <= n:
		if abs(sum1 - sum(arr[j:j + i]) - sum(arr[j:j + i])) < sum2:
			sum2 = abs(sum1 - sum(arr[j:j + i]) - sum(arr[j:j + i]))
		j += 1
	i += 1
print(sum2)


import sys

def fastio():
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()
INF = 10 ** 20
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br
(n,) = I()
a = I() * 2
ans = INF
for i in range(n):
	cur = 0
	for j in range(i, i + n):
		cur += a[j]
		ans = min(ans, abs(360 - 2 * cur))
print(ans)


p = input().strip().split()
arr = list(map(int, input().strip().split()))
if len(arr) == 1:
	print(360)
else:
	minimum = 360
	for i in range(len(arr)):
		(a, b) = (0, 360)
		before = 0
		for j in range(i, len(arr)):
			if i == j:
				before = arr[i]
			else:
				before += arr[j]
			minimum = min(abs(360 - 2 * before), minimum)
	print(minimum)


n = int(input())
a = list(map(int, input().split()))
t = 0
b = []
while t < n:
	temp = a[0]
	i = 1
	while temp < 180:
		temp += a[i]
		i += 1
		if i == n:
			break
	tem = sum(a[i:])
	b.append(abs(temp - tem))
	a.append(a[0])
	a.remove(a[0])
	t += 1
print(min(b))


from math import inf

def pizza(lst):
	result = inf
	for i in range(len(lst)):
		count = 0
		for j in range(i, len(lst)):
			count += lst[j]
			result = min(result, abs(360 - 2 * count))
	return result
n = int(input())
a = [int(x) for x in input().split()]
print(pizza(a))


n = int(input().strip())
kosi = list(map(int, input().strip().split()))
mini = 400
for a in range(len(kosi)):
	for b in range(a, len(kosi)):
		first = sum(kosi[a:b])
		second = sum(kosi[:a]) + sum(kosi[b:])
		if abs(first - second) < mini:
			mini = abs(first - second)
print(mini)


n = int(input())
l = list(map(int, input().split()))
s = [0]
r_s = [0]
for i in range(n):
	s.append(s[-1] + l[i])
	r_s.append(r_s[-1] + l[n - 1 - i])
m = float('inf')
for right_end in range(n):
	for left_end in range(n - right_end + 1):
		if abs(s[left_end] + r_s[right_end] - (r_s[-left_end - 1] - r_s[right_end])) < m:
			m = abs(s[left_end] + r_s[right_end] - (r_s[-left_end - 1] - r_s[right_end]))
print(m)


import sys
import bisect
try:
	fin = open('in')
except:
	fin = sys.stdin
input = lambda : fin.readline().strip()
n = int(input())
r = list(map(int, input().split()))
m = 360
for i in range(n):
	s = 0
	for j in range(n):
		s += r[(i + j) % n]
		m = min(2 * abs(s - 180), m)
print(m)


n = int(input())
B = list(map(int, input().split()))
sum = 0
A = []
for w in range(len(B)):
	sum = 0
	for q in range(w, len(B)):
		sum = sum + B[q]
		if sum >= 180:
			A.append(min(2 * abs(180 - sum), 2 * abs(180 - sum - B[q])))
			break
	B.append(B[w])
print(min(A))


n = int(input())
a = list(map(int, input().split()))
sol = 360
for i in range(n):
	sm = 0
	for j in range(i, n):
		sm += a[j]
		sol = min(sol, abs(sm - (360 - sm)))
print(sol)


n = int(input())
arr = [int(num) for num in input().strip().split()]
ans = 360
for i in range(n):
	l = 0
	r = 360
	for j in range(n):
		ans = min(ans, abs(l - r))
		l += arr[j]
		r -= arr[j]
	if ans == 0:
		break
	val = arr[0]
	arr.remove(arr[0])
	arr.append(val)
print(ans)


n = int(input())
a = list(map(int, input().split()))
delta = sum(a)
for i in range(len(a)):
	for j in range(len(a)):
		if delta == 0:
			break
		if delta > abs(sum(a[j:]) + sum(a[:i]) - sum(a[i:j])):
			delta = abs(sum(a[j:]) + sum(a[:i]) - sum(a[i:j]))
print(delta)


from collections import deque
n = int(input())
a = deque(map(int, input().split()))
piece = 0
ans = []
for cnt in range(n):
	for p in a:
		piece += p
		if piece >= 180:
			ans.append(piece - (360 - piece))
			piece = 0
			a.appendleft(a.pop())
			break
print(min(ans))


n = int(input())
a = list(map(int, input().split()))
mina = None
flag = 0
for i in range(0, len(a)):
	for j in range(i, len(a)):
		x = sum(a[i:j + 1])
		y = sum(a[:i]) + sum(a[j + 1:])
		if x - y == 0:
			print(0)
			flag = 1
			break
		if mina == None or abs(x - y) < mina:
			mina = abs(x - y)
	if flag == 1:
		break
if flag == 0:
	print(mina)


n = int(input())
a = [int(i) for i in input().split()]
min_dif = 180
for i in range(n + 1):
	for j in range(i, n + 1):
		dif = abs(sum(a[i:j + 1]) - 180)
		if dif < min_dif:
			min_dif = dif
	if min_dif == 0:
		break
print(min_dif * 2)


n = int(input())
vals = list(map(int, input().split()))
vals += vals
mindiff = 360
for i in range(1, n // 2 + 1):
	for j in range(n):
		x = sum(vals[j:j + i])
		if abs(360 - 2 * x) < mindiff:
			mindiff = abs(360 - 2 * x)
print(mindiff)


from itertools import product, accumulate
n = int(input())
arr = list(map(int, input().split()))
arr_sum = sum(arr)
arr_cum = list(accumulate(arr))
arr_cum_rev = list(reversed(list(accumulate(reversed(arr)))))
m = sum(arr)
for (left, right) in product(range(n), range(n)):
	(a, b) = (min(left, right), max(left, right))
	x = sum(arr[:a]) + sum(arr[b:])
	y = arr_sum - x
	m = min(m, abs(x - y))
print(m)


n = int(input())
pices = list(map(int, input().split()))
scores = []
suma2 = 0
for i in range(n):
	suma = 0
	k = i
	while suma < 180:
		suma2 = suma
		suma += pices[k]
		if k + 1 == n:
			k = -1
		k += 1
	scores.append(min(suma - (360 - suma), 360 - suma2 - suma2))
print(min(scores))


n = int(input())
a = [int(i) for i in input().split()]
a = a + a
pref_sum = [0] * (2 * n)
for i in range(2 * n):
	pref_sum[i] = pref_sum[i - 1] + a[i]
dif = int(1000000000.0)
for i in range(n):
	for j in range(n):
		dif = min(dif, abs(pref_sum[n - 1] - 2 * (pref_sum[j + i] - pref_sum[j])))
print(dif)


from __future__ import print_function
import sys
try:
	range = xrange
	input = raw_input
except NameError:
	pass
MOD = int(1000000000.0 + 7)
MAXN = int(10000.0 + 8)
N = int(input().strip())
angs = list(map(int, input().strip().split()))
angs.extend(angs)
su = [0] * (N * 2 + 1)
for i in range(1, 2 * N + 1):
	su[i] = su[i - 1] + angs[i - 1]
ans = 360
for i in range(1, 2 * N + 1):
	for j in range(i, 2 * N + 1):
		c = su[j] - su[i - 1]
		ans = min(ans, abs(360 - 2 * c))
print(ans)


n = int(input())
A = list(map(int, input().split()))
print(2 * min((abs(180 - sum(A[i:j])) for i in range(n) for j in range(i, n))))


n = int(input())
a = [int(x) for x in input().split()] + [0]
Tot = sum(a)
B = 360
lena = len(a) - 1
for i in range(0, lena):
	for j in range(i + 1, lena):
		P = abs(Tot - 2 * sum(a[i:j]))
		if P < B:
			B = P
print(B)


n = int(input())
sectors = list(map(int, input().split()))
ans = 360
for _ in range(n):
	for i in range(n):
		temp = abs(sum(sectors[:i]) - sum(sectors[i:]))
		if temp < ans:
			ans = temp
	sectors[:] = sectors[-1:] + sectors[:-1]
print(ans)


n = int(input())
a = list(map(int, input().split()))
x = sum(a)
a += a
an = 0
ann = 1000000
for j in range(n):
	an = 0
	for i in range(j, 2 * n):
		an += a[i]
		if an >= x // 2:
			if abs(x - 2 * an) < abs(x - 2 * ann):
				ann = an
			an = 0
print(abs(x - 2 * ann))


i1 = int(input())
ar = list(map(int, input().split()))
lii = []
if i1 == 1:
	print(360)
else:
	for j in range(i1 + 1):
		ar.insert(0, ar.pop())
		for x in range(i1 - 1):
			if sum(ar[0:x + 1]) >= sum(ar[x + 1:]):
				lii.append(abs(sum(ar[x + 1:]) - sum(ar[0:x + 1])))
				lii.append(abs(sum(ar[x:]) - sum(ar[0:x])))
				break
	print(min(lii))


n = int(input())
A = list(map(int, input().split()))
mndiff = 10000
for st in range(n):
	for en in range(st, n):
		if abs(180 - sum(A[st:en])) < mndiff:
			mndiff = abs(180 - sum(A[st:en]))
print(2 * mndiff)


n = int(input())
inp = list(map(int, input().split()))
sol = []
if n == 1:
	print(inp[0])
else:
	for i in range(n):
		for j in range(i + 1, n):
			sol.append(abs(360 - 2 * sum(inp[i:j])))
	print(min(sol))


def findAngel(ang, n):
	summ = 0
	i = -1
	while summ < 180:
		i += 1
		summ += ang[i]
	return summ
n = int(input())
a = [int(i) for i in input().split()]
i = 0
summ = 0
minSumm = 360
while abs(360 - 2 * summ) != 0 and i < n:
	summ = findAngel([a[i]] + a[i + 1:len(a)] + a[0:i], n)
	i += 1
	if summ < minSumm:
		minSumm = summ
print(abs(360 - 2 * minSumm))


n = int(input())
a = [int(i) for i in input().split()]
pref = []
s = 0
for i in range(n):
	s += a[i]
	pref.append(s)
mins = 1000
for i in range(n):
	for j in range(i, n):
		s = abs(pref[j] - pref[i] - (pref[i] + (pref[n - 1] - pref[j])))
		if s < mins:
			mins = s
print(mins)


import sys
sys.setrecursionlimit(100000000)
N = int(input())
arr = [int(x) for x in input().split()]
result = 360
for i in range(N):
	vasya = 0
	petya = sum(arr)
	for j in range(i, i + N):
		vasya += arr[j % N]
		petya = sum(arr) - vasya
		check = abs(vasya - petya)
		result = min(result, check)
print(result)


from math import *
n = int(input())
l = list(map(int, input().split()))
ka = inf
for i in range(n):
	s = 0
	for j in range(i, n):
		s = s + l[j]
		ka = min(ka, abs(360 - 2 * s))
print(ka)


m = 1000000000
n = int(input())
a = list(map(int, input().split()))
for _ in range(n):
	for x in range(n):
		m = min(m, abs(sum(a[:x]) - sum(a[x:])))
	a.append(a.pop(0))
print(m)


from collections import deque
n = int(input())
a = deque(map(int, input().split()))
ps = [0] * n
mindif = 2000000000.0
for i in range(n):
	for i in range(n):
		ps[i] = ps[i - 1] if i > 0 else 0
		ps[i] += a[i]
	for i in range(n):
		mindif = min(mindif, abs((ps[i - 1] if i > 0 else 0) - (ps[n - 1] - (ps[i - 1] if i > 0 else 0))))
	a.append(a.popleft())
print(mindif)


n = int(input())
line = input()
line = 2 * [int(i) for i in line.split()]
ans = 360
vasya = 0
if n == 1:
	print(line[-1])
else:
	for i in range(n):
		j = i + 1
		vasya = line[i]
		ans = min(ans, abs(2 * vasya - 360))
		while vasya <= 180:
			vasya += line[j]
			j += 1
			ans = min(ans, abs(2 * vasya - 360))
	print(ans)


n = int(input())
a = list(map(int, input().split()))
maxh = 360
for i in range(n):
	res1 = 0
	for j in range(i, n):
		res1 += a[j]
		maxh = min(abs(360 - 2 * res1), maxh)
print(maxh)


n = int(input())
s = [int(s) for s in input().split()]
m = s * 2
d = 360
t = sum(s)
for i in range(n):
	a = 0
	for j in range(i, i + n):
		a += m[j]
		if abs(2 * a - t) < d:
			d = abs(2 * a - t)
print(d)


n = int(input())
nums = list(map(int, input().split()))
answer = float('inf')
for l in range(n):
	for s in range(n):
		if s + l - 1 >= n:
			continue
		current = sum(nums[s:s + l])
		answer = min(answer, abs(360 - 2 * current))
print(answer)


def circular(l, start):
	while True:
		for j in range(start, l.__len__()):
			yield l[j]
		start = 0
count = int(input())
pieces = list(map(int, input().split()))
result = 360
for i in range(count):
	gen = circular(pieces, i)
	s = 0
	while s < 180:
		s += next(gen)
	result = min(result, 2 * abs(180 - s))
print(result)


n = int(input())

def get(l, r):
	if not l:
		return pr[r]
	return pr[r] - pr[l - 1]
arr = list(map(int, input().split()))
gg = 360
ans = 360
pr = [0] * n
pr[0] = arr[0]
for i in range(1, n):
	pr[i] = arr[i] + pr[i - 1]
for i in range(n):
	for j in range(i, n):
		if abs(i - j) == n - 1:
			continue
		s = get(i, j)
		ans = min(ans, abs(360 - s - s))
print(ans)


n = int(input())
l = [int(i) for i in input().split()]
result = 360
for i in range(n):
	for j in range(i, n):
		result = min(result, abs(sum(l[i:j]) - 180) * 2)
print(result)


def main(lst):
	l = len(lst)
	my_ind = [i for i in range(l)]
	res = []
	for outer in range(l):
		summ = 0
		prev_sum = 0
		for ind in range(outer, outer + l):
			cur = ind % l
			if summ > 180:
				break
			prev_sum = summ
			summ += lst[cur]
		res.append(summ - 180)
		res.append(180 - prev_sum)
	return min(res) * 2
a = int(input())
lst = [int(el) for el in input().split()]
print(main(lst))


N = n = int(input())
sec = []
minn = 400
line = input().split()
summ = 0
i = 0
while n > 0:
	sec.append(int(line[i]))
	i += 1
	n -= 1
sec.append(0)
i = 0
j = len(sec) - 1
while j > i:
	summ += sec[j]
	pit = summ
	while i < j:
		pit += sec[i]
		sit = 360 - pit
		if minn > abs(sit - pit):
			minn = abs(sit - pit)
		i += 1
	i = 0
	j -= 1
print(minn)


n = int(input())
a = list(map(int, input().split()))
sectorSize = [sum(a[l:r]) for l in range(n) for r in range(l + 1, n)]
differenceBetweenSectorAndRest = [360] + [2 * abs(180 - sectorSize[i]) for i in range(len(sectorSize))]
print(min(differenceBetweenSectorAndRest))


n = int(input())
a = [int(k) for k in input().split()]
maxx = 360
for i in range(n):
	for j in range(i + 1, n):
		maxx = min(maxx, abs(180 - sum(a[i:j])) * 2)
print(maxx)


test = int(input())
num = list(map(int, input().split()))
num += num
ans = 360
for i in range(test):
	for j in range(test):
		pias = sum(num[i:i + j + 1])
		ans = min(ans, abs(360 - 2 * pias))
print(ans)


n = int(input())
a = list(map(int, input().split()))
s = sum(a)
m = s
for i in range(n):
	st = 0
	sp = s
	for j in range(i, n):
		st += a[j]
		if abs(s - st - st) > sp:
			break
		sp = abs(s - st - st)
	if abs(s - st - st) < m:
		m = abs(s - st - st)
	if sp < m:
		m = sp
print(m)


n = int(input())
a = list(map(int, input().split()))
maxv = 0
minv = 360
for i in range(0, n):
	sum = 0
	for j in range(i, n):
		sum = sum + a[j]
		if sum > maxv and sum <= 180:
			maxv = sum
		if sum < minv and sum >= 180:
			minv = sum
print(min(360 - 2 * maxv, 2 * minv - 360))


import math
n = int(input())
a = list(map(int, input().split()))
rs = 360
for i in range(n):
	t = 0
	for j in range(i, n):
		t = t + a[j]
		rs = min(rs, abs(360 - 2 * t))
print(rs)


import sys
N = int(sys.stdin.readline())
p = [int(x) for x in sys.stdin.readline().split()]
ans = 360
for i in range(0, N, 1):
	sum = 0
	for j in range(i, N, 1):
		sum = sum + p[j]
		ans = min(ans, abs(360 - 2 * sum))
print(ans)


n = int(input())
lst = []
for x in input().split():
	lst.append(int(x))
k = 360
for x in range(len(lst) - 1):
	for y in range(x + 1, len(lst)):
		s1 = sum(lst[:x] + lst[y:])
		s2 = sum(lst[x:y])
		k = min(k, abs(s1 - s2))
print(k)


import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcdefghijklmnopqrstuvwxyz/'
M = 1000000007
EPS = 1e-06

def Ceil(a, b):
	return a // b + int(a % b > 0)

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
n = int(input())
a = list(map(int, input().split(' ')))
ans = int(1e+100)
for y in range(2 * n + 2):
	for x in range(n):
		ans = min(ans, abs(sum(a[:x]) - sum(a[x:])))
	a = a[-1:] + a[:-1]
print(ans)


n = int(input())
a = [int(x) for x in input().split()]
m = 10 << 31
for i in range(n + 1):
	for j in range(i, n + 1):
		m = min(m, abs(sum(a[i:j]) - 180))
print(2 * m)


n = int(input())
sectors = list(map(int, input().split()))
sectors = sectors + sectors[:n - 1]
answer = 10 ** 5
for i in range(n):
	j = i + n - 1
	for k in range(i + 1, j + 1):
		temp = abs(sum(sectors[i:k]) - sum(sectors[k:j + 1]))
		if temp < answer:
			answer = temp
if n == 1:
	print(sectors[0])
else:
	print(answer)


n = int(input())
arr = list(map(int, input().split()))
a = 0
b = 0
arr += arr
ca = []
for i in range(len(arr)):
	a = 0
	ca_add = False
	for j in range(i, len(arr)):
		if a + arr[j] > 180:
			ca.append(180 - a)
			ca_add = True
			break
		a += arr[j]
	if ca_add == False:
		ca.append(180 - a)
print(min(ca) * 2)


from math import fabs
n = int(input())
m = list(map(int, input().split()))
a = 0
d = 360
for i in range(n):
	a = 0
	x = 360
	j = i
	while j < n:
		if fabs(180 - a - m[j]) > x:
			break
		a += m[j]
		x = fabs(180 - a)
		j += 1
	if x < d:
		d = x
print(int(d) * 2)


n = int(input())
a = list(map(int, input().split()))
a.extend(a)
mn = 360
for pea in range(1, n):
	l = 0
	r = pea
	full = 0
	for i in range(r - l):
		full += a[i]
	mn = min(abs(360 - full - full), mn)
	for i in range(n):
		full = full - a[l] + a[r]
		l += 1
		r += 1
		mn = min(abs(360 - full - full), mn)
print(mn)


n = int(input())
arr = list(map(int, input().split()))
min_list = set()
for i in range(n):
	s = 0
	l = []
	for j in range(i, n):
		s += arr[j]
		l.append(abs(360 - (s << 1)))
	min_list.add(min(l))
	l.clear()
print(min(min_list))


pieces_nr = int(input())
piece_idx___deg = [int(x) for x in input().split()]
ans = 360
for left_cl in range(pieces_nr):
	for right_op in range(left_cl + 1, pieces_nr + 1):
		curr_split = sum(piece_idx___deg[left_cl:right_op])
		rest = 360 - curr_split
		curr_ans = rest - curr_split
		if curr_ans < 0:
			curr_ans *= -1
		ans = min(curr_ans, ans)
print(ans)


n = int(input())
ls1 = input().split()
ls1 = [int(i) for i in ls1]
mangle = 180

def through(j):
	if j < n - 1:
		j = j + 1
	else:
		j = 0
	return j
for i in range(n):
	j = i
	angle = ls1[i]
	while True:
		j = through(j)
		angle += ls1[j]
		if angle >= 180:
			break
	mangle = min(abs(180 - angle), abs(180 - angle + ls1[j]), mangle)
	if mangle == 0:
		break
print(2 * mangle)


n = int(input())
a = list(map(int, input().split(' ')))
mi = 360
for i in range(1, n):
	a[i] = a[i - 1] + a[i]
for i in range(n):
	for j in range(i, n):
		sa = a[j] - (a[i - 1] if i > 0 else 0)
		sb = a[-1] - a[j] + (a[i - 1] if i > 0 else 0)
		if abs(sa - sb) < mi:
			mi = abs(sa - sb)
print(mi)