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



Sample input:
2


Sample output:
1

Submission status: Accepted

Solution code:
R = [0, 0, 1]
while True:
    try:
        N = int(input())
        
        if N <= 2:
            print(R[N])
        else:
            print((N-1)*(N-2)//2 + N - 1)
    except:
        break

Submission status: Accepted

Solution code:
from decimal import Decimal

n = Decimal(input())

print(int(n * ((n-1)/2)))

Submission status: Accepted

Solution code:
n = int(input())

if n == 1:
    print(0)
else:
    ans = n *(n-1) // 2
    print(ans)

Submission status: Accepted

Solution code:
n = int(input())
if n == 1:
    print(0)
else:
    a = (1+(n-1))*(n-1)//2
    print(a)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import math
N = int(input())-1
M = 0
x = int(math.ceil((N)/2))
if N%2 == 0:
    M = x*(N+1)
else:
    M = (x-1)*(N+1)+x
print(M)

Submission status: Accepted

Solution code:
N = int(input())
if N%2==0:
    print(N//2+N*((N-1)//2))
elif N%2!=0:
    print(N*(N//2))

Submission status: Accepted

Solution code:
N = int(input())

#P = [i for i in range(1,N+1, 1)]

print (N*(N-1)//2)

Submission status: Accepted

Solution code:
N=int(input())
if (N-1)%2==0 :
  print(N*((N-1)//2))
else :
  print(N*((N-1)//2)+N//2)

Submission status: Accepted

Solution code:
import sys

if sys.platform =='ios':
    sys.stdin=open('input_file.txt')
    
N=int(input())

print((N*(N-1))//2)

Submission status: Accepted

Solution code:

N=int(input())

n=N-1

s=n*(n+1)//2

print(s)

Submission status: Accepted

Solution code:
N = int(input())
print( int( (N * (N -1) )//2))

Submission status: Accepted

Solution code:
n = int(input())

output = (n * (n - 1)) // 2
print(output)

Submission status: Accepted

Solution code:
N = int(input())

target = N
out = 0
while target > 2:
    if target % 2 == 0:
        mueikyo_start = 1
        mueikyo_end = target-1
        out += ( (mueikyo_start + mueikyo_end) * (mueikyo_end - mueikyo_start+1) // 2 )
        break
    else:
        mueikyo_start = (target // 2) + 1
        mueikyo_end = target - 1
        out += ( (mueikyo_start + mueikyo_end) * (mueikyo_end - mueikyo_start+1) // 2 )
        out += ( target % mueikyo_start)
        target = target // 2
        #print("target", target, "cur out", out)

if target == 2:
    out += (1+0)
elif target == 1:
    out += 0

print(out)

Submission status: Accepted

Solution code:
N = int(input())
N = N-1
print(N*(N+1)//2)

Submission status: Accepted

Solution code:
# import sys
# input = sys.stdin.readline
n = int(input())
if n==1:
    print(0)
    exit()
else:
    ans = ( (n-1) * n )//2
    print(ans)
    exit()

Submission status: Accepted

Solution code:
N = int(input())

ans = 0
if N == 1:
    ans = 0
else:
    ans = (N-1) * N // 2

print(ans)

Submission status: Accepted

Solution code:
N = int(input())

print(str(int((N-1)*N//2)))

Submission status: Accepted

Solution code:
N = int(input())
# Nを割るとき(N//2)+1が一番でかい

ans = N*(N-1)//2
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
n-=1
print(n*(n+1)//2)

Submission status: Accepted

Solution code:
N = int(input())

print((1 + (N-1)) * (N-1) // 2)

Submission status: Accepted

Solution code:
from decimal import Decimal
N = Decimal(int(input()))
print(int(((1 + N) * (N / 2)) - N))

Submission status: Accepted

Solution code:
n = int(input())-1
print(int(n*(n+1)//2))

Submission status: Accepted

Solution code:
N = int(input())


print(N*(N + 1) // 2 - N)

Submission status: Accepted

Solution code:
n = int(input())


a = (1+n-1)*(n-1)//2
print(a)

Submission status: Accepted

Solution code:
n=int(input())
n-=1
print(int((n+1)*n/2))

Submission status: Accepted

Solution code:
N = int(input())
print( (N-1)*N//2 )

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

def main():
    N=int(input())  #数値入力 「N」だけの入力のとき
    a = range(1, N+1)
    ans = 0
    for i in range(1, N):
        ans += i
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
num = int(input())
ans=0
if (num%2==0):
    ans  = int(num/2) * (num-1)
else:
    ans = int((num-1)/2) * num
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

if n%2 == 1:
    ans = n*(n-1)//2
else:
    ans = n*(n-2)//2 + n//2
print(ans)

Submission status: Accepted

Solution code:
from decimal import *
a = int(input())

print(int(Decimal((a -1)/2)*Decimal(a)))

Submission status: Accepted

Solution code:
N = int(input())
ans = N * (N-1)//2
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
#A = list(range(1,N+1))

print(N*(N-1)//2)

Submission status: Accepted

Solution code:
n = int(input())
if n == 1:
    print(0)
else:
    print((n - 1) * n // 2)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

n=int(input())

ans=(n*(n-1))//2
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
print((1+n-1)*(n-1)//2)

Submission status: Accepted

Solution code:
n = int(input())
print((n)*(n-1) // 2)

Submission status: Accepted

Solution code:
N = int(input())

#P = [(x + 2) for x in range(N-1)] + [1]
#M = [i % P[i-1] for i in range(N)]
print((N)*(N-1)//2)

Submission status: Accepted

Solution code:
N = int(input())
mod = 0
if N == 1:
  print(0)
else:
  print(N+N*(N-1)//2-N)

Submission status: Accepted

Solution code:
n = int(input())						# 5

ans=(1+n-1)*(n-1)//2

print(ans)

Submission status: Accepted

Solution code:
import sys
import math

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    [N] = string_to_int(inputs[0])
    num = N - 1
    if num == 0:
        return 0
    if num == 1:
        return 1
    if num % 2 == 0:
        # half_l = math.floor(num / 2)
        # half = (half_l + half_l + 1) / 2
        half = num // 2
        append = num // 2
    else:
        half = (num + 1) // 2
        append = 0
        # half = math.floor(num / 2)
    return half * num + append


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    ret = solve(inputs(1))
    print(ret)

Submission status: Accepted

Solution code:
import sys
inputs = sys.stdin.readlines()

N = int(inputs[0])

print((N-1)*N // 2)

Submission status: Accepted

Solution code:
n = int(input())
m = (n-1)*n//2
print(m)

Submission status: Accepted

Solution code:
N = int(input())
print((N + 1) * N // 2 - N)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


def main():
    n = int(input())
    print((n * (n - 1)) // 2)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input()) - 1
sum = 0

if N % 2 == 0:
  sum = (1+N)*int(N/2)
else:
  sum = (1+N)*int((N-1)/2) + int((N+1)/2)

print(int(sum))

Submission status: Accepted

Solution code:
n =int(input())
if n%2 == 0:
    print(int(n/2)*(n-1))
else:
    print(n*int((n-1)/2))

Submission status: Accepted

Solution code:
N = int(input())

print( ((N-1)*N) // 2)

Submission status: Accepted

Solution code:
def main():

    n = int(input())
    sum = 0

    for i in range(n-1):
        sum += i+1
    
    print(sum)



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n  = int(input())
ans = ( (n-1) + 1) * (n-1) //2 
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

n = N - 1
result = 0

if n != 0:
    result = n * (n+1) // 2

print(result)

Submission status: Accepted

Solution code:
# coding: utf-8
import sys
# import random
# import bisect
# import math
# import numpy as np
# from fractions import gcd
# import itertools

"""Template"""


class IP:
    """
    入力を取得するクラス
    """

    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        """
        1文字の取得に使います
        :return: int
        """
        return int(self.input())

    def S(self):
        """
        1文字の取得(str
        :return: str
        """
        return self.input()

    def IL(self):
        """
        1行を空白で区切りリストにします(int
        :return: リスト
        """
        return list(map(int, self.input().split()))

    def SL(self):
        """
        1行の文字列を空白区切りでリストにします
        :return: リスト
        """
        return list(map(str, self.input().split()))

    def ILS(self, n):
        """
        1列丸々取得します(int
        :param n: 行数
        :return: リスト
        """
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        """
        1列丸々取得します（str
        :param n: 行数
        :return: リスト
        """
        return [self.input() for _ in range(n)]

    def SILS(self, n):
        """
        Some Int LineS
        横に複数、縦にも複数
        :param n: 行数
        :return: list
        """
        return [self.IL() for _ in range(n)]

    def SSLS(self, n):
        """
        Some String LineS
        :param n: 行数
        :return: list
        """
        return [self.SL() for _ in range(n)]


class Idea:
    def __init__(self):
        pass

    def S(self, s, r=0, m=-1):
        """
        ソート関係行います。色々な設定あります。
        :param s: 元となるリスト
        :param r: reversするかどうか 0=False 1=True
        :param m: （2次元配列）何番目のインデックスのソートなのか
        :return: None
        """
        r = bool(r)
        if m == -1:
            s.sort(reverse=r)
        else:
            s.sort(reverse=r, key=lambda x: x[m])

    def ceil(self, x, y):
        """
        Round up
        小数点切り上げ割り算
        :param x: int
        :param y: int
        :return: int
        """
        return -(-x // y)

    def ave(self, a):
        """
        平均を求めます
        :param a: list
        :return: int
        """
        return sum(a) / len(a)

    def gcd(self, x, y):
        if y == 0:
            return x
        else:
            return self.gcd(y, x % y)

    def lcm(self, x, y):
        return (x * y) // self.gcd(x, y)


"""ここからメインコード"""


def make_divisors(n):
    # divisors = []
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            # divisors.append(i)
            return i
            # if i != n // i:
            #     divisors.append(n//i)


def n_to_10(X, n):
    if int(X / n):
        return n_to_10(int(X / n), n) + str(X % n)
    return str(X % n)


def main():
    ip = IP()
    id = Idea()
    """この下から書いてね"""
    n = int(input())
    memo = (n*n-n)//2
    print(memo)


main()

Submission status: Accepted

Solution code:
N = int(input())
if N%2 ==0:
  n = N//2
  print(n*(N-1))
else:
  n = (N-1)//2
  print(n*N)

Submission status: Accepted

Solution code:
n = int(input())

answer = n * (n - 1) // 2
print(answer)

Submission status: Accepted

Solution code:
n = int(input())
ans = (n-1)*n//2
print(ans)

Submission status: Accepted

Solution code:
import sys
 
N = int(input())
 
if N==1:
  print(0)
  sys.exit()

if N==2:
  print(1)
  sys.exit()

Ans = (1 + N - 1) * (N - 1)// 2
 
print('%d' %(Ans))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

def main():
    N = int(input())
    Answer = N * (N - 1) // 2
    print(Answer)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
if N == 1:
  print("0")
else:
  ans = (N * (N-1))//2
  print(ans)

Submission status: Accepted

Solution code:
n = int(input())

a =n
if n%2 == 0:
  a =n-1
b= n//2
print(a*b)

Submission status: Accepted

Solution code:
from decimal import *

N = Decimal(input())

record = (N-1 + 1) * (N-1) / 2

print(Decimal(record))

Submission status: Accepted

Solution code:
def solve(n):
    res = (n - 1) * n // 2
    return res


def main():
    n = int(input())
    res = solve(n)
    print(res)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
ans = int((n-1)*n//2)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

ans = N*(N-1)//2

print(ans)

# 1 2 3
# 2 3 1

Submission status: Accepted

Solution code:
n = int(input())
if n==1:
  b = 0
else:
  if n%2==0:
    b = (n//2)*(n-1)
  else:
    b = n * ((n-1)//2)
    
print(b)

Submission status: Accepted

Solution code:
N = int(input())

if N == 1:
    print(0)
else:
    print((1+(N-1))*(N-1)//2)

Submission status: Accepted

Solution code:
n=int(input())

res=sum(range(0, n))
print(res)

Submission status: Accepted

Solution code:

I0 = lambda :map(int,input().split())
I1 = lambda :int(input())
I2 = lambda :list(map(int,input().split()))
#####################################################
n = I1()
res = 0
n-=1
print(n*(n+1)//2)
'''
for i in range(1,n+1):
    Mi = i % pi
    res+=Mi
'''

Submission status: Accepted

Solution code:
N = int(input())
count = int( (N-1) / 2 )

if (N-1) % 2 == 0:
    intSum = N*count
else:
    intSum = N*count + count + 1

print(intSum)

Submission status: Accepted

Solution code:
n = int(input())
print((n*(n-1))//2)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
''' 
------------------------
author : iiou16
------------------------
'''
# import itertools

def main():
    N = int(input())
    # seq = list(itertools.permutations(ll))
    # print(seq)
    # modsum = []
    # for s in seq:
    #     tmp = []
    #     for i in range(len(s)):
    #         tmp.append((i+1) % s[i])
    #     modsum.append(sum(tmp))
    # print(max(modsum))

    # i+1になるように並び替えたときが一番大きくなる
    # ex 4のときは(2,3,4,1)とすればあまりが(1,2,3,0)
    print(N * (N-1) // 2)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int):
    print(N * (N-1) // 2)
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
N -= 1
print((N* (N + 1))//2)

Submission status: Accepted

Solution code:
n=int(input())
count=n*(n-1)//2
print(count)

Submission status: Accepted

Solution code:
a = int(input())
ans=((a)*(a-1))//2
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
if N%2==0:
    s=int(N/2)
    print(s*(N-1))
if N%2==1:
    s=int((N-1)/2)
    print(s*N)

Submission status: Accepted

Solution code:
n=int(input())
sumNum=n*(n-1)//2

#print(r)
print(sumNum)

Submission status: Accepted

Solution code:
N = int(input())

a = list(range(1, N+1))

if N ==1:
    sc = 0
else:
    sc = int((N**2-N)/2)
print(sc)

Submission status: Accepted

Solution code:
n = int(input())
ans = (n)*(n-1)//2
print(ans)

Submission status: Accepted

Solution code:
import sys

N = int(sys.stdin.readline())

print(N * (N - 1) // 2)

Submission status: Accepted

Solution code:
n = int(input())
print(str((n-1)*n//2))

Submission status: Accepted

Solution code:
N=int(input())
mod=N*(N-1)//2
print(mod)

Submission status: Accepted

Solution code:
n = int(input())

a0 = 1
l = n - 1
r = (a0 + l) * (n - 1) // 2
print(r)

Submission status: Accepted

Solution code:
from sys import stdin


def main():
    N = int(input())

    print((N-1)*N//2)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
if N % 2 == 0:
    ans = int(N /2) * (N -1) 
else:
    ans = int((N - 1) / 2) * N
print(ans)

Submission status: Accepted

Solution code:
def f_d():
    n = int(input())
    n -= 1
    if n%2==0:
        print(n*((n-2)//2+1)+n//2)
    else:
        print(n*((n-1)//2+1))

if __name__ == "__main__":
    f_d()

Submission status: Accepted

Solution code:
from decimal import Decimal 

N = int(input())

print((Decimal(N)*Decimal(N-1)/2))

Submission status: Accepted

Solution code:
n = int(input())
if n == 1:
    print(0)
else:
    n -= 1
    print((1+n) * n // 2)

Submission status: Accepted

Solution code:
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

n = readi()

ans = n * (1 + n) // 2 - n
print(int(ans))

Submission status: Accepted

Solution code:
N = int(input())
cnt = 0
if N == 1:
    print(0)
elif N == 2:
    print(1)
else:
    cnt =  N*(N-1)//2 
    print(cnt)

Submission status: Accepted

Solution code:
N = int(input())
print((N-1)*(N)//2)

Submission status: Accepted

Solution code:
def main():
    n=int(input())
    print((n)*(n-1)//2)



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
print( N*(N-1)//2)

Submission status: Accepted

Solution code:
n=int(input())
X=(1+n-1)*(n-1)//2
print(X)

Submission status: Accepted

Solution code:
n=int(input())
print(int((n*(n-1))//2))

Submission status: Accepted

Solution code:
n = int(input())
if n == 1:
    print(0)
elif n == 2:
    print(1)
elif n%2 == 1:
    print((n+1)*(n-2)//2+n%2)
else:
    print((n+1)*(n-2)//2+1)

Submission status: Accepted

Solution code:
N = int(input())
print((N*N-N)//2)

Submission status: Accepted

Solution code:
n = int(input())
print((1 + n - 1) * (n - 1) // 2)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
print((N*(N-1))//2)

Submission status: Accepted

Solution code:
n=int(input())
print( (n*(n-1))//2 )

Submission status: Accepted

Solution code:
N = int(input())
ans = 0
if N%2 == 0:
    ans = N//2 * (N-1)
else:
    ans = (N-1)//2 * N
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
print( (N-1)*N //2 )

Submission status: Accepted

Solution code:
n=int(input())
ans=(n-1)*n//2
print(int(ans))

Submission status: Accepted

Solution code:
n = int(input())

n-=1

ret = int(n*(n+1)//2)


print(ret)

Submission status: Accepted

Solution code:
N = int(input()) -1
print((N+N*N)//2)

Submission status: Accepted

Solution code:
N = int(input())
ans = N * (N -1) // 2
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

ans = (N*(N-1))//2
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
N = N-1
if N % 2 == 0:
    print((N+1) * (N//2))
else:
    n = N-1
    print((n+1) * (n//2) + N)

Submission status: Accepted

Solution code:
n = int(input())

ans = (n-1)*n//2

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
if n % 2 == 0:
    print(int(n/2)*(n-1))
else:
    print(n*int((n-1)/2))

Submission status: Accepted

Solution code:
N = int(input())
print(sum(range(N)))

Submission status: Accepted

Solution code:
n = int(input())

print((n-1)* n // 2)

Submission status: Accepted

Solution code:
N =int(input())

print(N*(N-1)//2)

Submission status: Accepted

Solution code:
def s(n):
  return N * (N + 1) // 2
N = int(input())

result = s(N-1) - N

print(result)

Submission status: Accepted

Solution code:
n=int(input())
ans=((n-1)*(n))//2
print(ans)

Submission status: Accepted

Solution code:
import sys


def input(): return sys.stdin.readline().strip()


def main():
    N = int(input())
    ans = (N-1)*(1+N-1) // 2
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
sum = (N*(N-1))//2
print(sum)

Submission status: Accepted

Solution code:
N = int(input())
N -= 1

ans = 0

if N % 2 == 0:
    ans = int(N + 1) * int(N / 2)
else:
    ans = int(N + 1) * int((N-1) / 2) + int((N+1)/2)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
print((N * (N - 1) // 2))

Submission status: Accepted

Solution code:
n = int(input())
if n % 2 == 0:
    print(n * ((n - 1) // 2) + (n // 2))
else:
    print(n * ((n - 1) // 2))

Submission status: Accepted

Solution code:
N = int(input())
if N%2 == 0:
    print(int(N/2)*(N-1))
else:
    print(N*int((N-1)/2))

Submission status: Accepted

Solution code:
N = int(input())
if N % 2 == 0:
    ans = (N+1)*(N//2)
    ans -= N
    print(ans)
else:
    x = (N+1)//2
    ans = x + x * ((N-1)//2) * 2
    ans -= N
    print(ans)

Submission status: Accepted

Solution code:
n = input()
n -= 1
print n*(n+1)/2

Submission status: Accepted

Solution code:
def calc(N):
    return (N - 1) * N // 2


N = int(input())
print(calc(N))

Submission status: Accepted

Solution code:
import sys


def input():
    return sys.stdin.readline()[:-1]


def main():
    N = int(input())

    print(N*(N-1)//2)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

def main():
	N = inputInt()

	if N == 1:
		print(0)
		sys.exit()

	ans = 0
	for i in range(1,N):
		ans += i

	print(ans)

if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
n = int(input())
ans = n * (n - 1) // 2

print(ans)

Submission status: Accepted

Solution code:
def stair_sum(x):
    return (x * (x+1)) // 2


target = int(input())

print(stair_sum(target-1))

Submission status: Accepted

Solution code:
N = int(input())
print(((N-1)+1)*(N-1)//2)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int):
    print((N-1)*N//2)
    
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    ans = ((N-1) * (N)) // 2
    print(ans)

main()

Submission status: Accepted

Solution code:
n = int(input())

s = 1
e = n-1

if s == e:
  print(1)
  exit()

print(((s + e) * (n-1)) // 2)

Submission status: Accepted

Solution code:
N = int(input())

if N == 1:
    print(0)
else:
    print(N * (N - 1) // 2)

Submission status: Accepted

Solution code:
n = int(input())

res = n * ((n - 1) // 2)
if (n - 1) % 2 == 1:
    res += ((n - 1) // 2) + 1

print(int(res))

Submission status: Accepted

Solution code:
n = int(input())
print((n*(n+1))//2-n)

Submission status: Accepted

Solution code:
N = int(input())
res = (N * (N - 1)) // 2
print(res)

Submission status: Accepted

Solution code:
n=int(input())
x=n-1
print((x*(x+1))//2)

Submission status: Accepted

Solution code:
n = int(input())
ans = 0

p = []

if (n-1) % 2 == 0:
  ans = n * ((n-1) // 2)
else:
  ans = n * ((n-1) // 2) + (n // 2)

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
n = N - 1
ans = (n + 1) * n
ans //= 2
print(ans)

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin
na = lambda: map(int, stdin.readline().split())
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())

n = ni()

print(n*(n+1)//2-n)

Submission status: Accepted

Solution code:
N = int(input())

ans = (N-1)*N // 2

print(ans)

Submission status: Accepted

Solution code:
# import numpy as np
# from itertools import permutations
# n=int(input())

# a=np.arange(n)+1
# maxv=0
# for i in permutations(a, n):
#     print(a, "%", np.array(i), ":", a%np.array(i), sum(a%np.array(i)))
#     maxv=max(sum(a%np.array(i)), maxv)
# print(maxv)

n=int(input())
print(n*(n-1)//2)

Submission status: Accepted

Solution code:
n = int(input())

if n%2==0:
    ans = int(n/2)*(n-1)
else:
    ans = int((n-1)/2)*n

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
n = N-1
ans = n*(n+1)//2
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
print(N * (N+1) // 2 - N)

Submission status: Accepted

Solution code:
n = input()
n = int(n)

max_value = n - 1

ret = max_value * (max_value + 1) // 2

print(ret)

Submission status: Accepted

Solution code:
n = int(input());

print(n*(n-1)//2);

Submission status: Accepted

Solution code:
import itertools
N = int(input())
# A = list(range(1,N+1))
# mx = 0
# for ls in itertools.permutations(A, N):
#     #print (ls)
#     sm = sum([n%(i+1) for i,n in enumerate(ls)])
#     #print (sm)
#     mx = max(sm,mx)
# print (mx)
print (N*(N-1)//2)

Submission status: Accepted

Solution code:
N = int(input())

if N == 1:
    ans = 0
else:
    ans = N * (N + 1) // 2 - N

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

n = int(input())
s = n - 1

print(s*(s+1)//2)

Submission status: Accepted

Solution code:
n = int(input())
ans = n*(n-1)//2

print(ans)

Submission status: Accepted

Solution code:
n = int(input())

m = n * (n - 1) // 2

print(m)

Submission status: Accepted

Solution code:
# 例： 1 - 8 までの数列
# 1 2 3 4 5 6 7 8

# 余りを最大化するには、Nに対する N-1 の余り。つまり１ずつ減じた値の余りをとる。最初の値は N
# 8 1 2 3 4 5 6 7

#  (8 % 1) + (1 % 2) + (2 % 3) + .... + (7 % 8)
#   0 + 1   2 + ... + 7

N = int(input())
print(N * (N-1) // 2)

Submission status: Accepted

Solution code:
N = int(input())
sum_n = (N*(N+1))//2
print(sum_n-N)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    not_n = ((n-1) * n)// 2
    print(not_n)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())

if n % 2 == 0:
  print(n * (n//2) - n//2)
else:
  print(n * (n //2))

Submission status: Accepted

Solution code:
N=int(input())
if(N==1):
    print(0)
    exit()
if((N-1)%2==0):
    print(((N-1)*N//2))
else:
    print((N-2)*(N-1)//2+N-1)

Submission status: Accepted

Solution code:
import sys

def resolve():
    n = int(input())
    ans = ((n-1) + (n-1)**2) // 2
    print(ans)


if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-

N = int(input())

if N == 1:
    print(0)
    exit(0)

print(N*(N-1)//2)

Submission status: Accepted

Solution code:
n=int(input())
ans=(n-1)*(n)//2
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
print((N*(N-1))//2)

Submission status: Accepted

Solution code:
N = int(input())
print((N+1)*N//2-N)

Submission status: Accepted

Solution code:
n = int(input())
if n == 1:
  print(0)
  exit()
if n %2 == 0:
  ans = int(n/2)
  ans = ans*(n-1)
else:
  ans = int((n-1)/2)
  ans = ans*n
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
ans = 0
if N == 2 :
    print(1)
    exit(0)
if (N - 1 ) % 2 == 0:
    ans = (1 + N -1) * (N // 2)
else:
    #print(N // 2)
    ans = (1 + N -1) * ((N // 2) -1) + N // 2
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

if n % 2 == 0:
    print((n-1)*int(n/2))
else:
    print(n*int((n-1)/2))

Submission status: Accepted

Solution code:
N = int(input())

ans = N * (N-1) // 2

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
if (N-1) % 2 == 0:
    print( (N) * ((N-1)//2) )
else:
    print( (N-1) * ((N-2)//2) + (N-1))

Submission status: Accepted

Solution code:
N = int(input())

A = N-1

answer = A * N//2
print(answer)

Submission status: Accepted

Solution code:
#https://atcoder.jp/contests/abc139/tasks/abc139_d

n = int(input())

a = (n-1)*n // 2

print(a)

Submission status: Accepted

Solution code:
n=int(input())
x=(n-1)*n//2
print(x)

Submission status: Accepted

Solution code:
N=int(input())
if N % 2 ==1:
    ans=int((N-1)/2) * N
else:
    ans=int(N/2) * (N-1)
print(int(ans))

Submission status: Accepted

Solution code:
N=int(input())

ans=N*(N-1)//2
    
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin

if __name__ == '__main__':
    N = int(stdin.readline().rstrip())
    print( ((N-1) * N) // 2)

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

# a, b = MAP()
# n = INT()
# a, b, c = MAP()
count = 0
N = INT()
# for i in range(1,N):
    # print(i)
    # count += i
# print(count)
a = N-1
ans = a * (a+1)//2
print(ans)