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: Accepted)

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

namespace AtCoder
{
    public class Program
    {
        // 最小公倍数
        public static long Lcm(long a, long b)
        {
            return a * b / Gcd(a, b);
        }

        // ユークリッドの互除法 
        public static long Gcd(long a, long b)
        {
            if (a < b)
                // 引数を入替えて自分を呼び出す
                return Gcd(b, a);
            while (b != 0)
            {
                var remainder = a % b;
                a = b;
                b = remainder;
            }
            return a;
        }

        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
            Console.ReadLine();
        }

        public void Solve(ConsoleInput cin)
        {
            int n = cin.ReadInt;
            int[] data = cin.ReadIntArray(n);

            long[] result = new long[100];
            for(int i = 1; i <= 100; i++)
            {
                for(int k = 0; k < n; k++)
                {
                    result[i-1] += (data[k] - i) * (data[k] - i);
                }
            }
            Console.WriteLine(result.Min());
        }

    }
    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return 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; }
    }

    class Mod
    {
        public int N { get; }
        private readonly List<long> fac = new List<long>() { 1, 1 };
        private readonly List<long> inv = new List<long>() { 0, 1 };
        private readonly List<long> facInv = new List<long>() { 1, 1 };

        /// <summary>
        /// コンストラクタでmod N のNの値を決める
        /// </summary>
        /// <param name="n"></param>
        public Mod(int n) { N = n; }

        /// <summary>
        /// 四則演算は下で
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public long Add(long a, long b) => (a % N + b % N + N) % N;
        public long Sub(long a, long b) => Add(a, -b);
        public long Mul(long a, long b) => (a % N * b % N + N) % N;
        public long Div(long a, long b) => Mul(a, Inv(b));

        public long Sum(params long[] args) => args.Aggregate(Add);

        public long Inv(long a)
        {
            if (a < inv.Count) return inv[(int)a];
            long b = N, x = 1, y = 0, tmp;
            while (b != 0)
            {
                var q = a / b;
                tmp = y;
                y = x - q * y;
                x = tmp;
                tmp = b;
                b = a - q * b;
                a = tmp;
            }
            return (x % N + N) % N;
        }

        public long Pow(long a, long n)
        {
            var result = 1L;
            while (n > 0)
            {
                if ((n & 1) == 1) result = Mul(result, a);
                a = Mul(a, a);
                n >>= 1;
            }
            return result;
        }

        public void InitSeq(int n)
        {
            for (var i = fac.Count; i <= n; i++)
            {
                fac.Add(fac[i - 1] * i % N);
                inv.Add(N - inv[N % i] * (N / i) % N);
                facInv.Add(facInv[i - 1] * inv[i] % N);
            }
        }

        public long Fac(int n)
        {
            InitSeq(n);
            return fac[n];
        }

        public long Per(int n, int k)
        {
            if (n < k || n < 0 || k < 0) return 0;
            InitSeq(n);
            return fac[n] * facInv[n - k] % N;
        }

        public long Com(int n, int k)
        {
            if (n < k || n < 0 || k < 0) return 0;
            InitSeq(n);
            return fac[n] * (facInv[k] * facInv[n - k] % N) % N;
        }
    }
}