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: Runtime Error

Solution code:
##
n1 = int(input())
if n1 == 1:
    print(0)
else:
    n2 = list(range(1, n1+1))
    n2.reverse()
    a1 = sum(n2[1:(len(n2))])
    print(a1)

Submission status: Runtime Error

Solution code:
print(sum(range(1,int(input())))

Submission status: Runtime Error

Solution code:
n = int(input())

a = list(range(1, n+1))
# b = sorted(a, reverse=True)

b = list(range(2, n+1))+[1]
ans = 0

for i in range(n):
    ans += a[i] % b[i]

print(ans)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
n = int(input())

l = list(range(1,n+1))

ans = 0
for i in range(n):
    ans += l[i] % l[i-n+1]

print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
lst1 = list(range(1,n+1))
lst2 = list(range(2,n+1))
lst2.append(1)
#lst3 = list(range(2,n+1))
#del lst3[lst3.index(n//2+1)]
#lst3.append(n//2+1)
m_sum = sum(list(map(lambda x,y,:x%y, lst1, lst2)))
#m_sum2 = sum(list(map(lambda x,y,:x%y, lst1, lst3)))
if n==1:
  print(0)
else:
  print(m_sum)

Submission status: Runtime Error

Solution code:
import numpy as np
N=int(input())
print(np.sum(np.array(np.arange(N))))

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())

P = np.arange(1,N+1)
M = np.arange(2,N+1)
M = np.append(M,[1])

ans = np.sum(P%M)

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())

l = list(range(1,N+1)) ## 1~Nのリスト
I = list(range(1,N))
l.pop(0)

print(sum([x % y for (x,y) in zip(I, l)]))

Submission status: Runtime Error

Solution code:
import numpy as np

n = int(input())

n_list =np.arange(1,n+1)
# print(n_list)
ans = np.sum(n_list)- n_list[-1]
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
r=list(range(1,n+1))

#print(r)
print(sum(r)-(n))

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
print(np.sum(np.arange(1, N)))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())

arr = [i+1 for i in range(N)]

print((arr[0]+arr[-2])*(N-1)//2)

Submission status: Runtime Error

Solution code:
n = int(input())
ans = 0
P = list(range(1,n+1))
for i in range(1, n+1):
  if i == n:
    break
  ans += i%(P[i])
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())

l = list(range(1,N+1)) ## 1~Nのリスト
I = list(range(1,N+1))

a = l.pop(0)
l.append(a)

print(sum([x % y for (x,y) in zip(I, l)]))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
mod=0
N=int(input())
a=list(range(1,N+1))
a.remove(1)
a.append(1)
#print(a)
b=list(range(1,N+1))
#print(b)
for i in range(N):
    mod=mod+(b[i]%a[i])
print(mod)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
import itertools
N = int(input())

sum = 0

if N == 1:
  print(0)
else:
  array = list(range(1, N))
  accum = list(itertools.accumulate(array))
  print(accum[N-2])

Submission status: Runtime Error

Solution code:
import copy
N = int(input())

l = list(range(1,N+1)) ## 1~Nのリスト
I = compy.deepcopy(l)

a = l.pop(0)
l.append(a)

print(sum([x % y for (x,y) in zip(I, l)]))

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

ll sumtoN(ll n){
  if(n%2==0){
    return (n/2)*(n+1);
  }
  else{
    return (((n-1)/2)*n+n);
  }
}

int main(){
  ll N;
  cin >> N;
  ll ans = sumtoN(N)-N;
  cout << ans << endl;
  return 0;
}

Submission status: Runtime Error

Solution code:
import random

n = int(input())
nums = random.shuffle([i for i in range(1,n+1)])
p = 0
for i,j in zip(nums,range(1,n+1)):
    p += j%i
print(p)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(range(1,N+1))
P = [A[len(A)-1]]
P.extend(A[:len(A)-1])
s = 0
for i,p in enumerate(P):
    s += p%(i+1)
print(s)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
//Remove below header file if c++ version greater than 14
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>

#define ll long long int
#define pb push_back
#define mp make_pair
#define all(X) X.begin(), X.end()
#define fastIO ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define endl '\n'
#define deb(x) cout << #x << " "<< x << endl;
#define fo(i, n) for(i=0; i<n; i++)
#define Fo(i, k, n) for(i=k; i<n; i++)

using namespace std;
using mii=map<int, int>;
using mll=map<ll, ll>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
const int mod = 1000000007;

ll desc(ll x, ll y)
{
    return x > y;
}

int main() {
    fastIO
    int n;
    cin >> n;

    long long int ans = (n * (n - 1)) / 2;
    cout << ans << endl;
    return 0;
}

Submission status: Runtime Error

Solution code:
n = int(input())
print(sum(list(range(1, n))))

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(1000000000)

N=int(input())
print(sum(list(range(N))))

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
ans = np.sum(np.arange(N))
print(ans)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
n = int(input())

l = list(range(1,n+1))
i = -1
ans = 0
while i > -n:
  tmp = 0
  for j in range(n):
    tmp += l[j+i] % l[j]
  ans = max(ans, tmp)
  i -= 1
print(ans)

Submission status: Runtime Error

Solution code:
from collections import deque

n = int(input())
a = deque(list(range(1,n,1)))
a.appendleft(n)

c = 0
for i in range(n):
	c += a[i]%(i+1)
print(c)

Submission status: Runtime Error

Solution code:
N = int(input())

l = list(range(1,N+1)) ## 1~Nのリスト
I = list(range(1,N+1))

a = l.pop(0)
l.append(a)

L= [x % y for (x,y) in zip(I, l)]

print(sum(L))

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
ans = np.sum(range(1,N))
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())

a = np.arange(1, n)
print(sum(a))

Submission status: Runtime Error

Solution code:
N = int(input())

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

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

Submission status: Runtime Error

Solution code:
N=int(input())
l1=list(range(1,N+1))
#l2=sorted(l1,reverse=True)
l2=list(range(2,N+1))
l2.append(1)
M=0
for i in range(N):
    M+=l1[i]%l2[i]
print(M)

Submission status: Runtime Error

Solution code:
N = int(input())

N_list = list(range(1, N+1, 1))
N_lista = []
for i in range(N):
  if i != (N - 1):
    N_lista.append(N_list[i+1])
  else:
    N_lista.append(N_list[0])

mod_sum = 0

for i in range(N):
  mod_sum += (i + 1) % N_lista[i]
  
print(mod_sum)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
N = int(input())

sum = 0

if N == 1:
  print(0)
else:
  print(np.sum(np.arange(N)))

Submission status: Runtime Error

Solution code:
N = int(input())
a = list(range(1,N+1))
b = list(range(2,N+2))
b[N-1] = 1

sum = 0
for i in range(N):
	sum += a[i]%b[i]
print(sum)

Submission status: Runtime Error

Solution code:
n = int(input())

a = list(range(1, n+1))
# b = []
total = 0
for i in range(n):
    # b.append(a[i-1])
    b = a[i-1]
    total += b % a[i]

print(total)

Submission status: Runtime Error

Solution code:
def culc(n):
    if n > 1:
        return n + culc(n-1)
    else:
        return 1

N = int(input())
if N == 1:
    print(0)
else:
    print(culc(N-1))

Submission status: Runtime Error

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(sum(list(range(N))))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
l = list(range(2, n+1))
l.append(1)
ans = 0
for i, m in enumerate(l): ans += (i+1)%m
print(ans)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
n = int(input())

l = list(range(1,n+1))
i = -1
ans = 0
while i > -n:
  ltmp = l[-i:] + l[:-i]
  tmp = sum(i%j for i,j in zip(l,ltmp))
  ans = max(ans, tmp)
  i -= 1
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())

import numpy as np

a = np.arange(1, N+1)
p = np.copy(a) + 1
p[-1] = 1

print(np.sum(a%p))

Submission status: Runtime Error

Solution code:
n=int(input())
l=[]
import itertools
 
for i in itertools.permutations(range(n)):
    l.append(sum(i[j]%(j+1) for j in range(n)))
print(max(l))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
# abc139/abc139_d
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N = i2n()
    n = N - 1
    print((n * (1+n))　>>　1)
    return

main()

Submission status: Runtime Error

Solution code:
N = int(input())

a = list(range(1, N+1))
sc = 0
print((a[-2]+a[0])*(N-1)//2)

Submission status: Runtime Error

Solution code:
n = int(input())
if n == 1:
    print(0)
else:
    print(sum(list(range(1, n))))

Submission status: Runtime Error

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: Runtime Error

Solution code:
#import sys
N = int(input())
NL = list(range(1,N+1))
print(sum(NL) - N)

Submission status: Runtime Error

Solution code:
n = int(input())

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

Submission status: Runtime Error

Solution code:
N = int(input())

a = list(range(1, N+1))
sc = 0
print(sum(a)-a[-1])

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())

x = np.arange(N)

print(np.sum(x))

Submission status: Runtime Error

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


def solve(N: int):
    x = range(1,N+1)
    r = list(x[1:]) + [1]

    print(sum([ x[i]%r[i] for i in range(N)]))

    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: Runtime Error

Solution code:
def main():
    N = input()
    ans = 0
    for i in range(N):
        ans += i
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
N = int(input())
M = [0]*N
for i in range(N-1):
    M[i+1] = M[i] + i + 1
print(M[-1])

Submission status: Runtime Error

Solution code:
# coding: utf-8
N = int(input())
ans = sum(list(range(N)))
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())

lN = list(range(1, N+1))
pN = list(range(2, N+1))
pN.append(1)

res = 0
for ln, pn in zip(lN, pN):
    res += (ln%pn)

print(res)

Submission status: Runtime Error

Solution code:
N = int(input())

a = list(range(1, N+1))
print(sum(a) - N)

Submission status: Runtime Error

Solution code:
N = int(input())
print(sum(list(range(N))[1:]))

Submission status: Runtime Error

Solution code:
N = int(input())
P = list(range(1,N))
print(sum(P))

Submission status: Runtime Error

Solution code:
N = input()

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

Submission status: Runtime Error

Solution code:
N=int(input())

print(sum(list(range(N+1)))-N)

Submission status: Runtime Error

Solution code:
n = int(input())
ans = list(range(1,n+1))
if n >= 3:
    print(sum(ans[1:-1]) + 1)
elif n == 2:
    print(1)
else:
    print(0)

Submission status: Runtime Error

Solution code:
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()

Submission status: Runtime Error

Solution code:
n = int(input())
l = list(range(1,n+1))
sum = (n*(n-1))//2
print(sum)

Submission status: Runtime Error

Solution code:
a = int(input())
print(int(0.5*a*(a+1))

Submission status: Runtime Error

Solution code:
import sys

def input(): return sys.stdin.readline()[:-1]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def MATINT(h): return [list(map(int, input().split())) for _ in range(h)]
def MATSTR(h): return [input() for _ in range(h)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
inf = float('inf')
mod = 10 ** 9 + 7

def main():
    N = INT()
    print(sum(list(range(1, N))))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
#include<bits/stdc++.h>
using namespace std;
using ll = long long; 
int main(){
  ll n;
  cin >> n;
  cout << (n-1)*n/2 << endl;
}