Problem:
Score : 400 points

Problem Statement

For an integer N, we will choose a permutation \{P_1, P_2, ..., P_N\} of \{1, 2, ..., N\}.

Then, for each i=1,2,...,N, let M_i be the remainder when i is divided by P_i.

Find the maximum possible value of M_1 + M_2 + \cdots + M_N.

Constraints

N is an integer satisfying 1 \leq N \leq 10^9.

Input

Input is given from Standard Input in the following format:

N

Output

Print the maximum possible value of M_1 + M_2 + \cdots + M_N.

Sample Input 1

2

Sample Output 1

1

When the permutation \{P_1, P_2\} = \{2, 1\} is chosen, M_1 + M_2 = 1 + 0 = 1.

Sample Input 2

13

Sample Output 2

78

Sample Input 3

1

Sample Output 3

0

Solution in C# (Mono 4.6.2.0) (judge verdict: Accepted)

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

namespace Atcoder
{
    /// <summary>
    /// ContestName : ABC139
    /// Problem : D
    /// </summary>
    class Program
    {
        static void Main()
        {
            var sc = new Scanner();
            new Program().Solve(sc, new AtMath());
        }
        private void Solve(Scanner sc, AtMath math)
        {
            int n = sc.NextInt();
            long m = math.SumOfInt(n) - n;
            Console.WriteLine(m);
        }
    }

    class AtMath
    {

        public const int MOD = 1000000007;
        public const int INF = 2147483647;
        public const long SINF = 9223372036854775807;

        public long SumOfInt(long n)
        {
            return n * (n + 1) / 2;
        }
        /// <summary>
        /// 確率統計「nCr」を求める
        /// </summary>
        /// <param name="n"></param>
        /// <param name="r"></param>
        /// <returns></returns>
        public long Ncr(int n, int r)
        {
            int nn = n;
            int rr = 1;
            //nCr
            for (int i = 1; i < r; i++)
            {
                nn *= (n - i);
                rr *= (i + 1);
            }
            return nn / rr;
        }
        /// <summary>
        /// 最大公約数を求める
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public int Gcd(int a, int b)
        {
            if (a < b) { Swap(ref a, ref b); }
            if (a % b == 0) { return b; }
            else { return Gcd(b, a % b); }
        }
        /// <summary>
        /// 入れ替える
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="a"></param>
        /// <param name="b"></param>
        public void Swap<T>(ref T a, ref T b)
        {
            T t = a;
            a = b;
            b = t;
        }
        /// <summary>
        /// 素因数分解
        /// </summary>
        /// <param name="n"></param>
        /// <returns></returns>
        public static Dictionary<long, int> Factorize(long n)
        {
            var ret = new Dictionary<long, int>();
            for (long i = 2; i * i <= n; i++)
            {
                if (n % i != 0)
                {
                    continue;
                }

                ret[i] = 0;
                while (n % i == 0)
                {
                    n /= i;
                    ret[i]++;
                }
            }

            if (n > 1)
            {
                if (ret.ContainsKey(n))
                {
                    ret[n]++;
                }
                else
                {
                    ret[n] = 1;
                }
            }

            return ret;
        }
    }
    class Scanner
    {
        public Scanner()
        {
            _pos = 0;
            _line = new string[0];
        }

        const char Separator = ' ';
        private int _pos;
        private string[] _line;

        #region スペース区切りで取得

        public string Next()
        {
            if (_pos >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _pos = 0;
            }

            return _line[_pos++];
        }

        public int NextInt()
        {
            return int.Parse(Next());
        }

        public long NextLong()
        {
            return long.Parse(Next());
        }

        public double NextDouble()
        {
            return double.Parse(Next());
        }

        #endregion

        #region 型変換

        private int[] ToIntArray(string[] array)
        {
            var result = new int[array.Length];
            for (int i = 0; i < array.Length; i++)
            {
                result[i] = int.Parse(array[i]);
            }

            return result;
        }

        private long[] ToLongArray(string[] array)
        {
            var result = new long[array.Length];
            for (int i = 0; i < array.Length; i++)
            {
                result[i] = long.Parse(array[i]);
            }

            return result;
        }

        private double[] ToDoubleArray(string[] array)
        {
            var result = new double[array.Length];
            for (int i = 0; i < array.Length; i++)
            {
                result[i] = double.Parse(array[i]);
            }

            return result;
        }

        #endregion

        #region 配列取得

        public string[] Array()
        {
            if (_pos >= _line.Length)
                _line = Console.ReadLine().Split(Separator);
            _pos = _line.Length;
            return _line;
        }

        public int[] IntArray()
        {
            return ToIntArray(Array());
        }

        public long[] LongArray()
        {
            return ToLongArray(Array());
        }

        public double[] DoubleArray()
        {
            return ToDoubleArray(Array());
        }

        #endregion
    }
}