using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ARC074
{
    public class D
    {
        private void Run()
        {
            var N = int.Parse(Console.ReadLine().Trim());
            var A = Console.ReadLine().Trim().Split().Select(long.Parse).ToArray();

            var headUsingElementQueue = new PriorityQueue<long>();
            long headMax = 0;
            var headMaxArray = new long[A.Length];
            for (int i = 0; i < A.Length; i++)
            {
                var a = A[i];
                if (headUsingElementQueue.Count < N)
                {
                    headUsingElementQueue.Push(a);
                    headMax += a;
                }
                else if (headUsingElementQueue.Peek() < a)
                {
                    var oldMax = headUsingElementQueue.Pop();
                    headMax -= oldMax;
                    headMax += a;
                    headUsingElementQueue.Push(a);
                }
                headMaxArray[i] = headMax;
            }

            var tailNotUsingMinusedElementQueue = new PriorityQueue<long>();
            long tailMin = 0;
            var tailMinArray = new long[A.Length];
            for (int i = A.Length - 1; i >= 0; i--)
            {
                var a = A[i];
                if (tailNotUsingMinusedElementQueue.Count < N)
                {
                    tailNotUsingMinusedElementQueue.Push(-a);
                    tailMin += a;
                }
                else if (tailNotUsingMinusedElementQueue.Peek() * -1 > a)
                {
                    var oldMin = tailNotUsingMinusedElementQueue.Pop() * -1;
                    tailMin -= oldMin;
                    tailMin += a;
                    tailNotUsingMinusedElementQueue.Push(-a);
                }
                tailMinArray[i] = tailMin;
            }

            var result = long.MinValue;
            for (int i = N - 1; i + N + 1 <= A.Length; i++)
            {
                //Console.WriteLine($"{i}, {headMaxArray[i]}, {tailMinArray[i]}");
                result = Math.Max(result, headMaxArray[i] - tailMinArray[i + 1]);
            }

            Console.WriteLine(result);
        }

        public static void Main()
        {
            var old = Console.Out;
            using (var writer = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false })
            {
                Console.SetOut(writer);
                new D().Run();
                Console.Out.Flush();
                Console.SetOut(old);
            }
        }

        // 最も小さな要素を返します
        public class PriorityQueue<T>
        {
            public PriorityQueue() : this(Comparer<T>.Default) { }
            public PriorityQueue(IComparer<T> compare)
            {
                this.m_buffer = new List<T>();
                this.m_comparer = compare;
            }

            public void Push(T elem)
            {
                int n = this.m_buffer.Count;
                this.m_buffer.Add(elem);
                while (n != 0)
                {
                    int i = (n - 1) / 2;
                    if (this.m_comparer.Compare(this.m_buffer[i], this.m_buffer[n]) > 0)
                    {
                        T temp = this.m_buffer[i];
                        this.m_buffer[i] = this.m_buffer[n];
                        this.m_buffer[n] = temp;
                    }
                    n = i;
                }
            }
            public T Pop()
            {
                int n = this.m_buffer.Count - 1;
                var res = this.m_buffer[0];
                this.m_buffer[0] = this.m_buffer[n];
                this.m_buffer.RemoveAt(n);
                int i = 0, j;
                while (true)
                {
                    j = 2 * i + 1;
                    if (j >= n) { break; }
                    if (j < n - 1 && this.m_comparer.Compare(this.m_buffer[j], this.m_buffer[j + 1]) > 0) { ++j; }
                    if (this.m_comparer.Compare(this.m_buffer[i], this.m_buffer[j]) > 0)
                    {
                        T temp = this.m_buffer[i];
                        this.m_buffer[i] = this.m_buffer[j];
                        this.m_buffer[j] = temp;
                    }
                    i = j;
                }
                return res;
            }
            public T Peek() { return this.m_buffer[0]; }
            public int Count { get { return this.m_buffer.Count; } }
            public void Clear() { this.m_buffer.Clear(); }

            private readonly List<T> m_buffer;
            private readonly IComparer<T> m_comparer;
        }
    }
}


Measured memory_bytes: 55560