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

import fractions
from functools import reduce
def gcd(i):
    return reduce(fractions.gcd, i)
def main():
    N = int(input())
    A = list(map(int, input().split()))
    tmp = []
    if gcd(A) == max(A):
        print(gcd(A))
        exit()
    else:
        for i in range(N):
            if i == 0 :
                tmp.append(gcd(A[1:]))
            elif i == N-1:
                tmp.append(gcd(A[:N-1]))
            else:
                tmp.append(gcd(A[:i]+A[i+1:]))
    print(max(tmp))
if __name__ == "__main__":
    main()

### FIXED CODE ###

import fractions
from functools import reduce
def gcd(*i):
    return reduce(fractions.gcd, i)
def main():
    N = int(input())
    A = list(map(int, input().split()))
    L=[0]
    R=[0]
    for i in range(N):
        L.append(gcd(L[i],A[i]))
        R.append(gcd(R[i],A[-(i+1)]))
    R=R[::-1]
    ans=[]
    for i in range(N):
        ans.append(gcd(L[i],R[i+1]))
    print(max(ans))
if __name__ == "__main__":
    main()
### BUGGY CODE ###

n, m = map(int, input().split())
h = list(map(int, input().split()))
h = [[i, h[i-1]] for i in range(1, n+1)]
path = [list(map(int, input().split())) for i in range(m)]
conn = {key: [] for key in range(1, n+1)}
tower = list(range(1, n+1))


for p in path:
    # h0 > h1
    if h[p[0]-1][1] == h[p[1]-1][1]:
        if p[0] in tower:
            tower.remove(p[0])
        if p[1] in tower:
            tower.remove(p[1])
    elif h[p[0]-1][1] > h[p[1]-1][1]:
        if p[1] in tower:
            tower.remove(p[1])
    else:
        if p[0] in tower:
            tower.remove(p[0])

"""
h.sort(key=lambda x: x[1], reverse=True)
for t in h:
    c = set(conn[t[0]])
    for i in c:
        if i in tower:
            tower.remove(i)
"""
print(len(tower), end="")


### FIXED CODE ###

n, m = map(int, input().split())
h = list(map(int, input().split()))
# h = [[i, h[i-1]] for i in range(1, n+1)]
# path = [list(map(int, input().split())) for i in range(m)]
# conn = {key: [] for key in range(1, n+1)}
tower = list(range(1, n+1))
ma = [0]*n

for i in range(m):
    p = list(map(int, input().split()))
    ma[p[0]-1] = max(ma[p[0]-1], h[p[1]-1])
    ma[p[1]-1] = max(ma[p[1]-1], h[p[0]-1])
    """
    # h0 > h1
    if h[p[0]-1] == h[p[1]-1]:
        if p[0] in tower:
            tower.remove(p[0])
        if p[1] in tower:
            tower.remove(p[1])
    elif h[p[0]-1] > h[p[1]-1]:
        if p[1] in tower:
            tower.remove(p[1])
    else:
        if p[0] in tower:
            tower.remove(p[0])
    """
cnt = 0
for i in range(n):
    cnt += (h[i] > ma[i])
print(cnt, end="")
### BUGGY CODE ###

N = int(input())
S = input()
St = []
for i in range(N):
  St += [ord(S[i])-97]
  
#初期化
dp=[[0 for i in range(N+1)] for j in range(N+1)]

ans = 0
#DP:dp[i][j] Sのi文字目以降とj文字目以降の最大マッチング
for i in range(N-1,-1,-1):
  for j in range(N-1, i-1, -1):
    if (St[i] == St[j]): 
      dp[i][j] = max(dp[i][j], dp[i+1][j+1] + 1)
      ans = max(ans, min(dp[i][j], j-i))
    if j-i <= dp[i][j]:
      break
      
print(ans)

### FIXED CODE ###

N = int(input())
S = input()
from collections import deque

def is_ok(l):
    hs = set()
    q = deque()
    for i in range(N-l+1):
        h = S[i:i+l]
        if h in hs:
            return True
        q.append(h)
        if len(q) >= l:
            hs.add(q.popleft())
    return False

ok = 0
ng = N//2+1
while ng-ok > 1:
    m = (ng+ok)//2
    if is_ok(m):
        ok = m
    else:
        ng = m
print(ok)
### BUGGY CODE ###

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

L=[0]*M
R=[0]*M
for i in range(M):
  L[i], R[i] = map(int, input().split())

keys = list(range(1, N+1))
common = [x for x in keys if x>=max(L) and x<=min(R)]
    
print(len(common))

### FIXED CODE ###

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

L=[0]*M
R=[0]*M
for i in range(M):
  L[i], R[i] = map(int, input().split())
    
print(max(min(R)-max(L)+1,0))
### BUGGY CODE ###

n = int(input())
ans = 0

for j in range(1, n + 1):
    for i in range(1, int(n // j) +1):
        ans += j * i
print(ans)

### FIXED CODE ###

n = int(input())
ans = 0

for i in range(1, n + 1):
    y = n // i
    ans += y * (y+1) * i // 2
print(ans)
### BUGGY CODE ###

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


for gakki in range(k+1,n+1):
    #pre = A[gakki-k-1:gakki-1]
    #pre_ = 1
    #for p in pre:
        #pre_ *= p

    
    #k_gakki = A[gakki-k:gakki]
    #k_gakki_ = 1
    #for ga in k_gakki:
        #k_gakki_ *= ga
    
    #if pre_ < k_gakki_:
    if sum(A[gakki-k-1:gakki-1])< sum(A[gakki-k:gakki]):
        print('Yes')
    else:
        print('No')

### FIXED CODE ###

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


for gakki in range(k+1,n+1):
    #pre = A[gakki-k-1:gakki-1]
    pre = A[gakki-k-1]
    #pre_ = 1
    #for p in pre:
        #pre_ *= p

    
    #k_gakki = A[gakki-k:gakki]
    k_gakki = A[gakki-1]
    #print(k_gakki)
    #k_gakki_ = 1
    #for ga in k_gakki:
        #k_gakki_ *= ga
    
    #if pre_ < k_gakki_:
    if pre < k_gakki:
        print('Yes')
    else:
        print('No')
### BUGGY CODE ###

import math
n,m = map(int,input().split())
s = input()
t = input()
lcm = n*m/math.gcd(n,m)
nx = []
for i in range(n):
  nx.append(i*(lcm//n)+1)
for j in range(m):
  if j*(lcm//m)+1 in nx:
    if t[j] != s[j*n//m]:
      print(-1)
      exit()
  elif j == m-1:
    print(int(lcm))

### FIXED CODE ###

import math
n,m = map(int,input().split())
s = input()
t = input()
lcm = int(n*m/math.gcd(n,m))
if (n-1)//(lcm//m) == 0:
  if s[0] == t[0]:
    print(lcm)
  else:
    print(-1)
else:
  for i in range((n-1)//(lcm//m)):
    if s[i*(lcm//m)] != t[i*(lcm//n)]:
      print(-1)
      exit()
    elif i == (n-1)//(lcm//m)-1:
      print(lcm)
### BUGGY CODE ###

a = input()
q = int(input())
b = 0
for i in range(q):
    qi=input()
    if qi==str(1):
        b = b+1
    else:
        qi = qi.split()
        if (int(qi[1])+b)%2==1:
            a = qi[2] + a
        else:
            a = a + qi[2]
if b%2==1:
    a = a[::-1]
    print(a)
else:
    print(a)

### FIXED CODE ###

import collections
 
s = collections.deque(list(input()))
q = int(input())
rev = 0
for i in range(q):
    tfc = list(input().split())
    if tfc[0]=='1':
        rev = abs(rev-1)
    else:
        t,f,c = tfc
        if rev:
            if f=='1':
                s.append(c)
            else:
                s.appendleft(c)
        else:
            if f=='1':
                s.appendleft(c)
            else:
                s.append(c)
if rev:
    t = []
    for i in range(len(s)):
        t.append(s.pop())
    print(''.join(t))
else:
    print(''.join(s))
### BUGGY CODE ###

import heapq
import math
import random
import sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, namedtuple, UserDict
from functools import cmp_to_key, lru_cache, reduce
from itertools import (chain, combinations, combinations_with_replacement,
                       permutations, product)

sys.setrecursionlimit(10**6+1)
write = sys.stdout.write
input = sys.stdin.buffer.readline

MOD = 10**9 + 7


if __name__ == "__main__":
    n = int(input())
    arr = sorted(enumerate(map(int, input().split())),
                 key=lambda x: x[1], reverse=True)
    dp = [[0] * (n+1) for _ in range(n+1)]

    for i in range(n):
        for j in range(n-i):
            idx, a = arr[i+j]
            dp[i+1][j] = max(dp[i+1][j], dp[i][j] + a*(idx-i))
            dp[i][j+1] = max(dp[i][j+1], dp[i][j] + a*(n-1-j-idx))

    print(max(dp[i][n-i] for i in range(n+1)))


### FIXED CODE ###

import heapq
import math
import random
import sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, namedtuple, UserDict
from functools import cmp_to_key, lru_cache, reduce
from itertools import (chain, combinations, combinations_with_replacement,
                       permutations, product)
import numpy as np


sys.setrecursionlimit(10**6+1)
write = sys.stdout.write
input = sys.stdin.buffer.readline

MOD = 10**9 + 7


if __name__ == "__main__":
    n = int(input())
    arr = sorted(enumerate(map(int, input().split()), 1),
                 key=lambda x: x[1], reverse=True)
    dp = np.zeros(n+1, dtype=np.int)

    for k, (i, a) in enumerate(arr, 1):
        ndp = dp.copy()
        
        add_left = np.abs(np.arange(1, k+1) - i) * a
        ndp[1:k+1] = np.maximum(ndp[1:k+1], dp[:k] + add_left)
        
        add_right = np.abs(np.arange(n-k+1, n+1) - i) * a
        ndp[:k] = np.maximum(ndp[:k], dp[:k] + add_right)

        dp = ndp

    print(dp.max())
### BUGGY CODE ###

# -*- coding: utf-8 -*-
N = int(input())
H = list(map(int, input().split()))
cnt = 0
ans = 0

for i in range(N - 1):

    if ans > N - i:
        break

    else:
        for j in range(i, N - 1):

            if H[j] >= H[j + 1]:
                cnt += 1
            else:
                break

    ans = max(ans, cnt)
    cnt = 0
print(ans)


### FIXED CODE ###

# -*- coding: utf-8 -*-
N = int(input())
H = list(map(int, input().split()))
ans = []
cnt = 0
for i in range(N - 1):
    if H[i] >= H[i + 1]:
        cnt += 1
    else:
        ans.append(cnt)
        cnt = 0

ans.append(cnt)
print(max(ans))
### BUGGY CODE ###

# coding: utf-8


def add_list(_n):
    _l = []
    for _ in range(_n):
        a, b = map(int, raw_input().split())
        _l.append([a for _ in range(b)])
    return [j for i in _l for j in i]

n, k = map(int, raw_input().split())
l = add_list(n)
l.sort()
print l[k-1]


### FIXED CODE ###

# coding: utf-8

l = 10 ** 5
num = [0] * (l + 1)
n, k = map(int, raw_input().split())

for _ in xrange(n):
    a, b = map(int, raw_input().split())
    num[a] += b

for i in xrange(1, l+1):
    k -= num[i]
    if k <= 0:
        print i
        break
### BUGGY CODE ###

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

for _ in range(M):
    max_value = max(A)
    max_index = A.index(max_value)
    A[max_index] = max_value // 2

print(sum(A))

### FIXED CODE ###

import heapq
import sys

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

def main():
    N,M = map(int,input().split())
    A = list(map(int,input().split()))
    A = list(map(lambda x: x*(-1),A))

    heapq.heapify(A)

    for _ in range(M):
        max_value = heapq.heappop(A) * (-1)
        heapq.heappush(A,max_value//2 * (-1))

    print(sum(A) * (-1))

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

MOD = pow(10, 9) + 7

n, m = map(int, input().split())
slist = list(map(int, input().split()))
tlist = list(map(int, input().split()))

dp = [[1 for _ in range(n+1)] for _ in range(m+1)]
for i, s in enumerate(slist):
  for j, t in enumerate(tlist):
    if s != t:
      dp[j+1][i+1] = ((dp[j+1][i] + dp[j][i+1]) % MOD - dp[j][i]) % MOD
    else:
      #if slist[i] == t and tlist[j] == s:
        dp[j+1][i+1] = (dp[j+1][i] + dp[j][i+1]) % MOD
      #else:
      #  dp[j+1][i+1] = ((dp[j+1][i] + dp[j][i+1]) % MOD - dp[j][i]) % MOD

print(dp[-1][-1])


### FIXED CODE ###

MOD = pow(10, 9) + 7

n, m = map(int, input().split())
slist = list(map(int, input().split()))
tlist = list(map(int, input().split()))

dp = [[1 for _ in range(n+1)] for _ in range(m+1)]
for i, s in enumerate(slist):
  for j, t in enumerate(tlist):
    if s != t:
      dp[j+1][i+1] = ((dp[j+1][i] + dp[j][i+1]) % MOD - dp[j][i]) % MOD
    else:
      if slist[i] == t and tlist[j] == s:
        dp[j+1][i+1] = (dp[j+1][i] + dp[j][i+1]) % MOD
      else:
        dp[j+1][i+1] = ((dp[j+1][i] + dp[j][i+1]) % MOD - dp[j][i]) % MOD

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

import numpy as np
import math 
N, K=map(int,input().split())
A2 = np.zeros(N)
A = list(map(int,input().split()))
A = list(map(lambda x: x -1 , A))
current_town = 0




for i in range(K):
    current_town = A[current_town]
    if  A2[current_town] != 0:
        cycle = i - A2[current_town] 
        i = K - (K-i) % cycle
    else:
        A2[current_town] = i

print(current_town+1)


### FIXED CODE ###

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

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

 
s = list()
ord = np.full(n+1, -1)
c=1
l=0

v=1
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])
### BUGGY CODE ###

# coding: utf-8
# Your code here!

import bisect

N, M = map(int, input().rstrip().split())
A = list(map(int, input().rstrip().split()))
A = sorted(A)

for _ in range(M):
    a = A.pop()
    a = a / 2
    bisect.insort_right(A, a)
    
print(sum([int(x) for x in A]))
    

### FIXED CODE ###

# coding: utf-8
# Your code here!

import heapq

N, M = map(int, input().rstrip().split())
A = list(map(lambda x: -int(x), input().rstrip().split()))
heapq.heapify(A)

for _ in range(M):
    a = heapq.heappop(A)
    a = a / 2
    heapq.heappush(A, a)
    
print(sum([-int(x) for x in A]))
### BUGGY CODE ###

N = int(input())
A = [int(a) for a in input().split()]
for i in range(1,N+1):
  print(A.count(i))

### FIXED CODE ###

N = int(input())
A = [int(a) for a in input().split()]
Buka = []
for i in range(N):
  Buka.append(0)
for j in A:
  Buka[j-1] += 1
for k in range(N):
  print(Buka[k])
### BUGGY CODE ###

def distanced_nodes(neighbor, start_node, depth_limit):
    visited = [start_node]
    next_nodes = neighbor[start_node]
    depth = 1
    while len(next_nodes) > 0 and depth < depth_limit:
        depth += 1
        queue = next_nodes[:]
        visited += next_nodes
        next_nodes = []
        for q in queue:
            for node in neighbor[q]:
                if node in visited:
                    continue
                else:
                    next_nodes.append(node)
        next_nodes = list(set(next_nodes))
    return next_nodes

N, X, Y = list(map(int, input().split()))
neighbor = { i: [] for i in range(1, N+1) }
for i in range(1,N):
    neighbor[i].append(i+1)
    neighbor[N-i+1].append(N-i)
neighbor[X].append(Y)
neighbor[Y].append(X)

distanced_neighbor = { i: { j: [] for j in range(1, N)} for i in range(1, N+1) }
for i in range(1, N+1):
    visited = [i]
    next_nodes = neighbor[i]
    for j in range(1, N):
        distanced_neighbor[i][j] = next_nodes[:]
        queue = next_nodes[:]
        visited += next_nodes
        next_nodes = []
        for q in queue:
            for node in neighbor[q]:
                if node in visited:
                    continue
                else:
                    next_nodes.append(node)
        next_nodes = list(set(next_nodes))
# for node in distanced_neighbor.keys():
#     print(node, distanced_neighbor[node])

for i in range(1, N):
    res = set()
    for j in range(1, N+1):
        for nei in distanced_neighbor[j][i]:
            if j < nei:
                res.add((j, nei))
            else:
                res.add((nei, j))
    print(len(res))
    

### FIXED CODE ###

def min_dist(i, j, X, Y):
    return min(abs(j-i), abs(X-1-i)+1+abs(Y-1-j), abs(Y-1-i)+1+abs(X-1-j))

N, X, Y = list(map(int, input().split()))
dists = [min_dist(i, j, X, Y) for i in range(N-1) for j in range(i+1, N)]
dist_dic = { i: 0 for i in range(1,N)}
for dist in dists:
    dist_dic[dist] += 1
for K in range(1,N):
    print(dist_dic[K])
### BUGGY CODE ###

from collections import deque
H,W=map(int,input().split())
S=[list(input()) for _ in range(H)]

ans=[]

for i in range(H):
    for j in range(W):
        sy=i
        sx=j
        if S[i][j]=='#':
            continue
        for k in range(H):
            for l in range(W):
                ey=k
                ex=l
                if S[k][l]=='#':
                    continue
                route=deque([(sy,sx,0)])
                while route:
                    a,b,n=route.popleft()
                    if a==ey and b==ex:
                        ans.append(n)
                        break
                    if 0<=a<=H-1 and 0<=b<=W-1:
                        if S[a][b]=='.':
                            S[a][b]=='#'
                            route.append((a+1,b,n+1))
                            route.append((a-1,b,n+1))
                            route.append((a,b+1,n+1))
                            route.append((a,b-1,n+1))

print(max(ans))

### FIXED CODE ###

from collections import deque
import copy
H,W=map(int,input().split())
S=[list(input()) for _ in range(H)]
S1=copy.deepcopy(S)
ans=[]

sy=0
sx=0
for i in range(H):
    for j in range(W):
        c=0
        route=deque([(i,j,0)])
        S=copy.deepcopy(S1)
        while route:
            a,b,n=route.popleft()
            c=n
            if 0<=a<=H-1 and 0<=b<=W-1:
                if S[a][b]=='.':
                    S[a][b]='#'
                    route.append((a+1,b,n+1))
                    route.append((a-1,b,n+1))
                    route.append((a,b+1,n+1))
                    route.append((a,b-1,n+1))
                    
        ans.append(c-1)

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

N = int(input())
A = list(int(input()) for _ in range(N))
cnt = 0
for i in set(A):
    if A.count(i)%2==0:
        continue
    else:
        cnt += 1
print(cnt)

### FIXED CODE ###

N = int(input())
A = list(int(input()) for _ in range(N))
s = set()
for i in A:
    if i not in s:
        s.add(i)
    else:
        s.remove(i)
print(len(s))
### BUGGY CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split()))
dict = {}
for Ai in A:
    if Ai in dict:
        dict[Ai] += 1
    else:
        dict[Ai] = 1
count = 0
while len(dict) > K:
    max_key = max(dict, key=dict.get)
    min_key = min(dict, key=dict.get)
    dict[max_key] += 1
    dict[min_key] -= 1
    count += 1
    if dict[min_key] == 0:
        del dict[min_key]
print(count)

### FIXED CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split()))
dict = {}
for Ai in A:
    if Ai in dict:
        dict[Ai] += 1
    else:
        dict[Ai] = 1
count = 0
if len(dict) > K:
    count = sum(sorted(dict.values())[:len(dict) - K])
print(count)
### BUGGY CODE ###

s=input()
K=int(input())
N=len(s)
tmp=set()

for i in range(N):
  for j in range(i,N):
    p=s[i:j+1]
    if len(p)<=K:
      tmp.add(p)
    
lis=sorted(tmp)
#print(lis)
print(lis[K-1])


### FIXED CODE ###

s=input()
K=int(input())
N=len(s)
tmp=set()

for i in range(N):
  for j in range(K):
    t= s[i:i+j+1]
    #print(i,j,t)
    tmp.add(t)
    
lis=sorted(tmp)
#print(lis)
print(lis[K-1])
### BUGGY CODE ###

while 1:
    n=input()
    if n==0:
        break
    else:
        a=[input() for _ in xrange(n)]
        ans=-float('inf')
        for i in xrange(n):
            for j in xrange(i,n):
                if ans<sum(a[i:j+1]):
                    ans=sum(a[i:j+1])
        print(ans)

### FIXED CODE ###

while 1:
    n=input()
    if n==0:break
    a=[int(raw_input()) for _ in xrange(n)]
    wa=[0]*(n+1)
    max_a=-1000000
    for i in xrange(n):
        wa[i+1]=a[i]+wa[i]
    for i in xrange(n):
        for j in xrange(i+1,n+1):
            if max_a<wa[j]-wa[i]:
                max_a=wa[j]-wa[i]
    print(max_a)
### BUGGY CODE ###

n = int(input())
p = list(map(int,input().split()))
count = 0
for i in range(n):
  if min(p[0:i+1]) == p[i]:
    count += 1
print(count)

### FIXED CODE ###

n = int(input())
p = list(map(int,input().split()))
count = 0
min = n+1
for i in range(n):
  if min > p[i]:
    count += 1
    min = p[i]
print(count)
### BUGGY CODE ###

import numpy as np
N,K = map(int, input().split())
As = input().split()
for i in range(N):
  As[i] = int(As[i])
  
As = np.array(As)

As_uni = np.unique(As)

As_uni_count = np.zeros_like(As_uni)
for i,a in enumerate(As_uni):
  As_uni_count[i] = (As==a).sum()
  
As_uni_count = np.sort(As_uni_count)

K2 = len(As_uni)

if K2 > K:
  ans = As_uni_count[:K2-K].sum()
else:
  ans = 0
  
print(int(ans))

### FIXED CODE ###

import numpy as np
import collections

N,K = map(int, input().split())
As = input().split()
for i in range(N):
  As[i] = int(As[i])
As = np.array(As)

As_c = collections.Counter(As)

ans = 0
counter = 0
for a in sorted(As_c.values()):
  if counter < len(As_c) - K:
    ans += a 
    counter += 1
  else:
    break
print(int(ans))
### BUGGY CODE ###

N=int(input())
v=100
count=0
while True:
  if N<v:
    break
  count+=1
  v*1.01//1
  
print(count)

### FIXED CODE ###


N=int(input())
v=100
count=0

while True:
  if N<=v:
    break
  count+=1
  v*=1.01
  v=int(v)
print(count)
### BUGGY CODE ###

n=int(input())
x=[]
cnt=0
for i in range(n):
  a="".join(sorted(input()))
  x.append(a)
  cnt+=x.count(a)-1
print(cnt)

### FIXED CODE ###

n=int(input())
x={}
cnt=0
for i in range(n):
  a=''.join(sorted(input()))
  if a in x:x[a]+=1
  else:x[a]=1

for a in x:
  cnt+=x[a]*(x[a]-1)//2
print(cnt)
### BUGGY CODE ###

H, W, M = map(int, input().split())
countH = [[h, 0] for h in range(H)]
countW = [[w, 0] for w in range(W)]
Bh = {}

for i in range(M):
  h, w = map(int, input().split())
  h, w = h-1, w-1
  if h in Bh:
    Bh[h].add(w)
  else:
    Bh[h] = {w}
  countH[h][1] += 1
  countW[w][1] += 1

countH.sort(reverse=True, key=lambda x: x[1])
countW.sort(reverse=True, key=lambda x: x[1])
#print(countH)
#print(countW)
#rint(Bh)

maxh = countH[0][1]
maxw = countW[0][1]
ans = maxh + maxw
ch = [countH[0][0]]
i = 1
while i < H and countH[i][1]==maxh:
  ch.append(countH[i][0])
  i += 1
cw = [countW[0][0]]
i = 1
while i < W and countW[i][1]==maxw:
  cw.append(countW[i][0])
  i += 1
flag = False
for h in ch:
  for w in cw:
    #print(h,w)
    if w not in Bh[h]:
      flag = True
if flag:
  print(ans)
else:
  print(ans-1)

### FIXED CODE ###

H, W, M = map(int, input().split())
countH = [[h, 0] for h in range(H)]
countW = [[w, 0] for w in range(W)]
Bh = {}

for i in range(M):
  h, w = map(int, input().split())
  h, w = h-1, w-1
  if h in Bh:
    Bh[h].add(w)
  else:
    Bh[h] = {w}
  countH[h][1] += 1
  countW[w][1] += 1

countH.sort(reverse=True, key=lambda x: x[1])
countW.sort(reverse=True, key=lambda x: x[1])
#print(countH)
#print(countW)
#rint(Bh)

maxh = countH[0][1]
maxw = countW[0][1]
ans = maxh + maxw
ch = [countH[0][0]]
i = 1
while i < H and countH[i][1]==maxh:
  ch.append(countH[i][0])
  i += 1
cw = [countW[0][0]]
i = 1
while i < W and countW[i][1]==maxw:
  cw.append(countW[i][0])
  i += 1
flag = False
for h in ch:
  for w in cw:
    #print(h,w)
    if w not in Bh[h]:
      flag = True
      break
if flag:
  print(ans)
else:
  print(ans-1)
### BUGGY CODE ###

X, Y, Z, K = map(int, input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]

data_AB = []
for i in range(X):
    for j in range(Y):
        data_AB.append(A[i]+B[j])
data_AB.sort()
data_AB.reverse()
data_AB_K = []
ab = min([K, X*Y])
for i in range(ab):
    data_AB_K.append(data_AB[i])

data_KC = []
C.sort()
C.reverse()
for i in range(ab):
    for j in range(Z):
        data_KC.append(data_AB_K[i] + C[j])
data_KC.sort()
data_KC.reverse()
for i in range(K):
    print(data_KC[i])

### FIXED CODE ###

import heapq as hq

X, Y, Z, K = map(int, input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]

pri = []
data = []
hq.heapify(pri)

A.sort()
B.sort()
C.sort()
A.reverse()
B.reverse()
C.reverse()

hq.heappush(pri, [-A[0]-B[0]-C[0],0,0,0])
data.append([0,0,0])

for i in range(K):
    s = pri[0][1]
    t = pri[0][2]
    u = pri[0][3]
    if s+1 <= X-1:
        if [s + 1, t, u] not in data:
            data.append([s+1, t, u])
            hq.heappush(pri, [-A[s+1]-B[t]-C[u],s+1,t,u])
    if t+1 <= Y-1:
        if [s, t+1, u] not in data:
            data.append([s, t+1, u])
            hq.heappush(pri, [-A[s]-B[t+1]-C[u],s,t+1,u])
    if u+1 <= Z-1:
        if [s, t, u+1] not in data:
            data.append([s, t, u+1])
            hq.heappush(pri, [-A[s]-B[t]-C[u+1],s,t,u+1])
    print(hq.heappop(pri)[0] * -1)