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

N = int(input())
list1 = []
for i in range(N):
    taisho = input()
    if not taisho in list1:
        list1.append(taisho)
print(len(list1))


### FIXED CODE ###

N = int(input())
list1 = set()
for i in range(N):
    taisho = input()
    if not taisho in list1:
        list1.add(taisho)
print(len(list1))
### BUGGY CODE ###

n,q=map(int,input().split())
s=[0]*-~n
for _ in[0]*q:
 a,v=map(int,input().split())
 s[a]+=v
 m=max(s)
 print(s.index(m),m)


### FIXED CODE ###

import sys
def f():
 w=m=0;n,q=map(int,input().split());s=[0]*-~n
 for e in sys.stdin:
  a,v=map(int,e.split());s[a]+=v
  if v<0 and a==w:m=max(s);w=s.index(m)
  elif s[a]>m:w,m=a,s[a]
  elif s[a]==m and w>a:w=a
  print(w,m)
f()
### BUGGY CODE ###

def main():
    s = input()
    ss = s
    for i in range(len(s)//2):
        ss = ss.replace("01", "").replace("10", "")
    print(len(s)-len(ss))
    
if __name__ == "__main__":
    main()

### FIXED CODE ###

s=input()
zero = s.count("0")
one = s.count("1")
print(len(s)-abs(zero-one))
### BUGGY CODE ###

N = int(input())
ans = []
for i in range(N):
    S = input()
    if S not in ans: ans.append(S)
print(len(ans))


### FIXED CODE ###

N = int(input())
ans = []
for i in range(N):
    ans.append(input())
print(len(set(ans)))
### BUGGY CODE ###

import itertools

N, K = map(int, input().split())
p = list(map(int, input().split()))

ans = sum(p)
for v in itertools.permutations(p, K):
    ans = min(ans, sum(v))

print(ans)


### FIXED CODE ###

import itertools

N, K = map(int, input().split())
p = list(map(int, input().split()))

ans = 0
for _ in range(K):
    min_index = p.index(min(p))
    minv = p.pop(min_index)
    ans += minv

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

def f(n):
  a=[];f=2
  while f*f<=n:
    if n%f==0:a.append(f);n//=f
    else:f+=1
  if n!=1:a.append(n)
  return set(a)
s=[2];n=int(input())
for L in range(3,n+1):
  c=True
  for M in s:
    if L%M==0:c=False
  if c==True:s.append(L)
A=[int(input())for i in range(n+1)]
P=sorted(list(set(s)|f(abs(A[0]))))
for p in P:
  B=A[0:n+2];b=0
  for j in range(n+1):
    if p+j<n+1:B[j+p-1]=(B[j+p-1]+B[j])%p
    elif B[j]%p!=0:b=1;break
  if b==0:print(p)

### FIXED CODE ###

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

sosuu=[2];n=int(input())
for L in range(3,n+100):
    chk=True
    for L2 in sosuu:
        if L%L2 == 0:chk=False
    if chk==True:sosuu.append(L)
S=set(sosuu)



A=[0]*(n+1)
g=0
for i in range(n+1):
  A[i]=int(input())
P=[]
PP=factorization(abs(A[0]))
for i in range(len(PP)):
  P.append(PP[i][0])
if P==[1]:
  P=[]
P=set(P)
P=S|P
P=list(P)
P.sort()
for i in range(len(P)):
  p=P[i]
  B=A[0:n+2]
  b=0
  for j in range(n+1):
    if p+j<n+1:
      B[j+p-1]=(B[j+p-1]+B[j])%p
    else:
      if B[j]%p!=0:
        b=1
        break
  if b==0:
    print(p)
### BUGGY CODE ###

S = input()[::-1]
dp = [0]*2019
dp[0] = 1
for i in range(1,len(S)+1):
    dp[int(S[:i][::-1])%2019] += 1

print(sum([i*(i-1)//2 for i in dp]))

### FIXED CODE ###

P = 2019
S = input()
N = len(S)
res = 0
 
if P in [2,5]:
    for i in range(N):
        if int(S[i])% P == 0:
            res += i+1
else:
    dic = {0:1}
    t1 = 0
    t2 = 1
    for i in range(N):
        t2 = (10*t2) % P
        t1 = (int(S[N-1-i])*t2 + t1) % P
        if t1 in dic:
            res += dic[t1]
            dic[t1] += 1
        else:
            dic[t1] = 1
 
print(res)
### BUGGY CODE ###

import sys

read = sys.stdin.read

H, N, *AB = map(int, read().split())

INF = 10 ** 10
dp = [INF] * (H + 2)
dp[0] = 0

for a, b in zip(*[iter(AB)] * 2):
    for i in range(a, H + 1):
        dp[i] = min(dp[i], dp[i - a] + b)

    dp[-1] = min(dp[-1], min(dp[-a - 1:]) + b)

print(min(dp[-2], dp[-1]))


### FIXED CODE ###

import sys

read = sys.stdin.read

H, N, *AB = map(int, read().split())

INF = 10 ** 10
dp = [INF] * (H + 1)
r = INF
dp[0] = 0

for a, b in zip(*[iter(AB)] * 2):
    for i in range(a, H + 1):
        dp[i] = min(dp[i], dp[i - a] + b)
    r = min(r, min(dp[-a:]) + b)

print(min(r, dp[-1]))
### BUGGY CODE ###

n = int(input())
x = input()
x_int = int(x, 2)
xi = []
for i in range(n):
    if x[i] == "0":
        xi.append(x_int + 2**(n-i-1))
    else:
        xi.append(x_int - 2**(n-i-1))
def popcount(m):
    return bin(m).count("1")
for i in range(len(xi)):
    m = xi[i]
    ans = 0
    while m != 0:
        m %= popcount(m)
        ans += 1
    print(ans)

### FIXED CODE ###

n = int(input())
x = int(input(),2)

def popcount(l):
    return bin(l).count("1")
def count(l):
    res = 0
    while l != 0:
        p = popcount(l)
        l %= p
        res += 1
    return res
m = popcount(x)
x_plus = x%(m+1)
if m != 1:
    x_minus = x%(m-1)
else:
    x_minus = 1
lis_plus = [0]*n
lis_minus = [0]*n
for i in range(n):
    if i == 0:
        lis_plus[i] = 1%(m+1)
        if m != 1:
            lis_minus[i] = 1%(m-1)
    else:
        lis_plus[i] = lis_plus[i-1]*2%(m+1)
        if m != 1:
            lis_minus[i] = lis_minus[i-1]*2%(m-1)
for i in range(n):
    if (x >> (n-i-1)) & 1:
        if m == 1:
            print(0)
        else:
            print(count((x_minus - lis_minus[-i-1])%(m-1)) + 1)
    else:
        print(count((x_plus + lis_plus[-i-1])%(m+1)) + 1)
### BUGGY CODE ###

N = int(input())
X = list(map(int,input().split()))
for i in range(N):
    X2 = X.copy()
    X2.pop(i)
    X2.sort()
    ans = X2[N//2-1]
    print(ans)

### FIXED CODE ###

N = int(input())
X = list(map(int,input().split()))
X2 = sorted(X)
mid1 = X2[N//2-1]
mid2 = X2[N//2]
for i in X:
    if i <= mid1:
        print(mid2)
    else:
        print(mid1)
### BUGGY CODE ###

from heapq import heappush, heappop
h, w, k = map(int, input().split())
x1, y1, x2, y2 = map(int, input().split())
x1 -= 1
y1 -= 1
x2 -= 1
y2 -= 1
c = [list(input()) for _ in range(h)]
# print(x1, y1)
# print(x2, y2)

dx = [+1, 0, -1, 0]
dy = [0, +1, 0, -1]
MAX = 10**7
dp = [[[(MAX, MAX)] * 4 for _ in range(w)] for _ in range(h)]

q = [((1, 0), (x1, y1, i)) for i in range(4)]

while q:
    (c1, c2), (x, y, d) = q.pop()
    # print(x, y, d, c1, c2)
    if c1 > dp[x][y][d][0]:
        continue
    for i in range(4):
        nx = x + dx[i]
        ny = y + dy[i]
        if nx < 0 or nx >= h or ny < 0 or ny >= w:
            continue
        if c[nx][ny] == '@':
            continue
        if i == d and c2 < k:
            if dp[nx][ny][i] > (c1, c2 + 1):
                dp[nx][ny][i] = (c1, c2 + 1)
                q.append(((c1, c2 + 1), (nx, ny, i)))
        else:
            if dp[nx][ny][i] > (c1 + 1, 1):
                dp[nx][ny][i] = (c1 + 1, 1)
                q.append(((c1 + 1, 1), (nx, ny, i)))

ans = min(dp[x2][y2][i][0] for i in range(4))
if ans == MAX:
    ans = -1
print(ans)


### FIXED CODE ###

from heapq import heappush, heappop
import sys
input = sys.stdin.readline

h, w, k = map(int, input().split())
x1, y1, x2, y2 = map(int, input().split())
x1 -= 1
y1 -= 1
x2 -= 1
y2 -= 1
c_ = [tuple(input()) for _ in range(h)]
c = [[False] * w for _ in range(h)]
for i in range(h):
    for j in range(w):
        if c_[i][j] == '@':
            c[i][j] = True
# print(x1, y1)
# print(x2, y2)

dx = [+1, 0, -1, 0]
dy = [0, +1, 0, -1]
MAX = 10**7


def convert(x, y, d):
    return (x * w + y) * 4 + d


# dp = [[[(MAX, MAX)] * 4 for _ in range(w)] for _ in range(h)]
dp = [MAX * (k + 1) + k] * (h * w * 4)

# q = [((1, 0, x1, y1, i)) for i in range(4)]
q = [((k + 1, convert(x1, y1, i))) for i in range(4)]

while q:
    c0, xyd = heappop(q)
    c1 = c0 // (k + 1)
    c2 = c0 % (k + 1)
    # print(x, y, d, c1, c2)
    d = xyd % 4
    y = (xyd // 4) % w
    x = (xyd // 4) // w
    if c1 > dp[xyd] // (k + 1):
        continue
    for i in range(4):
        nx = x + dx[i]
        ny = y + dy[i]
        nxyi = convert(nx, ny, i)
        if nx < 0 or nx >= h or ny < 0 or ny >= w:
            continue
        if c[nx][ny]:
            continue
        if i == d and c2 < k:
            if dp[nxyi] > c1 * (k + 1) + c2 + 1:
                dp[nxyi] = c1 * (k + 1) + c2 + 1
                heappush(q, (dp[nxyi], nxyi))
        else:
            if dp[nxyi] > (c1 + 1) * (k + 1) + 1:
                dp[nxyi] = (c1 + 1) * (k + 1) + 1
                heappush(q, (dp[nxyi], nxyi))

ans = min(dp[convert(x2, y2, i)] // (k + 1) for i in range(4))
if ans == MAX:
    ans = -1
print(ans)
### BUGGY CODE ###

n = int(input())
l = [int(input()) for _ in range(n)]
ans = [i for i in l if l.count(i) % 2 == 1]
print(len(ans))

### FIXED CODE ###

n = int(input())
l = [int(input()) for _ in range(n)]
d = {}
for i in l:
    d[i] = d.get(i, 0) + 1
ans = 0
for v in d.values():
    if v % 2 == 1:
        ans += 1
print(ans)
### BUGGY CODE ###

from collections import deque

h, w = map(int, input().split())
maze = [input() for _ in range(h)]
direction = [(1, 0), (0, 1), (-1, 0), (0, -1)]

# BFSでは、同じステップ数のノードを先に全探索するので、訪問済みフラグはグローバル共有しても大丈夫

max_step = 0
for i in range(h):
    for j in range(w):
        largest_step = 0
#        print("start: ", i, j)
        if maze[i][j] == "#":
            continue
        visited = [[False] * w for _ in range(h)]
        plan = deque()
        step = 0
        plan.appendleft((i, j, step))
        while True:
            if len(plan) == 0:
                break
            y, x, step = plan.pop()
#            print(" ", x, y, step)
            visited[y][x] = True
            if step > largest_step:
                largest_step = step
            for next_direction in direction:
                next_y = y + next_direction[0]
                next_x = x + next_direction[1]
                if next_x == -1 or next_x == w or next_y == -1 or next_y == h:
                    continue
                if maze[next_y][next_x] == "#":
                    continue
                # 訪問済みでないかチェック
                if visited[next_y][next_x]:
                    continue
                plan.appendleft((next_y, next_x, step + 1))
#        print(largest_step)
        if largest_step > max_step:
            max_step = largest_step

print(max_step)


### FIXED CODE ###

import sys
import numpy as np
from collections import deque

h, w = map(int, input().split())
maze = [list(input()) for _ in range(h)]
direction = [(1, 0), (0, 1), (-1, 0), (0, -1)]

max_step = 0
for i in range(h):
    for j in range(w):
        largest_step = 0
#        print("start: ", i, j)
        if maze[i][j] == "#":
            continue
        visited = [[False] * w for _ in range(h)]
        distance = [[-1] * w for _ in range(h)]
        plan = deque()
        step = 0
        plan.appendleft((i, j, step))
        distance[i][j] = step
        visited[i][j] = True
        while plan:
            y, x, step = plan.pop()
#            print(" ", x, y, step)
            # if step > largest_step:
            #     largest_step = step
            for next_direction in direction:
                next_y = y + next_direction[0]
                next_x = x + next_direction[1]
                if -1 == next_x or next_x == w or -1 == next_y or next_y == h or maze[next_y][next_x] == "#" or visited[next_y][next_x]:
                    continue
                distance[next_y][next_x] = distance[y][x] + 1
                visited[next_y][next_x] = True
                plan.appendleft((next_y, next_x, step + 1))
#        print(largest_step)
        # if largest_step > max_step:
        #     max_step = largest_step
        max_step = max(max_step, np.max(np.array(distance)))

print(max_step)
### BUGGY CODE ###

from bisect import *
while 1:
	N,M = map(int,raw_input().split())
	if N == 0: break
	P = [int(raw_input()) for i in range(N)] + [0]
	P = sorted([i+j for i in P for j in P])
	s = bisect(P,M) - 1
	print max(i + P[bisect(P,M-i) - 1] for i in P[:s])

### FIXED CODE ###

from bisect import *
while 1:
	N,M = map(int,raw_input().split())
	if N == 0: break
	P = [int(raw_input()) for i in range(N)] + [0]
	P = sorted(set(i+j for i in P for j in P))
	s = bisect(P,M) - 1
	print max(i + P[bisect(P,M-i) - 1] for i in P[:s])
### BUGGY CODE ###

n = int(input())
a_s = [] 
for i in range(n):
    a_s.append([int(item) - 1 for item in input().split()])

total = n * (n - 1) // 2
days = 0
itrs = [0] * n
fights = 0

while True:
    wants = set()
    has_match = False
    for item in range(n):
        idx = itrs[item]
        if idx == n - 1:
            continue
        want = a_s[item][idx]
        # Check there is match or not
        if a_s[want][itrs[want]] == item:
            has_match = True
            if item < want:
                wants.add((item, want))
            else:
                wants.add((want, item))
    if not has_match:
        break
    # Process match
    for a, b in wants:
        itrs[a] += 1
        itrs[b] += 1
        fights += 1
    days += 1
    if days > total:
        print(-1)
        exit()

if fights == total:
    print(days)
else:
    print(-1)

### FIXED CODE ###

class DirectedGraph:
    def __init__(self, adj):
        self.n = len(adj)
        self.adj = adj
        self.is_asyclic = False
        self.max_path_len = None

    def topological_sort(self):
        indegree = [0] * self.n
        for i, vs in enumerate(self.adj):
            for dest in vs:
                indegree[dest] += 1
        zero_v = []
        for v, indeg in enumerate(indegree):
            if indeg == 0:
                zero_v.append(v)
        max_path_len = 1
        tp_sorted = []
        to_be_added = []
        while True:
            while zero_v:
                v = zero_v.pop()
                tp_sorted.append(v)
                for dest in self.adj[v]:
                    indegree[dest] -= 1
                    if indegree[dest] == 0:
                        to_be_added.append(dest)
            if len(to_be_added) > 0:
                zero_v += to_be_added
                to_be_added = []
                max_path_len += 1
            else:
                break
        if len(tp_sorted) == self.n:
            self.is_asyclic = True
            self.max_path_len = max_path_len
            return tp_sorted
        else:
            self.is_asyclic = False
            return None

if __name__ == "__main__":
    n = int(input())
    dic = {}
    itr = 0
    for i in range(n):
        for j in range(i+1, n):
            dic[i*n + j] = itr
            itr += 1
    edge = [[] for _ in range(n * (n-1) // 2)]
    for i in range(n):
        a = [int(item) - 1 for item in input().split()]
        for j1, j2 in zip(a, a[1:]):
            if i < j1:
                u = i * n + j1 
            else:
                u = j1 * n + i 
            if i < j2:
                v = i * n + j2 
            else:
                v = j2 * n + i 
            edge[dic[u]].append(dic[v])

    DG = DirectedGraph(edge)
    tps = DG.topological_sort()

    if DG.is_asyclic:
        print(DG.max_path_len)
    else:
        print(-1)
### BUGGY CODE ###

n, m = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(m)]

C = [card_set[1] for card_set in BC for j in range(card_set[0])]
A.extend(C)

A = sorted(A, reverse=True)
result = []
for i in range(n):
    result.append(A[i])
print(sum(result))

### FIXED CODE ###

import sys

input = sys.stdin.readline
n, m = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(m)]
BC.sort(key=lambda x: -x[1])

maxi = n*2
extend = A.extend
[extend([ls[1]] * ls[0]) for ls in BC if len(A) <= maxi]
A.sort(reverse=True)

print(sum(A[:n]))
### BUGGY CODE ###

from collections import defaultdict
import sys

S=sys.stdin.readline().strip()
l=len(S)

mod=10**9+7

dp=defaultdict(lambda: 0)   #dp[ (i,j) ]	i: nan-mojime,  j=0:All mojiretsu pattern , 1:A, 2:AB, 3:ABC
dp[(0,0)]=1

n=1
for i, s in enumerate(S):
	if s in "ABC":
		dp[ (i+1,0) ]=n
	elif s=="?":
		n*=3
		dp[ (i+1,0) ]=n		

nashi=0
a=1
ab=2
abc=3

for i,s in enumerate(S):
	if s =="A":
		dp[ (i+1,a) ]+=dp[ (i,nashi) ]
		dp[ (i+1,a) ]+=dp[ (i,a) ]
		dp[ (i+1,ab) ]+=dp[ (i,ab) ]
		dp[ (i+1,abc) ]+=dp[ (i,abc) ]
	elif s=="B":
		dp[ (i+1,ab) ]+=dp[ (i,ab) ]
		dp[ (i+1,ab) ]+=dp[ (i,a) ]
		dp[ (i+1,a) ]+=dp[ (i,a) ]
		dp[ (i+1,abc) ]+=dp[ (i,abc) ]
	elif s=="C":
		dp[ (i+1,abc) ]+=dp[ (i,abc) ]
		dp[ (i+1,abc) ]+=dp[ (i,ab) ]
		dp[ (i+1,a) ]+=dp[ (i,a) ]
		dp[ (i+1,ab) ]+=dp[ (i,ab) ]
	elif s=="?":
		dp[ (i+1,a) ]+=dp[ (i,a) ]*3
		dp[ (i+1,a) ]+=dp[ (i,nashi) ]
		dp[ (i+1,a) ]%=mod

		dp[ (i+1,ab) ]+=dp[ (i,ab) ]*3
		dp[ (i+1,ab) ]+=dp[ (i,a) ]	
		dp[ (i+1,ab) ]%=mod

		dp[ (i+1,abc) ]+=dp[ (i,abc) ]*3
		dp[ (i+1,abc) ]+=dp[ (i,ab) ]
		dp[ (i+1,abc) ]%=mod


print ( dp[(l,3)]%mod )




### FIXED CODE ###

S=raw_input()

M=10**9+7

all=1
abc=0
ab=0
a=0

for x in S:
	if x=="A":
		a+=all
	if x=="B":
		ab+=a
	if x=="C":
		abc+=ab

	if x=="?":
		abc=abc*3+ab
		ab=ab*3+a
		a= a*3+all
		all*=3

	abc%=M
	ab%=M
	a%=M
	all%=M


print abc%M
### BUGGY CODE ###

# 初期入力
import sys
input = sys.stdin.readline  #文字列では使わない
N = int(input())
A = list(map(int, input().split()))
mod =10**9 +7
a =0
for i in range(N-1):
    for j in range(i+1,N):
        #a +=(A[i] *A[j]) %mod
        a +=(A[i] *A[j])
a %=mod        
print(a)

### FIXED CODE ###

# 初期入力
import sys
input = sys.stdin.readline  #文字列では使わない
N = int(input())
A = list(map(int, input().split()))
mod =10**9 +7
sum_a =sum(A)
ans =0
for i in range(N-1):
    sum_a -=A[i]
    ans +=(A[i] *(sum_a)) %mod
ans %=mod        
print(ans)
### BUGGY CODE ###

import math

def combinations_count(n, r):
    return (math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) % 998244353)



N, R, B, K = [int(i) for i in input().split()]
G = R + B

lst = []
for i in range(N + 1):
    if R * i > K:
        break
    for j in range(N + 1 - i):
        if R * i + G * j > K:
            break
        k = (K - R * i - G * j) // B
        if R * i + G * j + B * k == K:
            lst.append((i, j, k))

result = 0
for l in lst:
    result += combinations_count(N, l[0]) * combinations_count(N - l[0], l[1]) * combinations_count(N - l[0] - l[1], l[2])

print(result)

### FIXED CODE ###

mod = 998244353

class ModComb:
    def __init__(self, MAX):
        fac = [1, 1]
        finv = [1, 1]
        inv = [0, 1]
        for i in range(2, MAX):
            fac.append(fac[i - 1] * i % mod)
            inv.append(mod - inv[mod % i] * (mod // i) % mod)
            finv.append(finv[i - 1] * inv[i] % mod)
        self.fac, self.finv, self.mod = fac, finv, mod

    def nCk(self, n, k):
        if n < k or n < 0 or k < 0:
            return 0
        fac, finv, mod = self.fac, self.finv, self.mod
        return fac[n] * (finv[k] * finv[n - k] % mod) % mod

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

mc = ModComb(3 * 10 ** 5 + 10)

ans = 0
for a in range(N + 1):
    b, r = divmod(K - A * a, B)
    if r != 0:
        continue
    ans += mc.nCk(N, a) * mc.nCk(N, b) % mod
    ans %= mod

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

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

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

memo = [-1] * (k+1)
def rec(x):
    if memo[x] >= 0:
        return memo[x]
    flag = 0
    for i in range(n):
        if x - a[i] < 0:
            continue
        if rec(x - a[i]) == 0:
            flag = 1
    if flag == 1:
        memo[x] = 1
        return 1
    else:
        memo[x] = 0
        return 0

if rec(k) == 1:
    print("First")
else:
    print("Second")

### FIXED CODE ###

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

dp = [0] * (k+1)

for i in range(1, k+1):
    for a in A:
        if i - a < 0:
            break
        if dp[i-a] == 0:
            dp[i] = 1

if dp[k] == 1:
    print("First")
else:
    print("Second")
### BUGGY CODE ###

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

ans = []
for i in range(n):
    ans.append(str(a.index(i+1)+1))

print(" ".join(ans))

### FIXED CODE ###

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

ans = [0 for i in range(n)]
for i,j in enumerate(a,1):
    ans[j-1] = str(i)
    
print(" ".join(ans))
### BUGGY CODE ###

import sys
HK,WK,M = map(int, input().split())
W = [0 for _ in range(WK+1)]
H = [0 for _ in range(HK+1)]
HW = [[0 for i in range(WK+1)] for _ in range(HK+1)]
# 3*10^5

for i in range(M):
    h, w = map(int, input().split())

    H[h] += 1
    W[w] += 1

    HW[h][w] = 1

answer = 0
HMAX = max(H)
WMAX = max(W)

HEMAX = H.count(HMAX)
WEMAX = W.count(WMAX)
if HEMAX * WEMAX > M:
    print(HMAX + WMAX)
    sys.exit(0)

HMAXES = [i for i, _ in enumerate(H) if _ == HMAX]
WMAXES = [i for i, _ in enumerate(W) if _ == WMAX]

# 3*10^5
answer = HMAX + WMAX
for h in HMAXES:
    for w in WMAXES:
        if HW[h][w] == 0:
            print(answer)
            sys.exit(0)
print(answer-1)

### FIXED CODE ###

import sys
HK,WK,M = map(int, input().split())
W = [0] * (WK + 1)
H = [0] * (HK + 1)
HW = {}
# 3*10^5

for i in range(M):
    h, w = map(int, input().split())

    H[h] += 1
    W[w] += 1

    HW[(h,w)] = 1

answer = 0
HMAX = max(H)
WMAX = max(W)

HEMAX = H.count(HMAX)
WEMAX = W.count(WMAX)
if HEMAX * WEMAX > M:
    print(HMAX + WMAX)
    sys.exit(0)

HMAXES = [i for i, _ in enumerate(H) if _ == HMAX]
WMAXES = [i for i, _ in enumerate(W) if _ == WMAX]

# 3*10^5
answer = HMAX + WMAX
for h in HMAXES:
    for w in WMAXES:
        if not (h,w) in HW:
            print(answer)
            sys.exit(0)
print(answer-1)
### BUGGY CODE ###

s = input()[::-1]
current = 0
a = [0] * 2019
a[0] = 1
digit = 1
for i in s:
  current += int(i) * digit
  digit *= 10
  current %= 2019
  a[current] += 1
ans = 0
for i in a:
  ans += i * (i - 1) // 2
print(ans)

### FIXED CODE ###

s = input()[::-1]
current = 0
a = [0] * 2019
a[0] = 1
digit = 1
for i in s:
  current += int(i) * digit
  digit *= 10
  digit %= 2019
  current %= 2019
  a[current] += 1
ans = 0
for i in a:
  ans += i * (i - 1) // 2
print(ans)
### BUGGY CODE ###

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

n, m = [int(x) for x in input().split()]
g = [[] for _ in range(n)]
for _ in range(m):
    x, y = [int(x) for x in input().split()]
    g[x - 1].append(y - 1)

memo = [-1]*n

def dp(v):
    if memo[v] >= 0:
        return memo[v]
    else:
        res = 0
        for u in g[v]:
            res = max(res, dp(u) + 1)
        return res

for i in range(n):
    memo[i] = dp(i)
print(max(memo))




### FIXED CODE ###

import sys
input = sys.stdin.readline
n, m = [int(x) for x in input().split()]
g = [[] for _ in range(n)]
for _ in range(m):
    x, y = [int(x) for x in input().split()]
    g[x - 1].append(y - 1)
from functools import lru_cache
sys.setrecursionlimit(10**7)
@lru_cache(maxsize=None)
def dp(v):
    res = 0
    for u in g[v]:
        res = max(res, dp(u) + 1)
    return res
ans = -1
for i in range(n):
    ans = max(ans, dp(i))
print(ans)