Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(input()) for _ in range(n)]
for i in range(0, n-1):
    a_i = a[0:i] + a[i+1:n]
    print(max(a_i))
print(max(a[0:n]))

Fixed submission:
n = int(input())
a = [int(input()) for _ in range(n)]
a_sorted = sorted(a, reverse=True)
for i in range(0, n):
    if a[i]==a_sorted[0]:
        print(a_sorted[1])
    else:
        print(a_sorted[0])

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(input()) for _ in range(n)]
for i in range(0, n-1):
    a_i = a[0:i] + a[i+1:n]
    print(max(a_i))
print(max(a[0:n]))

Fixed submission:
n = int(input())
a = [int(input()) for _ in range(n)]
a_sorted = sorted(a, reverse=True)
for i in range(0, n):
    if a[i]==a_sorted[0]:
        print(a_sorted[1])
    else:
        print(a_sorted[0])
Buggy python submission (verdict: Runtime Error):
import math
a, b , c, d = map(int, input().split())
def num_cm(a, b, m):
    if a % m == 0:
        return (b//m) - (a//m) + 1 
    else:
        return (b//m) - (a//m)
lcm = (c * d) // math.gcd(c, d)
ans =  b - a + 1 - num_cm(a, b, c) - num_cm(a, b, d) + num_cm(a, b, lcm)
print(ans)

Fixed submission:
a, b , c, d = map(int, input().split())
def num_cm(a, b, m):
    if a % m == 0:
        return (b//m) - (a//m) + 1 
    else:
        return (b//m) - (a//m)
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a    
lcm = (c * d) // gcd(c, d)
ans =  b - a + 1 - num_cm(a, b, c) - num_cm(a, b, d) + num_cm(a, b, lcm)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(M)]
common = set(range(LR[0][0], LR[0][1]+1))
for lr in LR:
    common = common & set(range(lr[0], lr[1]+1))
print(len(common))    

Fixed submission:
import numpy as np
N, M = map(int, input().split())
LR = np.array([list(map(int, input().split())) for _ in range(M)])
lmax, rmin = LR.max(axis=0)[0], LR.min(axis=0)[1]
print(max(0, rmin-lmax+1))
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [list(map(int, input().split())) for _ in range(N-1)]

T = [[] for _ in range(N)]
for i in range(N-1):
    u, v = A[i][0] - 1, A[i][1] - 1
    d = A[i][2] % 2 
    T[u].append([v, d])
    T[v].append([u, d])

visited = [True] + [False] * (N-1)
ans = [0] * N
def find(i):
    if visited[i]:
        for t in T[i]:
            if visited[t[0]]:
                pass
            else:
                ans[t[0]] = t[1]
                visited[t[0]] = True
                find(t[0])

find(0)                
            
for a in ans:
    print(a)

Fixed submission:
from collections import deque
N = int(input())
A = [list(map(int, input().split())) for _ in range(N-1)]

T = [[] for _ in range(N)]
for i in range(N-1):
    u, v = A[i][0] - 1, A[i][1] - 1
    d = A[i][2] % 2 
    T[u].append([v, d])
    T[v].append([u, d])

visited = [True] + [False] * (N-1)
ans = [0] * N
que = deque([0]) 
while len(que) > 0:
    q = que.popleft()
    for v, d in T[q]:
        if visited[v]:
            pass
        else:
            que.append(v)
            visited[v] = True
            ans[v] = (ans[q] + d) % 2
            
for a in ans:
    print(a)
Buggy python submission (verdict: Runtime Error):
N, Q = map(int, input().split())
S = input()
LR = [list(map(int, input().split())) for _ in range(Q)]

t = [0] * (N+1)
for i in range(N):
    t[i+1] = t[i] + (1 if S[i: i+2] == 'AC' else 0)
ans = [t[LR[i][1] - 1] - t[LR[i][0] - 1] for i in range(Q)]    

print(*ans, sep='\n')

Fixed submission:
b = input()

dic = {'A':'T', 'T':'A', 'C':'G', 'G':'C' }

print(dic[b])
Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()
LR = [list(map(int, input().split())) for _ in range(Q)]

ans = [S[LR[i][0]-1:LR[i][1]].count('AC') for i in range(Q)]

print(*ans, sep='\n')

Fixed submission:
N, Q = map(int, input().split())
S = input()
LR = [list(map(int, input().split())) for _ in range(Q)]

t = [0] * (N+1)
for i in range(N):
    t[i+1] = t[i] + (1 if S[i: i+2] == 'AC' else 0)
ans = [t[LR[i][1] - 1] - t[LR[i][0] - 1] for i in range(Q)]    

print(*ans, sep='\n')

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()
LR = [list(map(int, input().split())) for _ in range(Q)]

for i in range(Q):
    l, r = LR[i]
    print(S[l-1:r].count('AC'))


Fixed submission:
N, Q = map(int, input().split())
S = input()
LR = [list(map(int, input().split())) for _ in range(Q)]

t = [0] * (N+1)
for i in range(N):
    t[i+1] = t[i] + (1 if S[i: i+2] == 'AC' else 0)
ans = [t[LR[i][1] - 1] - t[LR[i][0] - 1] for i in range(Q)]    

print(*ans, sep='\n')

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()
LR = [list(map(int, input().split())) for _ in range(Q)]

for i in range(Q):
    l, r = LR[i]
    print(S[l-1:r].count('AC'))


Fixed submission:
N, Q = map(int, input().split())
S = input()
LR = [list(map(int, input().split())) for _ in range(Q)]

t = [0] * (N+1)
for i in range(N):
    t[i+1] = t[i] + (1 if S[i: i+2] == 'AC' else 0)
ans = [t[LR[i][1] - 1] - t[LR[i][0] - 1] for i in range(Q)]    

print(*ans, sep='\n')
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = list(map(int, input().split()))
num = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}

dp = [0]*(N+1)
INF = -float('inf')

for i in range(1, N+1):
    dp[i] = max([dp[i-num[j]] if i - num[j] >= 0 else INF for j in A]) + 1

A.sort(reverse = True)
ans = ''
tmp = N
while tmp > 0:
    for a in A:
        if dp[tmp-num[a]] == dp[tmp] - 1:
            ans += str(a)
            break
    else:
        ans += str(a)
    tmp -= num[a]
    
print(ans)    

Fixed submission:
N, M = map(int, input().split())
A = list(map(int, input().split()))
num = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}

dp = [0]*(N+1)
INF = -float('inf')

for i in range(1, N+1):
    dp[i] = max([dp[i-num[j]] if i - num[j] >= 0 else INF for j in A]) + 1

A.sort(reverse = True)
ans = ''
tmp = N
while tmp > 0:
    for a in A:
        if tmp-num[a] >=0:
            if dp[tmp-num[a]] == dp[tmp] - 1:
                break
    ans += str(a)
    tmp -= num[a]
    
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
c=0
for i in range(n):
  if a[i]>=a[i+1]:
    c+=1
  if a[i]<a[i+1]:
    c=0
print(c)



Fixed submission:
n=int(input())
a=list(map(int,input().split()))
c=0
mx=0
for i in range(n-1):
  if a[i]>=a[i+1]:
    c+=1
    if mx<c:
        mx=c
  if a[i]<a[i+1]:
    c=0
print(mx)
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/python3

import os
import sys


def main():
    N = read_int()
    A = read_ints()
    print(solve(N, A))


MOD = 1000000007


def solve(N, A):
    c = 1
    nums = [0, 0, 0]

    for a in A:
        z = nums.count(a)
        c *= z
        c %= MOD
        nums[nums.index(a)] = a + 1

    return c


###############################################################################

DEBUG = 'DEBUG' in os.environ


def inp():
    return sys.stdin.readline().rstrip()


def read_int():
    return int(inp())


def read_ints():
    return [int(e) for e in inp().split()]


def dprint(*value, sep=' ', end='\n'):
    if DEBUG:
        print(*value, sep=sep, end=end)


if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/python3

import os
import sys


def main():
    N = read_int()
    A = read_ints()
    print(solve(N, A))


MOD = 1000000007


def solve(N, A):
    c = 1
    nums = [0, 0, 0]

    for a in A:
        z = nums.count(a)
        if z == 0:
            return 0
        c *= z
        c %= MOD
        nums[nums.index(a)] = a + 1

    return c


###############################################################################

DEBUG = 'DEBUG' in os.environ


def inp():
    return sys.stdin.readline().rstrip()


def read_int():
    return int(inp())


def read_ints():
    return [int(e) for e in inp().split()]


def dprint(*value, sep=' ', end='\n'):
    if DEBUG:
        print(*value, sep=sep, end=end)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/python3

import os
import sys


def main():
    X, Y = read_ints()
    print(solve(X, Y))


MOD = 10 ** 9 + 7


def mpow(a, n):
    p = a
    v = 1
    while n > 0:
        if n & 1:
            v *= p
            v %= MOD
        n >>= 1
        p *= p
        p %= MOD
    return v


def solve(X, Y):
    s = X + Y
    if s % 3 != 0:
        return 0
    s //= 3

    a = 2 * s - X
    b = 2 * s - Y
    c = a + b

    facts = [0] * (c + 1)
    facts[0] = 1
    for i in range(1, c + 1):
        facts[i] = (facts[i - 1] * i) % MOD

    return (facts[c] * mpow(facts[a], MOD - 2) * mpow(facts[b], MOD - 2)) % MOD


###############################################################################

DEBUG = 'DEBUG' in os.environ


def inp():
    return sys.stdin.readline().rstrip()


def read_int():
    return int(inp())


def read_ints():
    return [int(e) for e in inp().split()]


def dprint(*value, sep=' ', end='\n'):
    if DEBUG:
        print(*value, sep=sep, end=end)


if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/python3

import os
import sys


def main():
    X, Y = read_ints()
    print(solve(X, Y))


MOD = 10 ** 9 + 7


def mpow(a, n):
    p = a
    v = 1
    while n > 0:
        if n & 1:
            v *= p
            v %= MOD
        n >>= 1
        p *= p
        p %= MOD
    return v


def solve(X, Y):
    s = X + Y
    if s % 3 != 0:
        return 0
    s //= 3

    a = 2 * s - X
    b = 2 * s - Y
    if a < 0 or b < 0:
        return 0

    c = a + b

    facts = [0] * (c + 1)
    facts[0] = 1
    for i in range(1, c + 1):
        facts[i] = (facts[i - 1] * i) % MOD

    return (facts[c] * mpow(facts[a], MOD - 2) * mpow(facts[b], MOD - 2)) % MOD


###############################################################################

DEBUG = 'DEBUG' in os.environ


def inp():
    return sys.stdin.readline().rstrip()


def read_int():
    return int(inp())


def read_ints():
    return [int(e) for e in inp().split()]


def dprint(*value, sep=' ', end='\n'):
    if DEBUG:
        print(*value, sep=sep, end=end)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def solve(target):
    n = int(target / 100)
    if n  100 <= target <= n  105:
        print(1)
    else:
        print(0)

solve(int(input()))

Fixed submission:
def solve(target):
    n = int(target / 100)
    if n * 100 <= target <= n * 105:
        print(1)
    else:
        print(0)

solve(int(input()))
Buggy python submission (verdict: Runtime Error):
    n,k = map(int,input().split())
    print(n-k+1)

Fixed submission:
n,k = map(int,input().split())
print(n-k+1)

Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().spolit())
print(n-k+1)

Fixed submission:
n,k = map(int,input().split())
print(n-k+1)
Buggy python submission (verdict: Runtime Error):
import math

n = int(input())
a = [int(i) for i in input().split()]
#print(n)
prefix,suffix=[0]*n,[0]*n
prefix[0]=a[0]
suffix[n-1]= a[n-1]
#print(prefix)
for i in range(1,n):
    prefix[i]= math.gcd(prefix[i-1],a[i])
    suffix[n-i-1]= math.gcd(suffix[n-i],a[n-i-1])
    pass
maxgcd= max(suffix[1],prefix[-2])
for i in range(1,n-1):
    maxgcd = max(maxgcd, math.gcd(prefix[i-1],suffix[i+1]))
print(maxgcd)

Fixed submission:
import math
def gcd(x, y): 
   while(y): 
       x, y = y, x % y 
  
   return x 
n = int(input())
a = [int(i) for i in input().split()]
#print(n)
prefix,suffix=[0]*n,[0]*n
prefix[0]=a[0]
suffix[n-1]= a[n-1]
#print(prefix)
for i in range(1,n):
    prefix[i]= gcd(prefix[i-1],a[i])
    suffix[n-i-1]= gcd(suffix[n-i],a[n-i-1])
    pass
maxgcd= max(suffix[1],prefix[-2])
for i in range(1,n-1):
    maxgcd = max(maxgcd, gcd(prefix[i-1],suffix[i+1]))
print(maxgcd)
Buggy python submission (verdict: Runtime Error):
#config:utf-8
x = input()

if int(x) < 100:
    print(0)
    return
if 5 * int(x[0:-2]) >= int(x[-2:]):
    print(1)
else:
    print(0)


Fixed submission:
#config:utf-8
x = input()

if int(x) < 100:
    print(0)
elif 5 * int(x[0:-2]) >= int(x[-2:]):
    print(1)
else:
    print(0)

Buggy python submission (verdict: Runtime Error):
#config:utf-8
x = input()

if x < 100:
    print(0)
    return
if 5 * int(x[0:-2]) >= int(x[-2:]):
    print(1)
else:
    print(0)


Fixed submission:
#config:utf-8
x = input()

if int(x) < 100:
    print(0)
elif 5 * int(x[0:-2]) >= int(x[-2:]):
    print(1)
else:
    print(0)

Buggy python submission (verdict: Runtime Error):
#config:utf-8
x = input()

if 5 * int(x[0:-2]) >= int(x[-2:]):
    print(1)
else:
    print(0)


Fixed submission:
#config:utf-8
x = input()

if int(x) < 100:
    print(0)
elif 5 * int(x[0:-2]) >= int(x[-2:]):
    print(1)
else:
    print(0)

Buggy python submission (verdict: Runtime Error):
#config:utf-8
x = input()

if 5 * int(x[0:-2]) >= int(x[-2:]):
    print(1)
else:
    print(0)


Fixed submission:
#config:utf-8
x = input()

if int(x) < 100:
    print(0)
elif 5 * int(x[0:-2]) >= int(x[-2:]):
    print(1)
else:
    print(0)

Buggy python submission (verdict: Runtime Error):
prices = [100, 101, 102, 103, 104, 105]
dp = [100, 101, 102, 103, 104, 105]

x = int(input())
while x > dp[-1]:
  maxv = dp[-1]
  next_max = 100000
  for v in dp:
    for p in prices:
      if v + p < next_max and v + p > maxv:
        next_max = v + p
 
if x = dp[-1]:
  print(1)
else:
  print(0)
  



Fixed submission:
#config:utf-8
x = input()

if int(x) < 100:
    print(0)
elif 5 * int(x[0:-2]) >= int(x[-2:]):
    print(1)
else:
    print(0)
Buggy python submission (verdict: Runtime Error):
#coding:utf-8

n = int(input())

nums = list(map(int,input()))
sorted(nums, reverse=True)
diff = 0
for i in range(n):
  if i % 2 == 0:
    diff += num[i]
  else:
    diff -= num[i]
print(diff)

Fixed submission:
#coding:utf-8

n = int(input())

nums = list(map(int,input().split(' ')))
nums = sorted(nums, reverse=True)
diff = 0
for i in range(n):
  if i % 2 == 0:
    diff += nums[i]
  else:
    diff -= nums[i]
print(diff)
Buggy python submission (verdict: Runtime Error):
#coding:utf-8

a,b = map(int, input().split(' '))

if a % 2 == 1 && b % 2 == 1:
  print('Odd')
else:
  print('Even')

Fixed submission:
#coding:utf-8

a,b = map(int, input().split(' '))

if a % 2 == 1 and b % 2 == 1:
  print('Odd')
else:
  print('Even')
Buggy python submission (verdict: Time Limit Exceeded):
#coding:utf-8

n = int(input())
nums = list(map(int,input().split(' ')))

cnt = 0
while True:
  for num in nums:
    if num % 2 == 0:
      continue
    else:
      break
    break
  else:
    cnt += 1

Fixed submission:
#coding:utf-8

n = int(input())
nums = list(map(int,input().split(' ')))

def calc():
  cnt = 0
  while True:
    for i in range(len(nums)):
      num = nums[i]
      if num % 2 == 0 and num != 0:
        nums[i] = num / 2
      else:
        return cnt
    else:
      cnt += 1

print(calc())

Buggy python submission (verdict: Time Limit Exceeded):
#coding:utf-8

n = int(input())
nums = list(map(int,input().split(' ')))

cnt = 0
while True:
  for num in nums:
    if num % 2 != 0:
      break
    else:
      continue
    break
  else:
    cnt += 1

Fixed submission:
#coding:utf-8

n = int(input())
nums = list(map(int,input().split(' ')))

def calc():
  cnt = 0
  while True:
    for i in range(len(nums)):
      num = nums[i]
      if num % 2 == 0 and num != 0:
        nums[i] = num / 2
      else:
        return cnt
    else:
      cnt += 1

print(calc())
Buggy python submission (verdict: Time Limit Exceeded):
import sys,random
try: sys.stdin = open('in.in','r')
except: pass

R,G,B,N = map(int,input().split())

ans = 0
for r in range(0,N+1):
	if r*R > N: break
	for b in range(0,N+1):
		if b*B + r*R > N: break
		if (N-b*B-r*R)%G != 0: continue
		ans += 1
print(ans)


Fixed submission:
import sys,random
try: sys.stdin = open('in.in','r')
except: pass

R,G,B,N = map(int,input().split())

ans = 0
for r in range(0,N+1,R):
	for b in range(0,N+1-r,B):
		if (N-b-r)%G != 0: continue
		ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys,random
try: sys.stdin = open('in.in','r')
except: pass

ans = 0
allboth = 1
l = r = 0

n = int(input())
for i in range(n):
	s = input().strip()
	ans += s.count('AB')
	if s[0] == 'B' or s[-1] == 'A':
		l += s[0] == 'B'
		r += s[-1] == 'A'
		if s[0] != 'B' or s[-1] != 'A':
			allboth = 0

ans += min(l,r)
if allboth and ans:
	while True:
		pass
	ans -= 1
print(ans)


Fixed submission:
import sys,random
try: sys.stdin = open('in.in','r')
except: pass

ans = 0
allboth = 1
l = r = 0

n = int(input())
for i in range(n):
	s = input().strip()
	ans += s.count('AB')
	if s[0] == 'B' or s[-1] == 'A':
		l += s[0] == 'B'
		r += s[-1] == 'A'
		if s[0] != 'B' or s[-1] != 'A':
			allboth = 0

ans += min(l,r)
if allboth and l:
	ans -= 1
print(ans)
Buggy python submission (verdict: Runtime Error):
print( 'Yes' if len(collections.Counter(map(int,input().split())).items()) == 1 else 'No' )

Fixed submission:
import collections
print( 'Yes' if len(collections.Counter(map(int,input().split())).items()) == 1 else 'No' )
Buggy python submission (verdict: Time Limit Exceeded):
digits = int(input())
num_list = [int(i) for i in list(input())]
flag1 = 0
flag2 = 0
counter = 0


for num1 in range(10):
	for num2 in range(10):
		for num3 in range(10):
			flag1 = 0
			flag2 = 0
			for digit in range(digits):
				if flag1 == 0 and flag2 == 0 and num1 == num_list[digit]:
					flag1 = 1
					continue
				if flag1 == 1 and num2 == num_list[digit]:
					flag2 = 1
					flag1 = 0
					continue
				if flag2 == 1 and num3 == num_list[digit]:
					counter += 1
					flag2 = 0
					break
print(counter)



Fixed submission:
digits = int(input())
num_list = [int(i) for i in list(input())]
flag1 = 0
flag2 = 0
counter = 0


for num1 in range(10):
	for num2 in range(10):
		for num3 in range(10):
			flag1 = 0
			flag2 = 0
			for digit in range(digits):
				if flag1 == 0 and flag2 == 0 and num1 == num_list[digit]:
					flag1 = 1
					continue
				if flag1 == 1 and num2 == num_list[digit]:
					flag2 = 1
					flag1 = 0
					continue
				if flag2 == 1 and num3 == num_list[digit]:
					counter += 1
					flag2 = 0
					break
print(counter)
Buggy python submission (verdict: Time Limit Exceeded):
in_num = int(input())
check_num = 0
ans_counter = 0

while check_num <= in_num:
	i = 1
	div_counter = 0
	while i < check_num /2:
		if check_num % i == 0:
			div_counter += 1
		i += 2
	if div_counter == 8:
		ans_counter += 1

print(ans_counter)






Fixed submission:
in_num = int(input())
check_num = 1
ans_counter = 0



while check_num <= in_num:
	i = 1
	div_counter = 0
	while i <= check_num :
		if check_num % i == 0:
			div_counter += 1
		i += 2
	if div_counter == 8:
		ans_counter += 1
	check_num += 2

print(ans_counter)
Buggy python submission (verdict: Runtime Error):
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
# 一次元累積和
from itertools import accumulate
from bisect import bisect_left, bisect_right
from heapq import heappush, heappop

import re
# import numpy as np
# from scipy.misc import comb

# 再帰がやばいとき
import sys
sys.setrecursionlimit(10**9)

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
def line_inpl(x): return [i_inpl() for _ in range(x)]

INF = int(1e30)
MOD = int(1e9)+7 # 10^9 + 7

# field[H][W]
def create_grid(H, W, value = 0):
    return [[ value for _ in range(W)] for _ in range(H)]

########

def main():
    N = i_inpl()
    a = list(range(1, N+1))
    P = a[1:] + [a[0]]
    ans = 0
    for ai, Pi in zip(a, P):
        ans += ai % Pi
    print(ans)
if __name__ == "__main__":
    main()


Fixed submission:
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
# 一次元累積和
from itertools import accumulate
from bisect import bisect_left, bisect_right
from heapq import heappush, heappop

import re
# import numpy as np
# from scipy.misc import comb

# 再帰がやばいとき
import sys
sys.setrecursionlimit(10**9)

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
def line_inpl(x): return [i_inpl() for _ in range(x)]

INF = int(1e30)
MOD = int(1e9)+7 # 10^9 + 7

# field[H][W]
def create_grid(H, W, value = 0):
    return [[ value for _ in range(W)] for _ in range(H)]

########

def main():
    N = i_inpl()
    if N == 1:
        print(0)
        return
    print(((1+(N-1))*(N-1))//2)
if __name__ == "__main__":
    main()