#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << "\n";
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i, MAT.size()){
    REP(j, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << "\n";
  }
};

template <typename CLASS1, typename CLASS2>
class HOGE{
  public:
    CLASS1 key;
    CLASS2 value;
    HOGE(void){
      return;
    };
    HOGE(CLASS1 key, CLASS2 value){
      this->key = key;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "key : " << key << ", value : " << value << "\n";
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

ll calc1(const vll& a){
  ll N = a.size()/3;
  ll score = -(INFLL-1);

  FOR(i, N, 2*N){
    vll a_pre(i);
    vll a_post(3*N-i);
    FOR(j, 0, i) a_pre[j] = a[j];
    FOR(j, i, 3*N) a_post[j-i] = a[j];
    sort(a_pre.begin(), a_pre.end(), greater<ll>());
    sort(a_post.begin(), a_post.end());

    ll score_tmp = 0;
    ll score_posi = 0;
    ll score_nega = 0;
    REP(i, N) score_posi += a_pre[i];
    REP(i, N) score_nega -= a_post[i];
    score_tmp = score_posi + score_nega;
    score = max(score_tmp, score);
  }
  return score;
}

ll calc2(const vll& a){
  ll N = a.size()/3;

  vll score_pre(N+1);
  multiset<ll> st_pre;
  REP(i, N){
    score_pre[0] += a[i];
    st_pre.emplace(a[i]);
  }

  vll score_post(N+1);
  multiset<ll> st_post;
  REP(i, N){
    score_post[N] += a[i+2*N];
    st_post.emplace(a[i+2*N]);
  }

  //cout << 0 << " " << score_pre[0] << "\n";
  //cout << 0 << " " << score_post[N] << "\n";
  FOR(i, N, 2*N){
    auto itr_begin_tmp = st_pre.begin();
    if(*itr_begin_tmp < a[i]){
      score_pre[i-N+1] = score_pre[i-N] + a[i] - *itr_begin_tmp;
      st_pre.erase(itr_begin_tmp);
      st_pre.emplace(a[i]);
    }else{
      score_pre[i-N+1] = score_pre[i-N];
    }

    //cout << i-N+1 << " " << score_pre[i-N+1] << "\n";

    auto itr_end_tmp = st_post.end();
    itr_end_tmp--;
    if(*itr_end_tmp > a[3*N-1-i]){
      //cout << "hoge: " << a[3*N-1-i] << " " << *(itr_end_tmp) << "\n";
      score_post[2*N-i-1] = score_post[2*N-i] + a[3*N-1-i] - *itr_end_tmp;
      st_post.erase(itr_end_tmp);
      st_post.emplace(a[3*N-1-i]);
    }else{
      score_post[2*N-i-1] = score_post[2*N-i];
    }

    //cout << i-N+1 << " " << score_post[2*N-i-1] << "\n";
    //
  }

  ll score = score_pre[0] - score_post[0];
  FOR(i, 1, N+1){
    score = max(score_pre[i]-score_post[i], score);
  }
  return score;
}

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N;
  cin >> N;
  vll a(3*N);
  REP(i, 3*N) cin >> a[i];

  //cout << calc1(a) << " " << calc2(a) <<  "\n";
  cout << calc2(a) << "\n";

  /*
  ll N = 100;
  while(true){
    vll a(3*N);
    REP(i, 3*N){
      a[i] = rand()%100000-50000;
    }
    if(calc1(a) != calc2(a)){
      REP(i, 3*N){
        printf("%d ", a[i]);
      }
      break;
    }
  }
  */

  return 0;
}

Measured memory_bytes: 13568