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# (Mono 4.6.2.0) (judge verdict: Time Limit Exceeded)

using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;

public class Program
{

    public void Proc()
    {
        int inputCount = int.Parse(Reader.ReadLine());
        int[] items = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();

        PriorityList listZ = new PriorityList();
        PriorityList listK = new PriorityList();

        for (int i = 0; i < inputCount; i++) {
            listZ.Push(items[i]);
            listK.Push(items[inputCount * 3 - i - 1]*-1);
        }

        long[] zenhan = new long[inputCount * 3];

		zenhan[inputCount-1] = listZ.GetTotal();
        for (int i = inputCount; i < inputCount * 2;i++) {
            listZ.Push(items[i]);
            listZ.Pop();
            zenhan[i] = listZ.GetTotal();
        }
        long max = long.MinValue;
        max = zenhan[inputCount * 2 - 1] + listK.GetTotal();

		for (int i = inputCount * 2 - 1; i >= inputCount; i--) {
            listK.Push(items[i]*-1);
            listK.Pop();
            max = Math.Max(max, zenhan[i-1] + listK.GetTotal());
        }
        Console.WriteLine(max);

    }


    private class PriorityList {
        public long GetTotal() {
            return this.Total;
        }
        private long Total = 0;
        private List<int> Items = new List<int>();
        public void Push(int num) {
            int idx = GetInsertIndex(num, 0, this.Items.Count-1);
            this.Items.Insert(idx, num);
            Total += num;
		}
        public int Pop() {
            int num = this.Items[0];
            this.Items.RemoveAt(0);
            Total -= num;
            return num;
        }

        private int GetInsertIndex(int num, int min, int max) {
            if(this.Items.Count == 0) {
                return 0;
            }
            if(num <= this.Items[min]) {
                return min;
            }
            if(num>this.Items[max]) {
                return max + 1;
            }
            if(max-min<=1) {
                return max;
            }
            int mid = (max + min) / 2;
            if(this.Items[mid] == num) {
                return mid;
            }
            if(this.Items[mid]<num) {
                return GetInsertIndex(num, mid, max);
            } else {
                return GetInsertIndex(num, min, mid);
            }
        }

    }

    public class Reader
	{
		private static StringReader sr;
		public static bool IsDebug = false;
		public static string ReadLine()
		{
			if (IsDebug)
			{
				if (sr == null)
				{
					sr = new StringReader(InputText.Trim());
				}
				return sr.ReadLine();
			}
			else
			{
				return Console.ReadLine();
			}
		}
		private static string InputText = @"


3
8 2 2 7 4 6 5 3 8


";
	}

	public static void Main(string[] args)
	{
#if DEBUG
		Reader.IsDebug = true;
#endif
		Program prg = new Program();
		prg.Proc();
	}
}