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

price = [1, 5, 10, 50, 100, 500]

while True:
    values = list(map(int, input().split()))
    p, n = values[0], values[1:]
    ans = 1e100
    if p == 0:
        break

    p_sum = sum(map(lambda s: s[0] * s[1], zip(price, n)))

    for change in range(p_sum - p + 1):
        coins = 0
        _change = change
        for i in reversed(range(6)):
            while _change >= price[i]:
                _change -= price[i]
                coins += 1

        total = p + change
        pay = [0] * 6
        for i in reversed(range(6)):
            while total >= price[i] and n[i] > pay[i]:
                total -= price[i]
                pay[i] += 1

        if total > 0:
            break

        coins += sum(pay)

        ans = min(ans, coins)
    
    print(ans)

### FIXED CODE ###

price = [1, 5, 10, 50, 100, 500]

while True:
    values = list(map(int, input().split()))
    p, n = values[0], values[1:]
    ans = 1e100
    if p == 0:
        break

    p_sum = sum(map(lambda s: s[0] * s[1], zip(price, n)))

    for change in range(1000):
        total = p + change
        pay = [0] * 6
        for i in reversed(range(6)):
            if total >= price[i]:
                pay[i] = min(n[i], int(total / price[i]))
                total -= pay[i] * price[i]

        if total > 0:
            break

        coins = sum(pay)

        _change = change
        for i in reversed(range(6)):
            if _change >= price[i]:
                coins += int(_change / price[i])
                _change %= price[i]

        ans = min(ans, coins)

    print(ans)
### BUGGY CODE ###

n,k=map(int,input().split())
a=list(map(int,input().split()))
count=0
lst=[]
now=1
for i in range(n):
    if now in set(lst):
        
        break
    lst.append(now)
    now=a[now-1]
ind=lst.index(now)

if k<=len(lst):
    print(lst[k])

else:
    newlst=lst[ind:]
    num=len(lst)-len(newlst)
    newk=k-num
    num2=newk%len(newlst)
    print(newlst[num2])

### FIXED CODE ###

n,k=map(int,input().split())
a=list(map(int,input().split()))
count=0
lst={}
lst2=[]
now=1
c=0

while True:
    lst2.append(now)
    lst[now]=c
    now=a[now-1]
    if now in lst:
        break
    c+=1



amari=lst[now]
looplen=c-lst[now]+1


if k<=amari:
    print(lst2[k])

else:
    newlst=lst2[amari:]
    
    newk=k-amari
    num=newk%looplen
    print(newlst[num])
### BUGGY CODE ###

from fractions import Fraction
from collections import defaultdict


def inverse(key):
    if key == "inf":
        return Fraction(0, 1)

    if key == Fraction(0, 1):
        return "inf"

    return - Fraction(key.denominator, key.numerator)


mod = 10 ** 9 + 7
n = int(input())
fishes = defaultdict(int)

zero_zero = 0
for _ in range(n):
    a, b = map(int, input().split())
    if a == 0 and b == 0:
        zero_zero += 1
        continue

    elif b == 0:
        key = "inf"

    else:
        key = Fraction(a, b)

    fishes[key] += 1

ans = 1
counted_key = set()
for fish_key, count in fishes.items():
    if fish_key in counted_key:
        continue

    bad_pair = inverse(fish_key)
    if bad_pair in fishes:
        pair_count = fishes[bad_pair]
        pattern = pow(2, count, mod) + pow(2, pair_count, mod) - 1
        counted_key.add(bad_pair)

    else:
        pattern = pow(2, count, mod)

    ans = ans * pattern % mod

if zero_zero:
    ans += zero_zero

ans -= 1
print(ans % mod)


### FIXED CODE ###

from collections import defaultdict
from math import gcd

mod = 10 ** 9 + 7
n = int(input())
fishes = defaultdict(int)
zero_zero = 0
zero = 0
inf = 0

for _ in range(n):
    a, b = map(int, input().split())
    if a == 0 and b == 0:
        zero_zero += 1

    elif a == 0:
        zero += 1

    elif b == 0:
        inf += 1

    else:
        div = gcd(a, b)
        a //= div
        b //= div
        if b < 0:
            a *= -1
            b *= -1
        key = (a, b)
        fishes[key] += 1


def get_bad_pair(fish):
    a, b = fish
    if a < 0:
        a *= -1
        b *= -1
    return (-b, a)


ans = 1
counted_key = set()
for fish_key, count in fishes.items():
    if fish_key in counted_key:
        continue

    bad_pair = get_bad_pair(fish_key)
    if bad_pair in fishes:
        pair_count = fishes[bad_pair]
        pattern = pow(2, count, mod) + pow(2, pair_count, mod) - 1
        counted_key.add(bad_pair)

    else:
        pattern = pow(2, count, mod)

    ans = ans * pattern % mod

ans *= pow(2, zero, mod) + pow(2, inf, mod) - 1
if zero_zero:
    ans += zero_zero

ans -= 1
print(ans % mod)
### BUGGY CODE ###

#N, *a = map(int, open(0).read().split())
def main():
    N = int(input())
    a=[]
    for i in range(N):
        a.append(int(input()))

    b = [1 for _ in range(N+1)]
    cnt = 1
    ans = 0
    flag = 1
    i = 0
    for i in reversed(range(N)):
        if a[i] + 1 in a[i:]:
            b[a[i]] = b[a[i]+1] + 1
        
        
    return N-max(b)
print(main())


### FIXED CODE ###

#N, *a = map(int, open(0).read().split())
def main():
    N = int(input())
    a=[]
    for i in range(N):
        a.append(int(input()))

    b = [0 for _ in range(N+2)]
    cnt = 1
    ans = 0
    flag = 1
    i = 0
    for i in reversed(range(N)):
        if b[a[i]+1] > 0:
            b[a[i]] = b[a[i]+1] + 1
        else:
            b[a[i]] = 1
        
    return N-max(b)
print(main())
### BUGGY CODE ###

n = int(input())
a = n
while(1):
    if a % 2 == 0 and a % n == 0:
        print(a)
        break
    a += 1


### FIXED CODE ###

n = int(input())
if n % 2 == 0:
    print(n)
else:
    print(n*2)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
A_ = [0] * (N+1)
for a in A:
    A_[a] += 1
A_ = sorted(A_)
c = 0
for i in range(N+1):
    A_[i] = c = A_[i] + c
A_.reverse()

Ans = A_[:]

for i in range(1, N):
    for j, a in enumerate(A_):
        d = a//(i+1)
        if Ans[i+j] > d:
            Ans[i+j] = d
        if d==0:
            break
    if j==0:
        for ii in range(i+1, N):
            Ans[ii] = 0
        break
del Ans[-1]
print("\n".join(map(str, Ans)))


### FIXED CODE ###

def main():
    N = int(input())
    A = list(map(int, input().split()))
    C = [0] * (N+1)
    Cnt_A = [0] * (N+1)
    for a in A:
        Cnt_A[a] += 1
        cnt = Cnt_A[a]
        C[cnt] += 1
    cum_C = []
    cu = 0
    for c in C:
        cu += c
        cum_C.append(cu)
    Ans = []
    for k in range(1, N+1):
        # K = k のとき、 n 組以上作れる <=> 使えるカードが nk 枚以上
        # n 組以上作れる <=> 同じカードは n 枚以下
        # 同じカードは n 枚以下で全体として nk 枚以上用意できるか？
        ok, ng = 0, N//k+1
        while ok + 1 < ng:
            n = ok+ng>>1
            if cum_C[n] >= n*k:
                ok = n
            else:
                ng = n
        Ans.append(ok)
    print("\n".join(map(str, Ans)))

main()
### BUGGY CODE ###

#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify

import itertools
import bisect
import math
import fractions
import sys
import copy


def L(): return sys.stdin.readline().split()


def I(): return int(sys.stdin.readline().rstrip())


def S(): return list(sys.stdin.readline().rstrip())


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]


def LS(): return [list(x) for x in sys.stdin.readline().split()]


def IR(n): return [I() for _ in range(n)]


def LIR(n): return [LI() for _ in range(n)]


def LIR1(n): return [LI1() for _ in range(n)]


def SR(n): return [S() for _ in range(n)]


def LSR(n): return [LS() for _ in range(n)]


def LR(n): return [L() for _ in range(n)]


alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

sys.setrecursionlimit(1000000)
dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
MOD = 1000000007


def main():
    K = I()
    ans = 1
    tmp = 7

    if K % 2 == 0:
        print(-1)
        return

    while tmp % K != 0:
        tmp *= 10
        tmp += 7
        tmp %= K
        ans += 1

    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify

import itertools
import bisect
import math
import fractions
import sys
import copy


def L(): return sys.stdin.readline().split()


def I(): return int(sys.stdin.readline().rstrip())


def S(): return list(sys.stdin.readline().rstrip())


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]


def LS(): return [list(x) for x in sys.stdin.readline().split()]


def IR(n): return [I() for _ in range(n)]


def LIR(n): return [LI() for _ in range(n)]


def LIR1(n): return [LI1() for _ in range(n)]


def SR(n): return [S() for _ in range(n)]


def LSR(n): return [LS() for _ in range(n)]


def LR(n): return [L() for _ in range(n)]


alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

sys.setrecursionlimit(1000000)
dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
MOD = 1000000007


def main():
    K = I()
    ans = 1
    tmp = 7

    if K % 2 == 0 or K % 5 == 0:
        print(-1)
        return

    while tmp % K != 0:
        tmp *= 10
        tmp += 7
        tmp %= K
        ans += 1

    print(ans)


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

s = input()
k = int(input())

S = []
for len_i in range(1,len(s)+1):
	for left_j in range(len(s)-len_i+1):
		cur_s = s[left_j:left_j+len_i]
		if cur_s not in S:
			S.append(s[left_j:left_j+len_i])
S.sort()
# print(S)
print(S[k-1])

### FIXED CODE ###

s = input()
k = int(input())

S = []
for len_i in range(1,k+1):
	for left_j in range(len(s)-len_i+1):
		cur_s = s[left_j:left_j+len_i]
		if cur_s not in S:
			S.append(s[left_j:left_j+len_i])
S.sort()
# print(S)
print(S[k-1])
### BUGGY CODE ###

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


#S_R = []
#S_G = []
#S_B = []
R = 0
G = 0
B = 0

for i in range(N):
    s = S[i]
    if (s == 'R'):
        #_R.append(i)
        R +=1
    if (s == 'G'):
        #S_G.append(i)
        G +=1
    if (s == 'B'):
        #S_B.append(i)
        B +=1

count = R * G * B

#count = len(S_R) * len(S_G) * len(S_B)
#rgb = {'R', 'G', 'B'}


#for i in range(N):
    #for j in range(i):
        #x = S[j::i]
        #for a, b, c in zip(x, x[1:], x[2:]):
            #if({a,b,c} == rgb):
                #count -=1

for i in range(N):
    for j in range(N//2 + 1):
        if(i + j*2 >= N):
            continue
        if((S[i] != S[i + j]) & (S[i + j] != S[i + 2 * j]) & (S[i + 2 * j] != S[i])):
            count -= 1




print(count)

### FIXED CODE ###

n = int(input())
s = input()
 
r, b, g = 0, 0, 0
for i in range(n):
    if s[i] == 'R':
        r += 1
    if s[i] == 'G':
        g += 1
    if s[i] == 'B':
        b += 1
ans = r * g * b
 
for i in range(n):
    for j in range(1, n // 2 + 1):
        if i + 2 * j >= n:
            break
        if s[i] != s[i+j] and s[i] != s[i+2*j] and s[i+j] != s[i+2*j]:
            ans -= 1
 
print(ans)
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
ans = 0
t = 0
u = 0
m = max(A)
for i in range(60):
    if m >= 2**i:
        u += 1
    else: break
for i in range(u):
    for j in range(N):
        if A[j]%(2**(i+1)) >= 2 ** i:
            t += 1
    ans += (t * (N-t)) * 2**i
    t = 0
print(ans%1000000007) 

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
ans = 0
t = 0
u = 0
m = max(A)
for i in range(60):
    if m >= 2**i:
        u += 1
    else: break
for i in range(u):
    for j in range(N):
        t += (A[j] >> i) & 1
    ans += (t * (N-t)) * 2**i
    t = 0
print(ans%1000000007)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**7)

def cur(x):
    for i in neighbor[x]:
        ans[i]+=ans[x]
        neighbor[i].remove(x)
        cur(i)

n,q=map(int,input().split())
neighbor=[[]  for _ in range(n+1)]
ans=[0]*(n+1)
for _ in range(n-1):
    a,b=map(int,input().split())
    neighbor[a].append(b)
    neighbor[b].append(a)


for _ in range(q):
    p,x=map(int,input().split())
    ans[p]+=x

cur(1)
print(" ".join(map(str,ans[1:])))

### FIXED CODE ###

n,q=map(int,input().split())
neighbor=[[]  for _ in range(n+1)]
ans=[0]*(n+1)

for _ in range(n-1):
    a,b=map(int,input().split())
    neighbor[a].append(b)
    neighbor[b].append(a)


for _ in range(q):
    p,x=map(int,input().split())
    ans[p]+=x

visit=[True]*(n+1)
tmp=[1]
for x in tmp:
    visit[x]=False
    for y in neighbor[x]:
        if visit[y]:
            tmp.append(y)
            ans[y]+=ans[x]

print(*ans[1:])
### BUGGY CODE ###

n,k=map(int,input().split())
mod=10**9+7
ans=0
l=[0]*(k+1)

for i in range(k,0,-1):
    l[i]=(k//i)**n%mod
    for j in range(2*i,k+1,i):
        l[i]-=l[j]
        l[i]%=mod
    ans+=l[i]*i
    ans%=mod

print(ans)

### FIXED CODE ###

n,k=map(int,input().split())
mod=10**9+7
ans=0
l=[0]*(k+1)
 
for i in range(k,0,-1):
    l[i]=pow(k//i,n,mod)
    for j in range(2*i,k+1,i):
        l[i]-=l[j]
        l[i]%=mod
    ans+=l[i]*i
    ans%=mod
 
print(ans)
### BUGGY CODE ###

l, r = map(int, input().split())
ans = []
for i in range(l, r+1):
    for j in range(i+1, r+1):
        if j == i+1:
            start = (i*j) % 2019
        tmp = (i*j) % 2019
        if j != i+1 and tmp == start:
            break
        else:
            ans.append(tmp)
print(min(ans))

### FIXED CODE ###

l, r = map(int, input().split())
ans = []
for i in range(l, r+1):
    for j in range(i+1, r+1):
        if j == i+1:
            start = (i*j) % 2019
        tmp = (i*j) % 2019
        if tmp == 0:
            print(0)
            exit()
        if j != i+1 and tmp == start:
            break
        else:
            ans.append(tmp)
print(min(ans))
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**6)

mod=10**9+7
N,K=map(int,input().split())

tree=[]
for i in range(N+1):
  tree.append([])

for i in range(N-1):
  a,b=map(int,input().split())
  tree[a].append(b)
  tree[b].append(a)
#print(tree)

answer=1
visited=[False]*(N+1)
def dfs(node,depth,cind):
  #print(node,depth,cind)
  global answer
  visited[node]=True
  
  if depth==0:
    answer*=K
    answer%=mod
  elif depth==1:
    answer*=K-1-cind
    answer%=mod
  else:
    answer*=K-2-cind
    answer%=mod
  
  next_nodes=tree[node]
  i=0
  for nn in next_nodes:
    if not visited[nn]:
      dfs(nn,depth+1,i)
      i+=1

node=N//2
dfs(node,0,0)
print(answer)


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)

mod=10**9+7
N,K=map(int,input().split())

tree=[]
for i in range(N+1):
  tree.append([])

for i in range(N-1):
  a,b=map(int,input().split())
  tree[a].append(b)
  tree[b].append(a)
#print(tree)

answer=1
visited=[False]*(N+1)
def dfs(node,depth,cind):
  #print(node,depth,cind)
  global answer
  visited[node]=True
  
  if depth==0:
    answer*=K
    answer%=mod
  elif depth==1:
    answer*=K-1-cind
    answer%=mod
  else:
    answer*=K-2-cind
    answer%=mod
  
  next_nodes=tree[node]
  i=0
  for nn in next_nodes:
    if not visited[nn]:
      dfs(nn,depth+1,i)
      i+=1

node=N//2
dfs(node,0,0)
print(answer)
### BUGGY CODE ###

n = int(input())
a = [int(input()) for i in range(n)]
for i in range(n):
    tmp = a.pop(0)
    print(max(a))
    a.append(tmp)
    

### FIXED CODE ###

n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
a_max = max(a)
ind_M = a.index(a_max)
tmpl = a
tmpl.pop(ind_M)
for i in range(n):
    if i != ind_M:
        print(a_max)
    else:
        print(max(tmpl))
### BUGGY CODE ###

def __lower_bound(arr, x, left, right):
    if left >= right:
        return right
    mid = (left+right)//2
    if arr[mid] < x:
        return __lower_bound(arr, x, mid+1, right)
    else:
        return __lower_bound(arr, x, left, mid-1)
def lower_bound(arr, x, left, right):
    result = __lower_bound(arr, x, left, right)
    if arr[result] >= x:
        result -= 1
    return result

n = int(input())
data = list(map(int, input().split()))
data.sort()
ans = 0
for a in range(n):
    for b in range(a+1, n):
        bound = lower_bound(data, data[a]+data[b], b+1, n-1)
        if bound >= 0:
            ans += bound - b

print(ans)

### FIXED CODE ###

from bisect import bisect_left
n = int(input())
sides = list(map(int, input().split()))
sides.sort()
ans = 0
for a in range(len(sides)):
    for b in range(a+1,len(sides)):
        bound = bisect_left(sides, sides[a]+sides[b], b+1)
        if bound >= n:
            ans += bound - b - 1
        elif sides[bound] < sides[b]:
            ans += bound - b
        elif bound > b+1:
            ans += bound - b - 1

print(ans)
### BUGGY CODE ###

from fractions import gcd
N = int(input())
a = [int(c) for c in input().split()]
mod = 10**9+7
ans = a[0]
for i in range(1, N):
  ans = ans* a[i]//gcd(ans, a[i])
b = 0
for i in range(N):
  b += (ans//a[i])%mod
print(b%mod)

### FIXED CODE ###

import numpy as np
N = int(input())
a = np.array(input().split(), np.int64)
MOD = 10**9+7
U = 10**6+10
is_prime = np.zeros(U, np.bool)
is_prime[2] = 1
is_prime[3::2] = 1
for p in range(3, U, 2):
  if p*p>U:
    break
  if is_prime[p]==1:
    is_prime[p*p::p+p] = 0

M = 10**3
small_primes = np.where(is_prime[:M])[0].tolist()

B = a.copy()
lcm = 1
for p in small_primes:
  e = 0
  while np.any(a%p==0):
    a[a%p==0] //= p
    e += 1
  lcm *= p**e
  lcm %= MOD

for x in set(a.tolist()):
  lcm *= x
  lcm %= MOD

answer = sum(pow(x, MOD-2, MOD) for x in B.tolist())%MOD
answer *= lcm
answer %= MOD
print(answer)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(100000)

def intinput(): return map(int,sys.stdin.readline().split())

n,m=intinput()
a=[]
memo={x:0 for x in range(n+4)}
memo[0]=1
mod = 10**9+7
for i in range(m):
    a.append(int(input()))
for i in range(n):
    if i+1 not in a:
        memo[i+1]=(memo[i+1]+memo[i])%mod
    if i+2 not in a:
        memo[i+2]=(memo[i+2]+memo[i])%mod
print(memo[n])

### FIXED CODE ###

import sys
sys.setrecursionlimit(100000)

def intinput(): return map(int,sys.stdin.readline().split())

fib={0:0,1:1,2:1}
for i in range(3,100003):
    fib[i]=fib[i-1]+fib[i-2]
  #  fib.append(fib[i-1]+fib[i-2])

n,m=intinput()
mod=10**9+7
a=[int(sys.stdin.readline()) for _ in range(m)]
if m!=0:
    l=[a[0]]
    for i in range(len(a)-1):
        l.append(a[i+1]-a[i]-1)
    l.append(n-a[-1])
    k=1
    for i in l:
        k=fib[i]*k%mod
    print(k%mod)
else:
    print(fib[n+1]%mod)
### BUGGY CODE ###

n, m = map(int,input().split())
s = input()
for _ in range(m):
    x, y = map(int,input().split())
    print(s[x-1:y].count("AC"))

### FIXED CODE ###

n, m = map(int,input().split())
dp = [0 for _ in range(n+1)]
S = input()
a = [0 for _ in range(m)]
for i in range(1,n):
    if S[i-1:i+1] == "AC":
        dp[i] = dp[i-1]+1
    else:dp[i] = dp[i-1]
for i in range(m):
    x, y = map(int,input().split())
    a[i] = dp[y-1] - dp[x-1]
print(*a,sep="\n")
### BUGGY CODE ###

N, M = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(M)]
 
 
ans = set(range(l[0][0], l[0][1] + 1))
for i in range(1, M):
    ans = ans.intersection(set(range(l[i][0], l[i][1] + 1)))
print(len(ans))

### FIXED CODE ###

import numpy as np
N, M = map(int, input().split())

l = [list(map(int, input().split())) for _ in range(M)]
l = np.array(l)
ans = list(range(l[:, 0].max(), l[:, 1].min() + 1))
print(len(ans))
### BUGGY CODE ###

N = int(input())

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

### FIXED CODE ###

N = int(input())


def f(x):
    result = N // x
    return result

ans = 0
for x in range(1, N + 1):
    Y = f(x)
    ans += x * Y * (Y + 1) / 2
print(int(ans))
### BUGGY CODE ###

from collections import deque
K = int(input())

q = deque([1])
used = [False] * K
def cost(x):
    ret = 0
    while x:
        ret += x % 10
        x //= 10
    return ret

while True:
    x = q.popleft()
    if x % K == 0:
        print(cost(x))
        break
    elif used[x % K]:
        continue
    used[x % K] = True
    q.appendleft(10*x)
    q.append(x+1)


### FIXED CODE ###

from collections import deque
K = int(input())

q = deque()
q.append((1, 1, 1))
used = set()
while True:
    x, y, k = q.popleft()
    if k % K == 0:
        print(x)
        break
    if (x, 0, k*10%K) in used:
        continue
    else:
        used.add((x, 0, k*10%K))
    q.appendleft((x, 0, k*10%K))
    if (y + 1) % 10 == 0:
        q.appendleft((x, 0, k+1))
    else:
        q.append((x+1, y+1, k+1))
### BUGGY CODE ###

h,w,m=map(int,input().split())
h_=[0]*(h+1)
w_=[0]*(w+1)
plot=[[] for _ in range(h+1)]
for _ in range(m):
    x,y=map(int,input().split())
    h_[x]+=1
    w_[y]+=1
    plot[x].append(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 j in plot[i]:
            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 ###

MOD=10**9+7

S=input()
S=S[::-1]
N=len(S)

def POWt(N):
    arr=[1]
    for i in range(1,N+1):
        arr.append(arr[-1]*10%13)
    return arr

dp=[[0]*13 for i in range(N+1)]
dp[0][0]=1
POW=POWt(N)
for i in range(N):
    for j in range(13):
        if(S[i]!='?'):
            dp[i+1][(j+(int(S[i])*POW[i]%13))%13]=(dp[i+1][(j+(int(S[i])*POW[i])%13)%13]+dp[i][j])%MOD
        else:
            for k in range(10):
                dp[i+1][(j+k*POW[i]%13)%13]=(dp[i+1][(j+k*POW[i]%13)%13]+dp[i][j])%MOD
print(dp[N][5])

### FIXED CODE ###

MOD=10**9+7

S=input()
S=S[::-1]
N=len(S)

def POWt(N):
    arr=[1]
    for i in range(1,N+1):
        arr.append(arr[-1]*10%13)
    return arr

dp=[[0]*13 for i in range(N+1)]
dp[0][0]=1
POW=POWt(N)
for i in range(N):
    for j in range(13):
        if(S[i]!='?'):
            dp[i+1][(j+(int(S[i])*POW[i]%13))%13]=(dp[i+1][(j+(int(S[i])*POW[i])%13)%13]+dp[i][j])%MOD
        else:
            for k in range(10):
                dp[i+1][(j+k*POW[i]%13)%13]=(dp[i+1][(j+k*POW[i]%13)%13]+dp[i][j])%MOD
print(dp[N][5])
### BUGGY CODE ###

n = int(input())
sl = [input() for _ in [0]*n]
for i in range(len(sl)):
  sl[i] = sorted(sl[i])
  sl[i] = ''.join(sl[i])
count = 0
sl.sort()
while len(sl)>1:
  i = sl.count(sl[-1])
  if i > 1:
    count += i*(i-1)//2
  sl = sl[:-i]
print(count)

### FIXED CODE ###

n = int(input())
sl = sorted([''.join(sorted(input())) for _ in [0]*n])
count = 0
while len(sl)>1:
  i = 1
  flag = True
  while flag:
    if sl[-1] == sl[-(i+1)]:
      i += 1
      if i == len(sl):
        flag=False
    else:
      flag = False
  if i>1:
    count += i*(i-1)//2
  del sl[-i:]
  flag=True
print(count)
### BUGGY CODE ###

L, R = map(int, input().split())
min_l = []
ij = list(set([_ % 2019 for _ in range(L, R+1)]))


for i in ij:
    for j in ij:
        if i < j:
            min_l.append((i*j) % 2019)
        else:
            continue
print(min(min_l))

### FIXED CODE ###

l, r = map(int, input().split())
if r // 3 > (l - 1) // 3 and r // 673 > (l - 1) // 673:
    print(0)
else:
    print(min(i * j % 2019 for i in range(l, r + 1) for j in range(l, i)))