#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, BinaryHeap, BTreeMap};
use std::iter::FromIterator;

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn get<T: FromStr>() -> T
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }

    #[allow(dead_code)]
    pub fn get2<T: FromStr, U: FromStr>() -> (T, U)
    where
        <T as FromStr>::Err: Debug,
        <U as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        )
    }

    #[allow(dead_code)]
    pub fn get3<S: FromStr, T: FromStr, U: FromStr>() -> (S, T, U)
    where
        <S as FromStr>::Err: Debug,
        <T as FromStr>::Err: Debug,
        <U as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        )
    }
}

#[allow(unused_macros)]
macro_rules! debug {
    ($x: expr) => {
        println!("{}: {:?}", stringify!($x), $x)
    }
}

#[derive(Eq, PartialEq, Clone, Debug)]
struct Rev<T>(pub T);

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

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

fn main() {
    let n: usize = util::get();
    let a: Vec<i64> = util::gets();

    let mut left_max = a[..n].iter().sum::<i64>();
    let mut left_que = BinaryHeap::from_iter(a[..n].iter().map(|&x| Rev(x)));

    let mut right = Vec::from(&a[n..]);
    right.sort();

    let mut right_min = right[..n].iter().sum::<i64>();
    let mut dropped = BTreeMap::new();


    for &x in &right[n..] {
        *dropped.entry(x).or_insert(0) += 1;
    }

    let mut ans = left_max - right_min;
    for &x in &a[n..2 * n] {
        let l = left_que.pop().unwrap().0;
        left_max += max(l, x) - l;
        left_que.push(Rev(max(l, x)));

        if let Some(&c) = dropped.get(&x) {
            if c == 1 {
                dropped.remove(&x);
            } else {
                *dropped.entry(x).or_insert(0) -= 1;
            }
        } else {
            let (&k, &v) = dropped.iter().next().unwrap();
            right_min += -x + k;
            if v == 1 {
                dropped.remove(&k);
            } else {
                *dropped.entry(k).or_insert(0) -= 1;
            }
        }

        ans = max(ans, left_max - right_min);
    }

    println!("{}", ans);

}


Measured memory_bytes: 13428