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)

#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>

#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) v.erase(remove(v.begin(), v.end(), a), v.end())
using namespace std;

int a[300000];
priority_queue<int, vector<int>, greater<int> > q1;
priority_queue<int> q2;
int k1[100001];
int k2[100001];

signed main()
{
	int N;
	cin >> N;
	for (int i = 0; i < 3 * N; i++) cin >> a[i];

	int s1 = 0;
	for (int i = 0; i < N; i++)
	{
		q1.push(a[i]);
		s1 += a[i];
	}
	k1[0] = s1;
	for (int i = 0; i < N; i++)
	{
		int b = a[i + N];
		if (q1.top() < b)
		{
			s1 -= q1.top();
			s1 += b;
			q1.pop();
			q1.push(b);
		}
		k1[i + 1] = s1;
	}

	int s2 = 0;
	for (int i = N * 2; i < N * 3; i++)
	{
		q2.push(a[i]);
		s2 += a[i];
	}
	k2[N] = s2;
	for (int i = 0; i < N; i++)
	{
		int b = a[(N * 2 - 1) - i];
		if (q2.top() > b)
		{
			s2 -= q2.top();
			s2 += b;
			q2.pop();
			q2.push(b);
		}
		k2[N - 1 - i] = s2;
	}


	int ans = INT_MIN;
	for (int i = 0; i < N; i++)
	{
		ans = MAX(ans, k1[i] - k2[i]);
	}
	cout << ans << endl;
}