using System; using System.Linq; namespace y { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); int[] y = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); Array.Sort(y); int c = 0; int d = 0; if (n == 1) { c = y[0]; d = y[0]; } else if (n % 2 == 0) { c = y[n / 2]; d = y[n / 2 + 1]; } else { c = y[n / 2]; d = y[n / 2 + 1]; } long ans1 = 0; long ans2 = 0; foreach (var i in y) { ans1 += Math.Abs(c - i); ans2 += Math.Abs(d - i); } Console.WriteLine((long)Math.Min(ans1, ans2)); } } }