D - ModSum Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 400

問題文

整数 N に対して、\{1, 2, ..., N\} を並べ替えた数列 \{P_1, P_2, ..., P_N\} を選びます。

そして、各 i=1,2,...,N について、iP_i で割った余りを M_i とします。

M_1 + M_2 + \cdots + M_N の最大値を求めてください。

制約

  • N1 \leq N \leq 10^9 を満たす整数である。

入力

入力は以下の形式で標準入力から与えられる。

N

出力

M_1 + M_2 + \cdots + M_N の最大値を出力せよ。


入力例 1

2

出力例 1

1

\{1, 2\} を並び替えた数列として \{P_1, P_2\} = \{2, 1\} を選ぶと、M_1 + M_2 = 1 + 0 = 1 となります。


入力例 2

13

出力例 2

78

入力例 3

1

出力例 3

0

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