Harryxun/stf_run huggingface dataset:
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.append(n)
d=[]
for i in range(len(a)):
    d.append([i,a[i+1]-a[i]])
l=sorted(d,key=lambda x:x[1])

o=l[-1][0]
g=a[o]+n-a[o+1]
print(g)

### FIXED CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))
a.append(n)
d=[]
for i in range(len(a)-1):
    d.append([i,a[i+1]-a[i]])
d[-1][1]+=a[0]
l=sorted(d,key=lambda x:x[1])

o=l[-1][0]
if o==len(a)-2:
    g=a[-2]-a[0]
else:
    g=a[o]+n-a[o+1]
print(g)
n,k = map(int,input().split())
a = list(map(int,input().split()))
num = [a[0]]
while True:
    for i in range(len(num)-1):
        if num[i] == num[-1]:
            break
    num.append(a[num[-1]])
index = index(a[-1])
lstart = len(a[:index-1])
lroop = len(a[index])
number = (k-lstart)%lroop
for i in range(lroop-1):
    number = a[number-1]
    print(number)
print(number)

### FIXED CODE ###

import collections
n,k = map(int,input().split())
a = list(map(int,input().split()))
list = [1]
i = 0
num = a[0]
for i in range(3*n):
    list.append(num)
    num = a[num-1]

cnt = collections.Counter(list)
onevalue = [k for k,v in cnt.items() if v == 1]
lstart = len(onevalue)
lroop = len(set(list))-lstart

if k <= lstart:
    num = a[0]
    for i in range(k-1):
        num = a[num-1]
    print(num)
    exit()
elif lstart == 0:
    k = (k-lstart)%lroop
    num = 1
    for i in range(k):
        num = a[num-1]
    print(num)
    exit()
else:
    k = (k-lstart)%lroop
    num = a[0]
    if lstart > 0:
        for i in range(lstart-1):
            num = a[num-1]
    for i in range(k):
        num = a[num-1]
    print(num)
    exit()
n = int(input.()split())
if 1 in n and 9 in n and 7 in n and 4 in n:
  print("YES")
else:
  print("NO")

### FIXED CODE ###

n= list(map(int,input().split()))
n.sort()
if 1 in n and 7 in n and 9 in n and 4 in n:
  print("YES")
else:
  print("NO")
R=int,input()
import math
def circleround(s):
  s=R*math.pi*2
s=R*math.pi*2
print(s)

### FIXED CODE ###

import math
R=int(input())
print(math.pi*2*R)
row = 3
column = 3
c=[]

for i in range(1, (row+1)):
    c.append(list(map(str, input().split())))
print(c[0][0],c[1][1],c[2][2],sep="")


### FIXED CODE ###

row = 3
column = 3
c=[]

for i in range(1, (row+1)):
    c.append(input())

print(c[0][0],c[1][1],c[2][2],sep="")
import sys


for line in sys.stdin.readline():
    xa1, ya1, xa2, ya2, xb1, yb1, xb2, yb2 = map(float, line.rstrip('\n').split(' '))
    if ((xb1<=xa1 and xa1<=xb2) or (xa1<=xb1 and xb1<=xa2)) and ((yb1<=ya2 and ya2<=yb2) or (ya1<=yb2 and yb2<=ya2)):
        print 'YES'
    else:
        print 'NO'

### FIXED CODE ###


import sys


for line in sys.stdin:
    xa1, ya1, xa2, ya2, xb1, yb1, xb2, yb2 = map(float, line.strip().split(' '))
    if ((xb1<=xa1 and xa1<=xb2) or (xa1<=xb1 and xb1<=xa2)) and ((yb1<=ya2 and ya2<=yb2) or (ya1<=yb2 and yb2<=ya2)):
        print 'YES'
    else:
        print 'NO'
import numpy as np
from collections import deque

h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
s = np.array(s)
s = (s == ".") * 1
def neext(a):
    l, m = a[0], a[1]
    if l == 0:
        if m == 0:
            return [(l, m+1), (l+1, m)]
        elif m == w - 1:
            return [(l, m-1), (l+1, m)]
        else:
            return [(l, m+1), (l, m-1), (l+1, m)]
    elif m == 0:
        if l == h - 1:
            return [(l, m+1), (l-1, m)]
        else:
            return [(l, m+1), (l+1, m), (l-1, m)]
    elif l == h - 1:
        if m == w - 1:
            return [(l, m-1), (l-1, m)]
        else:
            return [(l, m+1), (l, m-1), (l-1, m)]
    elif m == w - 1:
        return [(l, m-1), (l+1, m), (l-1, m)]
    else:
        return [(l, m+1), (l, m-1), (l+1, m), (l-1, m)]
def solve(i, j):
    if s[i][j] == 0:
        return 0
    else:
        pre = 0
        p = np.full_like(s, -1)
        check = deque([((-1, -1), (i, j), 0)])#(from,now, dist)
        while check:
            From, now, d = check.popleft()
            p[now[0]][now[1]] = d
            pre = max(pre, d)
            for b, c in neext((now[0], now[1])):
                if (b == From[0] and c == From[1]) or p[b][c] != -1 or s[b][c] == 0:
                    continue
                else:
                    check.append(((i, j), (b, c), d + 1))
        return pre
ans = 0
for H in range(len(s)):
    for W in range(len(s[0])):
        ans = max(ans, solve(H, W))
print(ans)

### FIXED CODE ###

import numpy as np
from collections import deque
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
ans = 0
for i in range(len(s)):
    for j in range(len(s[0])):
        if s[i][j] == '#':
            continue
        pre = 0
        p = np.full((h, w), -1)
        p[i][j] = 0
        check = deque([((i, j), 0)])#(from,now, dist)
        while check:
            now, d = check.popleft()
            pre = max(pre, d)
            for k, l in [(1,0), (-1,0),(0,1), (0,-1)]:
                b = now[0] + k
                c = now[1] + l
                if b < 0 or c < 0 or b >= h or c >= w:
                    continue 
                elif p[b][c] == -1 and s[b][c] != '#':
                    check.append(((b, c), d + 1))
                    p[b][c] = d + 1
        ans = max(ans, pre)

print(ans)
s = list(input())
t = list(input())

result = []
for i in range(len(s) - len(t)):
    result.append(len(t))
    for j in range(len(t)):
        if(s[i+j] == t[j]):
            result[i] -= 1

print(min(result))



### FIXED CODE ###

s = list(input())
t = list(input())

if(t in s):
    print(0)

result = [0] * ((len(s) - len(t)) + 1)
for i in range(len(s) - len(t) + 1):
    result[i] = len(t)
    for j in range(len(t)):
        if(s[i+j] == t[j]):
            result[i] -= 1
 
print(min(result))
n = int(input())
d = list(map(int,input().split()))
p = 0
q = 0
d.sort(key=int)
if (len(d))%2 == 0:
  m = (d[(len(d)//2)-1]+d[len(d)//2])/2
else:
  m = d[(len(d)//2)]
for i in range(len(d)):
  if d[i]>=m:
    if d[i] == d[i+1]:
      break
    else:
      p = d[i]
      q = d[i-1]
      break
print(p-q)


### FIXED CODE ###

n = int(input())
d = sorted(list(map(int,input().split())))
print(d[n//2]-d[n//2-1])
a = input().split()

initial_middle = a[7]

print('A'+ initial_middle +'C')

### FIXED CODE ###

a = input()

initial_middle = a[8]

print('A'+ initial_middle +'C')
from sys import stdin, setrecursionlimit
from collections import deque

setrecursionlimit(10 ** 9)
INF = 1 << 60


def input():
    return stdin.readline().strip()


N, M = map(int, input().split())
A = [0] * M
B = [0] * M
G = [[] for _ in range(M)]
for i in range(M):
    a, b = map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)

dist = [-1] * N
dist[0] = 0
prev = [0] * N
q = deque([0])
while q:
    v = q.popleft()
    for nv in G[v]:
        if dist[nv] == -1:
            q.append(nv)
            dist[nv] = dist[v] + 1
            prev[nv] = v
    
print('Yes')
for v in prev[1:]:
    print(v+1)

### FIXED CODE ###

from sys import stdin, setrecursionlimit
from collections import deque

setrecursionlimit(10 ** 9)
INF = 1 << 60


def input():
    return stdin.readline().strip()


N, M = map(int, input().split())
G = [[] for _ in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)

dist = [-1] * N
dist[0] = 0
prev = [0] * N
q = deque([0])
while q:
    v = q.popleft()
    for nv in G[v]:
        if dist[nv] == -1:
            q.append(nv)
            dist[nv] = dist[v] + 1
            prev[nv] = v
    
print('Yes')
for v in prev[1:]:
    print(v+1)
W,H,x,y,r = input().split()

if r =< x and x =< W-r:
    if r =< y and y =< H-r:
        print("Yes")
    else:
        print("No")

else:
    print("No")

### FIXED CODE ###

W, H, x, y, r = input().split()

if int(r) <= int(x) and int(x) <= int(W) - int(r):
    if int(r) <= int(y) and int(y) <= int(H) - int(r):
        print("Yes")
    else:
        print("No")

else:
    print("No")
import sys
sys.setrecursionlimit(10000000000)


def process():
    data = []
    for line in get_data():
        line = line.split()
        if len(line) == 2:
            if line[0] == line[1] == '0':
                data = []
                continue
            H = int(line[0])
            W = int(line[1])
        elif len(line) == 0:
            pass
        else:
            data.append(line[0])
            if len(data) == H:
                field = create_field(H, W)
                print(search(H, W, data, field))


def search(H, W, data, field):
    count = 0
    for i in xrange(H):
        for j in xrange(W):
            if field[i][j] == 0:
                continue
            _search(i, j, H, W, data[i][j], data, field)
            count += 1
    return count


def _search(i, j, H, W, cell, data, field):
    field[i][j] = 0
    for a in xrange(i-1, i+2):
        if -1 < a < H:
            pass
        else:
            continue
        for b in xrange(j-1, j+2):
            if -1 < b < W:
                pass
            else:
                continue

            if a != i and b != j:
                continue

            if field[a][b] == 0:
                continue
            if cell == data[a][b]:
                _search(a, b, H, W, cell, data, field)
    return


def create_field(H, W):
    field = []
    for i in xrange(H):
        raw = []
        for j in xrange(W):
            raw.append(1)
        field.append(raw)
    return field


def get_data():
    line = input().rstrip()
    u = line.split()
    H = int(u[0])
    data = []
    for i in xrange(H):
        data.append(input().rstrip())

process()

### FIXED CODE ###

import sys
sys.setrecursionlimit(100000000)


def main():
    solve()


def solve():
    for data in get_dataset():
        print search(data)


def search(data):
    count = 0
    H = len(data)
    W = len(data[0])
    for i in xrange(H):
        for j in xrange(W):
            if data[i][j] == '.':
                continue
            _search(i, j, H, W, data[i][j], data)
            count += 1
    return count


def _search(i, j, H, W, cell, data):
    data[i][j] = '.'
    for a in xrange(i-1, i+2):
        if not -1 < a < H:
            continue
        for b in xrange(j-1, j+2):
            if not -1 < b < W:
                continue

            if a != i and b != j:
                continue

            if data[a][b] == '.':
                continue

            if cell == data[a][b]:
                _search(a, b, H, W, cell, data)
    return


def get_dataset():
    dataset = []
    while True:
        line = raw_input().rstrip().split()
        H = int(line[0])
        if H == 0:
            break

        data = []
        for i in xrange(H):
            data.append(list(raw_input().rstrip()))
        dataset.append(data)
    return dataset


if __name__ == '__main__':
    main()
import math
a = [input().split() for l in range(2)]
if sum(a[1]) >= a[0][0]
	print("Yes")
else
	print("No")

### FIXED CODE ###

a = [list(map(int,input().split())) for l in range(2)]

if sum(a[1]) >= a[0][0]:
    print("Yes")
else:
    print("No")
n, k, x, y = map(int, input().split())

if n <= k:
    print(k * x)
else:
    print(k * x + (n - k) * y)


### FIXED CODE ###

N = int(input())   
K = int(input())   
X = int(input())    
Y = int(input())    

if N <= K:
    print(N * X)
else:
    print(K * X + (N - K) * Y)
A,B,C = map(int. input().split(' '))
if A <= C <= B: print('Yes')
else: print('No')

### FIXED CODE ###

A,B,C = map(int, input().split(' '))
if A <= C <= B: print('Yes')
else: print('No')
M,A = map(int,input().split())
 
if X < A:
  print("0")
else:
  print("10")

### FIXED CODE ###

X,A = map(int,input().split())
 
if X < A:
  print(0)
else:
  print(10)
N = input()
sum = 0
for i in range(1, N+1):
    if i % 3 != 0 and i % 5 != 0:
        sum += i

print(sum)


### FIXED CODE ###

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

print(sum)
n = int(input())
x = input()
count_1 = x.count('1')
value = [0, 0]
x_int = int(x, 2)
value[0] = x_int % (count_1 - 1) if count_1 > 1 else 0
value[1] = x_int % (count_1 + 1)
for i in range(n):
    if x[i] == '0':
        tmp = (pow(2, n - i - 1, count_1 + 1) + value[1]) % (count_1 + 1)
    else:
        tmp = (-pow(2, n - i - 1, count_1 - 1) + value[0]) % (count_1 - 1)
    ans = 1
    while tmp > 0:
        tmp = tmp % (bin(tmp).count('1'))
        ans += 1
    print(ans)

### FIXED CODE ###

n = int(input())
x = input()
count_1 = x.count('1')
value = [0, 0]
x_int = int(x, 2)
value[0] = x_int % (count_1 - 1) if count_1 > 1 else 0
value[1] = x_int % (count_1 + 1)
for i in range(n):
    if x[i] == '0':
        tmp = (pow(2, n - i - 1, count_1 + 1) + value[1]) % (count_1 + 1)
    else:
        if count_1 == 1:
            print(0)
            continue
        tmp = (-pow(2, n - i - 1, count_1 - 1) + value[0]) % (count_1 - 1)
    ans = 1
    while tmp > 0:
        tmp = tmp % (bin(tmp).count('1'))
        ans += 1
    print(ans)
print(input() ** 3)

### FIXED CODE ###

a = int(input())
print(a ** 3)
s = input().rstrip()
d = ['dream', 'dreamer']
e = ['erase', 'eraser']
ch = d + e

def search_(s, ch):
    if len(s) == 0:
        return True
    if len(s) < len(ch):
        return False
    else:
        if s[:len(ch)] == ch:
            return search(s[len(ch):])

def search(s):
    if len(s) == 0:
        return True
    if s[0] == 'd' or s[0] == 'e':
        for ci in ch:
            if search_(s, ci):
                return True
    return False

if search(s):
    print('YES')
else:
    print('NO')


### FIXED CODE ###

s = input().rstrip()
d = ['dream', 'dreamer']
e = ['erase', 'eraser']
ch = d + e

st = [s]

def search_(s, st, ch):
    if len(s) == 0:
        return
    if len(s) < len(ch):
        return
    else:
        if s[:len(ch)] == ch:
            st.append(s[len(ch):])

def search(s):
    if len(s) == 0:
        return True
    if s[0] == 'd' or s[0] == 'e':
        for ci in ch:
            if search_(s, ci):
                return True
    return False

while st:
    s = st.pop(0)
    if len(s) == 0:
        print('YES')
        exit()
    if s[0] == 'd' or s[0] == 'e':
        for ci in ch:
            search_(s, st, ci)
print('NO')
import os
import sys

import numpy as np
from scipy.sparse.csgraph import dijkstra

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

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N, M, L = list(map(int, sys.stdin.readline().split()))
ABC = [list(map(int, sys.stdin.readline().split())) for _ in range(M)]
Q = int(sys.stdin.readline())
S, T = list(zip(*[map(int, sys.stdin.readline().split()) for _ in range(Q)]))


D = np.full((N, N), IINF)
for a, b, c in ABC:
    D[a - 1][b - 1] = c
    D[b - 1][a - 1] = c

# warshall floyd
for via in range(N):
    D = np.minimum(D, sum(np.meshgrid(D[via], D[via], sparse=True)))

counts = dijkstra(D <= L, directed=False)
S = np.array(S, dtype=int) - 1
T = np.array(T, dtype=int) - 1

ans = counts[S, T] - 1
ans[ans == np.inf] = -1
print(*ans.astype(int), sep='\n')


### FIXED CODE ###

import os
import sys

import numpy as np
from scipy.sparse.csgraph import floyd_warshall

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

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N, M, L = list(map(int, sys.stdin.readline().split()))
ABC = [list(map(int, sys.stdin.readline().split())) for _ in range(M)]
Q = int(sys.stdin.readline())
S, T = list(zip(*[map(int, sys.stdin.readline().split()) for _ in range(Q)]))

D = np.full((N, N), 0)
for a, b, c in ABC:
    D[a - 1][b - 1] = c
    D[b - 1][a - 1] = c

floyd_warshall(D, directed=False, overwrite=True)
counts = floyd_warshall(D <= L, directed=False, unweighted=True)
S = np.array(S, dtype=int) - 1
T = np.array(T, dtype=int) - 1

ans = counts[S, T] - 1
ans[ans == np.inf] = -1
print(*ans.astype(int), sep='\n')
N, M = map(int,input().split())
connections=[]
for _ in range(M):
    connections.append(list(map(int,input().split())))
conditions = list(map(int,input.split()))

ans_cnt = 0
for i in range(2**N):
    condition_cnt = 0
    for j in range(M):

        cnt=0
        for k in connections[j][1:]:
            if (i >> k) & 1:
                cnt += 1
        if (cnt +conditions[j])%2 == 0:
            condition_cnt += 1
    if condition_cnt == M:
        ans_cnt += 1

print(ans_cnt)


### FIXED CODE ###

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

conditions = [list(map(int,input().split())) for _ in range(M)]
p = list(map(int,input().split()))

ans = 0
for i in range(2**N):
    light_cnt = 0
    for condition_idx in range(M):


        switch_num = 0
        for j in range(N):
            if i >> j & 1 and j+1 in conditions[condition_idx][1:]: # つながっているスイッチの押してあるものを数える
                switch_num += 1
        if switch_num%2 == p[condition_idx]:
            light_cnt += 1
    if light_cnt == M:
        ans += 1
print(ans)
def calc(val, unit):
	if unit == 'BTC':
		val *= 380000
	return val

sum41 = 0
n = int(input())
for i in range(n):
	tmp = input().rstrip('\n').split(' ')
	sum41 += calc(tmp[0], tmp[1])

print(1.0 * sum41)

### FIXED CODE ###

sum41 = 0
n = int(input())
for _ in range(n):
	tmp = input().split(' ')
	sum41 += float(tmp[0]) if tmp[1] == 'JPY' else float(tmp[0]) * 380000

print(1.0 * sum41)
print(' 'swapcase(1200))

### FIXED CODE ###

s = input()
print(s.swapcase())
a=int(input())
b=int(input())
print(max([a+b,a-b,a*b]))


### FIXED CODE ###

a, b = map(int, input().split())
print(max([a+b,a-b,a*b]))
a=input()
if a=A:
  print(T)
elif a=T:
  print(A)
elif a=C:
  print(G)
else:
  print(C)

### FIXED CODE ###

a=input()
if a=="A":
  print("T")
elif a=="T":
  print("A")
elif a=="C":
  print("G")
else:
  print("C")
#input
D, N = map(int, input().split())

#output
if D == 0:
    if N = 100:
        print(101)
    else:
        print(N)
elif D == 1:
    if N == 100:
        print(10100)
    else:
        print(100*N)
else:
    if N == 100:
        print(1010000)
    else:
        print(100**2*N)

### FIXED CODE ###

#input
D, N = map(int, input().split())

#output
if D == 0:
    if N == 100:
        print(101)
    else:
        print(N)
elif D == 1:
    if N == 100:
        print(10100)
    else:
        print(100*N)
else:
    if N == 100:
        print(1010000)
    else:
        print(100**2*N)
BWBWBW

### FIXED CODE ###

s = input()
w = 0
b = 0
wa = 0
ba = 0
l = len(s)
 
for i in range(l):
  if s[i] == 'W':
    wa += i - w
    w += 1
  if s[-1-i] == 'B':
    ba += i - b
    b += 1
    
print(min(ba, wa))
n, m = map(int, input().split())
dp = [0] * (10**5)
jud = [True]*(n+1)
for k in range(m):
    a = int(input())
    jud[a] = False

dp[0] = 1
if jud[1]:
    dp[1] = 1
else:
    dp[1] = 0

for i in range(2, n+1):
    if jud[i-1]:
        dp[i] += dp[i-1]
    if jud[i-2]:
        dp[i] += dp[i-2]
print(dp[n] % 1000000007)

### FIXED CODE ###

n, m = map(int, input().split())
dp = [0] * (10**5+10)
jud = [True]*(10**5)
for k in range(m):
    a = int(input())
    jud[a] = False

dp[0] = 1
if jud[1]:
    dp[1] = 1
else:
    dp[1] = 0

for i in range(2, n+1):
    if jud[i-1]:
        dp[i] += dp[i-1]
    if jud[i-2]:
        dp[i] += dp[i-2]
print(dp[n] % 1000000007)
N, W = map(int, input().split())
w, v = [0]*N, [0]*N
total_v = 0
for _ in range(N):
  w[i], v[i] = map(int, input().split())
  total_v += v[i]

dp = [[float('inf') for _ in range(total_v+1)] for _ in range(N+1)]
dp[0][0] = 0

for i in range(1, N+1):
  for j in range(1, total_v+1):
    if j < v[i-1]:
      dp[i][j] = dp[i-1][v]
    else:
      dp[i][j] = min(dp[i-1][j], dp[i-1][j-v[i-1]] + w[i-1])
for i in range(total_v, -1, -1):
  if dp[-1][i] <= W:
    print(i)
    break

### FIXED CODE ###

n, w = map(int, input().split())
nums = []
for _ in range(n):
  nums.append(list(map(int, input().split())))
  
total_v = sum(nums[i][1] for i in range(n))

dp = [[float('inf') for _ in range(total_v+1)] for _ in range(n+1)]
dp[0][0] = 0

for i in range(1, n+1):
  for j in range(total_v+1):
    if j < nums[i-1][1]:
      dp[i][j] = dp[i-1][j]
    else:
      dp[i][j] = min(dp[i-1][j], dp[i-1][j-nums[i-1][1]] + nums[i-1][0])
for i in range(total_v, -1, -1):
  if dp[n][i] != float('inf') and dp[n][i] <= w:
    print(i)
    break
a = int(raw_input())
b = int(raw_input())

print = (a *  b), (a*2 + b*2)

### FIXED CODE ###

a,b = map(int,raw_input().split())
print ("{0} {1}").format(a*b,2*a+2*b)
K = int(input())
a,b = map(int,input().split())
for i in range(a,b+1):
  if i%K == 0:
  print('OK')
  else:
  print('No')
  return

### FIXED CODE ###

K = int(input())
a,b = map(int,input().split())
c = 'NG'
for i in range(a,b+1):
  if i % K == 0:
    c = 'OK'
    break
print(c)
A = input()
B = input()

if len(A) > len(B):
    print("GREATER")
elif len(A) < len(B):
    print("LESS")
else:
    i = 0
    while A[i] == B[i]:
        i += 1
    if int(A[i]) > int(B[i]):
        print("GREATER")
    else:
        print("LESS")



### FIXED CODE ###

A = int(input())
B = int(input())
 
if A > B:
    print("GREATER")
elif A < B:
    print("LESS")
else:
    print("EQUAL")
H,W,M=map(int,input().split())
row=[0]*H
col=[0]*W
for i in range(M):
    h,w=map(int,input().split())
    row[h-1]+=1
    col[w-1]+=1
A=max(row)
B=max(col)
a=[x for x in range(H) if row[x]==A]
b=[x for x in range(W) if col[x]==B]
cnt=0
for i in a:
    for j in b:
        cnt+=1
        if (i,j) not in target:
            print(A+B)
            exit(0)
        if cnt>M:
            print(A+B-1)
            exit(0)
print(A+B-1)

### FIXED CODE ###

H,W,M=map(int,input().split())
row=[0]*H
col=[0]*W
target=set()
for i in range(M):
    h,w=map(int,input().split())
    row[h-1]+=1
    col[w-1]+=1
    target.add((h-1,w-1))
A=max(row)
B=max(col)
a=[x for x in range(H) if row[x]==A]
b=[x for x in range(W) if col[x]==B]
cnt=0
for i in a:
    for j in b:
        cnt+=1
        if (i,j) not in target:
            print(A+B)
            exit(0)
        if cnt>M:
            print(A+B-1)
            exit(0)
print(A+B-1)
import re

date_s = input()

date_l = date_s.replace("/", "")

if(date_l <= 20190430):
  print "Heisei"
else:
  print "TBD"
    


### FIXED CODE ###

import re

date_s = input()

date_l = int(date_s.replace("/", ""))

if(date_l <= 20190430):
  print("Heisei")
else:
  print("TBD")
n = int(input())
d = list(map(int,input().split()))
d.sort()
if len(d)%2 == 0:
    m = (d[(len(d)//2)-1]+d[len(d)//2])/2
else:
    m = d[(len(d)//2)]
p = 0
q = 0
for i in range(len(d)):
    if d[i]>=m:
        if d[i] == d[i+1]:
            break
        else:
            p = d[i]
            q = d[i-1]
            break
print(p-q)

### FIXED CODE ###

n = int(input())
d = sorted(list(map(int,input().split())))
print(d[n//2]-d[n//2-1])
A,B,K = (int(x) for x in input().split())

if A > K:
  print(A-K+B)
  
elif A+B>K
  print(B-K-A)
else:
  print(0)

### FIXED CODE ###

A,B,K = (int(x) for x in input().split())

if A > K:
  print(A-K,B)
  
elif A+B>K:
  print(0,B-K+A)
else:
  print(0,0)
while True:
    if input()=="0 ? 0":
        break
    print(eval(input()))

### FIXED CODE ###

while True:
    x=input()
    if "?" in x:
        break
    print(int(eval(x.replace("/","//"))))
N,L=map(int,input().split())
S=[input() for i in range(N)]


Ts=""
T=[]
for j in range(L):
    t=j
    for i in range(N):
        if t==L: t=0
        Ts+=S[t]
        t+=1
    T.append(Ts)
    Ts=""

print(min(T))

### FIXED CODE ###

N,L=map(int,input().split())
S=[input() for i in range(N)]

T=[]
for i in range(N):
    s=min(S)
    T.append(s)
    S.pop(S.index(s))

Ts=""
for i in range(len(T)):
    Ts+=T[i]

print(Ts)
a,b = input().split()
#print(a)
#print(b)

if a>8 or b>8:
    print(':(')
else:
    print('Yay!')




### FIXED CODE ###

a,b = input().split()
#print(a)
#print(b)

if int(a)>8 or int(b)>8:
    print(':(')
else:
    print('Yay!')