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

x,y,z,k = map(int,input().split())

info = [list(map(int,input().split())) for i in range(3)]
info[0]=sorted(info[0],reverse=True)
info[1]=sorted(info[1],reverse=True)
info[2]=sorted(info[2],reverse=True)
li = []
ans = []
li_append = li.append 
ans_append = ans.append

for i in info[0]:
  for j in info[1]:
    li_append(i+j)
li = sorted(li,reverse=True)

for i in li[:3000]:
  for j in info[2]:
    ans_append(i+j)
ans = sorted(ans,reverse = True)

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

### FIXED CODE ###

x,y,z,k = map(int,input().split())

info = [list(map(int,input().split())) for i in range(3)]
info[0]=sorted(info[0],reverse=True)
info[1]=sorted(info[1],reverse=True)
info[2]=sorted(info[2],reverse=True)
li = []
ans = []
li_append = li.append 
ans_append = ans.append

for i in info[0]:
  for j in info[1]:
    li_append(i+j)
li = sorted(li,reverse=True)

for i in li[:3000]:
  for j in info[2]:
    ans_append(i+j)
ans = sorted(ans,reverse = True)

for i in range(k):
  print(ans[i])
### BUGGY CODE ###

from collections import deque

N,K=map(int,input().split())
if N==1:print(K)
else:
  G=[[] for i in range(N+1)]
  deg=[0 for i in range(N+1)]
  mod=10**9+7

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

  deg2 = sorted(enumerate(deg),key=lambda x:x[1])
  first = deg2[1][0]
  second = G[first][0]
  color = [1 for i in range(N+1)]
  color[first],color[second]=K,K-1

  def bfs(s):
      seen = [0 for i in range(N+1)]
      todo = deque([])
      now = s
      seen[now]=1
      todo.append(now)
      while 1:
        if len(todo)==0:break
        a = todo.popleft()
        if a != first: 
          acolor=K-1
        for b in G[a]:
          if seen[b] == 0:
            seen[b] = 1
            todo.append(b)
            if b != second:
              acolor -= 1
              color[b] = acolor

  bfs(first)
  total=1
  for i in range(1,N+1):
    total *= color[i]
  total %= mod
  print(total)

### FIXED CODE ###

from collections import deque

N,K=map(int,input().split())
mod = 10**9+7
G=[[] for _ in range(N)]
for i in range(N-1):
  a,b=map(int,input().split())
  G[a-1].append(b-1)
  G[b-1].append(a-1)

def bfs(s):
    seen = [0]*N
    prev = [0]*N
    color = [0]*N
    todo = deque()
    seen[s]=1
    todo.append(s)
    color[s]=K
    while todo:
      a = todo.popleft()
      if a == start: count = K-1
      else: count = K-2
      for b in G[a]:
        if seen[b] == 0:
          seen[b] = 1
          todo.append(b)
          prev[b] = a
          color[b] = count %mod
          count -= 1
    return color
  
MAX,start = 0,-1
for i in range(N):
  if len(G[i])>MAX:
    MAX=len(G[i])
    start = i
    
color = bfs(start)
ans = 1
for i in range(N):
  ans *= color[i]
  ans %= mod
  
print(ans)
### BUGGY CODE ###

N = int(input())
fact = 1
for integer in range(1,N+1):
    fact *= integer

res = fact % 1000000007
print(res)

### FIXED CODE ###

N = int(input())
fact = 1
for integer in range(1,N+1):
    fact = fact * integer % 1000000007
print(fact)
### BUGGY CODE ###

S = input()
N = len(S)
cells = [0]*N

seq = 0
for i, s in enumerate(S):
    if s == 'R':
        seq += 1
        cells[i] = seq
        continue
    seq = 0

rev_S = S[::-1]
seq = 0
for i, s in enumerate(rev_S):
    if s == 'L':
        seq += 1
        cells[N-1-i] = seq
        continue
    seq = 0

ans = [0]*N
pre_cell = 0
pre_s = 'R'
l_flag =False
for i, s in enumerate(S):
    cell = cells[i]
    if pre_s == 'R' and s == 'L':
        ans[i] = cell//2 + cell%2 + pre_cell//2
        ans[i-1] = pre_cell//2 + pre_cell % 2 + cell//2
    pre_s = s
    pre_cell = cell

ans_str = ""
for a in ans:
    ans_str += str(a)+" "
print(ans_str)

### FIXED CODE ###

S = input()
N = len(S)
cells = [0]*N

seq = 0
for i, s in enumerate(S):
    if s == 'R':
        seq += 1
        cells[i] = seq
        continue
    seq = 0

rev_S = S[::-1]
seq = 0
for i, s in enumerate(rev_S):
    if s == 'L':
        seq += 1
        cells[N-1-i] = seq
        continue
    seq = 0

ans = [0]*N
pre_cell = 0
pre_s = 'R'
l_flag =False
for i, s in enumerate(S):
    cell = cells[i]
    if pre_s == 'R' and s == 'L':
        ans[i] = cell//2 + cell%2 + pre_cell//2
        ans[i-1] = pre_cell//2 + pre_cell % 2 + cell//2
    pre_s = s
    pre_cell = cell

ans_str = ""
for a in ans:
    ans_str += str(a)+" "
print(ans_str)
### BUGGY CODE ###

n,q=list(map(int,input().split()))
s=input()
cnt=0

for i in range(q):
  n,q=list(map(int,input().split()))
  print(s[n-1:q].count("AC"))
  

### FIXED CODE ###

n,q=list(map(int,input().split()))
s=input()
cnt=0
t=[0]*n

for i in range(n-1):
  cnt+=s[i:i+2].count("AC")
  t[i+1]=cnt
##  t[-1]=cnt
##print(t)

for i in range(q):
  l,r=list(map(int,input().split()))
  print(t[r-1]-t[l-1])
### BUGGY CODE ###

import os, sys, re, math, fractions

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

def common_gcd(ex_idx):
    ret = 0
    for i in range(N):
        if i != ex_idx:
            if ret == 0:
                ret = A[i]
            else:
                ret = fractions.gcd(ret, A[i])
    return ret

ret = 1
for j in range(N):
    ret = max(ret, common_gcd(j))

print(ret)


### FIXED CODE ###

import os, sys, re, math, fractions

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

memo_L = [1] * N
memo_R = [1] * N

for i in range(N):
    if i == 0:
        memo_L[i] = A[i]
        memo_R[i] = A[N-1]
    elif i == N - 1:
        memo_L[i] = fractions.gcd(A[i], memo_L[i-1])
        memo_R[i] = fractions.gcd(A[0], memo_R[i-1])
    else:
        memo_L[i] = fractions.gcd(A[i], memo_L[i-1])
        memo_R[i] = fractions.gcd(A[N-1-i], memo_R[i-1])

memo_R.reverse()

ret = 1
for j in range(N):
    if j == 0:
        ret = max(ret, memo_R[1])
    elif j == N-1:
        ret = max(ret, memo_L[j-1])
    else:
        common_gcd = fractions.gcd(memo_L[j-1], memo_R[j+1])
        ret = max(ret, common_gcd)

print(ret)
### BUGGY CODE ###

n=int(input())
a = list(map(int, input("").split()))
b = list(map(int, input("").split()))
c = list(map(int, input("").split()))
out=0
a.sort()
b.sort()
c.sort()
for i in range(n):
    for j in range(n):
        if b[j] > a[i]:
            for k in range(n):
                if c[k] > b[j]:
                    out+=(n-k)
                    break
print(out)

### FIXED CODE ###

import bisect
n=int(input())
a = list(map(int, input("").split()))
b = list(map(int, input("").split()))
c = list(map(int, input("").split()))
out=0
a.sort()
b.sort()
c.sort()
for i in b:
    na = bisect.bisect_left(a,i)
    nc = bisect.bisect(c,i)
    out += na * (len(c)-nc)
print(out)
### BUGGY CODE ###

h,w,k = map(int, input().split())
sx,sy,gx,gy = map(int, input().split())
sx-=1
sy-=1
gx-=1
gy-=1

grid = ['' for _ in range(h)]

for i in range(h):
    grid[i] = input()
INF = 1001001001001001001  
costgrid = [[INF]*w for _ in range(h)]

import heapq

q = []
q.append((0,sx,sy))

dx = (0,1,0,-1)
dy = (1,0,-1,0)
ans=INF
while q:
    cost,x,y = heapq.heappop(q)
    for i in range(4):
        for j in range(1,k+1):
            nx = x+dx[i]*j
            ny = y+dy[i]*j
            if(not 0<=nx<h):
                break
            if(not 0<=ny<w):
                break
            if(grid[nx][ny]=='@'):
                break
            if(costgrid[nx][ny]!=INF):
                continue
            costgrid[nx][ny]=min(costgrid[nx][ny],cost+1)
            heapq.heappush(q,(cost+1,nx,ny))
            if nx==gx and ny==gy:
                ans=min(costgrid[nx][ny],ans)
                q=[]

if ans!=INF:
    print(ans)
else:
    print(-1)



### FIXED CODE ###

h,w,k = map(int, input().split())
sx,sy,gx,gy = map(int, input().split())
sx-=1
sy-=1
gx-=1
gy-=1

grid = ['' for _ in range(h)]

for i in range(h):
    grid[i] = input()
INF = 1001001001  
costgrid = [[INF]*w for _ in range(h)]

import heapq

q = []
q.append((0,sx,sy))

dx = (0,1,0,-1)
dy = (1,0,-1,0)
ans=INF
while q:
    cost,x,y = heapq.heappop(q)
    for i in range(4):
        for j in range(1,k+1):
            nx = x+dx[i]*j
            ny = y+dy[i]*j
            if(not 0<=nx<h):
                break
            if(not 0<=ny<w):
                break
            if(grid[nx][ny]=='@'):
                break
            if(costgrid[nx][ny]<=cost):
                break
            if(costgrid[nx][ny]>cost+1):
                costgrid[nx][ny]=cost+1
                heapq.heappush(q,(cost+1,nx,ny))
                if nx==gx and ny==gy:
                    ans=min(costgrid[nx][ny],ans)
                    q=[]

if ans!=INF:
    print(ans)
else:
    print(-1)
### BUGGY CODE ###

from collections import Counter

l=[]
N=int(input())
for _ in range(N):
    l.append(input())

c = Counter(l).most_common()
top=c.pop(0)
ans=[top[0]]
freq=top[1]

while len(c) > 0:
    top=c.pop(0)
    if top[1] == freq:
        ans.append(top[0])
    else:
        break

ans.sort()

for e in ans:
    print(e)

### FIXED CODE ###

from collections import Counter


N=int(input())
l=['']*N
for i in range(N):
    l[i]=input()

l.sort()

c=1
c_crt=1
pre=""
ans=[]
for e in l+[""]:
    if e == pre:
        c_crt+=1
    else:
        if c_crt > c:
            ans=[pre]
            c=c_crt
        elif c_crt == c:
            ans.append(pre)
        c_crt=1
    pre=e
for e in ans:
    print(e)
### BUGGY CODE ###

n, k, q = map(int, input().split())
point = [int(input()) for i in range(q)]
for i in range(1, n+1):
    if q - point.count(i) < k:
        print("Yes")
    else:
        print("No")

### FIXED CODE ###

n, k, q = map(int, input().split())
point = [0 for i in range(n)]
for i in range(q):
    point[int(input())-1] -= 1
for i in range(n):
    if q + point[i] < k:
        print("Yes")
    else:
        print("No")
### BUGGY CODE ###

# input
s = int(input())

# check
fn = {1: s}
lim = 1000001
fs = None
for m in range(2, lim):
    if m % 2 == 0:
        fn[m] = fn[m - 1] // 2
    else:
        fn[m] = 3 * fn[m - 1] + 1

    print(m, fn[m])

    if not fs and m == s: 
        fs = fn[m]
    
    if fs in [fn[k] for k in fn.keys() if k != s]:
        print(m)
        break

### FIXED CODE ###

# input
s = int(input())

# check
lim = 1000001
# 初項が 4 or 2 or 1 なら
# 4, 2, 1, 4, 2, 1, …
# となるので、答えは4になる
if s == 1 or s == 2:
  print(4)
else:

    c4 = 0
    c = 1
    for m in range(2, lim):
        # 4の出現回数をカウントする
        if s == 4:
            c4 += 1

        # 2回4が出てきたら終了
        if c4 == 2:
            print(c)
            exit()

        # 指示された操作
        if s % 2 == 0:
            s //= 2
        else:
            s = 3 * s + 1

        # 項番をインクリメント
        c += 1
### BUGGY CODE ###

import sys
sys.setrecursionlimit(1000000)

n = int(input())
x = list(map(int, input().split()))
d = [x[i+1] - x[i] for i in range(n - 1)]
 
def fact(m):
  return m * fact(m-1) if m != 1 else 1 

fact_n_1 = fact(n-1)

e = {}
for i in range(n-1):
  if i == 0:
    e[i] = fact_n_1
  else:
    e[i] = e[i - 1] + fact_n_1 // (i + 1)

print(sum(e[i] * d_i % 1000000007
          for i, d_i 
          in enumerate(d)) % 1000000007 ) 

### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000)

n = int(input())
x = list(map(int, input().split()))
d = [x[i+1] - x[i] for i in range(n - 1)]

def pow(x, y):
    if y == 0:
        return 1
    ans = 1
    while y > 1:
        if y % 2 != 0:
            ans *= x
            ans %= 1000000007
        x *= x
        x %= 1000000007
        y //= 2
    return ans * x % 1000000007

def fact(m):
  return m * fact(m-1) % 1000000007 if m != 1 else 1
 
fact_n_1 = fact(n-1)

e = [None] * (n-1)
for i in range(n-1):
  if i == 0:
    e[i] = fact_n_1
  else:
    e[i] = (e[i - 1] + fact_n_1 * pow(i + 1, 1000000005)) % 1000000007

print(sum(e_i * d_i % 1000000007
          for i, (d_i, e_i) 
          in enumerate(zip(d, e))) % 1000000007 )
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**6)

def dfs(v, p):
    for u in link[v]:
        if u == p:
            continue
        ans[u] += ans[v]
        dfs(u, v)

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

ans = [0] * N
for i in range(Q):
    p, x = map(int, input().split())
    ans[p-1] += x

dfs(0, -1)

print(*ans)


### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

def dfs(v, p):
    for u in link[v]:
        if u == p:
            continue
        ans[u] += ans[v]
        dfs(u, v)

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

ans = [0] * N
for i in range(Q):
    p, x = map(int, input().split())
    ans[p-1] += x

dfs(0, -1)

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

N, Q = map(int, input().split())
S = input()
l = []
r = []
for i in range(Q):
    li, ri = map(int, input().split())
    l += [li]
    r += [ri]

[print(S[max(0, l[ind]-1) : min(r[ind], N)].count("AC")) for ind in range(Q)]


### FIXED CODE ###

N, Q = map(int, input().split())
S = input()
l = []
r = []
for i in range(Q):
    li, ri = map(int, input().split())
    l += [li]
    r += [ri]

S_tf = [0]*(N+1)
for ind in range(N):
    S_tf[ind + 1] = S_tf[ind] + (1 if S[ind:ind+2] == "AC" else 0)
for ind in range(Q):
    print(S_tf[max(0, r[ind]-1)] - S_tf[min(l[ind]-1, N)])
### BUGGY CODE ###

import sys
input = sys.stdin.readline
N,M=map(int,input().split())
list1=list(map(int,input().split()))
for _ in range(M):
  B,C=map(int,input().split())
  if len(list1)<N or min(list1)<C:
    list1+=[C]*B  
  if len(list1)>N:
    for i in range(len(list1)-N):
        list1.remove(min(list1))
SUM=sum(list1)
print(SUM)

### FIXED CODE ###

N,M = map(int, input().split())
listA = list(map(int, input().split()))
listA.sort()
 
listBC = [list(map(int, input().split())) for i in range(M)]
listBC = sorted(listBC, key=lambda x: x[1], reverse=True)
countB = 0
 
for i in range(M):
  B, C = listBC[i][0], listBC[i][1]
  listA += [C]*B
  countB += B
  if countB >= N:
    break

listA.sort(reverse=True)
print(sum(listA[:N]))
### BUGGY CODE ###

S = input()

count = 0
flag = True

while flag:
    flag = False
    for i in range(len(S)-1):
        if S[i:i+2] == "BW":
            S = S[:i] + "WB" + S[i+2:]
            count += 1
            flag = True

print(count)

### FIXED CODE ###

S = input()

count = 0

i = 0

for j in range(len(S)):
    if S[j] == "W":
        count += j-i
        i += 1


print(count)
### BUGGY CODE ###

n, m = map(int, input().split())
a = list(map(int, input().split()))
for i in range(m):
    b, c = map(int, input().split())
    a += [c] * b
a.sort()
print(sum(a[-n:]))

### FIXED CODE ###

n, m = map(int, input().split())
a = sorted(list(map(int, input().split())))
li = []
for i in range(m):
    b, c = map(int, input().split())
    li.append((c, b))
li = sorted(li, reverse = True)

count = 0 #li[num][1]
num = 0  #index

for i in range(n):
    if a[i] < li[num][0]:
        a[i] = li[num][0]
        count += 1
    if count == li[num][1] :
        num += 1
        count = 0
    if num == m:
        break

print(sum(a))
### BUGGY CODE ###

n, w = map(int, input().split())
items = [tuple(map(int, input().split())) for _ in range(n)]

dp = [[0] * (w + 1) for _ in range(n + 1)]

for i, (wi, vi) in enumerate(items):
    for j in range(w + 1):
        if j >= wi:
            dp[i + 1][j] = max(dp[i][j], dp[i][j - wi] + vi)
        else:
            dp[i + 1][j] = dp[i][j]

print(dp[n][w])


### FIXED CODE ###

import sys
input = sys.stdin.readline

n, w = map(int, input().split())
items = [tuple(map(int, input().split())) for _ in range(n)]

dp = [[0] * (w + 1) for _ in range(n + 1)]

for i, (wi, vi) in enumerate(items):
    for j in range(w + 1):
        if j >= wi:
            dp[i + 1][j] = max(dp[i][j], dp[i][j - wi] + vi)
        else:
            dp[i + 1][j] = dp[i][j]

print(dp[n][w])
### BUGGY CODE ###

from collections import deque
from collections import defaultdict

def getlist():
	return list(map(int, input().split()))

class Graph(object):

    def __init__(self):
        self.graph = defaultdict(list)

    def __len__(self):
        return len(self.graph)

    def add_edge(self, a, b):
        self.graph[a].append(b)

G = Graph()

N, Q = getlist()
for i in range(N - 1):
	a, b = getlist()
	G.add_edge(a, b)
	G.add_edge(b, a)

plus = [0 for i in range(N + 1)]
for i in range(Q):
	p, x = getlist()
	plus[p] += x


q = deque() 
ans = [0 for i in range(N)]
visit = [-1 for i in range(N + 1)]
visit[1] = 1
q.append(1)
while q:
	m = q.pop()
	visit[m] = 1
	ans[m - 1] += plus[m]
	x = ans[m - 1]
	for i in G.graph[m]:
		if visit[i] == -1:
			q.append(i)
			ans[i - 1] += x

print(" ".join(list(map(str, ans))))

### FIXED CODE ###

from collections import deque
from collections import defaultdict

def getlist():
	return list(map(int, input().split()))

class Graph(object):

    def __init__(self):
        self.graph = defaultdict(list)

    def __len__(self):
        return len(self.graph)

    def add_edge(self, a, b):
        self.graph[a].append(b)

G = Graph()

N, Q = getlist()
for i in range(N - 1):
	a, b = getlist()
	G.add_edge(a, b)
	G.add_edge(b, a)

plus = [0] * (N + 1)
for i in range(Q):
	p, x = getlist()
	plus[p] += x

q = deque([]) 
ans = [0] * N
visit = [-1] * (N + 1)
visit[1] = 1
q.append(1)
while q:
	m = q.pop()
	visit[m] = 1
	ans[m - 1] += plus[m]
	x = ans[m - 1]
	for i in G.graph[m]:
		if visit[i] == -1:
			q.append(i)
			ans[i - 1] += x

print(" ".join(list(map(str, ans))))
### BUGGY CODE ###

import sys #追加


n=int(input())
sys.setrecursionlimit(10**6*2)

s=input()
X=int(s,2)

one_cnt=s.count("1")


ans=[]

ans_memo=[0]*(2*(10**5)+2)
#print(ans_memo)
ans_memo[1]=1
ans_memo[2]=1

def DEF(x,cnt):
    global ans_memo
    #print(x,cnt,ans_memo)
    if x==0:
        return 0
    if x<2*(10**5)+1:    
        if ans_memo[x]!=0:
            return ans_memo[x]
        else:
            if x%(str(bin(x)).count("1"))==0:
                ans_memo[x]=1
                return 1
            else:
                tmp=DEF(x%(str(bin(x)).count("1")),cnt+1)+1
                ans_memo[x]=tmp
                return tmp
    else:
        if x%(str(bin(x)).count("1"))==0:
            return 1
        else:
            tmp=DEF(x%(str(bin(x)).count("1")),cnt+1)+1
            return tmp


ans=[]

for i in range(n):
    tmp=2**(n-i-1)
    tmp_num=X
    #1の時
    if tmp&tmp_num:
        tmp_num-=tmp
        if tmp_num==0:
            ans.append(0)
        else:
            tmp_num=tmp_num%(one_cnt-1)
            ans.append(DEF(tmp_num,1)+1)
        
    else:
        tmp_num+=tmp
        #print(bin(tmp_num),n-i-1)
        tmp_num=tmp_num%(one_cnt+1)
        ans.append(DEF(tmp_num,1)+1)

#print(ans_memo)

for item in ans:
    print(item)
            









### FIXED CODE ###

def popcount(x):
    return bin(x).count("1")

n=int(input())
s=input()
X=int(s,2)

one_cnt=popcount(X)

modp=X%(one_cnt+1)
modm=X%(one_cnt-1) if one_cnt-1!=0 else 0

for i in range(n):
    if s[i]=="1":
        if one_cnt-1==0:
            print(0)
            continue
        else:
            num=(modm-pow(2,n-i-1,one_cnt-1))%(one_cnt-1)
    else:
        num=(modp+pow(2,n-i-1,one_cnt+1))%(one_cnt+1)

    #print(i,"num",num)
    cnt=1
    while num!=0:
        num=num%popcount(num)
        cnt+=1
    print(cnt)
### BUGGY CODE ###

h, w, m = map(int, input().split())
h_l = [[] for i in range(h + 1)]
w_l = [[] for i in range(w + 1)]
max_h = 0
max_h_l = []
max_w = 0
max_w_l = []
inputs = []
for _ in range(m):
    h, w = map(int, input().split())
    inputs.append([h,w])
    if h_l[h] :
        h_l[h][1].append(w)
        h_l[h][0] += 1
    else:
        h_l[h] = [1, [w]]
        
    if h_l[h][0] > max_h:
        max_h_l = [h]
        max_h = h_l[h][0]
    elif h_l[h][0] == max_h:
        max_h_l.append(h)
 
        
    if w_l[w]:
        w_l[w][1].append(h)
        w_l[w][0] += 1
    else:
        w_l[w] = [1, [h]]
    if w_l[w][0] > max_w:
        max_w_l = [w]
        max_w = w_l[w][0]
    elif w_l[w][0] == max_w:
        max_w_l.append(w)
 
flag = 0
ans = 0
for i in max_h_l:
    if flag == 1:
        break
    for j in max_w_l:
        if flag == 1:
            break
        if j in h_l[i][1]:
            ans = max_h + max_w - 1
        else:
            ans = max_h + max_w
            flag = 1
print(ans)

### FIXED CODE ###

h, w, m = map(int, input().split())
h_l = [[] for i in range(h + 1)]
w_l = [[] for i in range(w + 1)]
max_h = 0
max_h_l = []
max_w = 0
max_w_l = []
inputs = {}
for _ in range(m):
    h, w = map(int, input().split())
    inputs.setdefault(h, set([w]))
    inputs[h].add(w)

    if h_l[h] :
        h_l[h][1].add(w)
        h_l[h][0] += 1
    else:
        h_l[h] = [1, set([w])]
        
    if h_l[h][0] > max_h:
        max_h_l = [h]
        max_h = h_l[h][0]
    elif h_l[h][0] == max_h:
        max_h_l.append(h)
 
        
    if w_l[w]:
        w_l[w][1].add(h)
        w_l[w][0] += 1
    else:
        w_l[w] = [1, set([h])]
    if w_l[w][0] > max_w:
        max_w_l = [w]
        max_w = w_l[w][0]
    elif w_l[w][0] == max_w:
        max_w_l.append(w)

ans = max_h + max_w -1
flag = 0
for i in max_h_l:
    if flag == 1:
        break
    for j in max_w_l:
        if j not in inputs[i]:
            ans = max_h + max_w
            flag = 1
            break
        
print(ans)
### BUGGY CODE ###

import collections

n, t = map(int, input().split())
tpls = list(sorted(tuple(map(int, input().split())) for _ in range(n)))
a = [None] * n
b = [None] * n
for i in range(n):
    a[i], b[i] = tpls[i]

dp = [collections.defaultdict(int) for _ in range(n + 1)]
dp[0][0] = 0
for i in range(n):
    for cur in dp[i]:
        dp[i + 1][cur] = max(dp[i + 1][cur], dp[i][cur])
        if cur < t:
            dp[i + 1][cur + a[i]] = max(dp[i + 1][cur + a[i]], dp[i][cur] + b[i])
print(max(dp[n].values()))

### FIXED CODE ###

import collections

n, t = map(int, input().split())
tpls = list(sorted(tuple(map(int, input().split())) for _ in range(n)))
a = [None] * n
b = [None] * n
for i in range(n):
    a[i], b[i] = tpls[i]

dp = [[0] * (t + 1) for _ in range(n + 1)]
for i in range(n):
    for j in range(t):
        dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])
        k = min(t, j + a[i])
        dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + b[i])
print(max(map(max, dp)))
### BUGGY CODE ###

import collections

H,W,M = map(int, input().split())
h = [0]*M
w = [0]*M
for i in range(M):
    h[i], w[i] = map(int, input().split())
ch = collections.Counter(h).most_common()
mh = [ch[0][0]]
mnh = ch[0][1]
for i in range(1,len(ch)):
    if mnh == ch[i][1]:
        mh.append(ch[i][0])
        continue
    else:
        break
    break
cw = collections.Counter(w).most_common()
mw = [cw[0][0]]
mnw = cw[0][1]
for i in range(1,len(cw)):
    if mnw == cw[i][1]:
        mw.append(cw[i][0])
        continue
    else:
        break
    break
for h1 in mh:
    for w1 in mw:
        if (h1,w1) not in zip(h,w):
            print(mnh+mnw)
            exit()
print(mnh+mnw-1)

### FIXED CODE ###

from collections import defaultdict

H, W, M = map(int, input().split())
h = [0] * M
w = [0] * M

nh = [0] * H  # number of h == i+1
nw = [0] * W  # number of w == i+1
dic = defaultdict(bool)

for i in range(M):
    h[i], w[i] = map(int, input().split())
    h[i] -= 1
    w[i] -= 1
    nh[h[i]] += 1
    nw[w[i]] += 1
    dic["{}-{}".format(h[i],w[i])] = True

mnh = max(nh)
mnw = max(nw)

mh = [i for i, nh1 in enumerate(nh) if nh1 == mnh]
mw = [i for i, nw1 in enumerate(nw) if nw1 == mnw]

for h1 in mh:
    for w1 in mw:
        if not dic["{}-{}".format(h1,w1)]:
            print(mnh + mnw)
            exit()
print(mnh + mnw - 1)
### BUGGY CODE ###

n=int(input())
s=[]
for i in range(n):
  s.append("".join(sorted(input())))
ss=set(s)
ans=0
for _ in ss:
  l=s.count(_)
  ans+=l*(l-1)//2
print(ans)


### FIXED CODE ###

n=int(input())
s=[]
for i in range(n):
  s.append("".join(sorted(input())))
#sss=set(s)
ans=0
import collections
c=collections.Counter(s)

for l in c.values():
  ans+=l*(l-1)*(1/2)
print(int(ans))