#include using namespace std; int popcnt(int x) { return __builtin_popcount(x); } // (0, 1, 2, 3, 4) -> (-1, 0, 1, 1, 2) int topbit(int x) { return (x == 0 ? -1 : 31 - __builtin_clz(x)); } template inline bool chmin(T &a, const S &b) { return (a > b ? a = b, 1 : 0); } int main() { int N; cin >> N; vector R(N); for (int &r : R) cin >> r; if (N > 26) { cout << 0 << endl; return 0; } vector comb; function exh = [&](int bit, int sum) { if (popcnt(bit) == N / 2) { comb.emplace_back(sum); } else { for (int i = topbit(bit) + 1; i < N - N / 2 + popcnt(bit) + 1; ++i) { exh(bit | (1 << i), sum + R[i]); } } }; exh(0, 0); sort(comb.begin(), comb.end()); int ans = 1 << 30; for (int i = 0; i < comb.size() - 1; ++i) { chmin(ans, abs(comb[i] - comb[i + 1])); } cout << ans << endl; }