Problem:
Score : 300 points

Problem Statement

There are N people living on a number line.

The i-th person lives at coordinate X_i.

You are going to hold a meeting that all N people have to attend.

The meeting can be held at any integer coordinate. If you choose to hold the meeting at coordinate P, the i-th person will spend (X_i - P)^2 points of stamina to attend the meeting.

Find the minimum total points of stamina the N people have to spend.

Constraints

All values in input are integers.

1 \leq N \leq 100

1 \leq X_i \leq 100

Input

Input is given from Standard Input in the following format:

N
X_1 X_2 ... X_N

Output

Print the minimum total stamina the N people have to spend.

Sample Input 1

2
1 4

Sample Output 1

5

Assume the meeting is held at coordinate 2. In this case, the first person will spend (1 - 2)^2 points of stamina, and the second person will spend (4 - 2)^2 = 4 points of stamina, for a total of 5 points of stamina. This is the minimum total stamina that the 2 people have to spend.

Note that you can hold the meeting only at an integer coordinate.

Sample Input 2

7
14 14 2 13 56 2 37

Sample Output 2

2354

Solution in C# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

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

namespace competitive_programming
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sep = ' ';
            var cin = new ConsoleInput(Console.In, sep);
            var program = new Program();
            program.Solve(cin);
        }

        private void Solve(ConsoleInput cin)
        {
            var n = cin.ReadInt;
            var x = cin.ReadIntArray(n).Distinct();
            var xMax = x.Max();
            var xMin = x.Min();
            var ans = xMin;

            for (var i = xMin; i <= xMax; ++i)
            {
                var p = x.Sum(a => Math.Abs(a - i));
                ans = Math.Min(ans, p);
            }

            Console.WriteLine(ans);
        }
    }

    internal static class Util
    {
        internal static int DivideFloor(int a, int b) => (a + b - 1) / b;
    }

    internal class ConsoleInput
    {
        private readonly System.IO.TextReader stream;
        private readonly char separator = ' ';
        private readonly Queue<string> inputStream = new Queue<string>();
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this.separator = separator;
            this.stream = stream;
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0)
                {
                    return inputStream.Dequeue();
                }

                string[] tmp = stream.ReadLine().Split(separator);
                foreach (string v in tmp)
                {
                    inputStream.Enqueue(v);
                }
                return inputStream.Dequeue();
            }
        }
        public string ReadLine => stream.ReadLine();
        public int ReadInt => int.Parse(Read);
        public long ReadLong => long.Parse(Read);
        public double ReadDouble => double.Parse(Read);
        public string[] ReadStrArray(long N)
        {
            var ret = new string[N];
            for (long i = 0; i < N; ++i)
            {
                ret[i] = Read;
            }
            return ret;
        }
        public int[] ReadIntArray(long N)
        {
            var ret = new int[N];
            for (long i = 0; i < N; ++i)
            {
                ret[i] = ReadInt;
            }
            return ret;
        }
        public long[] ReadLongArray(long N)
        {
            var ret = new long[N];
            for (long i = 0; i < N; ++i)
            {
                ret[i] = ReadLong;
            }
            return ret;
        }
    }

    public class SegmentTree
    {
        private readonly int _n;
        private readonly int _N;
        private readonly int[] _values;
        public SegmentTree(int n)
        {
            _n = n;
            _N = 1;
            while (_N < _n) _N *= 2;
            _values = new int[_N];
        }

        public SegmentTree(int n, int init = int.MaxValue) : this(n)
        {
            for (var i = 0; i < _N; ++i) _values[i] = init;
        }

        public void Update(int i, int value)
        {
            int idx = i + _N - 1;
            _values[idx] = value;
            while (idx > 0)
            {
                idx = parent(idx);
                _values[idx] = Math.Min(_values[lchild(idx)], _values[rchild(idx)]);
            }
        }

        public int Find(int a, int b, int k = 0, int l = 0, int r = -1)
        {
            if (r < 0) r = _N;

            if (r <= a || b <= l) return int.MaxValue;

            if (a <= l && r <= b) return _values[k];

            int lvalue = Find(a, b, lchild(k), l, (l + r) / 2);
            int rvalue = Find(a, b, rchild(k), (l + r) / 2, r);
            return Math.Min(lvalue, rvalue);
        }

        private int parent(int i) => (int)((i - 1) / 2);

        private int lchild(int i) => 2 * i + 1;

        private int rchild(int i) => 2 * i + 2;
    }
}