using System;
using System.Linq;
using static System.Math;
using System.Collections.Generic;
using Li = System.Collections.Generic.List<int>;
using Ll = System.Collections.Generic.List<long>;

namespace AtCoder0705
{
	class Program
	{
		static void Main(string[] args)
		{
			D();
		}

		private static void D()
		{
			var n = int.Parse(Console.ReadLine());
			var a = ReadLongs();
			Array.Sort(a);
			var bigger = a.Skip(a.Length / 2).ToArray();
			var sumB = bigger.Sum();
			long result = 2 * sumB - bigger[bigger.Length - 1] - (a.Length % 2 == 0 ? 0 : bigger[0]);

			Console.WriteLine(result);
		}

		static int[] bestPerm;
		static Li besC;

		private static long SolveDBrutal(int[] a)
		{
			var permutations = GetPermutations(a);
			long score = 0;

			foreach (var p in permutations)
			{
				var current = new Li { p[0] };
				SolveDBrutalRec(p, current, 0, ref score);
			}

			return score;
		}

		private static void SolveDBrutalRec(int[] p, Li current, long score, ref long bestScore)
		{
			if (current.Count == p.Length)
			{
				if (score > bestScore)
				{
					besC = current.ToList();
					bestPerm = p;
					bestScore = score;
				}
				return;
			}

			for (int i = 0; i < current.Count; i++)
			{
				current.Insert(i, p[current.Count]);
				var left = current[(i - 1 + current.Count) % current.Count];
				var right = current[(i + 1) % current.Count];
				var scoreL = score + Min(left, right);
				SolveDBrutalRec(p, current, scoreL, ref bestScore);
				current.RemoveAt(i);
			}
		}

		public static List<int[]> GetPermutations(int[] list)
		{
			int x = list.Length - 1;
			var result = new List<int[]>();
			GetPermutations(list, result, 0, x);
			return result;
		}

		private static void GetPermutations(int[] list, List<int[]> result, int k, int m)
		{
			if (k == m)
				result.Add(list.ToArray());
			else
				for (int i = k; i <= m; i++)
				{
					Swap(ref list[k], ref list[i]);
					GetPermutations(list, result, k + 1, m);
					Swap(ref list[k], ref list[i]);
				}
		}

		public static void Swap<T>(ref T a, ref T b)
		{
			T t = a;
			a = b;
			b = t;
		}

		private static void A()
		{
			var n = int.Parse(Console.ReadLine());
			Console.WriteLine((1000 - n % 1000) % 1000);
		}

		private static void B()
		{
			var n = int.Parse(Console.ReadLine());
			var strs = Enumerable.Range(0, n).Select(x => Console.ReadLine()).ToArray().GroupBy(x => x).Select(g => Tuple.Create(g.Key, g.Count())).ToArray();
			var ac = strs.Where(x => x.Item1 == "AC").Select(x => x.Item2).FirstOrDefault();
			var wa = strs.Where(x => x.Item1 == "WA").Select(x => x.Item2).FirstOrDefault();
			var tle = strs.Where(x => x.Item1 == "TLE").Select(x => x.Item2).FirstOrDefault();
			var re = strs.Where(x => x.Item1 == "RE").Select(x => x.Item2).FirstOrDefault();

			Console.WriteLine($"AC x {ac}");
			Console.WriteLine($"WA x {wa}");
			Console.WriteLine($"TLE x {tle}");
			Console.WriteLine($"RE x {re}");
		}


		private static void C()
		{
			var ints = ReadInts();
			var h = ints[0];
			var w = ints[1];
			var k = ints[2];

			var ar = Enumerable.Range(0, h).Select(x => Console.ReadLine().Select(c => c == '#').ToArray()).ToArray();
			var rowCounts = ar.Select(x => x.Count(y => y)).ToArray();
			var columnCounts = Enumerable.Range(0, w).Select(i => Enumerable.Range(0, h).Count(j => ar[j][i])).ToArray();

			var countResult = 0;
			for (int i = 0; i < 1 << (h + w); i++)
			{
				var arCopy = ar.Select(x => x.ToArray()).ToArray();
				for (int j = 0; j < h; j++)
					if ((i & (1 << j)) != 0)
						for (int l = 0; l < w; l++)
							arCopy[j][l] = false;

				for (int j = h; j < w + h; j++)
					if ((i & (1 << j)) != 0)
						for (int l = 0; l < h; l++)
							arCopy[l][j - h] = false;

				var c = arCopy.Sum(x => x.Count(y => y));
				if (c == k)
					countResult++;
			}

			Console.WriteLine(countResult);
		}

		private static int[] ReadInts() => Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
		private static long[] ReadLongs() => Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray();

	}
}


Measured memory_bytes: 48308