import java.util.PriorityQueue
import java.util.Comparator

object MainKt {
  @JvmStatic fun main(args:Array<String>) {
    val N=readLine()!!.toInt()
    val a=readLine()!!.split(" ").map(String::toInt)
    assert(a.size==N)
    
    val front_queue = PriorityQueue<Int>()
    val last_queue=PriorityQueue<Int>(N,object: Comparator<Int> {
      override fun compare(a:Int,b:Int) = b-a
    })
    
    var front_acc=0L
    var last_acc=0L
    var front_sum=Array(N+1) {0L}
    var last_sum=Array(N+1) {0L}

    a.slice(0.until(N)).forEach{
          front_acc+=it
          front_queue.add(it)
          }
       a.slice((2*N).until(3*N)).forEach{ 
         last_acc+=it
         last_queue.add(it)
         }
    front_sum[0]=front_acc
    last_sum[N]=last_acc
    (N.until(2*N)).forEach{
      front_queue.add(a[it])
      front_acc+=a[it]-front_queue.poll()
      front_sum[it-N+1]=front_acc
    }
    (2*N-1 downTo N).forEach {
      last_queue.add(a[it])
      last_acc+=a[it]-last_queue.poll()
      last_sum[it-N]=last_acc
    }
    println((0..N).map{ front_sum[it]-last_sum[it]}.max()!!)
  }
}
