peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Wrong Answer
from itertools import accumulate
n = int(input())
lis = []
al=[]
bl=[]
for i in range(n):
    a,b=map(int, input().split())
    c=b-a%b
    al.append(a)
    bl.append(b)
ans=0
for i in range(n-1, -1, -1):
    if bl[i]==1:
        continue
    c=bl[i]-((al[i]+ans)%bl[i])
    ans+=c

print(ans)
# Judge status: Accepted
import collections
n, k = map(int, input().split())
r,s,p = map(int, input().split())
t = list(input())

for j in range(k, len(t)):
    if t[j] == t[j-k]:
        t[j] = ''
ts = collections.Counter(t)
print(ts['p']*s + ts['s']*r + ts['r']*p)
# Judge status: Wrong Answer
from operator import mul
def plus(n):
    return n+1


rows = int(input())
c = list(map(int, input().split()))
s = [[int(j) for j in input().split()] for i in range(rows)]

for i in range(rows):
    print(int((i+1)%25))
# Judge status: Accepted
a, b, c = map(int, input().split())

ans = 0
for i in range(10000):
    if (a + 1) * (b + 1) * (c + 1) % 2 == 0:
        print(ans)
        break
    if a == b == c:
        print(-1)
        break
    ans += 1
    a, b, c = a // 2, b // 2, c // 2
    a, b, c = b + c, a + c, b + c
# Judge status: Accepted
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

L = ['Sunny', 'Cloudy', 'Rainy']
S = sr()
i = L.index(S)
print(L[(i+1) % 3])
# Judge status: Accepted
s=input()
t=input()
r=1
for i in range(len(s)):
  if s[i]!=t[i]:
    r=0
if r==0:
  print('No')
else:
  print('Yes')
# Judge status: Wrong Answer
S = input()

if S == ('SUN'):
    print(7)
elif S == ('MON'):
    print(6)
elif S == ('TUE'):
    print(5)
elif S == ('WED'):
    print(4)
elif S == ('THU'):
    print(3)
elif S == ('FRY'):
    print(2)
elif S == ('SAT'):
    print(1)
else:
    print('入力に誤りがあります。SUN,MON,TUE,WED,THU,FRI,SATのいずれかを入力してください。')
# Judge status: Wrong Answer
n = int(input())

INF = 10**10
dp = [INF] * (n + 1)
dp[0] = 0
dp[1] = 1

num_list = [1]

for i in range(1, 9):
    n1 = 6**i
    n2 = 9**i
    if n1 < n:
        num_list.append(n1)
    if n2 < n:
        num_list.append(n2)

for i in range(1, n):
    for j in num_list:
        if i + j <= n:
            dp[i+j] = min(dp[i+j], dp[i] + 1)

print(dp[n])
# Judge status: Accepted
def f(s,t): return t in (s + s)
print 'Yes' if f(raw_input(),raw_input()) else 'No'
# Judge status: Accepted
def is_even_string(x):
    return x[:len(x)//2] == x[len(x)//2:]

s = input()

for i in range(len(s)-2,0,-2):
    sub=s[:i]
    if is_even_string(sub):
        print(len(sub))
        break
# Judge status: Accepted
n = int(input())
p = list(map(int, input().split()))

def bubble(input_list):
    cnt = 0
    flg = 0
    for i in range(len(input_list)):
        if i+1 != input_list[i]:
            cnt +=1
            flg = 1
    if flg == 1:
        return False, cnt
    else:
        return True, 0
a, b = bubble(p)

if b <= 2:
    print("YES")
else:
    print("NO")
# Judge status: Accepted
n, a, b, c, d = map(int, input().split())

s = input()

if c < d:
    if "##" in s[a-1:c] or "##" in s[b-1:d]:
        print("No")
    else:
        print("Yes")
else:
    if "..." in s[b-2:d+1] and "##" not in s[a-1:c] and "##" not in s[b-1:d]:
        print("Yes")
    else:
        print("No")
# Judge status: Accepted
S = input()
# シンプルに文字列のままでok
if '7' in S:
    print('Yes')
else:
  print('No')
# Judge status: Accepted
N = int(input())
L = list(map(int, input().split()))

import bisect

L.sort()
# print(L)

ans = 0
for i in range(0, N-1):
    for j in range(i+1, N-1):
        ix = bisect.bisect_left(L, L[i] + L[j])
        ans += max(0, ix - j - 1)

print(ans)
# Judge status: Wrong Answer
import sys
import copy
li1=list()
li2=list()
N=int(input())
for i in range(N):
  A,B=map(int,input().split())
  li1.append(B)
  li2.append(A)
L=copy.copy(li1)
L=sorted(set(L))
li2 = [[li2[i1] for i1 in range(len(li1)) if li1[i1] == idx] for idx in sorted(set(li1))]
for i in range(len(L)):
  if L[i]<sum(li2[i]):
    print("No")
    sys.exit()
print("Yes")
# Judge status: Wrong Answer
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n = int(input())
d = sorted(list(map(int, input().split())))

diff = d[n//2:][0] - d[:n//2][-1]
if diff <= 1:
    print(0)
else:
    print(diff)
# Judge status: Accepted
n=int(input())
s=input()
t=sorted(s)
t.append("X")
cnt=1
ans=1
for i in range(n):
    if t[i]==t[i+1]:
        cnt+=1
    else:
        ans*=(cnt+1)
        cnt=1
print((ans-1)%(10**9+7))
# Judge status: Wrong Answer
N = int(input())
A = list(map(int, input().split()))

eight = 0
one = 0
two = 0


for i in A:
    print(i%4)
    if i%4 == 0:
        eight = eight + 1
    if i == 1:
        one = one + 1
    if i%2 == 0:
        two = two + 1

if len(A)//2 <= eight:
    print("Yes")
elif (len(A)//2) <= (eight + (two//2)):
    print("Yes")

elif (eight >= one) and (eight + one +(two//2)) > (len(A)//2):
    print("Yes")
elif (two//2) == len(A):
    print("Yes")
else:
    print("No")
# Judge status: Wrong Answer
n = int(input())
if n >= 105:
    print(1)
else:
    print(0)
# Judge status: Wrong Answer
n=int(input())
print(n*(n+1)/2)
# Judge status: Accepted
n = int(input())
if n%10 in [2,4,5,7,9]:
    print("hon")
elif n%10 in [0,1,6,8]:
    print("pon")
else:
    print("bon")
# Judge status: Accepted
import math
h=int(input())
w=int(input())
n=int(input())
k=max(h,w)
print(math.ceil(n/k))
# Judge status: Accepted
import numpy as np


n, d = map(int ,input().split())
x = []
sq = [i**2 for i in range(200)]
for i in range(n):
    x.append(list(map(int, input().split())))
x = np.array(x)
count = 0
for i in range(n):
    for j in range(i+1, n):
        if sum((x[i]-x[j])**2) in sq:
            count += 1
print(count)
# Judge status: Wrong Answer
n,b = map(int,input().split())
if n >= 13:
  print(n)
elif n <= 5:
  print(0)
else:
  print(b//2)
# Judge status: Accepted
N = int(input())
A = list(map(int, input().split()))

Q = int(input())

count = [0] * (10**5 + 1)
for a in A:
    count[a-1] += 1

s = sum(A)
ans = []
for i in range(Q):
    a, b = map(int, input().split())

    s = s - a * count[a-1] + b * count[a-1]
    ans.append(s)
    count[b-1] += count[a-1]
    count[a-1] = 0

print(*ans, sep="\n")
# Judge status: Wrong Answer
s = input()

ans=0
for i in range(len(s)-1):
    ch=0
    for j in range(i,len(s)):
        if s[j] in 'ACGT':
            ch+=1
        else:
            ans=max(ans,ch)
            ch=0
        ans=max(ans,ch)
print(ans)
# Judge status: Accepted
a,b=map(int,input().split())
if a>=13:
    print(b)
elif a<=5:
    print(0)
else:
    print(b//2)
# Judge status: Wrong Answer
s=input()
n = len(s)

tt = 0
while(s[tt]=="T"):
    tt+=1
    
ss=n
while(s[ss-1]=="S"):
    ss -= 1
print(max(tt, n-ss)*2)
# Judge status: Wrong Answer
X, N = map(int, input().split())
if N == 0:
    print(X)
    quit()
p = set(map(int, input().split()))
not_p = sorted(set(range(1, 101)) - p)
ans = 0
minval = 101
for i in not_p:
    if minval > abs(X - i):
        minval = abs(X - i)
        ans = i
print(ans)
# Judge status: Accepted
S = input()
T = input()

l = len(T)

ind = 51
for i in range(len(S)-l+1):
    flag = 0
    for j in range(l):
        if S[i+j]!='?' and S[i+j]!=T[j]:
            flag = 1
    if flag==0:
        ind = i

if ind == 51:
    print('UNRESTORABLE')
    exit()

print(S[:ind].replace('?','a')+T+S[ind+l:].replace('?','a'))
# Judge status: Accepted
x,y,u,v=map(int,input().split())

p=u-x
q=v-y

S="U"*q+"R"*p+"D"*q
S+="L"*(p+1)+"U"*(q+1)+"R"*(p+1)+"D"+"R"+"D"*(q+1)+"L"*(p+1)+"U"
print(S)
# Judge status: Wrong Answer
import sys
input = sys.stdin.readline
 
x = int(input())
 
print(x * 2 // 11 + 1) if x * 2 % 11 <= 6 else print(x * 2 // 11 + 2)
# Judge status: Accepted
from collections import defaultdict
import math
import numpy as np
N, X, Y = map(int, input().split(' '))
d = defaultdict(int)
for i in range(1, N):
    for k in range(i+1, N+1):
        if(k < X):
            ans = k-i
            d[ans] += 1
        else:
            ans = min(k-i, abs(Y-k)+1+abs(i-X))
            d[ans] += 1

for i in range(1, N):
    print(d[i])
# Judge status: Accepted
def main():
    from itertools import zip_longest
    n, *a = map(lambda x: bin(int(x))[2:][::-1], open(0).read().split())
    n = int('0b' + n[::-1], 2)

    mod = 10 ** 9 + 7
    ans = 0
    
    for i, j in enumerate(zip_longest(*a)):
        o = j.count('1')
        z = n - o
        ans += z * o * pow(2, i, mod)
        ans %= mod

    print(ans)


if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
N = list(input())
print("Yes" if N[0] == 9 or N[1] == 9 else "No")
# Judge status: Accepted
a,b,c,k = map(int,input().split())


if k<=a :
 print(k)
elif  k< a+b:
 print(a)
else:
 print(2*a+b-k)
# Judge status: Accepted
s = int(input())


def f(n):
    if n % 2 == 0:
        return n // 2
    else:
        return 3 * n + 1


p = {s: 1}
m = 1
while True:
    s = f(s)
    m += 1
    if s in p:
        print(m)
        break
    else:
        p[s] = m
# Judge status: Accepted
#!/usr/bin/env python3

import sys
sys.setrecursionlimit(10**6)

def main():
    N = int(input())
    def calcSumOfDigit(x):
        str_x = str(x)
        acc = 0
        for s in str_x:
            acc += int(s)
            acc %= 9
        return acc
    
    print("Yes" if calcSumOfDigit(N)==0 else "No")
    return


if __name__ == '__main__':
    main()
# Judge status: Accepted
n = int(input())
p = list(map(int, input().split()))
cnt = 0
for i in range(n-2):
  if sum(p[i:i+3])-min(p[i:i+3])-max(p[i:i+3]) ==  p[i+1]:
    cnt += 1
print(cnt)
# Judge status: Wrong Answer
import sys
import os


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = int(sys.stdin.readline().rstrip())
    ret = 0
    for b in range(1, N):
        for p in range(2, N):
            if b ** p <= N:
                ret = max(ret, b ** p)

    print(ret)


if __name__ == '__main__':
    main()
# Judge status: Accepted
# https://atcoder.jp/contests/abc146/tasks/abc146_a

S = input()
week_list =  ['SUN','MON','TUE','WED','THU','FRI','SAT']

S_week = week_list.index(S)

ans = 7 - S_week

print(ans)
# Judge status: Accepted
import math
if __name__ == "__main__":
    n = int(input())
    ans = 0
    for i in range(1,n+1):
        for j in range(1,n+1):
            tmp = math.gcd(i,j)
            for k in range(1,n+1):
                ans += math.gcd(tmp,k)

    print(ans)
# Judge status: Accepted
import fractions as f
n,m=map(int,input().split())
a=list(map(int,input().split()))
g=1
def check(n):
  cnt=0
  while n%2==0:
    n//=2
    cnt+=1
  return cnt
chk=check(a[0])
for i in a:
  if chk!=check(i):
    print(0)
    exit()
  else:
    chk=check(i)
for i in range(n):
  g=g*(a[i]//2)//(f.gcd(g,a[i]//2))
  if g>m:print(0);exit()
print(m//g-m//(2*g))
# Judge status: Accepted
from numba import jit
import math

N, K = map(int,input().split())
h = list(map(int,input().split()))
@jit
def nya(N, K, h):
  dp=[0]*N
  for i in range(1,N):
    value=math.inf
    for j in range(1,K+1):
      if i-j<0:
        break
      value=min(value,dp[i-j]+abs(h[i]-h[i-j]))
    dp[i]=value
  return(dp[N-1])
 
print(nya(N,K,h))
# Judge status: Wrong Answer
N = list(input())
N.insert(0, '')
even = N[2::2]
odd = N[1::2]
print(odd, even)
if ('R' in even or 'L' in odd):
    print('No')
else:
    print('Yes')
# Judge status: Accepted
n = input()

# 上の段:その桁をピッタリ払った, 下の段:その桁を払わなかった(上の桁で1多く払った)
dp = [[0 for i in range(len(n))] for j in range(2)]

dp[0][0] = int(n[0])
dp[1][0] = 1 + 10 - int(n[0])

for i in range(1, len(n)):
    dp[0][i] = min(dp[0][i-1], dp[1][i-1]) + int(n[i])
    dp[1][i] = min(dp[0][i-1]+1+10-int(n[i]), dp[1][i-1]-1+10-int(n[i]))

print(min(dp[0][len(n)-1], dp[1][len(n)-1]))
# Judge status: Wrong Answer
import sys

n, T, *ct = map(int, sys.stdin.read().split())
ct = zip(*[iter(ct)] * 2)

def main():
    res = float('inf')
    for c, t in ct:
        if t <= T:
            res = min(res, c)
    
    return res

if __name__ == '__main__':
    ans = main()
    print(ans)
# Judge status: Wrong Answer
n, k = map(int, input().split())
a = list(map(int, input().split()))
ans = 10**10
for i in range(n-k+1):
    if a[i] >= 0:
        tmp = a[k+i-1]
    else:
        tmp = a[k+i-1] - 2*a[i]
    if ans > tmp:
        ans = tmp
print(ans)
# Judge status: Wrong Answer
s = input()

a = int(s[6])

if a >= 5:
  print('TBD')
else:
  print('Heisei')
# Judge status: Wrong Answer
a,b = map(int,input().split())
S = []
tmp = 0
for i in range(1,1000):
    tmp += i
    S.append(tmp)

for i in S:
    if a < i and i <= b:
        print(i-a)
        break
# Judge status: Accepted
first = input().split(' ')
skills_count = int(first[1])

second = input().split(' ')
healths = [int(s) for s in second]
healths.sort(reverse=True)

print(sum(healths[skills_count:]))
# Judge status: Accepted
import sys
input = sys.stdin.readline

N = int(input())
A = [[None]*2 for i in range(N)]
for i in range(N):
    A[i][1],A[i][0] = map(int,input().split())

A.sort()

zum = 0
now = 0
for i in range(N):
    zum += A[i][1]
    now = A[i][0]
    if zum > now:
        print("No")
        break
else:
    print("Yes")
# Judge status: Accepted
N, X, Y = map(int,input().split())
X = X-1
Y = Y-1
CNT = [0]*(N)
for i in range(N):
  for j in range(i+1,N):
    nn1 = j-i
    nn2 = abs(i-X)+abs(j-Y)+1
    if nn1>nn2:
      CNT[nn2] += 1
    else:
      CNT[nn1] += 1
for i in range(1,N):
  print(CNT[i])
# Judge status: Accepted
n = int(input())
for i in range(n, 1000):
    n_s = str(i)
    if n_s[0] == n_s[1] == n_s[2]:
        print(i)
        exit()
# Judge status: Accepted
N,M = map(int, input().split())
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]

ans = "No"
for i in range(N-M+1):
    for j in range(N-M+1):
        flag = True
        for k in range(M):
            for l in range(M):
                if A[i+k][j+l] != B[k][l]:
                    flag = False
                    break
        if flag:
            ans = "Yes"
            break
print(ans)
# Judge status: Accepted
N, D = map(int, input().split())
X = [0]*N
for i in range(N):
  X[i] = list(map(int, input().split()))
cnt = 0
for i in range(N):
  for j in range(i+1,N):
    prod = 0
    for p in range(D):
      prod += (X[i][p]-X[j][p])**2
    prod **= 0.5
    if prod==int(prod):
      cnt += 1
print(cnt)
# Judge status: Wrong Answer
s=input()
n=len(s)//2
while n!=0:
  
  if s[:n]==s[n:2*n]:
    print(2*n)
    break
  n=-1
# Judge status: Accepted
N=int(input())
S=input()

ans=0
for i in range(N):
    X=S[0:i]
    Y=S[i:N] 
    XY=set(X) & set(Y)
    cnt=len(XY)
    ans=max(ans,cnt)

print(ans)
# Judge status: Accepted
import sys
sys.setrecursionlimit(500000)
MOD = 10**9+7

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

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    N = ii()
    ans = 1
    for i in range(1, N+1):
      ans *= i
      ans %= MOD
    print(ans)


if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
n, m = map(int, input().strip().split())

num = [0]*n
nn = []
WA = 0
AC = 0

for i in range(m):
  text = input().strip().split()
  p = int(text[0])
  s = text[1]
  
  if p not in nn:
    if s == 'AC':
      AC += 1
      nn.append(p)
    elif s == 'WA':
      num[p-1] += 1
      
for i in range(len(nn)):
    WA += num[i-1]
    
print(AC, WA)
# Judge status: Wrong Answer
from collections import Counter
def solve():
    N = int(input())
    A = list(map(int, input().split()))
    counter = Counter(A)

    mx = -1
    for i in range(1,10):
        sm = counter[i-1]+counter[i]+counter[i+1]
        mx = max(sm,mx)
        
    print(mx)

if __name__ == '__main__':
    solve()
# Judge status: Accepted
x,y,z=map(int,input().split());print((x-z)//(y+z))
# Judge status: Accepted
from collections import Counter

N=int(input())
A=[input() for _ in range(N)]

M=int(input())
B=[input() for _ in range(M)]

a=Counter(A)
b=Counter(B)

ans=0
for p in A:
    ans=max(ans,a[p]-b[p])
    
print(ans)
# Judge status: Accepted
a, b, c = map(int, input().split())
count = 0
while a % 2 == 0 and b % 2 == 0 and c % 2 == 0:
    if a == b and b == c and c == a:
        count = -1
        break
    a_tmp = a
    b_tmp = b
    c_tmp = c
    a = (b_tmp + c_tmp) / 2
    b = (c_tmp + a_tmp) / 2
    c = (a_tmp + b_tmp) / 2
    count += 1
print(count)
# Judge status: Accepted
from collections import Counter

S = list(input())

tmp = Counter(S)

cnt = tmp.most_common()
cnt.append(("null", 0))

print(cnt[1][1] * 2)
# Judge status: Wrong Answer
n = int(input())

a = []
b = []

for i in range(n):
    A, B = map(int,input().split())
    a.append(A)
    b.append(B)

a.sort()
b.sort()

right = 0
left = 0

ans = 0

if n%2 == 0:
    right = b[n//2 + 1 -1]
    left = a[n//2 -1]
    ans = 2*(right-left)-1
else:
    right = b[(n+1)//2 -1 ]
    left = a[(n+1)//2 -1]
    ans = right -left +1

print(ans)
# Judge status: Accepted
n = list(map(int,input().split()))
n.sort()
if n[0] + n[1] == n[2]:
    print("Yes")
else:
    print("No")
# Judge status: Wrong Answer
# input
S = list(input())
N = len(S)

# check
cnt = 0
del_ind = []
append = del_ind.append

for i in range(0, N):
    if "".join(S[i:i + 2]) in ["01", "10"]:
        cnt += 2
        N -= 2
        del S[i:i + 2]
print(cnt)
# Judge status: Accepted
import collections

def main():
    S = list(input())
    Scount = collections.Counter(S)
    a = Scount['a']; b = Scount['b']; c = Scount['c']
    if abs(a-b) <= 1 and abs(b-c) <= 1 and abs(c-a) <= 1:
        print('YES')
    else:
        print('NO')

if __name__ == "__main__":
    main()
# Judge status: Accepted
n = int(input())
f_inf = float('inf')
dp = [f_inf]*(n+1)
dp[0] = 0
for i in range(1,n+1):
  for j in range(7):
    if i-pow(6,j) >= 0:
      dp[i] = min(dp[i], dp[i-pow(6,j)]+1)
  for k in range(6):
    if i-pow(9,k) >= 0:
      dp[i] = min(dp[i], dp[i-pow(9,k)]+1)
print(dp[-1])
# Judge status: Wrong Answer
s=input()
print(min(s[::2].count("1")+s[1::2].count("0"),s[::2].count("0")+s[::1].count("0")))
# Judge status: Accepted
N, X = map(int, input().split())

ARR = list(map(int, input().split()))


def calculate(n, x, arr):
    result = 0
    for i in range(1, n):
        sSum = arr[i - 1] + arr[i]
        if sSum <= x:
            continue

        diff = sSum - x

        if diff <= arr[i]:
            arr[i] -= diff
            result += diff
        else:
            result += diff
            arr[i] = 0

    print(result)


calculate(N, X, ARR)
# Judge status: Accepted
s = input()
ca = []
cz = []
ans = 0
for i in range(len(s)):
    if s[i] == "A":
        ca.append(i)
    if s[i] == "Z":
        cz.append(i)
ans = max(cz)-min(ca)+1
print(ans)
# Judge status: Accepted
def main():
    N = int(input())
    A = list(map(int,input().split()))
    for a in A:
        if a % 2 == 0:
            if a % 3 == 0 or a % 5 == 0:
                continue
            else:
                print("DENIED")
                exit()
    print("APPROVED")

if __name__ == "__main__":
    main()
# Judge status: Accepted
li = list(map(int,input().split()))

print('YES' if (li[0] * 100 + li[1] * 10 + li[2]) % 4 == 0 else 'NO')
# Judge status: Wrong Answer
n = int(input())
H = list(map(int, input().split()))

tmp = H[0]
cnt = 1
ans = 0
Ans = []
for h in H[1:]:
    if tmp >= h:
        cnt += 1
    else:
        ans, cnt = cnt, 0
    tmp = h
    ans = max(ans, cnt)
print(ans)
# Judge status: Accepted
a,b,c=map(int,input().split())
if b-a == c-b:
  print('YES')
else:print('NO')
# Judge status: Wrong Answer
n=int(input())
c=list(input())
ans=0
flag=0
for i in c:
  if i=="W":
    flag+=1
  elif flag==0 and i=="R":
    pass
  else:
    flag-=1
    ans+=1
cnt=0
for i in range(n-1):
  if c[i]=="W" and c[i+1]=="R":
    cnt+=1
print(ans-cnt//2)
# Judge status: Accepted
N = int(input())
ans = 1
A = list(map(int, input().split()))
prev = A[0]
trend = 0
for a in A[1:]:
    if (a - prev) * trend < 0:
        ans += 1
        trend = 0
    elif trend == 0:
        if a - prev > 0:
            trend = 1
        elif a - prev < 0:
            trend = -1
    prev = a
print(ans)
# Judge status: Accepted
import sys
N, M = map(int, input().split())
A = list(map(int, input().split()))
card = [ list(map(int, i.rstrip().split())) for i in sys.stdin.readlines()]
card = sorted(card, key=lambda x:x[1], reverse=True)
A = sorted(A)
i = 0
for b, c in card:
  for _ in range(b):
    if i >= N:
      break
    elif A[i] >= c:
      break
    else:
      A[i] = c
      i += 1
print(sum(A))
# Judge status: Accepted
n = int(input())
a = list(map(int,input().split()))
raw = [0 for _ in range(3*10**5)]
for x in a:
  raw[x] += 1
ans = 0
for y in raw:
  ans += y * (y-1) // 2
for x in a:
  tmp = int(ans)
  tmp -= raw[x] - 1
  print(tmp)
# Judge status: Wrong Answer
x, a, b = map(int, input().split())
print("A" if abs(x-a)<(x-b) else "B")
# Judge status: Accepted
def main():
    n,m=map(int,input().split())
    if n%2==1:
        x=[f"{i+1} {n-i}" for i in range(m)]
        print(" ".join(x))
    else:
        x=[f"{i+1} {n-i}" if i<m/2 else f"{i+1} {n-i-1}" for i in range(m)]
        print(" ".join(x))

if __name__ == "__main__":
    main()
# Judge status: Accepted
N = int(input())
s = 0
j = 1
for i in range(1, N+1):
	s += i
	if s >= N:
		j = i
		break
k = s - N
for i in range(1, j+1):
	if i == k: continue
	print(i)
# Judge status: Wrong Answer
import math

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

if n>=b:
	n1 = n//b*b-1
	ans = max((a*n//b)-a*(n//b), (a*n1//b)-a*(n1//b))
else:
	ans = (a*n//b)-a*(n//b)
print(ans)
# Judge status: Accepted
n=int(input())
a=list(map(int, input().split()))
two=0
four=0

for i in a:
    if i%4==0:
        four+=1
    elif i%2==0:
        two+=1
        
if 2*four+two>=n or 2*four+1>=n:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
import sys
from bisect import *
from heapq import *
from collections import *
from itertools import *
from functools import *

sys.setrecursionlimit(100000000)
input = lambda: sys.stdin.readline().rstrip()

S = input()
print('Good' if all(i != j for i, j in zip(S, S[1:])) else 'Bad')
# Judge status: Accepted
X,K,D=map(int,input().split())

if X < 0:
    X=-X
    
a=X//D
if a >= K:
    print(X-D*K)
else:
    if X%D<D-X%D:
        if (K-a)%2 == 0:
            print(X%D)
        else:print(D-X%D)
    else:
        if (K-(a+1))%2==0:
            print(D-X%D)
        else:print(X%D)
# Judge status: Accepted
from collections import Counter
s=input()
n=len(s)
ans=0
arr=[0]*(n+1)
if s=='0':
    print(1)
    exit()
elif n==1:
    print(0)
    exit()
for i in reversed(range(n)):
    arr[i]=(arr[i+1]+int(s[i])*pow(10,n-i-1,2019))%2019
m=Counter(arr)
for j in m.keys():
    ans+=m[j]*(m[j]-1)//2
print(ans)
# Judge status: Accepted
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
#import numpy as np
def main():
    n = int(input())
    if n == 1:
        print(1)
        sys.exit()
    r = 0
    for i1 in range(1, n + 1):
        num_of_div = n // i1
        r += num_of_div * (num_of_div + 1) // 2 * i1
    print(r)

if __name__ == '__main__':
    main()
# Judge status: Accepted
n, m = map(int, input().split())
Scc = min(n, m//2)
cccc = (m-Scc*2)//4
print(Scc+cccc)
# Judge status: Wrong Answer
n=int(input())
a=int(input())

if n>=500:
    n=n//500

if n<=a:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
n, m = map(int, input().split())
store = [[0, 0] for i in range(n)]
for i in range(n):
    store[i] = list(map(int, input().split()))
store.sort(key=lambda x:(x[0],x[1]))
count = m
money = 0
for el in store:
    a, b = el
    if count <= b:
        money += a*count
        break
    else:
        count -= b
        money += a*b
print(money)
# Judge status: Accepted
n,m = map(int,input().split())
if n > m:
    n,m = m,n
if n == 1 and m == 1:
    print(1)
elif n == 1 and m > 1:
    print(m-2)
else:
    print((n-2)*(m-2))
# Judge status: Accepted
a,b = map(int,input().split())
print(sum(range(b-a))-a)
# Judge status: Accepted
k, a, b = map(int, input().split())

if a + 2 > b or k < a:
    print(k + 1)
else:
    k -= (a - 1)
    have = a
    div, mod = divmod(k, 2)
    print((b - a) * div + a + mod)