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 Ruby (2.3.3) (judge verdict: Runtime Error)

def calcs(x,y,ax,ay,bx,by) ((ax-x)*(by-y)-(bx-x)*(ay-y))/2.0 end
def inpf() a=gets.chomp.split(" ").map(&:to_f)end
def inps() a=gets.chomp.split(" ")end  
def copy(a) Marshal.load(Marshal.dump(a)) end
def kaizyo(n)(n < 2)? 1 : (2..n).inject(:*) end
def scount(a) b=na(a.max+1);a.each{|n|b[n]+=1};return b end
def na(n=0,d=0) Array.new(n,d)end
def na2(n=0,m=0,d=0) Array.new(n){Array.new(m,d)}end
def na3(n=0,m=0,l=0,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end
def bit(n) n.to_s(2).split("").map(&:to_i) end
def inp() a=gets.chomp.split(" ").map(&:to_i)end
class Hp
  def initialize(len)
    @main = na(len,999999999)
    @ind = 1
    @main[0] = -99999999
  end
  def push(n)
    @main[@ind] = n
    sind = @ind
    while(sind != 0)
      nind = sind/2
      @main[sind], @main[nind] = @main[nind], @main[sind] if(@main[sind] < @main[nind])
      sind /= 2
    end
    @ind += 1
  end
  def put()
    return @main
  end
  def pop()
    ans = @main[1]
    @main[1] = @main[@ind]
    @main[@ind] = 999999999
    sind = 1
    while(true)
      nind = sind*2
      break if(nind > @ind)
      l = @main[nind]
      nind += 1 
      if(nind > @ind)
        ind = nind-1
        if(@main[ind] < @main[sind])
          @main[sind], @main[ind] = @main[ind], @main[sind] 
        end
        break 
      end
      r = @main[nind]
      ind = (l > r)? nind : nind-1
      if(@main[ind] < @main[sind])
        @main[sind], @main[ind] = @main[ind], @main[sind] 
      end
      sind = ind
    end
    @ind -= 1
    return ans
  end
end
hp = Hp.new(11111) 
n = inp[0]
a = inp 
zen = a[0..(n-1)]
zen.each do |d|
  hp.push(d)
end
def sumin(a,n)
  ans = 0
  a.each.with_index do |dd,i|
    break if(i >= n)
    ans += dd
  end
  return ans
end
sum = zen.inject(:+)
kou = a[n..(3*n-1)].sort
ans = -9999999999
((n)..(2*n-1)).each do |en|
  re = hp.pop
  rer = [re,a[en]].max - [re,a[en]].min
  sum += rer
  kou.delete_at(kou.index(a[en]))
  drf = sum - sumin(kou,n)
  hp.push([re,a[en]].max)
  if ans < drf
    ans = drf
  end
end
p ans
=begin
=end