Harryxun/stf_run huggingface dataset:
N, C, D = map(int, input().split())
check = [i*i for i in range(N)]
time = 0
stop = N * N

if C * D % 2 ==1:
 for i in range(2*N):
  for j in range(2*N):
   if (i + j) % 2 == 0:
    print(i, j)
    time += 1
    if stop == time:
     break
  if stop == time:
   break
elif (C+D) % 2 == 0:
 for i in range(2*N):
  for j in range(2*N):
   if (i + j) % 2 == 1:
    print(i, j)
    time += 1
    if stop == time:
     break
  if stop == time:
   break
else:
 for i in range(2*N):
  for j in range(2*N):
   if (i + j) % 2 == 0:
    if C % 2 == 1:
     if D - j * j not in check:
      print(i, j)
      time += 1
      if stop == time:
       break
    else:
     if C - j * j not in check:
      print(i, j)
      time += 1
      if stop == time:
       break
   if stop == time:
    break


### FIXED CODE ###

N = int(input())
while(N%10 == 0):
 N /= 10
if N == 1:
 print(10)
else:
 s = str(N)
 array = list(map(int, list(s)))
 print(sum(array))
import sys
d={' ':'101',"'":'000000',',':'000011','-':'10010001','.':'010001','?':'000001','A':'100101','B':'10011010','C':'0101','D':'0001','E':'110',
'F':'01001','G':'10011011','H':'010000','I':'0111','J':'10011000','K':'0110','L':'00100','M':'10011001','N':'10011110','O':'00101','P':'111',
'Q':'10011111','R':'1000','S':'00110','T':'00111','U':'10011100','V':'10011101','W':'000010','X':'10010010','Y':'10010011','Z':'10010000'}
for e in sys.stdin:
 a=''.join(d[c]for c in e.strip())
 l=len(a)+4
 #b=a.ljust(l//5*5,'0')
 b=a+'0'*(-len(a)%5)
 print(''.join("ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?"[int(b[i:i+5],2)]for i in range(0,l,5)))


### FIXED CODE ###

import sys
d={' ':'101',"'":'000000',',':'000011','-':'10010001','.':'010001','?':'000001','A':'100101','B':'10011010','C':'0101','D':'0001','E':'110',
'F':'01001','G':'10011011','H':'010000','I':'0111','J':'10011000','K':'0110','L':'00100','M':'10011001','N':'10011110','O':'00101','P':'111',
'Q':'10011111','R':'1000','S':'00110','T':'00111','U':'10011100','V':'10011101','W':'000010','X':'10010010','Y':'10010011','Z':'10010000'}
for e in sys.stdin:
 a=''.join(d[c]for c in e[:-1])
 a+='0'*(-len(a)%5)
 print(''.join("ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?"[int(a[i*5:i*5+5],2)]for i in range(len(a)//5)))
import sys
values = []
for line in sys.stdin:
    values.append(int(line))
ans = [1 for i in range(10) for j in range(10) for k in range(10) for l in range(10) if n == i + j + k + l]
print(ans.count(1))

### FIXED CODE ###

import sys
values = []
for line in sys.stdin:
    values.append(int(line))
    
for v in values:
    ans = [1 for i in range(10) for j in range(10) for k in range(10) for l in range(10) if v == i + j + k + l]
    print(ans.count(1))
S = input()
Q = int(input())

# print(S, Q)

queries = []
for i in range(Q):
    query = input()
    queries.append(query)

from collections import deque
slist = deque()
slist.append(S)
isReversed = False
for query in queries:
    if query == "1":
        isReversed = not isReversed
    else:
        t, f, c = query.split()
        if f == '1':
            if isReversed:
                slist.append(c)
            else:
                slist.appendleft(c)
        else:
            if isReversed:
                slist.appendleft(c)
            else:
                slist.append(c)
# slist = list(slist)
if isReversed:
    slist.reverse()

print("".join(slist))
# print(S)

### FIXED CODE ###

S = input()
if S == "AAA" or S=="BBB":
    print("No")
else:print("Yes")
import math

a, b, x = [int(v) for v in input().split(' ')]

l1 = x / (a * a)
l2 = b - l1

tan2 = (a / 2) / l2
rad2 = math.atan(tan2)

if l1 >= l2:
    tan = l2 / (a / 2)
    print(90 - math.degrees(math.atan(tan)))
else:
    tan1 = (a / 2) / l1
    rad1 = math.atan(tan1)
    if rad1 <= rad2:
        tan = l2 / (a / 2)
        print(90 - math.degrees(math.atan(tan)))
    else:
        tan3 = (2 * x) / (a * b * b)
        print(90-math.degrees(math.atan(tan3)))


### FIXED CODE ###

import math

a, b, x = [int(v) for v in input().split(' ')]


if a * a * b / 2.0 <= x:
    l = b - (x / (a * a))
    tan = l / (a / 2)
    print(math.degrees(math.atan(tan)))
else:
    tan = (2 * x) / (a * b * b)
    print(90-math.degrees(math.atan(tan)))
import sys
n = int(input())
a = list(map(int,input().split()))

dp = [sys.maxsize]*n
dp[0]=0

for i in range(n):
	for j in range(i+1,i+2+1):
      if j<n:
        dp[j] = min(dp[j],dp[i]+abs(a[i]-a[j]))
        
print(dp[n-1])

### FIXED CODE ###

import sys
n = int(input())

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

dp = [sys.maxsize]*n
dp[0] = 0
for i in range(n):
  for j in range(i+1,i+2+1):
    if j<n:
      dp[j]= min(dp[j],dp[i]+abs(a[i]-a[j]))
      
      
print(dp[n-1])
from itertools import permutations, compress

N = int(input())
S = input()

targets = tuple(f"{i:0>3}" for i in range(1000))
ans = []
for target in targets:
    a, b, c = target
    a_index = S.find(a)
    b_index = S.find(b, a_index + 1)
    c_index = S.find(c, b_index + 1)
    ret = (a_index, b_index, c_index)
    if -1 not in ret:
        # print(target, ret)
        ans.append(ret)
print(len(ans))

### FIXED CODE ###

N = int(input())
S = input()

targets = tuple("{:0>3}".format(i) for i in range(1000))
ans = []
for target in targets:
    a, b, c = target
    a_index = S.find(a)
    b_index = S.find(b, a_index + 1)
    c_index = S.find(c, b_index + 1)
    ret = (a_index, b_index, c_index)
    if -1 not in ret:
        # print(target, ret)
        ans.append(ret)
print(len(ans))
N = int(input())
total = 0
for i in range(1, N+1):
  if （i%3) !=0 and (i%5) !=0:
    total += i
print(total)


### FIXED CODE ###

N = int(input())
total = 0
for i in range(1, N+1):
  if (i%3) != 0 and (i%5) != 0:
    total =  total + i
print(total)
import copy 

def gcd(a,b):
    if b > a:
        a, b = b, a
    while b:
        a, b = b, a%b
    return a

N = int(input())
T = list(map(int,input().split()))
LIS = [0]*N
LIS[0] += T[0]
for i in range(N-1):
    LIS[i+1] += gcd(LIS[i],T[i+1])
F = LIS.index(min(LIS))
if F == 0:
    U = copy.copy(T)
    V = copy.copy(T)
    U.pop(1)
    V.pop(0)
    LU = [0]*(N-1)
    LU[0] = U[0]
    LV = [0]*(N-1)
    LV[0] = V[0]
    ANSU = 0
    ANSV = 0
    for i in range(N-2):
        LU[i+1] += gcd(LU[i],U[i+1])
    ANSU = LU[N-2]
    for i in range(N-2):
        LV[i+1] += gcd(LV[i],V[i+1])
    ANSV = LV[N-2]
    ANSP = max(ANSU,ANSV)
    ANS = max(ANSP,LIS[N-1])
    
if F == 0 or F == 1:
    U = copy.copy(T)
    V = copy.copy(T)
    U.pop(F)
    V.pop(0)
    LU = [0]*(N-1)
    LU[0] = U[0]
    LV = [0]*(N-1)
    LV[0] = V[0]
    ANSU = 0
    ANSV = 0
    for i in range(N-2):
        LU[i+1] += gcd(LU[i],U[i+1])
    ANSU = LU[N-2]
    for i in range(N-2):
        LV[i+1] += gcd(LV[i],V[i+1])
    ANSV = LV[N-2]
    ANSP = max(ANSU,ANSV)
    ANS = max(ANSP,LIS[N-1])
        
print(ANS)

### FIXED CODE ###

import copy 

def gcd(a,b):
    if b > a:
        a, b = b, a
    while b:
        a, b = b, a%b
    return a

N = int(input())
T = list(map(int,input().split()))
T.sort()
LIS = [0]*N
LIS[0] += T[0]
for i in range(N-1):
    LIS[i+1] += gcd(LIS[i],T[i+1])
F = LIS.index(min(LIS))
if len(T) == 2:
    ANS = max(T[0],T[1])
elif F == 0:
    U = copy.copy(T)
    V = copy.copy(T)
    U.pop(1)
    V.pop(0)
    LU = [0]*(N-1)
    LU[0] = U[0]
    LV = [0]*(N-1)
    LV[0] = V[0]
    for i in range(N-2):
        LU[i+1] += gcd(LU[i],U[i+1])
    ANSU = LU[N-2]
    for i in range(N-2):
        LV[i+1] += gcd(LV[i],V[i+1])
    ANSV = LV[N-2]
    ANS = max(ANSU,ANSV)
    
else:
    U = copy.copy(T)
    V = copy.copy(T)
    U.pop(F)
    V.pop(0)
    LU = [0]*(N-1)
    LU[0] = U[0]
    LV = [0]*(N-1)
    LV[0] = V[0]
    ANSU = 0
    ANSV = 0
    for i in range(N-2):
        LU[i+1] += gcd(LU[i],U[i+1])
    ANSU = LU[N-2]
    for i in range(N-2):
        LV[i+1] += gcd(LV[i],V[i+1])
    ANSV = LV[N-2]
    ANSP = max(ANSU,ANSV)
    ANS = max(ANSP,LIS[N-1])
        
print(ANS)
K,S = map(int,input().split())

ans = 0

for x in range(K + 1):
  for y in range (K + 1):
    z = S - (x + y)
    if 0 <= z <= k:
      ans += 1

print(ans)



### FIXED CODE ###

K,S = map(int,input().split())

ans = 0

for x in range(K + 1):
  for y in range (K + 1):
    z = S - (x + y)
    if 0 <= z <= K:
      ans += 1

print(ans)
import math

a,b,c,d = map(int,input().split(" "))
dif = 0
plus = 0
lcm = c * d // math.gcd(c,d)
e = b + 1 - a

dif += b // c - (a - 1) // c
dif += b // d - (a - 1) // d
if c != d:
    plus += b // lcm - (a -1) // lcm

print(e - dif + plus)


### FIXED CODE ###

a,b,c,d = map(int,input().split(" "))
dif = 0
plus = 0

gcd = c
t = d
while t:
    gcd, t = t, gcd % t

lcm = c * d // gcd
e = b + 1 - a

dif += b // c - (a - 1) // c
dif += b // d - (a - 1) // d
plus += b // lcm - (a -1) // lcm

print(e - dif + plus)
def inp():
    return input()
def iinp():
    return int(input())
def inps():
    return input().split()
def miinps():
    return map(int,input().split())
def linps():
    return list(input().split())
def lmiinps():
    return list(map(int,input().split()))
def lmiinpsf(n):
    return [list(map(int,input().split()))for _ in range(n)]

n = iinp()
q = lmiinps()

b = [0]*n
d = [0]*n

k = 1
l = 0
s = 0

a = sorted(q)
a.append(0)

from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

for i in range(n):
    if a[i] == a[i+1]:
        k += 1
    else:
        l = cmb(k,2)
        s += l
        b[a[i]-1]=l
        d[a[i]-1]=k
        k = 1

for j in q:
    if d[j-1] == 0:
        continue
    p = s-((b[j-1])-((b[j-1] *(d[j-1]-2)) // d[j-1]))
    print(p)

### FIXED CODE ###

def inp():
    return input()
def iinp():
    return int(input())
def inps():
    return input().split()
def miinps():
    return map(int,input().split())
def linps():
    return list(input().split())
def lmiinps():
    return list(map(int,input().split()))
def lmiinpsf(n):
    return [list(map(int,input().split()))for _ in range(n)]

n = iinp()
q = lmiinps()

k = 1
l = 0
s = 0

a = sorted(q)
a.append(0)

b = [0]*(a[n-1])
d = [0]*(a[n-1])

for i in range(n):
    if a[i] == a[i+1]:
        k += 1
    else:
        l = ((k*(k-1))//2)
        s += l
        b[a[i]-1]=l
        d[a[i]-1]=k
        k = 1

for j in q:
    p = s-((b[j-1])-((b[j-1] *(d[j-1]-2)) // d[j-1]))
    print(p)
h,w = map(int, input().split())
k = h*w
if (h-1)(w-1)==0:
  print(1)
else:
  print(k-int(k/2))


### FIXED CODE ###

h,w = map(int, input().split())
k = h*w
if (h-1)*(w-1)==0:
  print(1)
else:
  print(k-int(k/2))
import math

def bisearch(function, ok, ng):
    tmp = 0
    while abs(ok-ng) > 1:
        mid = (ok + ng)//2
        ans = function(mid)
        if ans > tmp:
            ok = mid
        else:
            ng = mid
        print("mid:{}".format(mid))
        tmp = ans
    return ok

def calc(x):
    return (math.floor(A*x/B) - A*math.floor(x/B))

A, B, N = map(int, input().split())
ok = N
ng = 0

# print(bisearch(calc, ok, ng))
ans = []
tmp = calc(1)
for i in range(1, min(N+1)):
    a = calc(i)
    ans.append(a)
    if tmp > a:
        break
    tmp = a

print(max(ans))

### FIXED CODE ###

import math

def calc(x):
    return (math.floor(A*x/B) - A*math.floor(x/B))

A, B, N = map(int, input().split())
print(calc(min(B-1, N)))
S=list(map(str,input()))
T=list(map(str,input()))
x=[]
y=0

for i in range(len(S)-len(T)):
    Y=S[i:i+len(T)]
    y=0
    for j in range(len(T)):
        if Y[j]==T[j]:
            y=y+1
    x.append(y)
print(len(T)-max(x)) 

### FIXED CODE ###

S=list(map(str,input()))
T=list(map(str,input()))
X=[]
Z=0
for I in range(len(S)-len(T)+1):
    Y=S[I:I+len(T)]
    Z=0
    for J in range(len(T)):
        if Y[J]==T[J]:
            Z=Z+1
    X.append(Z)
if not X==[]:
    print(len(T)-max(X))
elif S==T:
    print(0)
else:
    print(len(T))
N = int(input())
C = [-1]

prev = -1
for _ in range(N):
    c = int(input())
    if c == prev:
        continue
    else:
        C.append(c)
        prev = c

MOD = 10**9+7
n = len(C)
dp = [0]*(n+2)
last = [-1]*(N*2)
dp[0] = 1
for i in range(1, n):
    if last[C[i]] == -1:
        last[C[i]] = i
        dp[i] = dp[i-1]
    else:
        dp[i] = dp[i-1]+dp[last[C[i]]]
        dp[i] %= MOD
        last[C[i]] = i
print(max(dp))


### FIXED CODE ###

N = int(input())
C = [-1]

for _ in range(N):
    c = int(input())
    if c == C[-1]:
        continue
    else:
        C.append(c)

MOD = 10**9+7
dp = 1
prev = [0]*(max(C)+1)

for c in C[1:]:
    dp = (dp+prev[c]) % MOD
    prev[c] = dp
print(dp)
import bisect
n,K = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
ans = [0]
if K>2*n:
    K = 2*n
if K == 1:
    print(max(a[0],a[n-1],0))
    exit()
for k in range((K+1)//2,K+1):
    r = K-k
    for i in range(k+1):
        ls = a[:i]+a[n-k+i:]
        ls.sort()
        if r == 0:
            ans.append(sum(ls))
        elif ls[r-1]<0:
            ans.append(sum(ls[r:]))
        else:
            x = bisect.bisect_left(ls,0)
            ans.append(sum(ls[x:]))
print(max(ans))

### FIXED CODE ###

import bisect
n,K = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
ans = [0]
if K>2*n:
    K = 2*n
if K == 1:
    print(max(a[0],a[n-1],0))
    exit()
for k in range((K+1)//2,min(K+1,n+1)):
    r = K-k
    for i in range(k+1):
        ls = a[:i]+a[n-k+i:]
        ls.sort()
        if r == 0:
            ans.append(sum(ls))
        elif ls[r-1]<0:
            ans.append(sum(ls[r:]))
        else:
            x = bisect.bisect_left(ls,0)
            ans.append(sum(ls[x:]))
print(max(ans))
import time

x,y = map(int,input().split())
b = int(min(x,y))
a = int(max(x,y))

def gcd(a,b):
    if a % b != 0:
        r = a % b
        return gcd(b,r)
    else:
        print(b)

gcd(a,b)
		

### FIXED CODE ###

def lcd(a,b): ##return least common multiple of a and b
    if a > b:
        return lcd(a-b,b)
    elif a < b:
        return lcd(b-a,a)
    elif a == b:
        return a

a,b = map(int,input().split())
print(lcd(a,b))
m=int(input())
a=list(map(int,input().split()))
D=1
n=1

while n < m:
 if a[n] < max(a[0:n]):
  D=D 
  n=n+1
 else:
  D=D+1 
  n=n+1

print(D)

### FIXED CODE ###

a,b=map(int,input().split())
print(max(2*a-1,2*b-1,a+b))
# 初期入力
import sys
#input = sys.stdin.readline  #文字列では使わない
#S =input().strip()
*S, = input() 
count =0
flag =1
while len(S) >=2 and flag==1:
    flag =0
    l =len(S)
    for i in range(l -1):
        if S[i:i+2] ==["1","0"] or S[i:i+2] ==["0","1"]:
            #print(S[i:i+2])
            del S[i:i+2]
            print(S,end=" ")
            count +=2
            flag =1
            #break
    #print()
print(count)

### FIXED CODE ###

#計算でもとまるのか・・・
# 初期入力
import sys
#input = sys.stdin.readline  #文字列では使わない
#*S, = input() 
S =input().strip()
c1 =S.count("1")
c0 =S.count("0")
print(min(c0,c1)*2)
N = int(input())
X = [int(i) for i in input().split()]

for i in range(N):
    tmp = []
    once = True
    delnum = X[i]
    for j in range(len(X)):
        if X[j] == delnum and once:
            continue  
        else:
            tmp.append(X[j])
            once = False
    tmp = sorted(tmp)
    print(tmp[int((len(tmp)+1)/2)])

### FIXED CODE ###

import copy

N = int(input())
X = [int(i) for i in input().split()]
tmp = copy.deepcopy(X)

X = sorted(X)
for i in range(N):
    ans1 = X[int(len(X)/2)]
    ans2 = X[int(len(X)/2)-1]
    if tmp[i] < ans1:
        print(ans1)
    else:
        print(ans2)
d = int(input())

if (d ==25):
    print("Christmas")
else if (d==24):
    print("Christmas Eve")
else if (d==23):
    print("Christmas Eve Eve")
else:
    print("Christmas Eve Eve Eve")

### FIXED CODE ###

d = int(input())

if (d ==25):
    print("Christmas")
elif (d==24):
    print("Christmas Eve")
elif (d==23):
    print("Christmas Eve Eve")
else:
    print("Christmas Eve Eve Eve")
S = input()
if S == "ABC":
    print("ARC")
else:
    print("ABC"

### FIXED CODE ###

S = input()
if S == "ABC":
    print("ARC")
else:
    print("ABC")
n = int(input())
s = input()
dp = [0]*n
j = 1

for i in range(n):
    while S[i:j] in S[j:s]:
        j += 1
    dp[i] = j-i-1
print(max(dp))

### FIXED CODE ###

n = int(input())
s = input()
dp = [0]*n
j = 1

for i in range(n):
    while s[i:j] in s[j:n]:
        j += 1
    dp[i] = j-i-1
print(max(dp))
while True:
    n,x = map(int, raw_input().split()
    if n == 0 and x == 0: break
    c = 0
    for i in range(1, n/3 +1):
        for j in range(i+1, n/2 +1):
            ij = i + j
            for k in range(j+1, n+1):
                if ij+k == x:
                    c += 1
    print c    

### FIXED CODE ###

def count(n, x):
    c = 0
    for i in range(1, n-1):
        for j in range(i+1, n,):
            for k in range(j+1, n+1):
                s = i + j + k
                if s == x:
                    c += 1
                    break
                elif s > x: break
    return c

while True:
    p = map(int, raw_input().split())
    if p == [0, 0]: break
    print count(*p)
n, a, b = map( int, input().split() )

mod = 10 ** 9 + 7

def comb( n, r, mod ):
  c = 1
  m = 1
  r = min( n - r, r )
  for i in range( r ):
    c = c * ( n - i ) % mod
    m = m * ( i + 1 ) % mod
  return c * pow( m, mod - 2, mod ) % mod

N = pow( 2, n, mod )
A = comb( n, a )
B = comb( n, b )
print(( N - A - B ) % mod )

### FIXED CODE ###

N, A, B = map( int, input().split() )
MOD = 10 ** 9 + 7

def comb( n, r ):
  c = 1
  m = 1
  r = min( r, n - r )
  for i in range( r ):
    c = ( c * ( n - i )) % MOD
    m = ( m * ( i + 1 )) % MOD 
  return c * pow( m, MOD - 2, MOD ) % MOD

n = pow( 2, N, MOD ) - 1
a = comb( N, A )
b = comb( N, B )
print(( n - a - b ) % MOD )
import heapq
import numpy as np
import sys
sys.setrecursionlimit(10 ** 9)

x, y, z, k =  map(int,input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

hq = [[-a[0]-b[0]-c[0], 0, 0, 0]]
heapq.heapify(hq)
# visited = [[[0] * z for yy in range(y)] for xx in range(x)]
visited = np.zeros((x, y, z), dtype=int)

for i in range(k):
    ii, ia, ib, ic = heapq.heappop(hq)
    print(-ii)
    na = min(ia+1, x-1)
    nb = min(ib+1, y-1)
    nc = min(ic+1, z-1)
    if visited[na][ib][ic] == 0:
        heapq.heappush(hq, [-a[na] -b[ib] -c[ic], na, ib, ic])
        visited[na][ib][ic] = 1
    if visited[ia][nb][ic] == 0:
        heapq.heappush(hq, [-a[ia] -b[nb] -c[ic], ia, nb, ic])
        visited[ia][nb][ic] = 1
    if visited[ia][ib][nc] == 0:
        heapq.heappush(hq, [-a[ia] -b[ib] -c[nc], ia, ib, nc])
        visited[ia][ib][nc] = 1


### FIXED CODE ###

import heapq

x, y, z, k =  map(int,input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

hq = [[-a[0]-b[0]-c[0], 0, 0, 0]]
heapq.heapify(hq)
visited = {(0,0,0)}

for i in range(k):
    ii, ia, ib, ic = heapq.heappop(hq)
    print(-ii)
    na = min(ia+1, x-1)
    nb = min(ib+1, y-1)
    nc = min(ic+1, z-1)
    if not (na, ib, ic) in visited:
        heapq.heappush(hq, [-a[na] -b[ib] -c[ic], na, ib, ic])
        visited.add((na, ib, ic))
    if not (ia, nb, ic) in visited:
        heapq.heappush(hq, [-a[ia] -b[nb] -c[ic], ia, nb, ic])
        visited.add((ia, nb, ic))
    if not (ia, ib, nc) in visited:
        heapq.heappush(hq, [-a[ia] -b[ib] -c[nc], ia, ib, nc])
        visited.add((ia, ib, nc))
n=int(input())
t=list(map(int,input(),split()))
m=int(input())
p=[0]* m 
x=[0]* m 
for i in range(m):
    p[i],x[i]= map(int(input(),split()))
for i in range(m):
    print(sum(t)-t[p[i]-1]+x[i])

### FIXED CODE ###

n=int(input())
t=list(map(int,input().split()))
m=int(input())
p=[0]*m
x=[0]*m
for i in range(m):
  p[i],x[i]=map(int,input().split())  
for i in range(m):
  print(sum(t)-t[p[i]-1]+x[i])
s = input()[::-1]
n = len(s)
dp = [0]*2018
now = 0

dp[0] = 1
for i in range(n):
    now += 10**i * int(s[i])
    tmp = now % 2019
    dp[tmp] += 1

ans = sum([i*(i-1)/2 for i in dp if i > 1])
print(int(ans))


### FIXED CODE ###

s = input()
n = len(s)
dp = [1] + [0]*2019
now = 0
i = 1

for c in reversed(s):
    now = (now+i*int(c))%2019
    dp[now] += 1
    i *= 10
    i %= 2019

ans = sum([i*(i-1)/2 for i in dp])
print(int(ans))
i=list(map(int, input().split()))
a=list(map(int, input().split()))
b=list(map(int, input().split()))
A=i[0]
B=i[1]
M=i[2]
x = []
y = []
c = []
for i in range(M):
    x1,y1,c1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)
    c.append(c1)
d=200001
e=100001
f=100001
for k in range (A):
    if a[k]<e:
        e=a[k]

for l in range (B):
    if b[k]<f:
        f=b[k]
d=e+f

for n in range (M):
    if a[x[n]]+b[y[n]]-c[n]<d:
        d= a[x[n]]+b[y[n]]-c[n]
print(d)

### FIXED CODE ###

i=list(map(int, input().split()))
a=list(map(int, input().split()))
b=list(map(int, input().split()))
A=i[0]
B=i[1]
M=i[2]
x = []
y = []
c = []
for j in range(M):
    x1,y1,c1=[int(j) for j in input().split()]
    x.append(x1)
    y.append(y1)
    c.append(c1)
d=200001
e=100001
f=100001
for k in range (A):
    if a[k]<e:
        e=a[k]

for l in range (B):
    if b[l]<f:
        f=b[l]
d=e+f

for p in range (M):
    if a[x[p]-1]+b[y[p]-1]-c[p]<d:
        d= a[x[p]-1]+b[y[p]-1]-c[p]

print(d)
a,b,c=input().split()

a=int(a)
b=int(b)
c=int(c)

res=0
if b/a > c:
    res=c
else:
    res=b/a
print(int(res)

### FIXED CODE ###

a,b,c=input().split()

a=int(a)
b=int(b)
c=int(c)

res=0
if b/a > c:
    res=c
else:
    res=b/a

print(int(res))
import math

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

N, M = map(int, input().split())
S = input()
T = input()
L = lcm(N , M)
x = [""] * L
for i in range(N):
    idx = i * (L // N)
    x[idx] = S[i]
# for i in range(M):
#     idx = i * (L // M)
#     if x[idx] != "" and x[idx] != T[i]:
#         print(-1)
#         exit()
print(L)


### FIXED CODE ###

import math

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

N, M = map(int, input().split())
S = input()
T = input()
L = lcm(N , M)
x = {}
for i in range(N):
    idx = i * (L // N)
    x[idx] = S[i]
for i in range(M):
    idx = i * (L // M)
    if idx in x and x[idx] != T[i]:
        print(-1)
        exit()
print(L)
import statistics
import math

N = int(input())
A = list(map(int, input().split(" ")))
A_i = [0]*N
K_1 = 0
K_2 = 0
K_3 = 0

for i in range(N):
    A_i[i] = A[i] - i - 1

b_0 = statistics.mode(A_i)

b_1 = int(b_0)
b_2 = b_1 - 1
b_3 = b_1 + 1

for i in range(N):
    K_1 = K_1 + abs(A_i[i] - b_1)
    K_2 = K_2 + abs(A_i[i] - b_2)
    K_3 = K_3 + abs(A_i[i] - b_3)

print(min(K_1, K_2, K_3))


### FIXED CODE ###

import statistics
import math

N = int(input())
A = list(map(int, input().split(" ")))
A_i = [0]*N
K_1 = 0
K_2 = 0
K_3 = 0


for i in range(N):
    A_i[i] = A[i] - i - 1

try:
    b_1 = statistics.mode(A_i)
except:
    b_1 = int(statistics.mean(A_i))

b_2= int(statistics.mean(A_i))
b_3 = int(statistics.median(A_i))

for i in range(N):
    K_1 = K_1 + abs(A_i[i] - b_1)
    K_2 = K_2 + abs(A_i[i] - b_2)
    K_3 = K_3 + abs(A_i[i] - b_3)

print(min(K_1, K_2, K_3))
import sys
import bisect
input = sys.stdin.readline()
num=0
n=int(input())
top=list(map(int,input().split()))
mid=list(map(int,input().split()))
und=list(map(int,input().split()))
top.sort()
mid.sort()
und.sort()
for i in mid:
    a=bisect.bisect_left(top,i)
    c=len(c)-bisect.bisect_right(und,i)
    num+=a*c
print(num)

### FIXED CODE ###

import sys
import bisect
input = sys.stdin.readline
num=0
n=int(input())
top=list(map(int,input().split()))
mid=list(map(int,input().split()))
und=list(map(int,input().split()))
top.sort()
mid.sort()
und.sort()
for i in mid:
    a=bisect.bisect_left(top,i)
    c=n-bisect.bisect_right(und,i)
    num+=a*c
print(num)