using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var N = Sarray()[0];
            var Ai = Sarray();
            var pq = Enumerable.Repeat(0, (int)2).Select(_ => new priority_queue<long>((l, r) => r.CompareTo(l))).ToArray();
            var maxN = new long[2, N + 1];
            for (var lr = 0; lr < 2; ++lr)
            {
                var sum = Ai.Take((int)N).Sum();
                maxN[lr, 0] = sum;
                for (var i = 0; i < N; ++i)
                    pq[lr].insert(Ai[i]);
                for (var i = N; i < 2 * N; ++i)
                {
                    var ml = pq[lr].extract();
                    pq[lr].insert(Max(ml, Ai[i]));
                    maxN[lr, i - N + 1] = maxN[lr, i - N] + Ai[i] - Min(Ai[i], ml);
                }
                Ai = Ai.Reverse().Select(a => -a).ToArray();
            }
            var ans = long.MinValue;
            for (var i = 0; i <= N; ++i)
                ans = Max(ans, maxN[0, i] + maxN[1, N - i]);
            WriteLine(ans);
        }               
        class priority_queue<T>
        {
            Comparison<T> cmp;
            T[] A = new T[2000000];
            // var pq = new priority_queue<long>((l, r) => l.CompareTo(r));
            // とすれば値の大きいものから優先
            public priority_queue(Comparison<T> c)
            {
                cmp = c;
            }
            public int num { get; private set; } = 0;
            public void insert(T v)
            {
                A[num] = v;
                ++num;
                increaseKey(num);
            }
            void increaseKey(int i)
            {
                while (1 < i && 0 < cmp(A[i - 1], A[i / 2 - 1]))
                {
                    var t = A[i - 1];
                    A[i - 1] = A[i / 2 - 1];
                    A[i / 2 - 1] = t;
                    i = i / 2;
                }
            }
            public T extract()
            {
                if (num < 1) return default(T);
                var max = A[0];
                A[0] = A[num - 1];
                --num;
                maxHeapify(1);
                return max;
            }
            void maxHeapify(int i)
            {
                var H = num;
                var l = left(i);
                var r = right(i);
                var largest = 0;
                if (l <= H && 0 < cmp(A[l - 1], A[i - 1])) { largest = l; } else { largest = i; }
                if (r <= H && 0 < cmp(A[r - 1], A[largest - 1])) { largest = r; }
                if (largest != i)
                {
                    var t = A[i - 1];
                    A[i - 1] = A[largest - 1];
                    A[largest - 1] = t;
                    maxHeapify(largest);
                }
            }
            int left(int l) => l * 2;
            int right(int r) => r * 2 + 1;
        }


        static long Mod = (long)1e9 + 7;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}

Measured memory_bytes: 68436