Language: C++

#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <ctime>
#include <sstream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair < int, int >
#define pll pair < long long, long long>
#define ull unsigned long long
#define y1 stupid_cmath
#define left stupid_left
#define right stupid_right
#define vi vector <int>
#define sz(a) (int)a.size()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++)
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x))

const int inf = (int)1e9;
const int mod = inf + 7;
const double eps = 1e-9;
const double pi = acos(-1.0);

ll read_long() {
    ll ans = 0;
    char c;
    bool started = false;
    bool is_negative = false;
    while (true) {
        c = getchar();
        if ((c < '0' || c > '9') && c != '-' && !started) continue;
        if ((c < '0' || c > '9') && c != '-' && started) break;
        if (started) {
            ans = ans * 10;
        }
        started = true;
        if (c == '-') is_negative = true;
        else ans += c - '0';
    }
    if (is_negative) ans *= -1;
    return ans;
}

int n, a[2020];

void add(int val, int &k, vector<int> &down, vector<int> &up, int value) {
    if (value == val) {
        k++;
    }
    else if (value < val) down.pb(value);
    else up.pb(value);
}

void print(string label, vector<int> &a) {
    cout << label << ":";
    forit (it, a) cout << " " << *it;
    cout << endl;
}

int sign(int val) {
    int k = 0;
    vector<int> up;
    vector<int> down;
    for (int i = 0; i < n; i++) {
        int x = a[i];
        int sz_up = sz(up);
        int sz_down = sz(down);
        for (int j = 0; j < sz_up; j++) {
            add(val, k, down, up, up[j] + x);
        }
        for (int j = 0; j < sz_down; j++) {
            add(val, k, down, up, down[j] + x);
        }
        add(val, k, down, up, x);
        while (sz(up) > 0 && sz(down) > 0) {
            up.pop_back();
            down.pop_back();
        }
        cout << "Iteration: " << i << endl;
        cout << "value = " << x << endl;
        cout << "k = " << k << endl;
        print("up", up);
        print("down", down);
    }
    if (up.size() == 0 && down.size() == 0) {
        return 0;
    }
    if (up.size() > 0) {
        if (k - 1 >= sz(up)) {
            return 0;
        }
        return 1;
    }
    if (k - 1 >= sz(down)) {
        return 0;
    }
    return -1;
}

#include <bitset>

bitset<4000002> dp, cur;

int main(){

    scanf("%d", &n);
    for (int i = 0; i < n; i++) scanf("%d", a + i);

    dp[0] = 1;
    for (int i = 0; i < n; i++) {
        cur = dp<<a[i];
        dp |= cur;
    }

    deque<int> v;
    for (int i = 1; i <= 2000 * 2000; i++) {
        if (dp[i]) v.pb(i);
    }

    while (sz(v) > 2) {
        v.pop_front();
        v.pop_back();
    }

    cout << v[0] << endl;

    return 0;
}


Compiler output:
a.cc:35:17: error: expected unqualified-id before '.' token
   35 | #define all(a) a.begin(), a.end()
      |                 ^