atcoder#ARC074B. [ABC062D] 3N Numbers

[ABC062D] 3N Numbers

Score : 500500 points

Problem Statement

Let NN be a positive integer.

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

Find the maximum possible score of aa'.

Constraints

  • 1N1051 \leq N \leq 10^5
  • aia_i is an integer.
  • 1ai1091 \leq a_i \leq 10^9

Partial Score

  • In the test set worth 300300 points, N1000N \leq 1000.

Input

Input is given from Standard Input in the following format:

NN

a1a_1 a2a_2 ...... a3Na_{3N}

Output

Print the maximum possible score of aa'.

2
3 1 4 1 5 9
1

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

1
1 2 3
-1

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

3
8 2 2 7 4 6 5 3 8
5

For example, when a2a_2, a3a_3 and a9a_9 are removed, aa' will be (8,7,4,6,5,3)(8, 7, 4, 6, 5, 3), which has a score of (8+7+4)(6+5+3)=5(8 + 7 + 4) - (6 + 5 + 3) = 5.