CodeEff/ECCO huggingface dataset:
# Original solution
k=int(eval(input()))
if k%2==0:
    print((-1))
    exit()
count=1
a=0
while True:
    a=(a*10+7)%k
    if a==0:
        print(count)
        exit()
    count+=1

# Optimized solution
k=int(eval(input()))
if k%2==0 or k%5==0:
    print((-1))
    exit()
a=0
for i in range(k):
    a=(a*10+7)%k
    if a==0:
        print((i+1))
        exit()
# Original solution
#! /usr/bin/env python3

import sys
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)


def isMultiple(s, m):
    tmp = 0
    for i in range(len(s)):
        tmp = (tmp * 10 + int(s[i])) % m
        if tmp == 0:
            return i
    return -1


k = int(readline())
acc = "7" * 50000000
if k % 2 == 0:
    ans = -1
else:

    ans = isMultiple(acc, k)
    if ans != -1:
        ans += 1

print(ans)


# Optimized solution
#! /usr/bin/env python3

import sys
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

k = int(readline())

ans = -1
acc = 7 % k
for n in range(1, k + 10):
    if acc == 0:
        ans = n
        break
    acc = (10 * acc + 7) % k

print(ans)
# Original solution
k = int(eval(input()))
x = 1

if k%7 != 0:
    mod = 9*k
else:
    mod = 9*k//7

for i in range(10**6):
    x = x*10%mod
    if x == 1:
        print((i + 1))
        exit()

print((-1))

# Optimized solution
k = int(eval(input()))
a = 0

for i in range(k + 10):
    a = (a*10 + 7)%k
    if a == 0:
        print((i + 1))
        exit()
print((-1))
# Original solution
a=sorted(map(int,input().split()));print((a[-1]*(2**(int(eval(input()))))+sum(a)-a[-1]))

# Optimized solution
a=sorted(map(int,input().split()))[::-1];print((a[0]*(2**(int(eval(input()))))+sum(a)-a[0]))
# Original solution
L = [list(map(int,input().split()))]
K = int(eval(input()))
import copy

def peice_double(L):
    l = []
    for x in L:
        tmp = copy.copy(x)
        for i in range(3):
            tmp[i] = tmp[i] * 2
            l.append(copy.copy(tmp))
            tmp[i] = tmp[i] // 2
    return l
for i in range(K):
    L = peice_double(L)
ans = 0
for x in L:
    ans = max(ans, sum(x))
print(ans)

# Optimized solution
L = list(map(int,input().split()))
K = int(eval(input()))
m = max(L)
print((sum(L)-m + m* (2 ** K)))
# Original solution
import heapq
def main():
    A, B, C = list(map(int, input().split()))
    K = int(eval(input()))
    lv = []
    heapq.heappush(lv, -A)
    heapq.heappush(lv, -B)
    heapq.heappush(lv, -C)

    for _ in range(K):
        v = heapq.heappop(lv)
        heapq.heappush(lv, v*2)

    return -sum(lv)
    
if __name__ == '__main__':
    print((main()))

# Optimized solution
def main():
     A, B, C = list(map(int, input().split()))
     K = int(eval(input()))
     v = [A, B, C]
     v.sort(reverse = True)
     return pow(2, K)*v[0] + v[1] + v[2]

if __name__ == '__main__':
    print((main()))
# Original solution
A,B,C = list(map(int,input().split()))
K = int(eval(input()))
maxV = max(A,B,C)
print((A+B+C-maxV+maxV*2**K))

# Optimized solution
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
A,B,C = list(map(int,input().split()))
K = int(eval(input()))

print((A+B+C+max([A,B,C])*(2**K-1)))
# Original solution
A=list(map(int,(input().split())))
K=int(eval(input()))
X=sum(A)
for i in range(K) :
  X+=max(A)*(2**i)
print(X)

# Optimized solution
A=list(map(int,(input().split())))
K=int(eval(input()))
print((sum(A)+max(A)*((2**K)-1)))
# Original solution
a,b,c = list(map(int, input().split()))
k = int(eval(input()))
print((a+b+c+max(a,b,c)*((2**k)-1)))

# Optimized solution
L = sorted(map(int, input().split()))
k = int(eval(input()))
print((L[0]+L[1]+L[2]*2**k))
# Original solution
from collections import Counter
from functools import reduce
import fractions
import math
import statistics
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]  # LIST INT
def LF(): return [float(x) for x in sys.stdin.readline().split()]  # LIST FLOAT
def LS(): return sys.stdin.readline().split()  # LIST STRING
def MI(): return map(int, sys.stdin.readline().split())  # MAP INT
def II(): return int(sys.stdin.readline())  # INPUT INT
def IS(): return input()  # INPUT STRING
def P(x): return print(x)
def C(x): return Counter(x)
def GCD_LIST(numbers):  # greatest common divisor
    return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers):  # least common multiple
    return reduce(LCM, numbers)
def LCM(m, n):
    return (m * n // fractions.gcd(m, n))


li = LI()
k = II()
ans = []

def calc(a, b, c, count):

    if count == k:
        val = a+b+c
        ans.append(val)
        count -= 1
        return

    count += 1
    calc(a*2, b, c, count)
    calc(a, b*2, c, count)
    calc(a, b, c*2, count)


calc(li[0], li[1], li[2], 0)
print(max(ans))
# 変だな


# Optimized solution
from collections import Counter
from functools import reduce
import fractions
import math
import statistics
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]  # LIST INT
def LF(): return [float(x) for x in sys.stdin.readline().split()]  # LIST FLOAT
def LS(): return sys.stdin.readline().split()  # LIST STRING
def MI(): return map(int, sys.stdin.readline().split())  # MAP INT
def II(): return int(sys.stdin.readline())  # INPUT INT
def IS(): return input()  # INPUT STRING
def P(x): return print(x)
def C(x): return Counter(x)
def GCD_LIST(numbers):  # greatest common divisor
    return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers):  # least common multiple
    return reduce(LCM, numbers)
def LCM(m, n):
    return (m * n // fractions.gcd(m, n))


li = LI()
k = II()
print(li[0] + li[1] + li[2] + max(li)*((2**k)-1))
# Original solution
a,b,c,=list(map(int,input().split()))
k=int(eval(input()))
while k>0:
    if max(a,b,c)==c:
        c=2*c
        k-=1
    elif max(a,b,c)==b:
        b=2*b
        k-=1
    else:
        a=2*a
        k-=1
print((sum([a,b,c])))

# Optimized solution
a=list(map(int,input().split()))
k=int(eval(input()))
a.sort()
for _ in range(k):
    a[-1]*=2
print((sum(a)))
# Original solution
l=[int(_) for _ in input().split()]
k=int(eval(input()))
print((max(l)*2**k+sum(l)-max(l)))

# Optimized solution
l=[int(_) for _ in input().split()]
print((max(l)*2**int(eval(input()))+sum(l)-max(l)))
# Original solution
A,B,C = list(map(int,input().split()))
K = int(eval(input()))
S = A+B+C-max(A,B,C)
M = max(A,B,C)
for k in range(K):
    M = M*2
print((M+S))


# Optimized solution
a = list(map(int,input().split()))
k = int(eval(input()))
a.sort()
print((a[0]+a[1]+a[2]*(2**k)))
# Original solution
a = list(map(int,input().split()))
b = int(eval(input()))
print((sum(a)+max(a)*(2**b)-max(a)))

# Optimized solution
A,B,C = sorted(list(map(int,input().split())),reverse=True)
K = int(eval(input()))
print((A*(2**K)+B+C))
# Original solution
l = list(map(int, input().split()))
k = int(eval(input()))
ans = sum(l) - max(l) + max(l)*2**k
print(ans)

# Optimized solution
l = list(map(int, input().split()))
k = int(eval(input()))

print((max(l)*2**k + sum(l)- max(l)))
# Original solution
A, B, C = list(map(int, input().split()))
print((max(A, B, C) * 2 ** int(eval(input())) + A + B + C - max(A, B, C)))

# Optimized solution
a, b, c = list(map(int, input().split()))
k = int(eval(input()))
print((a + b + c + max(a, b, c) * 2 ** k - max(a, b, c)))
# Original solution
A = list(map(int, input().split()))
k = int(eval(input()))
x = max(A)

for _ in range(k):
    x *= 2
    
print((sum(A) - max(A) + x))

# Optimized solution
A =  [int(i) for i in input().split()]
k = int(eval(input()))

print((max(A) * (2 ** k) + (sum(A) - max(A))))
# Original solution
N=int(eval(input()))
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))

res=0
back=-1

for a in A:
	res=res+B[a-1]					#listは０スタート
	if a-1==back:					#A内の今考えている変数が前のと同じなら
		res=res+C[back-1]			#listは０スタート
	back=a
    
print(res)

# Optimized solution
n=int(eval(input()))
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
res=sum(B)

for i in range(n-1):
	if A[i+1]-A[i]==1:
		res += C[A[i]-1]
print(res)
# Original solution
n = int(eval(input()))
a = [input().split() for l in range(3)]
mnpk = 0
fl = 0
for i in range(n):
  b = int(a[0][i]) - 1
  mnpk = mnpk + int(a[1][b])
  if fl == 1:
    if int(a[0][i-1]) == b:
      mnpk = mnpk + int(a[2][b-1])
  else:
    fl = 1

print(mnpk)
    

# Optimized solution
n = int(eval(input()))
a = [list(map(int,input().split())) for l in range(3)]
mnpk = 0
fl = 0
for i in range(n):
  b = a[0][i] - 1
  mnpk = mnpk + a[1][b]
  if fl == 1:
    if a[0][i-1] == b:
      mnpk = mnpk + a[2][b-1]
  else:
    fl = 1
 
print(mnpk)
# Original solution
def main():
    n = int(eval(input()))
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    c = list(map(int, input().split()))
    point = sum(b)

    for i in range(1,n):
        if a[i-1] +1 == a[i]:
            point += c[a[i-1]-1]


    print(point)

if __name__ == '__main__':
    main()

# Optimized solution
def main():
    n = int(eval(input()))
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    c = list(map(int, input().split()))
    total_score = sum(b)

    for i in range(1, n):
        prev = a[i - 1]
        if prev + 1 == a[i]:
            total_score += c[prev - 1]

    print(total_score)


if __name__ == '__main__':
    main()
# Original solution
n = int(eval(input()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c= list(map(int,input().split()))
cnt=0
for i in range(n-1):
    if a[i+1] == a[i]+1:
        cnt+=c[a[i]-1]

print((sum(b)+cnt))

# Optimized solution
n = int(eval(input()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

ans = sum(b)
for i in range(1,n):
    if a[i]-1==a[i-1]:
        ans+=c[a[i-1]-1]
print(ans)
# Original solution
import sys
import math

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

def iinput():
    return int(eval(input()))

def finput():
    return float(eval(input()))

def tinput():
    return input().split()

def rinput():
    return list(map(int, tinput()))

def rlinput():
    return list(rinput())

def pro(k, l, n):
    if l < n:
        if k == 0:
            return(n - l)
        return (n - l + 2)
    if l == n:
        if k == 0:
            return 0
        elif k == 1:
            return 1
        return 3
    else:
        l -= n - 1
        if l == k:
            return 1
        elif l > k:
            return 0
        if l < k - 1:
            return 2
        else:
            return 3
            

def rt(k, l , n):
    if k < n:
        if l == 0:
            return (k * 2 + n)
        return (n + k * 2 - 1)
    elif k == n:
        if l == 1:
            return (k * 3 - 2)
        elif l == 0:
            return (k * 3)
        return (k * 3 - 3)
    else:
        k -= n - 1
        if k == l:
            return (n * 3 - 2)
        elif k > l:
            return (n * 3)
        if k < l - 1:
            return ((n - 1) * 3 - 1)
        else:
            return ((n - 1) * 3)



def main():
    n = iinput()
    a = rlinput()
    res = sum(rlinput())
    c = rlinput()
    for i in range(n - 1):
        if a[i] - a[i + 1] == -1:
            res += c[a[i] - 1]
    print(res)
            
        
    
    
    
    
    


main()

# Optimized solution
n = int(eval(input())); summ = 0;
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
for i in range(n):
    summ = summ + b[a[i]-1]
    if i>0:
        if a[i] == a[i-1] + 1:
            summ = summ + c[a[i-1]-1]
print(summ)
# Original solution
n=int(eval(input()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))

ans=0
b_n=-2
for i in range(n):
  num=a[i]-1
  ans+=b[num]
  if num==b_n+1:
    ans+=c[b_n]
  b_n=a[i]-1
print(ans)

# Optimized solution
n=int(eval(input()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))

ans=sum(b)
for i in range(n-1):
  if a[i+1]==a[i]+1:
    ans+=c[a[i]-1]
print(ans)
# Original solution
N = int(eval(input()))
A = [-1] + list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = 0
for i in range(1, N + 1):
    ans += B[A[i] - 1]
    if A[i] == A[i - 1] + 1:
        ans += C[A[i] - 2]

print(ans)


# Optimized solution
N = int(eval(input()))
A = [-1] + list(map(int, input().split()))
B, C = list(map(int, input().split())), list(map(int, input().split()))

ans = 0
for i in range(1, N + 1):
    ans += B[A[i] - 1]
    if A[i] == A[i - 1] + 1:
        ans += C[A[i] - 2]

print(ans)
# Original solution
n = int(eval(input()))
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
a_sp = [c[a[i] - 1] for i in range(n - 1) if a[i + 1] - a[i] == 1]
print((sum(b + a_sp)))

# Optimized solution
n = int(eval(input()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
print((sum(b + [c[a[i] - 1] for i in range(n - 1) if a[i + 1] - a[i] == 1])))
# Original solution
def resolve():
    n=int(eval(input()))
    A=list([int(x)-1 for x in input().split()])
    ans=sum(map(int,input().split()))
    C=list(map(int,input().split()))

    for i in range(n-1):
        if A[i+1]-A[i]==1: ans+=C[A[i]]

    print(ans)
resolve()

# Optimized solution
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n=int(eval(input()))
    A=list(map(int,input().split()))
    B=list(map(int,input().split()))
    C=list(map(int,input().split()))
    ans=sum(B)
    for i in range(n-1):
        if(A[i+1]-A[i]==1):
            ans+=C[A[i]-1]

    print(ans)
resolve()
# Original solution
N=int(eval(input()))
Alist=list(map(int,input().split()))
Blist=list(map(int,input().split()))
Clist=list(map(int,input().split()))

Cplus=0
for n in range (N-1):
  if Alist[n+1] == Alist[n]+1:
    Cplus += Clist[Alist[n]-1]

print((sum(Blist)+Cplus))

# Optimized solution
N=int(eval(input()))
Alist=list(map(int,input().split()))
Blist=list(map(int,input().split()))
Clist=list(map(int,input().split()))
 
Cplus=0
for n in range (0,N-1):
  if Alist[n+1] == Alist[n]+1:
    Cplus += Clist[Alist[n]-1]
 
print((sum(Blist)+Cplus))
# Original solution

def main():
    n = int(eval(input()))
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    c = list(map(int, input().split()))

    point= 0
    for i in range(n):
        point += b[a[i]-1]
        if i != 0:
            if a[i-1]+1 == a[i]:
                point += c[a[i]-2]
    
    print(point)

    
if __name__ == '__main__':
    main()



# Optimized solution
n = int(eval(input()))

a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
c_list = list(map(int, input().split()))

ans = 0
for i in range(n):
    
    ans += b_list[a_list[i]-1]
    #print(b_list[a_list[i]-1])
    if i == 0:
        continue
    else:
        if a_list[i] == a_list[i-1]+1:
            #print(a_list[i-1]-1)
            #print(c_list[a_list[i-1]-1])
            ans += c_list[a_list[i-1]-1]

print(ans)
# Original solution
n=int(eval(input()))
a=[0]+[int(i) for i in input().split()]
b=[0]+[int(i) for i in input().split()]
c=[0]+[int(i) for i in input().split()]
 
res = 0
prev = -1
for i in range(1, n+1):
    res += b[a[i]]
    if prev+1 == a[i]:
        res += c[prev]
    prev = a[i]

print(res)


# Optimized solution
n=int(eval(input()))
a=[int(i)-1 for i in input().split()]
b=[int(i) for i in input().split()]
c=[int(i) for i in input().split()]

res = 0
prev = -2
for i in range(n):
    res += b[a[i]]
    if prev+1 == a[i]:
        res += c[prev]
    prev = a[i]

print(res)
# Original solution
n = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = 0

for a in A:
    ans += B[a-1]

for i in range(n-1):
    if A[i] + 1 == A[i+1]:
        ans += C[A[i]-1]

print(ans)

# Optimized solution
n = int(eval(input()))
a = [i-1 for i in map(int, input().split())]
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = 0
prev_ind = 50
for i in a:
    ans += b[i]
    if prev_ind + 1 == i:
        ans += c[prev_ind]
    prev_ind = i

print(ans)
# Original solution
n = int(eval(input()))
a, b, c = [list(map(int, input().split())) for _ in range(3)]

ans = sum(b)
last = -1
for x in a:
    if last+1 == x:
        ans += c[last-1]
    last = x
print(ans)


# Optimized solution
n = int(eval(input()))
a, b, c = [list(map(int, input().split())) for _ in range(3)]

ans = sum(b)
for x, y in zip(a[:-1], a[1:]):
    if x + 1 == y:
        ans += c[x-1]
print(ans)
# Original solution
n = int(eval(input())) #waiting_for_pudging
a = list(map(int, input().split())) #waiting_for_pudging
b = list(map(int, input().split())) #waiting_for_pudging
c = list(map(int, input().split())) #waiting_for_pudging
summ = 0 #waiting_for_pudging
for i in range(n-1): #pudging
    if a[i] + 1 == a[i + 1]: #pudging
        summ += c[a[i]-1] #pudging
        summ += b[a[i]-1] #pudging
    else: #pudging
        summ += b[a[i]-1] #pudging
print((summ + b[a[n-1]-1])) #pudging
#accepted
    

# Optimized solution
n = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
s = sum(B)
for i in range(len(A)-1):
   # print(A[i], A[i+1]-1, C[i+1], i)
    if A[i] == A[i+1]-1:
        s+=C[A[i]-1]
print(s)
# Original solution
N = int(eval(input()))
ans = 0
for i in range(N):
  ans += i
print(ans)

# Optimized solution
N = int(eval(input()))
print((N*(N-1)//2))
# Original solution
# ABC139
# D
# ModSum

n = int(eval(input()))
print((sum(i for i in range(n))))

# Optimized solution
# ABC139
# D
# ModSum

n = int(eval(input()))
print((n*(n-1)//2))
# Original solution
ans=0
N=int(eval(input()))
for i in range(N-1):
  ans=ans+i+1
print(ans)

# Optimized solution
N=int(eval(input()))
print((N*(N-1)//2))
# Original solution

def calc(n):
    r = 0
    for i in range(1, n):
        r += i
    return r


n = int(eval(input()))
r = calc(n)
print(r)


# Optimized solution

def calc(n):
    return (1 + n - 1) * (n-1) // 2


n = int(eval(input()))
r = calc(n)
print(r)
# Original solution
#!/usr/bin/env python3

N = int(eval(input()))

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

print(ans)


# Optimized solution
#!/usr/bin/env python3

N = int(eval(input()))

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

print(ans)
# Original solution
n = int(eval(input()))
s = 0
for i in range(n):
    s += i
print(s)

# Optimized solution
n = int(eval(input()))
print((n * (n-1) // 2))
# Original solution
n = int(eval(input()))
answer = 0
for i in range(1, n):
	answer += i
print(answer)

# Optimized solution
#!/usr/bin/env python3
import sys


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


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()
# Original solution
N = int(eval(input()))
if N == 1:
    print((0))
else:
    num = 0
    for i in range(1, N):
        num += i
    print(num)

# Optimized solution
N = int(eval(input()))
if N == 1:
    print((0))
else:
    print(((N-1)*N//2))
# Original solution
n = int(eval(input()))
ans = 0
for i in range(n - 1):
    ans += i + 1
print(ans)

# Optimized solution
n = int(eval(input()))
if n % 2 == 1:
    print((n * (n // 2)))
else:
    print(((n * n - n) // 2))
# Original solution
N = int(eval(input()))
sum = 0
for i in range(N):
  sum += i
print(sum)

# Optimized solution
N = int(eval(input()))
print((N*(N-1)//2))
# Original solution
n = int(eval(input()))
s = 0
for i in range(n-1):
  s += i + 1
print(s)

# Optimized solution
n = int(eval(input()))
print((n * (n - 1) // 2))
# Original solution
N = int(eval(input()))
ans = 0

for i in range(N):
    ans += i
print(ans)

# Optimized solution
N = int(eval(input()))
print(((N)*(N-1) //2))
# Original solution
n = int(eval(input()))
total = 0
for i in range(n):
    total += i
print(total)

# Optimized solution
n = int(eval(input()))
print((n*(n-1)//2))
# Original solution
a=int(eval(input()))
c=0
for i in range(a):
  c = c+i
  
print(c)

# Optimized solution
N = int(eval(input()))
print(((N-1)*N//2))
# Original solution
N=int(eval(input()))
P=[]
ans=0
for i in range(N):
  P.append(i+1)
print((sum(P) - N))

# Optimized solution
N=int(eval(input()))
print(((N+1) * (N // 2) - N if N%2==0 else (N+1) * (N // 2) + int(N/2+1) - N))
# Original solution
N = int(eval(input()))

print((sum(i % (i + 1) for i in range(1, N))))


# Optimized solution
N = int(eval(input()))

print((int(N * (N - 1) // 2)))
# Original solution
def main():
    n = int(eval(input()))
    p = [i for i in range(1, n+1)]

    ans = sum([p[i] % (p[i]+1) for i in range(n-1)])
    # for i in range(n-1):
    #     ans += p[i] % (p[i]+1)
    print(ans)


if __name__ == "__main__":
    main()


# Optimized solution
def main():
    n = int(eval(input()))

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


if __name__ == "__main__":
    main()
# Original solution
N=int(eval(input()))
S=0
for i in range(N):
  S+=i
print(S)

# Optimized solution
N=int(eval(input()))
print((N*(N-1)//2))
# Original solution
n = int(eval(input()))
l = [i+1 for i in range(n)]
print((sum(l)-max(l)))

# Optimized solution
n = int(eval(input()))
print(((1 + n-1)*(n-1)//2))
# Original solution
N = int(eval(input()))
print((sum(v for v in range(N))))


# Optimized solution
N = int(eval(input()))
print((N * (N - 1) // 2))
# Original solution
n=int(eval(input()))
p=[i+1 for i in range(n)]
ans=sum(p)-p[n-1]
print(ans)

# Optimized solution
n=int(eval(input()))
ans=n*(n-1)//2
print(ans)
# Original solution
import sys
def input():
    return sys.stdin.readline()[:-1]

N = int(eval(input()))
total = 0
for i in range(1, N):
  total += i

print(total)


# Optimized solution
import sys
def input():
    return sys.stdin.readline()[:-1]

N = int(eval(input()))
total = sum(range(1, N))
  
print(total)
# Original solution
N = int(eval(input()))

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


# Optimized solution
N = int(eval(input()))

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

print(ans)
# Original solution
def main():
    N = int(eval(input()))
    ans = sum(range(1, N + 1)) - N
    print(ans)


if __name__ == "__main__":
    main()

# Optimized solution
def main():
    N = int(eval(input()))
    ans = N * (N - 1) // 2
    print(ans)


if __name__ == "__main__":
    main()
# Original solution
n = int(eval(input()))
print((sum([i+1 for i in range(n-1)])))

# Optimized solution
n = int(eval(input()))

count = 0
for i in range(n-1):
    count += i+1

print(count)
# Original solution
N = int(eval(input()))
M = 0
for i in range(N - 1):
    M += (i + 1) % (i + 2)
print(M)

# Optimized solution
N = int(eval(input()))
print((N * (N + 1) // 2 - N))
# Original solution
N=int(eval(input()))
s=N
ans=0
m=N
for i in range(N-1,0,-1):
    if i%s<m%s:
        ans+=m%s
        m=s-1
        s-=1
    else:
        ans+=i%s
        s-=1
print(ans)
        

# Optimized solution
N=int(eval(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))
# Original solution
n = list(x for x in range(1, int(eval(input())) + 1))
p = [max(n)]
p.extend(n)

m = []
ans = 0

for i in range(len(n)):
  m.append(p[i] % (i+1))

for i in range(len(n)):
  ans += m[i]

print(ans)

# Optimized solution
n = int(eval(input()))
print((n*(n-1)//2))