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

H,N = map(int,input().split())

dp = [float("INF")]*(H+1)
dp[0] = 0
for i in range(N):
    a,b= map(int,input().split())
    for j in range(1,H+1):
        dp[j] = min(dp[j],dp[max((j-a),0)]+b)

print(dp[-1])

### FIXED CODE ###

#モンスターの体力は H
#トキはN種類の魔法が使え、
#i番目の魔法を使うと、モンスターの体力を Ai減らすことができますが、
#トキの魔力を Bi消耗します。

#dp[i] = モンスターの体力を i 減らすため消耗する魔力の最小値
#dp[i+1] = min(dp[i-Ai]+Bi,dp[i])
#dp[0]=0

import numpy as np
 
h, n = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ab = np.array(ab)
 
a = ab[:, 0]
b = ab[:, 1]
 
dp = np.zeros(100001, dtype=np.int)
for i in range(1, h+1):
    dp[i] = (dp[i-a]+b).min()
print(dp[h])
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
for i in range(n):
    a1 = a
    a2 = set(a1)
    ans = 0
    for j in a2:
        if j == a1[i]:
            cnt = a1.count(j) - 1
        else:
            cnt = a1.count(j)
        ans += cnt * (cnt - 1) // 2
    print(ans)

### FIXED CODE ###

from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
cnt = 0
for i in c.values():
    cnt += i * (i - 1) // 2
for i in a:
    print(cnt - c[i] + 1)
### BUGGY CODE ###

def find(A,x) -> int:
    p = A[x]
    if p == x:
        return x
    a = find(A,p)
    A[x] = a
    return a

def union(A, x, y):
    if find(A,x) > find(A,y):
        bx, by = find(A,y), find(A,x)
    else:
        bx, by = find(A,x), find(A,y)
    A[y] = bx
    A[by] = bx

def examD():
    N = I()
    x = [[] for _ in range(N)]; y = [[] for _ in range(N)]
    for i in range(N):
        a, b = LI()
        x[i] = (a-1,i)
        y[i] = (b-1,i)
    v = [ i for i in range(N)]
    x.sort(); y.sort()
    H = []
    heapify(H)
    for i in range(N - 1):
        x1, j1 = x[i]
        x2, j2 = x[i + 1]
        y1, k1 = y[i]
        y2, k2 = y[i + 1]
        heappush(H, (x2 - x1, j1, j2))
        heappush(H, (y2 - y1, k1, k2))
    ans = 0
#    print(H)
#    print(v)
    while H:
        w, s, t = heappop(H)
        if find(v, s) != find(v, t):
            union(v, s, t)
            ans += w
    print(ans)

import sys
import copy
import bisect
from heapq import *
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examD()


### FIXED CODE ###

def find(A,x) -> int:
    p = A[x]
    if p == x:
        return x
    a = find(A,p)
    A[x] = a
    return a

def union(A, x, y):
    if find(A,x) > find(A,y):
        bx, by = find(A,y), find(A,x)
    else:
        bx, by = find(A,x), find(A,y)
    A[y] = bx
    A[by] = bx
def examD():
    N = I()
    x = [[] for _ in range(N)]; y = [[] for _ in range(N)]
    for i in range(N):
        a, b = LI()
        x[i] = (a-1,i)
        y[i] = (b-1,i)
    v = [ i for i in range(N)]
    x.sort(); y.sort()
    H = []
    heapify(H)
    for i in range(N - 1):
        x1, j1 = x[i]
        x2, j2 = x[i + 1]
        y1, k1 = y[i]
        y2, k2 = y[i + 1]
        heappush(H, (x2 - x1, j1, j2))
        heappush(H, (y2 - y1, k1, k2))
    ans = 0
#    print(H)
#    print(v)
    while H:
        w, s, t = heappop(H)
        if find(v, s) != find(v, t):
            union(v, s, t)
            ans += w
    print(ans)

import sys
import copy
import bisect
from heapq import *
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examD()
### BUGGY CODE ###

n = int(input())
A = [int(i) for i in input().split()]
q = int(input())
ms = [int(i) for i in input().split()]

def solve(i, m):
    if m == 0:
        return True
    if i >= n:
        return False
    # i?????????????´?????????°????????£?????´?????¨???????????´?????§?????°????????????
    res = solve(i+1, m) or solve(i+1, m-A[i])
    return res

for m in ms:
    if solve(0, m):
        print('yes')
    else:
        print('no')

### FIXED CODE ###

is_able_make = [False] * 2000
n = int(input())
A = [int(i) for i in input().split()]
q = int(input())
M = [int(i) for i in input().split()]

for i in A:
    for j in range(2000-i, 0, -1):
        if is_able_make[j] == True:
            is_able_make[i+j] = True
    is_able_make[i] = True

for x in M:
    if is_able_make[x] == True:
        print('yes')
    else:
        print('no')
### BUGGY CODE ###

p = 10**9 + 7

def modpow(a, n, p):
    if n == 1:
        ans = a % p
    else:
        if n % 2 == 0:
            ans = (modpow(a, n // 2, p) ** 2) % p
        else: # n % 2 == 1
            ans = (a * (modpow(a, n // 2, p) ** 2)) % p

    return ans

def C(N, K, p):
    X, Y = 1, 1
    for k in range(1, K + 1):
        X = X * (N - k + 1) % p
        Y = Y * k % p
    
    Z = modpow(Y, p - 2, p)
    ans = X * Z % p

    return ans

N, K = [int(x) for x in input().split()]
A = sorted([int(x) for x in input().split()])

maxS = 0
for i in range(N):
    maxS = (maxS + A[i] * C(i, K - 1, p)) % p

minS = 0
for i in range(N):
    minS = (minS + A[i] * C(N - i - 1, K - 1, p)) % p

ans = (maxS - minS) % p

print(ans)

### FIXED CODE ###

p = 10**9 + 7

def modpow(a, n, p):
    if n == 1:
        ans = a % p
    else:
        if n % 2 == 0:
            ans = (modpow(a, n // 2, p) ** 2) % p
        else: # n % 2 == 1
            ans = (a * (modpow(a, n // 2, p) ** 2)) % p

    return ans

Fact = [[1, 1] for _ in range(10**5 + 1)]
for i in range(1, 10**5 + 1):
    Fact[i][0] = (Fact[i - 1][0] * i) % p
    Fact[i][1] = modpow(Fact[i][0], p - 2, p)

def C(a, b, p, Fact):
    if a < b:
        return 0
    else:
        ans = Fact[a][0] * Fact[b][1] * Fact[a - b][1] % p
        return ans

N, K = [int(x) for x in input().split()]
A = sorted([int(x) for x in input().split()])
 
maxS = 0
for i in range(N):
    maxS = (maxS + A[i] * C(i, K - 1, p, Fact)) % p

minS = 0
for i in range(N):
    minS = (minS + A[i] * C(N - i - 1, K - 1, p, Fact)) % p

ans = (maxS - minS) % p
 
print(ans)
### BUGGY CODE ###

n = int(input())
p = list(map(int, input().split()))
cnt = 0
for _ in range(n):
    for j in range(_+1):
        if p[_] <= p[j]:
            if _ == j:
                cnt += 1
        else:
            break
print(cnt)

### FIXED CODE ###

n = int(input())
p = list(map(int, input().split()))
cnt = 0
for _ in p:  #p[i]よりも小さいものが出てきたらだめ
    if _ <= n:
        cnt += 1
        n = _
print(cnt)
### BUGGY CODE ###

S = list(input())
ans = []
N = len(S) + 1


def search(n):
    temp = [0, 0]
    # right
    if n != N-1:
        j = n
        ret = 0
        while j < N-1 and S[j] == ">":
            ret += 1
            j += 1
        temp[1] = ret

    # left
    if n != 0:
        j = n - 1
        ret = 0
        while j >= 0 and S[j] == "<":
            ret += 1
            j -= 1
        temp[0] = ret
    return temp


for i in range(N):
    l, r = search(i)
    ans.append(max(l, r))
print(sum(ans))

### FIXED CODE ###

S = list(input())
ans = []
N = len(S) + 1

lr = [[] for _ in range(N)]

# 左から見る
temp = 0
for i in range(N):
    if i == 0:
        lr[i].append(0)
    else:
        if S[i-1] == "<":
            temp += 1
            lr[i].append(temp)
        else:
            temp = 0
            lr[i].append(temp)

# 右から見る
temp = 0
for i in reversed(range(N)):
    if i == N - 1:
        lr[i].append(0)
    else:
        if S[i] == ">":
            temp += 1
            lr[i].append(temp)
        else:
            temp = 0
            lr[i].append(temp)

ans = []
for i in range(N):
    ans.append(max(lr[i]))
print(sum(ans))
### BUGGY CODE ###

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

ss = [[] for i in range(2)]
for i in range(2):
    ss[i] = list(map(int,input().split()))


A = ss[0]
F = ss[1]
A.sort()
F.sort()
F.reverse()

left = -1
right = max([(A[j] * F[j]) for j in range(n)])

while (right - left) > 1:
    b = [[] for i in range(n)]
    s = left + ((right - left) // 2)
    for i in range(n):
        b[i] = min(s//F[i],A[i])
    if (sum(A) - sum(b)) <= k:
        right = s 
    else:
        left = s 

print(right)


### FIXED CODE ###

import numpy as np
n,k = map(int,input().split())

A = np.array(input().split(),np.int)

F = np.array(input().split(),np.int)


A.sort()
F.sort()

F_ = F[::-1]

left = -1
right = (A * F_).sum()

while (right - left) > 1:
    s = (left + right) // 2
    r = np.maximum(0, A - s // F_).sum() <= k
    if r:
        right = s 
    else:
        left = s 

print(right)
### BUGGY CODE ###

N,K = map(int,input().split())
h = list(map(int,input().split()))
INF = 10**10

dp = [INF]*N
dp[0] = 0

def cost(i,j): #足場iから足場jにジャンプするコスト
    return dp[i] + abs(h[j] - h[i])

if N <= K:
    for i in range(1,N):
        for j in range(i):
            dp[i] = min(dp[i],cost(j,i))
else:
    for i in range(1,K):
        for j in range(i):
            dp[i] = min(dp[i],cost(j,i))
    for i in range(K,N):
        for j in range(i-K,i):
            dp[i] = min(dp[i],cost(j,i))

print(dp[N-1])

### FIXED CODE ###

N,K = map(int,input().split())
h = list(map(int,input().split()))
INF = 10**10

dp = [INF]*N
dp[0] = 0

def cost(i,j): #足場iから足場jにジャンプするコスト
    return dp[i] + abs(h[j] - h[i])

if N <= K:
    for i in range(1,N):
        for j in range(i):
            dp[i] = min(dp[i],cost(j,i))
else:
    for i in range(1,K):
        for j in range(i):
            dp[i] = min(dp[i],cost(j,i))
    for i in range(K,N):
        for j in range(i-K,i):
            dp[i] = min(dp[i],cost(j,i))

print(dp[N-1])
### BUGGY CODE ###

import math
import sys
import collections


mod = 1000000007
sys.setrecursionlimit(mod)
fact = {1: 1}


def run(n, m):
    # print('{}を{}個の数列で表現'.format(m, n))
    ans = 1
    primes = []
    for i in range(2, m):
        if m == 1:
            break
        if i*i > m:
            break
        if m % i == 0:
            cnt = 0
            while m % i == 0:
                cnt += 1
                m //= i
                primes.append(i)
            ans *= comb(cnt+n-1, n-1)
            ans %= mod
    # counts = collections.Counter(primes)
    # print(counts)
    # for (_, v) in counts.items():
    #     ans *= comb(v+n-1, n-1)
    #     ans %= mod
    if m != 1:
        ans *= n
        ans %= mod
    return ans


def comb(n, r):
    mul = math.factorial(n) // math.factorial(n - r)
    div = math.factorial(r)
    # mul = factorial(n) // factorial(n - r)
    # div = factorial(r)
    mul %= mod
    div %= mod
    return (mul * modpow(div, (mod-2))) % mod


'''
def factorial(n):
    if n in fact:
        return fact[n]
    else:
        fact[n] = n*factorial(n-1)
        return fact[n]
'''


def modpow(a, p):
    if p == 0:
        return 1
    if p % 2 == 0:
        halfp = p // 2
        half = modpow(a, halfp)
        return int((half * half) % mod)
    else:
        return int((a * modpow(a, p-1)) % mod)


def main():
    n, m = map(int, input().split())
    print(run(n, m))


if __name__ == '__main__':
    main()


### FIXED CODE ###

import math
import sys
import collections


mod = 1000000007
sys.setrecursionlimit(mod)
fact = {1: 1}


def run(n, m):
    # print('{}を{}個の数列で表現'.format(m, n))
    ans = 1
    primes = []
    for i in range(2, m):
        if m == 1:
            break
        if i*i > m:
            break
        if m % i == 0:
            cnt = 0
            while m % i == 0:
                cnt += 1
                m //= i
                primes.append(i)
            ans *= comb(cnt+n-1, n-1)
            ans %= mod
    # counts = collections.Counter(primes)
    # print(counts)
    # for (_, v) in counts.items():
    #     ans *= comb(v+n-1, n-1)
    #     ans %= mod
    if m != 1:
        ans *= n
        ans %= mod
    return ans


def comb(n, r):
    if r > (n-r):
        r = n-r
    mul = 1
    div = 1
    for i in range(r):
        mul *= n-i
        div *= i+1
        mul %= mod
        div %= mod
    # mul = math.factorial(n) // math.factorial(n - r)
    # div = math.factorial(r)
    # mul = factorial(n) // factorial(n - r)
    # div = factorial(r)
    mul %= mod
    div %= mod
    return (mul * modpow(div, (mod-2))) % mod


'''
def factorial(n):
    if n in fact:
        return fact[n]
    else:
        fact[n] = n*factorial(n-1)
        return fact[n]
'''


def modpow(a, p):
    if p == 0:
        return 1
    if p % 2 == 0:
        halfp = p // 2
        half = modpow(a, halfp)
        return int((half * half) % mod)
    else:
        return int((a * modpow(a, p-1)) % mod)


def main():
    n, m = map(int, input().split())
    print(run(n, m))


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

# D - Triangles
from itertools import combinations

N=int(input())
Li=list(map(int,input().split()))

ans=0

l=list(combinations(Li,3))
for i in range(len(l)):
    a,b,c=l[i]
    if a<b+c and b<c+a and c<a+b:
        ans+=1

print(ans)


### FIXED CODE ###

# D - Triangles
import bisect

N=int(input())
Li=list(map(int,input().split()))
Li.sort()

ans=0

for i in range(N):
    for j in range (i+1,N):
        a=Li[i]+Li[j]
        t=bisect.bisect_left(Li,a)
        ans+=t-(j+1)

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

import collections

N = int(input())
A = [int(i) for i in input().split()]

c = collections.Counter(A)

def count(c, x):
    c[x] -= 1
    ret = 0
    for v in c.values():
        ret += v*(v-1)//2
    return ret

N = len(A)
for i in range(N):
    print(count(c.copy(), A[i]))


### FIXED CODE ###

import collections

N = int(input())
A = [int(i) for i in input().split()]

c = collections.Counter(A)

def count_list(c):
    modify = {}
    ret = 0
    for k, v in c.items():
        a = v*(v-1)//2
        b = (v-1)*(v-2)//2
        ret += a
        modify[k] = -a + b
    return ret, modify

counts, modify = count_list(c)
for a in A:
    print(counts + modify[a])
### BUGGY CODE ###

n,k = map(int,input().split())
a = list(map(int,input().split()))
first = 1
for i in range(k):
    first = first*a[i]
b = [first]
for i in range(n-k):
    b.append(b[i]/a[i]*a[k+i])
    if b[i] < b[i+1]:
        print('Yes')
    else:
        print('No')

### FIXED CODE ###

n,k = map(int,input().split())
a = list(map(int,input().split()))
for i in range(n-k):
    if a[i] < a[k+i]:
        print('Yes')
    else:
        print('No')
### BUGGY CODE ###

n = int(input())

S = []
for i in range(n):
    s = input()
    s = sorted(list(s))
    S.append(s)

ans = [0 for i in range(n)]
for i in range(n-1):
    for j in range(i+1, n):
        if S[i] == S[j]:
            ans[i] += 1

print(sum(ans))

### FIXED CODE ###

n = int(input())

cnt = {}
for i in range(n):
    s = input()
    s = sorted(list(s))
    s = str(s)
    if s not in cnt:
        cnt[s] = 0
    else:
        cnt[s] += 1

ans = 0
for c in cnt.values():
    ans += c * (c+1) // 2

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

import sys
NK = input().split()
N,K = int(NK[0]),int(NK[1])
N = list(map(int,input().split()))
if K != 0 and len(N) < K:
    print(0)
    exit()
for i in range(K):
    N.remove(max(N))
print(sum(N))

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


### FIXED CODE ###

import sys
NK = input().split()
N,K = int(NK[0]),int(NK[1])
H = list(map(int,input().split()))
if K != 0 and len(H) < K:
    print(0)
    exit()
H.sort()
for i in range(K):
    H.pop(-1)
print(sum(H))

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

import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
N, Q = map(int, input().split())
graph = [[] for _ in range(N)]
point = [0]*N
for i in range(N-1):
    a, b = map(int, input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)
for i in range(Q):
    p, x = map(int, input().split())
    point[p-1] += x
def dfs(s,parent):
    for i in graph[s]:
        if i == parent:
            continue
        point[i] += point[s]
        dfs(i,s)
dfs(0,-1)
print(*point)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
N, Q = map(int, input().split())
graph = [[] for _ in range(N)]
point = [0]*N
for i in range(N-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)
for i in range(Q):
    p, x = map(int, input().split())
    point[p-1] += x
def dfs(s,parent):
    for i in graph[s]:
        if i == parent:
            continue
        point[i] += point[s]
        dfs(i,s)
dfs(0,-1)
print(*point)
### BUGGY CODE ###

import collections

n = int(input())
List = [input() for i in range(n)]

c = collections.Counter(List)

res = [kv[0] for kv in c.items() if kv[1] == max(c.values())]


#print(sortdict)
res = sorted(res)
leng = len(res)
for i in range(leng):
    print(res[i])

### FIXED CODE ###

import collections

n = int(input())
List = [input() for i in range(n)]
res = []

c = collections.Counter(List)
m = 0
for v in c.values():
  m = max(m, v)
  
for k, v in c.items():
  if v == m:
    res.append(k)
    
res.sort()
for i in range(len(res)):
  print(res[i])
### BUGGY CODE ###

N = int(input())
lst_A = list(map(int, input().split()))

def calc_comb(lst_A):

    elem_A = list(set(lst_A))
    sum_comb = 0

    for A in elem_A:
        numA  = lst_A.count(A)
        combA = (numA * (numA-1)) // 2
        sum_comb += combA

    return sum_comb



def main(N, lst_A):

    sum_comb_all = calc_comb(lst_A)
    lst_sum_comb = []

    for A in lst_A:
        numA = lst_A.count(A)
        prev_combA = (numA * (numA-1)) // 2
        new_combA  = ((numA-1) * (numA-2)) // 2

        sum_comb = sum_comb_all - prev_combA + new_combA
        lst_sum_comb.append(sum_comb)

    return lst_sum_comb

if __name__ == "__main__":

    lst_answer = main(N, lst_A)
    for answer in lst_answer:
        print(answer)
    

### FIXED CODE ###

from collections import Counter

N = int(input())
lst_A = list(map(int, input().split()))

def main(N, lst_A):

    dct_cntA = Counter(lst_A)
    sum_comb = 0

    for cntA in dct_cntA.values():
        comb = (cntA * (cntA - 1)) // 2
        sum_comb += comb

    for A in lst_A:
        print(sum_comb - (dct_cntA[A] - 1))

    return 0

if __name__ == "__main__":

    main(N, lst_A)
### BUGGY CODE ###

N = int(input())
l = list(map(int,input().split()))
l.sort()
ans = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        s = l[i]+l[j]
        if s <= l[j+1]:
            continue
        start = j+1
        end = N
        while start != end:
            center = (start + end)//2
            if s <= l[center]:
                end = center
            else:
                start = center + 1
        ans += end-j-1
print(ans)

### FIXED CODE ###

N = int(input())
l = list(map(int,input().split()))
l.sort()
ans = 0
max = l[N-1]
tc = N
st = [j+1 for j in range(N-1)]
for i in range(N-2):
    if l[i]+l[i+1] > max:
        k = N-i-1
        ans += ((k-1)*k*(k+1))//6
        break
    for j in range(i+1,N-1):
        if j == tc:
            ans += tp
            break
        s = l[i]+l[j]
        if s <= l[j+1]:
            continue
        if s > max:
            tc = j 
            tp = (N-j-1) * (N-j) //2 #これをiの中でできないか
            ans += tp
            break
        start = st[j]
        if s <= l[start]:
            ans += start-j-1
            continue
        end = N
        while start != end:
            center = (start + end)//2
            if s <= l[center]:
                end = center
            else:
                start = center + 1
        st[j] = end
        ans += end-j-1
print(ans)
### BUGGY CODE ###

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

ct1=0
if a[0]<=0:
  a[0]=1
  ct1+=1-a[0]
for i in range(1,n):
  if i%2==1:
    if sum(a[0:i+1])>=0:
      ct1+=sum(a[0:i+1])+1
      a[i]=-sum(a[0:i])-1
  else:
    if sum(a[0:i+1])<=0:
      ct1+=1-sum(a[0:i+1])
      a[i]=-sum(a[0:i])+1

ct2=0
if b[0]>=0:
  b[0]=-1
  ct2+=b[0]-1
for i in range(1,n):
  if i%2==0:
    if sum(b[0:i+1])>=0:
      ct2+=sum(b[0:i+1])+1
      b[i]=-sum(b[0:i])-1
  else:
    if sum(b[0:i+1])<=0:
      ct2+=1-sum(b[0:i+1])
      b[i]=-sum(b[0:i])+1

print(min(ct1,ct2))

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
b=[]
for i in range(n):
  b.append(a[i])

ct1=0
if a[0]<=0:
  ct1+=1-a[0]
  a[0]=1
x=a[0]
for i in range(1,n):
  y=x+a[i]
  if i%2==1:
    if y>=0:
      ct1+=y+1
      a[i]=-x-1
  else:
    if y<=0:
      ct1+=1-y
      a[i]=-x+1
  x+=a[i]

ct2=0
if b[0]>=0:
  ct2+=b[0]+1
  b[0]=-1
x=b[0]
for i in range(1,n):
  y=x+b[i]
  if i%2==0:
    if y>=0:
      ct2+=y+1
      b[i]=-x-1
  else:
    if y<=0:
      ct2+=1-y
      b[i]=-x+1
  x+=b[i]

print(min(ct1,ct2))
### BUGGY CODE ###

n, k = map(int, input().split())
h = list(map(int, input().split()))

for i in range(k):
  max_h = h.index(max(h))
  h[max_h] = 0
cnt = sum(h)
print(cnt)

### FIXED CODE ###

n, k = map(int, input().split())
h = list(map(int, input().split()))

h.sort(reverse=True)
del h[:k]
cnt = sum(h)
print(cnt)
### BUGGY CODE ###

from collections import Counter
H, W, M = map(int, input().split())
count_row = Counter()
count_col = Counter()
count_point = Counter()
for i in range(M):
    h, w = map(int, input().split())
    count_row[h] += 1
    count_col[w] += 1
    count_point[(h, w)] += 1

max_h, max_count_row = count_row.most_common()[0]
max_w, max_count_col = count_col.most_common()[0]
row_iter = [(h, c) for h, c in count_row.most_common() if c == max_count_row]
col_iter = [(w, c) for w, c in count_col.most_common() if c == max_count_col]
ans = 0
for h, row_c in row_iter:
    for w, col_c in col_iter:
        ans = max(ans, row_c+col_c-count_point[(h, w)])
print(ans)


### FIXED CODE ###

from collections import Counter
H, W, M = map(int, input().split())
count_row = Counter()
count_col = Counter()
count_point = Counter()
for i in range(M):
    h, w = map(int, input().split())
    count_row[h] += 1
    count_col[w] += 1
    count_point[(h, w)] += 1

max_h, max_count_row = count_row.most_common()[0]
max_w, max_count_col = count_col.most_common()[0]
row_iter = [h for h, c in count_row.most_common() if c == max_count_row]
col_iter = [w for w, c in count_col.most_common() if c == max_count_col]
ans = max_count_row + max_count_col - 1
flag = False
for h in row_iter:
    for w in col_iter:
        if count_point[(h, w)] == 1:
            continue
        ans += 1
        flag = True
        break
    if flag:
        break
print(ans)
### BUGGY CODE ###

import collections
mod=10**9+7
base=37
n=int(input())
S=list(ord(s)-96 for s in input())
ans=0
d=collections.defaultdict(int)
for i in range(n):
  h=0
  for j in range(i,n):
    h=(h*base+S[j])%mod
    if d[h]==0:
      d[h]=j
    else:
      if d[h]<i:
        ans=max(ans,j-i+1)
print(ans)


### FIXED CODE ###

import collections
mod=10**9+7
base=257
n=int(input())
S=list(ord(s)-96 for s in input())
B=[0]*(n+1)
B[0]=1
for i in range(n):
  B[i+1]=(B[i]*base)%mod

def chk(x):
  ret=False
  h=0
  bx=B[x]
  d=collections.defaultdict(int)
  for i in range(x):
    h=(h*base+S[i])%mod
  d[h]=x
  for i in range(x,n):
    h=(h*base+S[i]-S[i-x]*bx)%mod
    if d[h]==0:
      d[h]=i+1
    elif d[h]<=i-x+1:
      ret=True
  return ret

l,r=0,n//2
while r-l>1:
  m=(l+r)//2
  if chk(m):
    l=m
  else:
    r=m
print(r if chk(r) else l)
### BUGGY CODE ###

import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))

K = len(bin(np.max(A))) - 2

ans = 0
mod = 10 ** 9 + 7
power = 1
N %= mod

for i in range(K):
    bit = sum(A >> i & 1) % mod
    ans += power * bit * (N - bit)
    ans %= mod
    power *= 2
    power %= mod

print(ans)

### FIXED CODE ###

import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))

K = len(bin(np.max(A))) - 2

ans = 0
mod = 10 ** 9 + 7
N %= mod

for i in range(K):
    bit = np.count_nonzero(A >> i & 1) % mod
    ans += 2 ** i * bit * (N - bit)
    ans %= mod
    
print(ans)