#![allow(dead_code)]
#![allow(non_snake_case)]
// Original macro is in https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
// Thanks @tanakh :bow:
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = || -> String {
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
 
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
    
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [$t:tt]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

// for adhoc read (ex. https://atcoder.jp/contests/abc112/tasks/abc112_a)
fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[derive(Debug)]
struct Matrix<T=f32> {
    row: usize,
    col: usize,
    matrix: Vec<Vec<T>>,
}

impl Matrix {
    fn rank(&mut self) -> usize {
        let mut rank = 0;

        for col in 0..self.col {
            let mut pivot = 1000000;
            let mut ma = 1e-10;
            for row in rank..self.row {
                if self.matrix[row][col].abs() > ma {
                    ma = self.matrix[row][col].abs();
                    pivot = row;
                }
            }
            if pivot == 1000000 {
                continue;
            }
            self.matrix.swap(pivot, rank);

            let div = self.matrix[rank][col];
            for col2 in 0..self.col { self.matrix[rank][col2] /= div; }
            for row in 0..self.row {
                if row != rank && self.matrix[row][col].abs() > 1e-10 {
                    let fac = self.matrix[row][col];
                    for col2 in 0..self.col {
                        self.matrix[row][col2] -= self.matrix[rank][col2] * fac;
                    }
                }
            }
            rank += 1;
            // println!("---------------------");
            // println!("col {}", col);
            // println!("pivot {}, rank {}", pivot, rank);
            // println!("  swapped matrix {:?}", self.matrix);
        }
        return rank;
    }
}
// https://practice.contest.atcoder.jp/tasks/practice_1
fn main() {
    input! {
       N: usize, a: [i64; 3*N]
    }
    let mut ans = vec![];
    let mut ans2 = vec![];
    let mut sum = 0;
    let mut sum2 = 0;
    let mut h = std::collections::BinaryHeap::new();
    let mut h2 = std::collections::BinaryHeap::new();

    // 前半のＮ個を初期化
    for i in 0..N {
        h.push(-a[i]);
        sum += a[i];
    }

    // 後半のＮ個を初期化
    for i in 2*N..3*N {
        h2.push(a[i]);
        sum2 += a[i];
    }
    // println!("h2 init {:?} sum2 {}", h2, sum2);
    // println!("");
    ans.push(sum);
    for k in N..2*N {
        // 前半の調整
        h.push(-a[k]);
        sum += a[k]+h.pop().unwrap();
        // println!("h {:?} sum {}", h, sum);
        ans.push(sum);
    }
    // println!("ans {:?}", ans);
    // println!("");
    ans2.push(sum2);
    for l in (N..2*N).rev() {
        // println!("l {}", l);
        h2.push(a[l]);
        sum2 += a[l] - h2.pop().unwrap();
        // println!("h2 {:?} sum2 {}", h2, sum2);
        ans2.push(sum2);
    }
    // println!("ans2 {:?}", ans2);

    let mut ret = std::i64::MIN;
    for (i,j) in ans.iter().rev().zip(ans2) {
        if ret < i-j {
            ret = i-j;
        }
    }
    println!("{}", ret);
}


Measured memory_bytes: 14588