Harryxun/stf_run huggingface dataset:
N, K = map(int, input().split())
Alist = list(map(int, input().split()))

gone = []

isLooped = False


def dfs(index):
    global isLooped
    if index in gone:
        isLooped = True
        return

    gone.append(index)
    dfs(Alist[index-1])


dfs(1)

if isLooped:
    last = gone[-1]
    loopStartIndex = gone.index(Alist[last-1])
    divK = K % len(gone[loopStartIndex:])
    print(Alist[divK])

else:
    print(Alist[K-1])


### FIXED CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))
s = []
ord = [-1 for i in range(n+1)]
v = 1
c = 1
l = 0
while ord[v] == -1:
    ord[v] = len(s)
    s.append(v)
    v = a[v-1]
c = len(s) - ord[v]
l = ord[v]
if k < l:
    print(s[k])
else:
    k -= l
    k %= c
    print(s[l+k])
a,b=map(int,input().split())
list = [0]*a
t_cnt = 0
f_cnt = 0
for i in range(b):
  c, d = map(str,input().split())
  if d == 'AC':
    if list[c-1] == 0:
      list[c-1] = 1
      t_cnt += 1
  else:
    if list[c-1] == 0:
      f_cnt += 1
print("{} {}".format(t_cnt, f_cnt))


### FIXED CODE ###

a,b=map(int,input().split())
list = [0]*a
t_cnt = 0
f_cnt = [0]*a
for i in range(b):
  c, d = map(str,input().split())
  x = int(c) - 1
  if list[x] == 0:
    if d == 'AC':
        list[x] = 1
        t_cnt += 1
    else:
        f_cnt[x] += 1
for i in range(a):
  if list[i] ==0:
    f_cnt[i] = 0
print("{} {}".format(t_cnt, sum(f_cnt)))
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))
BC = []
for _ in range(M):
    BC.append(tuple(map(int, input().split())))
BC = sorted(BC, reverse=True, key=lambda x:x[1])

first_idx = 0
last_idx = 0
for num, val in BC:
    if A[last_idx] >= val:
        break
    if last_idx >= N:
        break

    for _ in range(num):
        if A[last_idx] < val:
            last_idx += 1
        else:
            A[first_idx:last_idx] = [val] * (last_idx - first_idx)
            first_idx = last_idx
            break

        if last_idx >= N:
            A[first_idx:last_idx] = [val] * (last_idx - first_idx)
            break
    else:
        A[first_idx:last_idx] = [val] * (last_idx - first_idx)
        first_idx = last_idx

print(sum(A))

### FIXED CODE ###

N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))
BC = []
for _ in range(M):
    BC.append(tuple(map(int, input().split())))
BC = sorted(BC, reverse=True, key=lambda x:x[1])

first_idx = 0
last_idx = 0
for num, val in BC:
    if last_idx >= N:
        break

    if A[last_idx] >= val:
        break
    

    for _ in range(num):
        if A[last_idx] < val:
            last_idx += 1
        else:
            A[first_idx:last_idx] = [val] * (last_idx - first_idx)
            first_idx = last_idx
            break

        if last_idx >= N:
            A[first_idx:last_idx] = [val] * (last_idx - first_idx)
            break
    else:
        A[first_idx:last_idx] = [val] * (last_idx - first_idx)
        first_idx = last_idx

print(sum(A))
n=int(input())
l=[[0,0,0]]
for _ in range(n):
    l.append(list(map(int,input().split())))

memo=[[-1,-1,-1] for _ in range(n+1)]
memo[0][0]=0
memo[0][1]=0
memo[0][2]=0
def dp(i,j):
    if memo[i][j]!=-1:
        return memo[i][j]
    else:
        memo[i][j]=max(dp(i-1,(j+1)%3)+l[i][j],dp(i-1,(j+2)%3)+l[i][j])
        return memo[i][j]
print(max(dp(n,0),dp(n,1),dp(n,2)))

### FIXED CODE ###

import sys
sys.setrecursionlimit(int(1e6))

n=int(input())
l=[[0,0,0]]
for _ in range(n):
    l.append(list(map(int,input().split())))

memo=[[-1,-1,-1] for _ in range(n+1)]
memo[0][0]=0
memo[0][1]=0
memo[0][2]=0
def dp(i,j):
    if memo[i][j]!=-1:
        return memo[i][j]
    else:
        memo[i][j]=max(dp(i-1,(j+1)%3)+l[i][j],dp(i-1,(j+2)%3)+l[i][j])
        return memo[i][j]
print(max(dp(n,0),dp(n,1),dp(n,2)))
import sys
import os
import bisect, collections, copy, itertools, math, string
def I(): return int(input())
def S(): return input()
def LI(): return list(map(int, input().split()))
def LS(): return list(input().split())



def solve():
	ABC = LI()
    
    def swap(i, j):
      tmp = ABC[i]
      ABC[i] = ABC[j]
      ABC[j] = tmp
      
    swap(0, 1)
    swap(0, 2)
    print(ABC[0], ABC[1], ABC[2])
    
    
	
if __name__ == '__main__':
	solve()


### FIXED CODE ###

import sys
import os
import bisect, collections, copy, itertools, math, string
def I(): return int(input())
def S(): return input()
def LI(): return list(map(int, input().split()))
def LS(): return list(input().split())

def solve():
	ABC = LI()

	def swap(i, j):
		tmp = ABC[i]
		ABC[i] = ABC[j]
		ABC[j] = tmp

	swap(0, 1)
	swap(0, 2)

	print(ABC[0], ABC[1], ABC[2])
	
if __name__ == '__main__':
	solve()
n,k,c = map(int, input().split())
s = input()

# 計算途中は0~N-1日とする

# [a,b] i日までで、限界まで働くとa回働けてb日まで働けない
pre = [[0,0] for i in range(n)]
if s[0]=='o':
    pre[0]=[1,c]
    for j in range(c):
        if 1+j < n:
            pre[1+j] = pre[0] + []

for i in range(1,n):
    if pre[i]==[0,0]:
        if s[i]=='o':
            pre[i][0]=pre[i-1][0]+1
            pre[i][1]+=i+c
            for j in range(c):
                if i+j+1<n:
                    pre[i+j+1]=pre[i]+[]
        else:
            pre[i]=pre[i-1]+[]

# i日以降で限界まで働くとa回働ける
post = [0 for i in range(n)]
if s[-1]=='o':
    post[-1]=1
    for j in range(c):
        if 0 <= n-1-j-1 < n:
            post[-1-j-1] = post[-1]

for i in range(1,n):
    if post[n-i-1]==0:
        if s[n-i-1]=='o':
            post[n-i-1]=post[n-i]+1
            for j in range(c):
                if 0<=n-i-1-j-1<n:
                    post[n-i-1-j-1]=post[n-i-1]
        else:
            post[n-i-1]=post[n-i]

# 0日、n+1日を追加。iを1~nにする
pre = [[0,0]]+pre+[[0,0]]
post = [0]+post+[0]

ans = []
for i in range(1,n+1):
    if s[i-1]=='o':
        work, rest = pre[i-1]
        day = max(rest,i)+1
        work = work + post[day]
        if work<k:
            ans.append(i)

for i in range(len(ans)):
    print(ans[i])

### FIXED CODE ###

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

# 計算途中はi=0~n-1日とする

# [a,b] i日までで、限界まで働くとa回働けてb日まで働けない
pre = [[0,0] for i in range(n)]
if s[0]=='o':
    pre[0]=[1,c]
    for j in range(c):
        if 1+j < n:
            pre[1+j] = pre[0] + []

for i in range(1,n):
    if pre[i]==[0,0]:
        if s[i]=='o':
            pre[i][0]=pre[i-1][0]+1
            pre[i][1]+=i+c
            for j in range(c):
                if i+j+1<n:
                    pre[i+j+1]=pre[i]+[]
        else:
            pre[i]=pre[i-1]+[]

# i日以降で限界まで働くとa回働ける
post = [0 for i in range(n)]
if s[-1]=='o':
    post[-1]=1
    for j in range(c):
        if 0 <= n-1-j-1 < n:
            post[-1-j-1] = post[-1]

for i in range(1,n):
    if post[n-i-1]==0:
        if s[n-i-1]=='o':
            post[n-i-1]=post[n-i]+1
            for j in range(c):
                if 0<=n-i-1-j-1<n:
                    post[n-i-1-j-1]=post[n-i-1]
        else:
            post[n-i-1]=post[n-i]

# 0日、n+1日を追加。iを1~n日にする
pre = [[0,0]]+pre+[[0,0]]
post = [0]+post+[0]

# i日に休んだときに、働く回数がkに到達するか調べる
ans = []
for i in range(1,n+1):
    if s[i-1]=='o':
        work, rest = pre[i-1]
        day = min(max(rest,i)+1,n+1)
        work = work + post[day]
        if work<k:
            ans.append(i)

for i in range(len(ans)):
    print(ans[i])
a = map(int, input().split())
b = a[0] - 2*a[1]
if b >= 0:
  print(b)
else:
  print(0)


### FIXED CODE ###

a = list(map(int, input().split()))
b = a[0] - 2*a[1]
if b >= 0:
  print(b)
else:
  print(0)
N = int(input())
A,B = map(int,input().split())

lis = []

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

for i in P:
  if i <= A:
    lis[0] += 1
  elif i <= B:
    lis[1] += 1
  else:
    lis[2] += 1
    
print (min(lis))

### FIXED CODE ###

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

lis = [0,0,0]

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

for i in P:
  if i <= A:
    lis[0] += 1
  elif i <= B:
    lis[1] += 1
  else:
    lis[2] += 1
    
print (min(lis))
a,b,c,d = map(int,input().split())
l = list(range(a,b+1))
ans = 0
for i in range(len(l)):
  if l[i] % c != 0 and l[i] % d != 0:
    ans += 1
print(ans)


### FIXED CODE ###

A,B,C,D = map(int,input().split())

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

def F(N,C,D):
  x = N
  x -= N//C
  x -= N//D
  lcm = C*D//gcd(C,D)
  x += N//lcm
  return x

answer = F(B,C,D) - F(A-1,C,D)
print(answer)
iter_num = input()
variables = input()

raw_variables = variables.split(' ')
variables = list()

for raw_variable in raw_variables:
    variables.append(int(raw_variable))


def calc(variable):
    process_count = 0
    while (variable % 2 == 0):
        process_count += 1
        variable = variable / 2
    return process_count


min_count = None

for variable in variables:
    process_count = calc(variable)
    if min_count is None:
        min_count = process_count
    if process_count < min_count:
        min_count = process_count

print(min_count)


### FIXED CODE ###

chars = input()
count = 0
for char in chars:
    if char == '1':
        count += 1
print(count)
x.append(int(input()))N = int(input())
x = []
hp = []
xa = 0
hpsum = 0

x = [int(e) for e in input().split()]
for i in range(N):
    xa += x[i]



xa = xa / N

if xa % 1 < 0.5:
    xa = int(xa / 1)
elif xa % 1 >= 0.5:
    xa = int(xa / 1 + 1)

for j in range(N):
    hp.append((x[j]-xa)*(x[j]-xa))
    hpsum += hp[j]

print(int(hpsum))

### FIXED CODE ###

N = int(input())
x = []
hp = []
xa = 0
hpsum = 0

x = [int(e) for e in input().split()]
for i in range(N):
    xa += x[i]



xa = xa / N

if xa % 1 < 0.5:
    xa = int(xa / 1)
elif xa % 1 >= 0.5:
    xa = int(xa / 1 + 1)

for j in range(N):
    hp.append((x[j]-xa)*(x[j]-xa))
    hpsum += hp[j]

print(int(hpsum))
# -*- coding: utf-8 -*-

import sys
import os
import math

directions = [(1, 0), (-1, 0), (0, 1), (0, -1)]

for s in sys.stdin:
    H, W = map(int, s.split())
    if H == W == 0:
        break

    # map
    M = []
    for i in range(H):
        s = input().strip()
        M.append(s)

    # W x H white map
    A = [[None for i in range(H)] for j in range(W)]

    def drawable(x, y):
        if 0 <= x < W and 0 <= y < H and A[y][x] == None:
            return True
        else:
            return False

    color_num = 0

    def fill(x, y):
        global color_num

        A[y][x] = color_num
        for direction in directions:
            new_x = x + direction[0]
            new_y = y + direction[1]
            if drawable(new_x, new_y) and M[y][x] == M[new_y][new_x]:
                fill(new_x, new_y)

    for y in range(H):
        for x in range(W):
            if drawable(x, y):
                color_num += 1
                fill(x, y)

    print(color_num)

### FIXED CODE ###

# -*- coding: utf-8 -*-

import sys
import os
import math

directions = [(1, 0), (-1, 0), (0, 1), (0, -1)]

for s in sys.stdin:
    H, W = map(int, s.split())
    if H == W == 0:
        break

    # map
    M = []
    for i in range(H):
        s = input().strip()
        M.append(s)

    # W x H white map
    A = [[None for i in range(W)] for j in range(H)]

    def drawable(x, y):
        if 0 <= x < W and 0 <= y < H and A[y][x] == None:
            return True
        else:
            return False

    color_num = 0

    def fill(x, y):
        global color_num

        Q = [(x, y)]
        while Q:
            p = Q.pop(0)
            _x = p[0]
            _y = p[1]
            A[_y][_x] = color_num
            for direction in directions:
                new_x = _x + direction[0]
                new_y = _y + direction[1]
                if drawable(new_x, new_y) and M[_y][_x] == M[new_y][new_x]:
                    A[new_y][new_x] = color_num
                    Q.append((new_x, new_y))

    for y in range(H):
        for x in range(W):
            if drawable(x, y):
                color_num += 1
                fill(x, y)

    print(color_num)
n,k=map(int(input()).split())
A=list(map(int,input().split()))


if k>=n:
  print(abs(A[k-1]-A[0]))
else:
  dp=list(range(n))
  for i in range(k):
    dp[i]=abs(A[i]-A[0])
  for i in range(n-k):
    temp=list(range(k))
    for j in range(k):
      temp[j-1]=dp[i]+abs(A[i+k]-A[i])
      dp[i+k]=min(temp)
  print(dp[n-1])

### FIXED CODE ###

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

if k>=n:
  print(abs(A[n-1]-A[0]))
else:
  dp=list(range(n))
  for i in range(k):
    dp[i]=abs(A[i]-A[0])
  for i in range(n-k):
    temp=list(range(k))
    for j in range(k):
      temp[j]=dp[i+j]+abs(A[i+k]-A[i+j])
    dp[i+k]=min(temp)
  print(dp[n-1])
l_ans = [0] * n
g = 0
for i in range(1, n):
    g = gcd(g, v[i-1])
    l_ans[i] = g
r_ans = [0] * n
g = 0
for i in range(1, n):
    g = gcd(g, v[n-i])
    r_ans[i] = g
r_ans.reverse()
ans = 1
for i in range(n):
    ans = max(ans, gcd(l_ans[i], r_ans[i]))
print(ans)


### FIXED CODE ###

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

def gcd(a,b):
  while b != 0:
    a, b = b, a % b
  return a

l_ans = [0] * n
g = 0
for i in range(1, n):
    g = gcd(g, v[i-1])
    l_ans[i] = g
r_ans = [0] * n
g = 0
for i in range(1, n):
    g = gcd(g, v[n-i])
    r_ans[i] = g
r_ans.reverse()
ans = 1
for i in range(n):
    ans = max(ans, gcd(l_ans[i], r_ans[i]))
print(ans)
sample = input()
new = []
for i in sample:
  new.append(i)
if "A" in new:
  a_pos = list.index(new)
if "Z" in new:
  z_pos = list.index(new)
if a_post < z_pos:
  out = new[a_pos:(z_pos+1)]
    
new_string = ""
for i in out:
  new_string += i
print(len(new_string))


### FIXED CODE ###

sample = input()
#new = list(sample)
#if "A" in new:
a_pos = sample.index('A')
#if "Z" in new:
z_pos = sample.rfind('Z')
print(z_pos-a_pos+1)
N = int(intput())
stocks = list(map(int, input().split()))
curr = 1000
for i in range(N - 1):
  cnt = 0
  if stocks[i] < stocks[i + 1]:
    cnt = curr // stocks[i]
  curr += cnt * (stocks[i + 1] - stocks[i])
print(curr)

### FIXED CODE ###

N = int(input())
stocks = list(map(int, input().split()))
curr = 1000
for i in range(N - 1):
  cnt = 0
  if stocks[i] < stocks[i + 1]:
    cnt = curr // stocks[i]
  curr += cnt * (stocks[i + 1] - stocks[i])
print(curr)
N,M = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
INF = float("inf")
num = [INF,2,5,5,4,5,6,3,7,6]
if N==2, and M==9:
    print(1)
    exit()

dp = [0]+[-INF]*N
#dpテーブルを作成
for i in range(1,N+1):
    ins = -INF
    for a in A:
        try:
            tmp = dp[i-num[a]]+1
            ins = max(ins,tmp)
        except:
            continue
    dp[i] = ins

#各桁の数字を決定
A.sort(reverse=True)
digit = ["0"]*dp[N]
mat = 0
for i in range(dp[N]):
    for a in A:
        try:
            t1 = dp[N-mat-num[a]]
            t2 = dp[N-mat]-1
        except:
            continue
        if t1 == t2:
            digit[i] = str(a)
            mat += num[a]
            break
print("".join(digit))


### FIXED CODE ###

N,M = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
INF = float("inf")
num = [INF,2,5,5,4,5,6,3,7,6]
if N==2 and M==9:
    print(1)
    exit()

dp = [0]+[-INF]*N
#dpテーブルを作成
for i in range(1,N+1):
    ins = -INF
    for a in A:
        try:
            tmp = dp[i-num[a]]+1
            ins = max(ins,tmp)
        except:
            continue
    dp[i] = ins

#各桁の数字を決定
A.sort(reverse=True)
digit = ["0"]*dp[N]
mat = 0
for i in range(dp[N]):
    for a in A:
        try:
            t1 = dp[N-mat-num[a]]
            t2 = dp[N-mat]-1
        except:
            continue
        if t1 == t2:
            digit[i] = str(a)
            mat += num[a]
            break
print("".join(digit))
# -*- coding: utf-8 -*-


def search(n, m, tile, N, M):
    for dy, dx in zip([-1, -1, -1, 0, 0, 1, 1, 1], [-1, 0, 1, -1, 1, -1, 0, 1]):
        if 0 <= dy + n < N and 0 <= dx + m < M:
            if tile[dy + n][dx + m] == '1':
                tile[dy + n][dx + m] = '2'
                search(dy + n, dx + m, tile, N, M)


while True:
    M, N = map(int, input().split())
    if M == 0 and N == 0:
        break
    tile = [input().split() for n in range(N)]
    ans = 0
    for n in range(N):
        for m in range(M):
            if tile[n][m] == '1':
                tile[n][m] = '2'
                search(n, m, tile, N, M)
                ans += 1
    print(ans)




### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10000)


def search(n, m, tile, N, M):
    for dy, dx in zip([-1, -1, -1, 0, 0, 1, 1, 1], [-1, 0, 1, -1, 1, -1, 0, 1]):
        if 0 <= dy + n < N and 0 <= dx + m < M:
            if tile[dy + n][dx + m] == '1':
                tile[dy + n][dx + m] = '2'
                search(dy + n, dx + m, tile, N, M)


while True:
    M, N = map(int, input().split())
    if M == 0 and N == 0:
        break
    tile = [input().split() for n in range(N)]
    ans = 0
    for n in range(N):
        for m in range(M):
            if tile[n][m] == '1':
                tile[n][m] = '2'
                search(n, m, tile, N, M)
                ans += 1
    print(ans)
vv = list(input())

ccc = "7" in vv

if ccc = True:
    print("Yes")
else:
    print("No")


### FIXED CODE ###

vv = int(input())

if vv <= 999 and vv >= 100:
    vvvv = list(str(vv))


    ccc = "7" in vvvv

    if ccc == True:
        print("Yes")
    else:
        print("No")
S,T = input().split()
A,B = input().split()
U = input()
if U == S:
    A = int(A)-1
else:
    B = int(B)-1
print(str(A)+' '+str(B))

### FIXED CODE ###

S,T = input().split()
A,B = input().split()
U = input()
if U == S:
    A = int(A)-1
else:
    B = int(B)-1
print(str(A)+' '+str(B))
def isOdd(num):
	if num % 2 == 0:
		return False
	else:
		return True

A, B, C = map(int, raw_input().split())
ans = 0
while not isOdd(A) and not isOdd(B) and not isOdd(C):
	ans += 1
	new1, new2, new3 = B/2 + C/2, A/2 + C/2, A/2 + B/2
	if set(A, B, C) == set(new1, new2, new3):
		print -1
	else:
		A, B, C = new1, new2, new3
print ans


### FIXED CODE ###

A, B, C = map(int, raw_input().split())
[A, B, C] = sorted([A, B, C])
ans = 0
while A%2==0 and B%2==0 and C%2==0:
	ans += 1
	new1, new2, new3 = B/2 + C/2, A/2 + C/2, A/2 + B/2
	if new1 == new3:
		ans = -1
		break
	else:
		A, B, C = new1, new2, new3
print ans
prime_list = [2]
for num in range(3,10**5,2):
    if all(num % prime != 0 for prime in prime_list):
        prime_list.append(num)
        if (num >= x):
            print(num)
            exit()
print(100003)

### FIXED CODE ###

import math
x = int(input())
if (x <= 2):
    print(2)
    exit()
ans = 100003
if (x%2 == 0):
    x += 1
for num in range(x, 10**5, 2):
    flag = True
    for i in range(3, math.floor(math.sqrt(num))+1, 2):
        if(num % i == 0):
            flag = False
            break
    if(flag):
        ans = num
        break
print(ans)
import numpy as np
from numpy import linalg as LA

mat_dic = {}

def f(mat, n):
    if mat_dic.get(n, None) is not None:
        return mat_dic.get(n, None)

    if n == 1:
        return mat
    return mat.dot(f(mat, n-1))


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

mat = np.identity(N)
res = np.zeros(N)

for m in range(M):
    a, b = tuple(map(int, input().split(' ')))
    mat[a-1, b-1] = 1
    mat[b-1, a-1] = 1
    mat[a-1, a-1] = 1
    mat[b-1, b-1] = 1

Q = int(input())

for q in range(Q):
    v, d, c = tuple(map(int, input().split(' ')))
    x = f(mat, d)
    res[x[v-1,:] > 0] = c


for i in range(N):
    print(int(res[i]))


### FIXED CODE ###

import numpy as np

def dp(v, d, c):
    if memo[v-1][d]:
        return

    memo[v-1][d] = True
    if d == 0:
        res[v-1] = str(c)
        return

    dp(v, d-1, c)
    for e in dic[v-1]:
        dp(e, d-1, c)


N, M = [int(e) for e in input().split(' ')]

dic = [[] for _ in range(N)]
memo = [[False]*11 for _ in range(N)]

for m in range(M):
    a, b = [int(e) for e in input().split(' ')]
    dic[a-1].append(b)
    dic[b-1].append(a)

Q = int(input())


vdc = [[int(e) for e in input().split(' ')] for _ in range(Q)]

res = ['0']*N

[dp(v, d, c) for v, d, c in vdc[::-1]]


print('\n'.join(res))
s = int(input())
ans = 0
for i in s:
  if i == '+':
    ans += 1
  else:
    ans -= 1
print(ans)

### FIXED CODE ###

s = input()
ans = 0
for i in s:
  if i == '+':
    ans += 1
  else:
    ans -= 1
print(ans)
X = input()
if X == 3 || X == 5 || X == 7:
  print("YES")
else:
  print("NO")

### FIXED CODE ###

print(["NO", "YES"][[7, 5, 3].count(int(input()))])
import math
n=int(input())
a=list(map(int,input().split()))
print(math.gcd(a))
      

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
def gcd(x,y):
  while x%y>0:
    x,y=y,x%y
  return y
a.sort(reverse=True)
ans=a[0]
for j in range(n-1):
  ans=gcd(ans,a[j+1])
print(ans)
import sys
from collections import Counter
H,W,m = map(int,input().split())
h_ls = [0] * H
w_ls = [0] * W
bombers = [[0,0] for _ in range(m)]
for i in range(m):
    h,w = map(int,input().split())
    h_ls[h-1] += 1
    w_ls[w-1] += 1
    bombers[i] = [h-1,w-1]

h_max = max(h_ls)
h_counter = Counter(h_ls)
# Couter使ってみる
h_max_args = [0]*h_counter[h_max]
next_ind = 0
for i in range(H):
    if h_ls[i] == h_max:
        h_max_args[next_ind] = i
        next_ind += 1

w_max = max(w_ls)
w_counter = Counter(w_ls)
w_max_args = [0]*w_counter[w_max]
next_ind = 0
for i in range(W):
    if w_ls[i] == w_max:
        w_max_args[next_ind] = i
        next_ind += 1

bombers = set(bombers)
for h in h_max_args:
    for w in w_max_args:
        if not [h,w] in bombers:
            print(w_max+h_max)
            sys.exit()

print(w_max+h_max-1)


### FIXED CODE ###

import sys
from collections import Counter
H,W,m = map(int,input().split())
h_ls = [0] * H
w_ls = [0] * W
bombers = [(0,0) for _ in range(m)]
for i in range(m):
    h,w = map(int,input().split())
    h_ls[h-1] += 1
    w_ls[w-1] += 1
    bombers[i] = (h-1,w-1)

h_max = max(h_ls)
h_counter = Counter(h_ls)
# Couter使ってみる
h_max_args = [0]*h_counter[h_max]
next_ind = 0
for i in range(H):
    if h_ls[i] == h_max:
        h_max_args[next_ind] = i
        next_ind += 1

w_max = max(w_ls)
w_counter = Counter(w_ls)
w_max_args = [0]*w_counter[w_max]
next_ind = 0
for i in range(W):
    if w_ls[i] == w_max:
        w_max_args[next_ind] = i
        next_ind += 1

bombers = set(bombers)
for h in h_max_args:
    for w in w_max_args:
        if not (h,w) in bombers:
            print(w_max+h_max)
            sys.exit()

print(w_max+h_max-1)
import sys
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read 
inp = sys.stdin.buffer.readline


def resolve():
    MOD = 10 ** 9 + 7

    # 0: white, 1: black
    def dfs(v, parent):
        dp[v][0] = 1
        dp[v][1] = 1
        for to in G[v]:
            if to == parent:
                continue
            dfs(to, v)
            # 親が白の時は子は白黒どっちでも良い
            # 親が黒の時は子は白のみ
            dp[v][0] = (dp[v][0] * (dp[to][0] + dp[to][1])) % MOD
            dp[v][1] = (dp[v][1] * dp[to][0]) % MOD

    N = int(input())
    G = [[] for _ in range(N)]
    for _ in range(N - 1):
        x, y = map(lambda x: int(x) - 1, inp().split())
        G[x].append(y)
        G[y].append(x)
    dp = [[0] * 2 for _ in range(N + 1)]

    dfs(0, -1)
    ans = dp[0][0] + dp[0][1]
    print(ans % MOD)


if __name__ == "__main__":
    resolve()

### FIXED CODE ###


import sys
sys.setrecursionlimit(10 ** 7)
inp = sys.stdin.buffer.readline


def resolve():
    MOD = 10 ** 9 + 7

    # 0: white, 1: black
    def dfs(v, parent):
        vistied[v] = True
        dp[v][0] = 1
        dp[v][1] = 1
        for to in G[v]:
            if to == parent or vistied[to]:
                continue
            dfs(to, v)
            # 親が白の時は子は白黒どっちでも良い
            # 親が黒の時は子は白のみ
            dp[v][0] *= (dp[to][0] + dp[to][1]) % MOD
            dp[v][1] *= dp[to][0] % MOD

    N = int(inp())
    G = [[] for _ in range(N)]
    for _ in range(N - 1):
        x, y = map(lambda x: int(x) - 1, inp().split())
        G[x].append(y)
        G[y].append(x)
    dp = [[0] * 2 for _ in range(N)]
    vistied = [False] * N

    dfs(0, -1)
    ans = dp[0][0] + dp[0][1]
    print(ans % MOD)


if __name__ == "__main__":
    resolve()