def popcount(n): c=(n&0x5555555555555555)+((n>>1)&0x5555555555555555) c=(c&0x3333333333333333)+((c>>2)&0x3333333333333333) c=(c&0x0f0f0f0f0f0f0f0f)+((c>>4)&0x0f0f0f0f0f0f0f0f) c=(c&0x00ff00ff00ff00ff)+((c>>8)&0x00ff00ff00ff00ff) c=(c&0x0000ffff0000ffff)+((c>>16)&0x0000ffff0000ffff) c=(c&0x00000000ffffffff)+((c>>32)&0x00000000ffffffff) return c N = int(input()) R = list(map(int,input().split())) if N >= 26: print(0) exit() dp = [[] for n in range(N + 1)] stack = [(0,0,-1)] while len(stack): r,c,i = stack.pop() dp[c].append(r) if (c + 1) * 2 > N: continue for j in range(i + 1,N): stack.append((r + R[j],c + 1,j)) ans = 800000 for n in range(1,N + 1): if 2 * n > N: break le = len(dp[n]) dp[n].sort() for i in range(le - 1): ans = min(ans,dp[n][i + 1] - dp[n][i]) print(ans)