Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
val2ind = {}
for i, one in enumerate(A):
    if one not in val2ind:
        val2ind[one] = []
    val2ind[one].append(i)

Q = int(input())

for _ in range(Q):
    B, C = list(map(int, input().split()))
    if B in val2ind:
        cand = val2ind[B]
        del val2ind[B]
        if C not in val2ind:
            val2ind[C] = cand
        else:
            cand.extend(val2ind[C])
            val2ind[C] = list(set(cand))
        for one in cand:
            A[one] = C
    print(sum(A))

### FIXED CODE ###

from collections import Counter
N = int(input())
val2ind = Counter(list(map(int, input().split())))
ans = sum([key*val2ind[key] for key in val2ind])
Q = int(input())

for _ in range(Q):
    B, C = list(map(int, input().split()))
    if B in val2ind:
        cand = val2ind[B]
        del val2ind[B]
        if C not in val2ind:
            val2ind[C] = cand
        else:
            val2ind[C] += cand
        ans = ans+(C-B)*cand
    print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
n, m = map(int, input().split())

ab = [[int(x) for x in input().split()] for _ in range(n)]

ab.sort(key=lambda x: x[0])

temp = sum(ab, [])  # 疑似Flatten
a, b = temp[0::2], temp[1::2]

count, index, remainder = 0, 0, 0

for i in range(n):
  if count + b[i] < m:  
    count += b[i]
  else:
    index = i
    remainder = m - count
    break
    
total = a[index] * remainder
total += sum([a[i] * b[i] for i in range(index)])


print(total)

### FIXED CODE ###

# cf. https://rion778.hatenablog.com/entry/2019/03/10/004006
import sys
input = sys.stdin.readline
 
N, M = [int(i) for i in input().split()]
 
plices = [[int(i) for i in input().split()] for _ in range(N)]
 
plices.sort(key = lambda x:x[0])
 
m = 0
cost = 0
 
for i in range(N):
    if m < M:
      buy = min(M - m, plices[i][1])
      cost += plices[i][0] * buy
      m += buy
    else:
      break

print(cost)
### BUGGY CODE ###

def chmin(dp,i,x):
  if x<dp[i]:
    dp[i]=x
    return True
  return False

N, K = map(int,input().split())
h = list(map(int,input().split()))
inf = float('inf')
dp = [inf]*(110000)
dp[0]=0
for i in range(0,N):
  for j in range(1,K+1):
    if i+j<N:
      chmin(dp, i + j, dp[i] + abs(h[i] - h[i + j]))
 
print(dp[N-1])




### FIXED CODE ###

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))
### BUGGY CODE ###

N,M = input().split()
N = int(N)
M = int(M)
price_list = input().split()
 
price_list = list(map(int, price_list))
 
for _ in range(M):
  num = max(price_list)
  price_list.remove(num)
  price_list.append(int(num/2))
print(sum(price_list))

### FIXED CODE ###

import heapq

N,M = input().split()
N = int(N)
M = int(M)
price_list = input().split()
 
heap_list = []
for i in price_list:
  heapq.heappush(heap_list, int(i) * (-1))

for _ in range(M):
  max_num = heapq.heappop(heap_list)
  heapq.heappush(heap_list, int(max_num /2))
  
print(sum(heap_list) * (-1))
### BUGGY CODE ###

from collections import Counter
import sys
input = sys.stdin.readline

n = int(input())
a = list(map(int, input().split()))
cnt = Counter(a)
p, q, r = cnt[1], cnt[2], cnt[3]

dp = []
for _ in range(n + 1):
    dp.append([[0] * (n + 1) for _ in range(n + 1)])
dp[0][0][0] = 0

for k in range(r + 1):
    for j in range(r + q + 1):
        for i in range(n + 1):
            if (i + j + k == 0) or (i + j + k) > n:
                continue
            tmp = 0
            if i > 0:
                tmp += dp[i - 1][j][k] * i
            if j > 0:
                tmp += dp[i + 1][j - 1][k] * j
            if k > 0:
                tmp += dp[i][j + 1][k - 1] * k
            tmp += n
            dp[i][j][k] = tmp / (i + j + k)

print(dp[p][q][r])


### FIXED CODE ###

import sys,queue,math,copy,itertools,bisect,collections,heapq
sys.setrecursionlimit(10**7)
INF = 10**18
MOD = 10**9 + 7
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())

N = NI()
a = [0,0,0]
for x in LI():
    a[x-1] += 1
dp = [[[0.0] * (N+1) for _ in range(N+1)] for _ in range(N+1)]

for k in range(a[2]+1):
    for j in range(a[1]+a[2]+1):
        for i in range(N+1):
            if not (0 < i+j+k <= N): continue
            x = 0.0
            if i > 0: x += dp[i-1][j][k] * (i/N)
            if j > 0: x += dp[i+1][j-1][k] * (j/N)
            if k > 0: x += dp[i][j+1][k-1] * (k/N)
            x += 1.0
            x *= N / (i+j+k)
            dp[i][j][k] = x
print(dp[a[0]][a[1]][a[2]])
### BUGGY CODE ###

import sys
from bisect import bisect_left as b
def main():
	input=sys.stdin.readline
	n=int(input())
	s=list(input().rstrip())
	q=int(input())
	word=[[]for _ in range(26)]
	for i,j in enumerate(s):
		ch=ord(j)-97
		word[ch].append(i)
	for _ in range(q):
		query=input().split()
		if query[0]=="1":
			i,x=int(query[1])-1,ord(query[2])-97
			old=ord(s[i])-97
			if s==x:
				continue
			word[old].remove(i)
			new=b(word[x],i)
			word[x].insert(new,i)
			s[i]=chr(x+97)
		else:
			l,r=int(query[1])-1,int(query[2])-1
			kind=0
			for i in range(26):
				ll=b(word[i],l)
				if ll==len(word[i]):
					continue
				if word[i][ll]<=r:
					kind+=1
			print(kind)
if __name__ == '__main__':
	main()

### FIXED CODE ###

import sys
input=sys.stdin.readline
n=int(input())
BIT=[[0]*n for i in range(26)]
w=[ord(x)-ord("a") for x in input()]
for i in range(n):
	k=i+1
	while k<=n:
		BIT[w[i]][k-1]+=1
		k=k+(k&-k)
q=int(input())
for i in range(q):
	a,b,c=input().split()
	if a=="1":
		k=int(b)
		while k<=n:
			BIT[ord(c)-ord("a")][k-1]+=1
			k=k+(k&-k)
		k=int(b)
		while k<=n:
			BIT[w[int(b)-1]][k-1]-=1
			k=k+(k&-k)	
		w[int(b)-1]=ord(c)-ord("a")
	else:
		b=int(b);c=int(c)
		ans=0
		for i in range(26):
			cnt=0
			k=c
			while k!=0:
				cnt+=BIT[i][k-1]
				k=k-(k&-k)
			k=b-1
			while k!=0:
				cnt-=BIT[i][k-1]
				k=k-(k&-k)
			if cnt>0:
				ans+=1
		print(ans)
### BUGGY CODE ###

N, Q = list(map(int, input().split()))
S = input()
for n in range(Q):
    l, r = list(map(int, input().split()))
    s = S[(l-1):r]
    c = 0
    for a in range(len(s)):
        if s[a] == 'A':
            if a < (len(s) - 1):
                if s[a+1] == 'C':
                    c += 1
                    a += 1
                elif s[a+1] != 'A':
                    a += 1
    print(c)


### FIXED CODE ###

N, Q = list(map(int, input().split()))
S = input()
w = [0]
v = 0
for a in range(len(S)-1):
    if S[a] == 'A' and S[a+1] == 'C':
        v += 1
    w.append(v)
for n in range(Q):
    l, r = list(map(int, input().split()))
    print(w[r-1] - w[l-1])
### BUGGY CODE ###

#!/usr/bin/env python3

def main():
    S = input()
    Q = int(input())

    for i in range(Q):
        query = list(input())
        if query[0] == '1':
            S = S[::-1]
        elif query[2] == '1':
            S = query[4] + S
        else:
            S = S + query[4]
    print(S)


if __name__ == "__main__":
    main()


### FIXED CODE ###

#!/usr/bin/env python3
from collections import deque


def main():
    d = deque()
    d.extend(list(input()))

    Q = int(input())
    reflag = False

    for i in range(Q):
        query = list(input().split())
        if query[0] == '1':
            reflag = not reflag
        elif (query[1] == '1' and not reflag) or (query[1] == '2' and reflag):
            d.appendleft(query[2])
        else:
            d.append(query[2])

    if reflag:
        print("".join(reversed(d)))
    else:
        print("".join(d))


if __name__ == "__main__":
    main()
### BUGGY CODE ###

import fractions
import math
n = int(input())
a = list(map(int, input().split()))
MOD = 10**9 + 7
ans = 0

lcm = a[0]
for i in range(1, n):
    lcm = lcm * a[i] // fractions.gcd(lcm, a[i])
    #lcm = lcm * a[i] // math.gcd(lcm, a[i])

for i in range(n):
    ans += (lcm // a[i]) % MOD
    ans %= MOD

print(ans)


### FIXED CODE ###

import fractions
import math
n = int(input())
a = list(map(int, input().split()))
MOD = 10**9 + 7
ans = 0

lcm = a[0]
for i in range(1, n):
    lcm = lcm * a[i] // fractions.gcd(lcm, a[i])
    #lcm = lcm * a[i] // math.gcd(lcm, a[i])
lcm %= MOD
for i in range(n):
    ans += lcm * pow(a[i] , MOD-2, MOD)
    ans %= MOD
print(ans)
### BUGGY CODE ###

from bisect import bisect_left as bl
from collections import deque
from fractions import gcd
#from math import factorial
from math import sqrt
from math import ceil
from itertools import permutations
from heapq import *
from collections import defaultdict
from copy import deepcopy

A,B,Q=map(int,input().split())
S=[]
T=[]
X=[]
for i in range(A):
    S.append(int(input()))
for i in range(B):
    T.append(int(input()))
def rl(X,a):
    ind=bl(X,a)
    if ind>=len(X):
        return ind-1
    return ind
def ll(X,a):
    ind=bl(X,a)-1
    if ind<0:
        return ind+1
    return ind
t=[]
for i in range(A):
    if abs(T[rl(T,S[i])]-S[i])>=abs(T[ll(T,S[i])]-S[i]):
        t.append(abs(T[ll(T,S[i])]-S[i]))
    else:
        t.append(abs(T[rl(T,S[i])])-S[i])
s=[]
for i in range(B):
    if abs(S[rl(S,T[i])]-T[i])>=abs(S[ll(S,T[i])]-T[i]):
        s.append(abs(S[ll(S,T[i])]-T[i]))
    else:
        s.append(abs(S[rl(S,T[i])])-T[i])

for i in range(Q):
    x=int(input())
    a=rl(S,x)
    a=t[a]+abs(S[a]-x)

    b=ll(S,x)
    b=t[b]+abs(S[b]-x)

    c=rl(T,x)
    c=s[c]+abs(T[c]-x)

    d=ll(T,x)
    d=s[d]+abs(T[d]-x)

    print(min(a,b,c,d))


### FIXED CODE ###

from bisect import bisect_left as bl
A,B,Q=map(int,input().split())
S=[]
T=[]
X=[]
INF=10**18
S.append(-INF)
T.append(-INF)
for i in range(A):
    S.append(int(input()))
for i in range(B):
    T.append(int(input()))
S.append(INF)
T.append(INF)
for i in range(Q):
    x=int(input())
    b,d=bl(S,x),bl(T,x)
    res=INF
    for s in [S[b-1],S[b]]:
        for t in [T[d-1],T[d]]:
            d1,d2=abs(s-x)+abs(t-s),abs(t-x)+abs(s-t)
            res=min(res,d1,d2)
    print(res)
### BUGGY CODE ###

def main():
    from collections import Counter as ct
    from bisect import bisect_left as bl

    n = int(input())
    max_a = sorted(ct(list(map(int, input().split()))).values())
    now_a = [i for i in max_a]
    m = len(max_a)
    cnt = m
    ans = 0
    ans_list = [0]*(n-m)

    for use in range(m, 1, -1):
        rest = ans
        nex = now_a[0]
        while rest:
            val = nex
            start = bl(now_a, val+1)
            nex += 1
            q = bl(max_a, now_a[start-1]+1)-1
            flag = 0
            if now_a[start-1] == 0:
                flag = 1
            for i in range(start-1, max(-1, start-1-rest, q), -1):
                cnt += flag
                now_a[i] += 1
                rest -= 1
            if start != m:
                nex = now_a[start]
        while cnt >= use:
            ans += 1
            rest = use
            nex = now_a[-1]
            end = m
            while rest:
                val = nex
                start = bl(now_a, val)
                if start != 0:
                    nex = now_a[start-1]
                flag = 0
                if now_a[start] == 1:
                    flag = 1
                end = min(end, bl(now_a, val+1), start+rest)
                for i in range(start, end):
                    cnt -= flag
                    now_a[i] -= 1
                    rest -= 1
                end = start
        ans_list.append(ans)
    print(n)
    for i in ans_list[::-1]:
        print(i)


main()


### FIXED CODE ###

def main():
    from collections import Counter as ct
    from bisect import bisect_left as bl

    n = int(input())
    max_a = sorted(ct(list(map(int, input().split()))).values())
    now_a = [i for i in max_a]
    m = len(max_a)
    cnt = m
    ans = 0
    ans_list = []

    for use in range(n, 0, -1):
        rest = ans
        nex = now_a[0]
        # restの分だけ戻す
        while rest:
            val = nex
            start = bl(now_a, val+1)
            nex += 1
            for i in range(start-1, -1, -1):
                if now_a[i] == max_a[i]:
                    if start != m:
                        nex = now_a[start]
                    break
                elif now_a[i] == 0:
                    cnt += 1
                now_a[i] += 1
                rest -= 1
                if rest == 0:
                    break
        # 大きい方から使っていく
        while True:
            if cnt < use:
                ans_list.append(ans)
                break
            ans += 1
            rest = use
            nex = now_a[-1]
            end = m
            while rest:
                val = nex
                start = bl(now_a, val)
                if start != 0:
                    nex = now_a[start-1]
                for i in range(start, end):
                    if now_a[i] > val:
                        break
                    elif now_a[i] == 1:
                        cnt -= 1
                    now_a[i] -= 1
                    rest -= 1
                    if rest == 0:
                        break
                end = start
    for i in ans_list[::-1]:
        print(i)


main()
### BUGGY CODE ###

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

import numpy as np

S = np.array(S)

r = (S == "R").sum()
g = (S == "G").sum()
b = (S == "B").sum()

cnt = 0
for i in range(N):
    for j in range(i+1, N):
        k = j + j - i
        if 0 <= k < N:
            if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
                cnt += 1

print(r*g*b - cnt)

### FIXED CODE ###

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

r = S.count("R")
g = S.count("G")
b = S.count("B")

cnt = 0
for i in range(N):
    for j in range(i+1, N):
        k = j + j - i
        if 0 <= k < N:
            if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
                cnt += 1

print(r*g*b - cnt)
### BUGGY CODE ###

s = list(input())
ans = 0
while(s.count('W') != 0):
    ans += s.index('W')
    s.remove('W')
print(ans)

### FIXED CODE ###

s = input()
ans = 0
w = 0
for i in range(len(s)):
    if (s[i] == 'W'):
        ans += i - w
        w += 1
print(ans)
### BUGGY CODE ###

N = int(input())
A_array = list(map(int, input().split()))
ans = 0
check = [0 for _ in range(10 ** 6 + 5)]
A = sorted(A_array)

for i in range(N):
  for j in range(int((len(check) - 1) / A[i])):
    check[A[i] * (j + 1)] += 1

for i in range(len(check) - 1):
  if i + 1 in A:
    if check[i + 1] == 1:
      ans += 1
    else:
      continue
  else:
    continue

print(ans)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
A.sort()                  #エラトステネスの篩にかけるためソート
Amax = A[-1]
dp = [1]*(Amax+1)         #Aの最大値までのエラトステネスの篩を作る。
ans = 0
for i in range(len(A)-1):
  p = A[i]
  if dp[p] == 1:          #A[i]がA[j]の倍数でないかをエラトステネスの篩でチェック
    for q in range(Amax//p+1):
      dp[p*q] = 0         #A[i]の倍数をすべて0にする
    if A[i] != A[i+1]: 
      ans += 1            #A[i]が重複していなければカウント
if dp[Amax] == 1:         #重複チェック時にレンジオーバーするためAmaxだけ別で判定 
  ans += 1
print(ans)
### BUGGY CODE ###

n = int(input())
li = list(map(int,input().split()))
li2 = []
for i in range(n):
    a = li.index(i+1)
    li2.append(str(a + 1))
print(' '.join(li2))

### FIXED CODE ###

import numpy as np
n=int(input())
a=list(map(int,input().split()))
  
x = np.argsort(a)
for i in range(n):
  print(x[i]+1)
### BUGGY CODE ###

import sys
def input():
    return sys.stdin.readline()[:-1]
n=int(input())
ta=[list(map(int,input().split())) for i in range(n)]
t,a=ta[0][0],ta[0][1]
for i in range(n-1):
    wa=sum(ta[i+1])
    j=(t+a)//wa
    while wa*j<t+a or t>j*ta[i+1][0] or a>j*ta[i+1][1]:
        j+=1
    t,a=j*ta[i+1][0],j*ta[i+1][1]
    # print([t,a])
print(t+a)

### FIXED CODE ###

import sys
def input():
    return sys.stdin.readline()[:-1]
n=int(input())
ta=[list(map(int,input().split())) for i in range(n)]
t,a=ta[0][0],ta[0][1]
for i in range(n-1):
    wa=sum(ta[i+1])
    j=max((t+a+wa-1)//wa,(t+ta[i+1][0]-1)//ta[i+1][0],(a+ta[i+1][1]-1)//ta[i+1][1])
    # while wa*j<t+a or j*ta[i+1][0]<t or j*ta[i+1][1]<a:
    #     j+=1
    t,a=j*ta[i+1][0],j*ta[i+1][1]
    # print([t,a])
print(t+a)
### BUGGY CODE ###

k,s = map(int,input().split())

counter = 0

for x in range(k+1):
    for y in range(k+1):
        for z in range(k+1):
            if s == x+y+z:
                counter += 1
                
print(counter)

### FIXED CODE ###

k,s = map(int,input().split())
counter = 0

for x in range(k+1):
    if s-x > 2*k:
        continue
    for y in range(k+1):
        if s-x-y > k or s-x-y < 0:
            continue
        else:
            counter += 1
            
print(counter)
### BUGGY CODE ###

k = int(input())

ans = 1
r = 0
x = 0
while(True):
    if x == (r * 10 + 7) // k and r == (r * 10 + 7) % k:
        print(-1)
        exit()

    x = (r * 10 + 7) // k
    r = (r * 10 + 7) % k

    if r == 0:
        break
    else:
        ans += 1
print(ans)

### FIXED CODE ###

k = int(input())

arr = [0] * (k+1)
r = 7 % k
ans = 1

while arr[r] == 0:
    if r == 0:
        print(ans)
        exit()
    arr[r] += 1
    r = (10 * r + 7) % k
    ans += 1

print(-1)
### BUGGY CODE ###

n=int(input())
a=list(map(str,input().split()))
b=[]
#print(b)
for i in range(n):
    b.append(a[i])
    b=b[::-1]
print(" ".join(b))

### FIXED CODE ###

from collections import deque
n=int(input())
a=list(map(str,input().split()))
b=deque()
#print(b)
for i in range(n):
    if i%2==0:
        b.append(a[i])
    else:
        b.appendleft(a[i])
b=list(b)
if n%2==1:
    b=b[::-1]
print(" ".join(b))
### BUGGY CODE ###

s = int(input())

x0, y0 = 0, 0

ans = int(s**0.5) + 1
x1 = min(ans, 10**9)
y2 = min(ans, 10**9)

while True:
    tmp = x1*y2 - s
    cnt = 1
    while True:
        if tmp % 2 == 0:
            cnt *= 2
            tmp = tmp // 2
        else:
            a = cnt
            b = tmp
            if a <= 10**9 and b <= 10**9: 
                x2 = a
                y1 = b
                print(x0,y0,x1,y1,x2,y2)
                exit()
            else:
                x1 -= 1
                break

 

### FIXED CODE ###

s = int(input())

x0, y0 = 0, 0

ans = int(s**0.5) + 1
x1 = min(ans, 10**9)
y2 = min(ans, 10**9)


while True:
    tmp = x1*y2 - s
    cnt = 1
    while True:
        if tmp != 0 and tmp % 2 == 0:
            cnt *= 2
            tmp = tmp // 2
        else:
            a = cnt
            b = tmp
            if a <= 10**9 and b <= 10**9: 
                x2 = a
                y1 = b
                print(x0,y0,x1,y1,x2,y2)
                exit()
            else:
                x1 -= 1
                break
### BUGGY CODE ###

H,W=map(int,input().split())
s=[]
dp=[[10**9]*(W)for _ in range(H)]
dp[0][0]=0
for i in range(H):
    S=input()
    s.append(S)
q=[(0,0)]
while q:
    a,b=q.pop(0)
    if a+1<H:
        if s[a][b]=="." and s[a+1][b]=="#":
            dp[a+1][b]=min(dp[a][b]+1,dp[a+1][b])
        else:
            dp[a+1][b]=min(dp[a][b],dp[a+1][b])
        q.append((a+1,b))
    if b+1<W:
        if s[a][b]=="." and s[a][b+1]=="#":
            dp[a][b+1]=min(dp[a][b]+1,dp[a][b+1])
        else:
            dp[a][b+1]=min(dp[a][b],dp[a][b+1])
        q.append((a,b+1))
ans=dp[H-1][W-1]
if s[0][0]=="#":
    ans+=1
print(ans)

### FIXED CODE ###

H,W=map(int,input().split())
s=[]
dp=[[10**9]*W for _ in range(H)]
dp[0][0]=0
for _ in range(H):
    s.append(list(input()))
for i in range(H):
    for j in range(W):
        if j!=W-1:
            if s[i][j]=="." and s[i][j+1]=="#":
                dp[i][j+1]=min(dp[i][j]+1,dp[i][j+1])
            else:
                dp[i][j+1]=min(dp[i][j],dp[i][j+1])
        if i!=H-1:
            if s[i][j]=="." and s[i+1][j]=="#":
                dp[i+1][j]=min(dp[i][j]+1,dp[i+1][j])
            else:
                dp[i+1][j]=min(dp[i][j],dp[i+1][j])
ans=dp[H-1][W-1]
if s[0][0]=="#":
    ans+=1
print(ans)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(2147483647)
INF=float('inf')
MOD=10**9+7
input=sys.stdin.readline

n=int(input())
s=list(map(int,input().split()))
import copy
def DEF(ary,ary2):
    #print(ary,ary2)
    global n,s
    if len(ary2)==n:
        #print(ary)
        if ary==s:
            for item in ary2:
                print(item)
            exit()
    else:
        for i in range(len(ary)+1):
            tmp = copy.deepcopy(ary)
            tmp.insert(i,i+1)
            DEF(tmp,ary2+[i+1])

DEF([],[])
print(-1)


### FIXED CODE ###

n=int(input())
s=list(map(int,input().split()))


result=[]

for i in range(n):
    posi=-1
    for index,ss in enumerate(s):
        if ss==index+1:
            posi=index
    if posi==-1:
        print(-1)
        exit()
    else:
        result.append(s[posi])
        s.pop(posi)

for item in result[::-1]:
    print(item)
### BUGGY CODE ###

h,w,m=map(int,input().split())
h_=[0]*(h+1)
w_=[0]*(w+1)
plot=set()
for _ in range(m):
    x,y=map(int,input().split())
    h_[x]+=1
    w_[y]+=1
    plot.add((x,y))
x=max(h_)
y=max(w_)
a=[i for i,v in enumerate(h_) if v==x]
b=[j for j,q in enumerate(w_) if q==y]
u=0
c=0
for i in a:
    for j in b:
        if (i,j) in plot:
          u+=1
        c+=1
        
ans=x+y
if u==c:
    print(ans-1)
else:
    print(ans)                
               


### FIXED CODE ###

h,w,m=map(int,input().split())
h_=[0]*(h+1)
w_=[0]*(w+1)
plot=set()
for _ in range(m):
    x,y=map(int,input().split())
    h_[x]+=1
    w_[y]+=1
    plot.add((x,y))
x=max(h_)
y=max(w_)
a=[i for i,v in enumerate(h_) if v==x]
b=[j for j,q in enumerate(w_) if q==y]
ans=x+y-1
c=False
for i in a:
    for j in b:
        if (i,j) not in plot:
          c=True
          break
    if c:
      break
if c:
  print(ans+1)
else:
  print(ans)
### BUGGY CODE ###

A,B,K = map(int,input().split())
i = 0
for i in range(K):
  if A >= 1:
    A -= 1
  elif A < 1 and B >= 1:
    B -= 1
  i += 1
print(A)
print(B)

### FIXED CODE ###

A,B,K = map(int,input().split())
if K <= A:
  print(A-K,B)
else:
  if K <= A + B:
    print(0, A+B-K)
  else:
    print(0, 0)
### BUGGY CODE ###

import itertools
N = int(input())
L = list(map(int, input().split()))
answer = 0
for i in itertools.combinations(L, 3):
    if i[0] < i[1] + i[2] and i[1] < i[0] + i[2] and i[2] < i[1] + i[0]:
        answer += 1
print(answer)

### FIXED CODE ###

import itertools
import heapq
from bisect import bisect_left


def heapsort(iterable):
    h = []
    for value in iterable:
        heapq.heappush(h, value)
    return [heapq.heappop(h) for i in range(len(h))]

N = int(input())
L = list(map(int, input().split()))
L.sort()
# L_sort = heapsort(L)
# print (L)
answer = 0
for i, a in enumerate(L[0:N-2]):
    for j, b in enumerate(L[i+1:N-1]):
        index = bisect_left(L, a+b)
        answer += max(index - (j+i+1) -1, 0)
        # print(L, a+b, index, j+i+1, answer)
print(answer)