Problem:
Score : 500 points

Problem Statement

Let N be a positive integer.

There is a numerical sequence of length 3N, a = (a_1, a_2, ..., a_{3N}).
Snuke is constructing a new sequence of length 2N, a', by removing exactly N elements from a without changing the order of the remaining elements.
Here, the score of a' is defined as follows: (the sum of the elements in the first half of a') - (the sum of the elements in the second half of a').

Find the maximum possible score of a'.

Constraints

1 ≤ N ≤ 10^5

a_i is an integer.

1 ≤ a_i ≤ 10^9

Partial Score

In the test set worth 300 points, N ≤ 1000.

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_{3N}

Output

Print the maximum possible score of a'.

Sample Input 1

2
3 1 4 1 5 9

Sample Output 1

1

When a_2 and a_6 are removed, a' will be (3, 4, 1, 5), which has a score of (3 + 4) - (1 + 5) = 1.

Sample Input 2

1
1 2 3

Sample Output 2

-1

For example, when a_1 are removed, a' will be (2, 3), which has a score of 2 - 3 = -1.

Sample Input 3

3
8 2 2 7 4 6 5 3 8

Sample Output 3

5

For example, when a_2, a_3 and a_9 are removed, a' will be (8, 7, 4, 6, 5, 3), which has a score of (8 + 7 + 4) - (6 + 5 + 3) = 5.

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstring>;

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()
#define pb push_back

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

// 最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

// 最小公約数
long lcm(long a, long b) {
	return a / gcd(a, b) * b;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	ll n;
	cin >> n;
	vector<ll> a(3 * n);
	rep(i, 3 * n) cin >> a[i];

	priority_queue<ll, vector<ll>, greater<ll>> pq;
	priority_queue<ll> rpq;

	ll sumFirst = 0;
	ll sumSecond = 0;

	rep(i, n) {
		pq.push(a[i]);
		sumFirst += a[i];
	}
	for (int i = 2 * n; i < 3 * n; i++) {
		rpq.push(a[i]);
		sumSecond += a[i];
	}

	ll tail = n;
	ll head = 2 * n - 1;

	rep(i, n) {
		if (a[tail] - pq.top() > rpq.top() - a[head]) {
			//cout << pq.top() << "なくして" << a[tail] << "入れる" << endl;
			sumFirst += a[tail] - pq.top();
			pq.pop();
			pq.push(a[tail++]);
		}
		else {
			//cout << rpq.top() << "なくして" << a[head] << "入れる" << endl;
			sumSecond += a[head] - rpq.top();
			rpq.pop();
			rpq.push(a[head--]);
		}
	}

	//ll ans = 0;

	/*vector<ll> sumF;
	ll num = n;


	rep(i, 2 * n) {
		rpq.push(pq.top());
		pq.pop();
	}

	rep(i, n) {
		sumSecond += rpq.top();
		rpq.pop();
	}*/

	cout << sumFirst - sumSecond << endl;

	return 0;
}