#include <bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(), A.end()
#define RALL(A) A.rbegin(), A.rend()
typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 1000000007;
const ll LINF = 1LL << 60;
const int INF = 1 << 30;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    int m = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        m += a[i];
    }

    vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));
    for (int i = 0; i <= n; i++)
    {
        dp[i][0] = 1;
    }

    for (int i = 1; i <= n; i++)
    {
        for (int j = 0; j <= m; j++)
        {
            if (j - a[i - 1] >= 0 && dp[i - 1][j - a[i - 1]] == 1)
            {
                dp[i][j] = 1;
            }
            if (j + a[i - 1] <= m && dp[i - 1][j] == 1)
            {
                dp[i][j + a[i - 1]] = 1;
            }
            if (dp[i][j] == 0)
            {
                dp[i][j] = dp[i - 1][j];
            }
        }
    }
    int ans = INF;

    // for (int i = 0; i <= n; i++)
    // {
    //     for (int j = 0; j <= m; j++)
    //     {
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }

    for (int i = 0; i <= m; i++)
    {
        if (dp[n][i] == 1)
        {
            ans = min(ans, max(m - i, i));
        }
    }
    cout << ans << endl;

    return 0;
}

#include<iostream>
#include<algorithm>
#include<numeric>
#include<queue>
#include<vector>
using namespace std;
const int BUF = 400005;


int nVal;
int val[BUF];

void read() {
    cin >> nVal;
    nVal *= 2;
    for (int i = 0; i < nVal; ++i) {
        cin >> val[i];
    }
}

void work() {
    long long sum = accumulate(val, val + nVal, 0LL);
    priority_queue<int, vector<int>, greater<int> > Q;
    for (int i = 0, L = nVal / 2 - 1, R = nVal / 2; i < nVal; i += 2, --L, ++R) {
        Q.push(val[L]);
        Q.push(val[R]);
        sum -= Q.top();
        Q.pop();
    }
    
    cout << sum << endl;
}


int main() {
    read();
    work();
    return 0;
}
