N = int(input()) if N > 25: print(0) exit() rates = list(map(int, input().split())) rate_sums = [] for comb in range(1, 1 << N): if comb.bit_count() != N // 2: continue rate_sum = 0 for i in range(N): if (comb >> i) & 1: rate_sum += rates[i] rate_sums.append(rate_sum) rate_sums.sort() ans = 2 ** 30 for i in range(len(rate_sums) - 1): if ans > abs(rate_sums[i] - rate_sums[i + 1]): ans = abs(rate_sums[i] - rate_sums[i + 1]) print(ans)