#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> 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)*}
    };
}

#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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, 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")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};
use std::cmp::Ordering;

#[allow(unused_imports)]
use std::io::Write;
use std::collections::BinaryHeap;

#[derive(Debug, Copy, Clone, Eq, PartialEq)]
struct Rev(i64);

impl Ord for Rev {
    fn cmp(&self, other: &Rev) -> Ordering {
        other.0.cmp(&self.0)
    }
}

impl PartialOrd for Rev {
    fn partial_cmp(&self, other: &Rev) -> Option<Ordering> {
        Some(other.0.cmp(&self.0))
    }
}

fn main() {
    input!{
      n: usize,
      aa: [i64; 3*n],
    }

    let mut left_heap = BinaryHeap::new();
    let mut left_sum = 0;
    let mut right_sum = 0;

    for i in 0..n {
        left_heap.push(Rev(aa[i]));
        left_sum += aa[i];
    }

    let mut right_used = vec![false; 3*n];
    let mut right_heap = BinaryHeap::new();
    {
        let mut right = vec![];
        for i in n..3*n {
            right.push((aa[i], i));
        }
        right.sort();
        for i in 0..n {
            right_used[right[i].1] = true;
            right_sum += right[i].0;
        }
        for i in n..2*n {
            right_heap.push((Rev(right[i].0), right[i].1));
        }
    }

    let mut ans = left_sum - right_sum;
    for i in n..2*n {
        if let Some(Rev(min_value)) = left_heap.pop() {
            if min_value < aa[i] {
                left_heap.push(Rev(aa[i]));
                left_sum += aa[i] - min_value;
            } else {
                left_heap.push(Rev(min_value));
            }
        }
        if right_used[i] {
            loop {
                let (Rev(value), idx) = right_heap.pop().unwrap();
                if idx <= i {
                    continue;
                }

                right_sum += value - aa[i];
                right_used[i] = false;
                right_used[idx] = true;
                break;
            }
        }
        ans = max(ans, left_sum-right_sum);
    }
    println!("{}", ans);
}


Measured memory_bytes: 16372