You are given a numerical sequence of length ( 3N ):
[ a = (a_1, a_2, \ldots, a_{3N}) ]
You need to construct a new sequence ( a' ) of length ( 2N ) by removing exactly ( N ) elements from ( a ) without changing the order of the remaining elements. The score of the sequence ( a' ) is defined as follows:
[
\text{score}(a') = \text{(sum of the elements in the first half of } a') - \text{(sum of the elements in the second half of } a')
]
Your task is to find the maximum possible score of ( a' ).
Input Format
The first line contains a single integer ( N ) (1 ≤ ( N ) ≤ 10^5).
The second line contains ( 3N ) integers ( a_1, a_2, \ldots, a_{3N} ) (1 ≤ ( a_i ) ≤ 10^9).
Output Format
Output a single integer representing the maximum possible score of ( a' ).
Example
Input
text
2
1 3 2 5 4 6
Output
text
4
Explanation
In this example, the sequence ( a ) is of length 6 (which corresponds to ( N = 2 )). One optimal way to construct ( a' ) (of length 4) is by removing the elements ( 1 ) and ( 5 ) from ( a ). This results in:
[
a' = (3, 2, 4, 6)
]
The score is calculated as follows:
[
\text{sum of first half } = 3 + 2 = 5
]
[
\text{sum of second half } = 4 + 6 = 10
]
[
\text{score}(a') = 5 - 10 = -5
]
However, a better selection would be to remove ( 2 ) and ( 5 ) from ( a ), giving:
[
a' = (1, 3, 4, 6)
]
The score becomes:
[
\text{sum of first half } = 1 + 3 = 4
]
[
\text{sum of second half } = 4 + 6 = 10
]
[
\text{score}(a') = 4 - 10 = -6
]
The maximum achievable score from all combinations is what needs to be calculated.
Implementation
The solution should be implemented in the /app/ directory.
Important: place your implementation at /app/solution.py so the verifier can run it.