void main(){
  import std.stdio, std.string, std.conv, std.algorithm;
  
  int n; rd(n);
  auto a=readln.split.to!(long[]);

  import std.container;
  alias Heap=RedBlackTree!(long, "a>b", true);
  Heap[] heap;
  foreach(_; 0..3) heap~=new Heap;
  foreach(i; 0..n) heap[0].insert(a[i]);
  foreach(i; (n*2)..(n*3)) heap[2].insert(a[i]);
  long score=a[0..n].sum-a[(n*2)..(n*3)].sum, best=score;
  foreach(i; n..(n*2)){
    if(a[i]<heap[2].front){
      score-=(a[i]-heap[2].front);
      best=max(best, score);
      heap[1].insert(heap[2].front);
      heap[2].insert(a[i]);
      heap[2].removeFront;
    }else{
      heap[1].insert(a[i]);
    }
  }
  // writeln(score, " ", best);
  foreach(i; n..(n*2)){
    if((heap[2].equalRange(a[i]).empty)==false){
      score+=(a[i]-heap[1].back);
      heap[2].insert(heap[1].back);
      heap[2].removeKey(a[i]);
      heap[1].removeBack;
    }else{
      assert((heap[1].equalRange(a[i]).empty)==false);
      heap[1].removeKey(a[i]);
    }
    // writeln(i, " ", score, " ", best);        
    if(heap[0].back<a[i]){
      score+=(a[i]-heap[0].back);
      heap[0].removeBack;
      heap[0].insert(a[i]);
    }
    best=max(best, score);
    writeln(i, " ", score, " ", best);
    // foreach(k; 0..3) writeln(heap[k]);
  }
  writeln(best);
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}
