from bisect import bisect_left from collections import defaultdict N = int(input()) if N > 22: print(0) exit() rates = list(map(int, input().split())) rate_sums = defaultdict(lambda: []) def frontexh(i, dif, rate_sum): if i == N // 2: rate_sums[dif].append(rate_sum) else: frontexh(i + 1, dif, rate_sum) frontexh(i + 1, dif + 1, rate_sum + rates[i]) frontexh(i + 1, dif - 1, rate_sum - rates[i]) frontexh(0, 0, 0) if rate_sums[0]: rate_sums[0].pop(0) for dif in range(-N, N + 1): rate_sums[dif].sort() ans = 2 ** 30 for rate_sum in rate_sums[0]: ans = min(ans, abs(rate_sum)) has_anyone = False def backexh(i, dif, rate_sum): global ans, has_anyone if i == N - N // 2: if dif == 0: if has_anyone: ans = min(ans, min(ans, abs(rate_sum))) else: has_anyone = True it = bisect_left(rate_sums[dif], -rate_sum) if it < len(rate_sums[dif]): ans = min(ans, abs(rate_sum - rate_sums[dif][it])) if it > 0: ans = min(ans, abs(rate_sum - rate_sums[dif][it - 1])) else: backexh(i + 1, dif, rate_sum) backexh(i + 1, dif + 1, rate_sum + rates[N // 2 + i]) backexh(i + 1, dif - 1, rate_sum - rates[N // 2 + i]) backexh(0, 0, 0) print(ans)