n = int(input()) A = list(map(int, input().split())) c = n // 2 ma = max(A) * c tf = [False] * (ma + 1) def dfs(i, tot, cnt): if cnt == c: if tf[tot]: print(0) exit() tf[tot] = True return ma = cnt + n - i if ma < c: return dfs(i + 1, tot + A[i], cnt + 1) dfs(i + 1, tot, cnt) dfs(0, 0, 0) inds = [i for i in range(ma + 1) if tf[i]] le = len(inds) print(min(inds[i] - inds[i - 1] for i in range(1, le)))