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

stack = list(range(1,N+1))
stack.reverse()

ans = []
for i in range(M):
    # print(stack)
    now = stack.pop()
    cand = now+i+1
    # cand = now+i+1 if now + i + 1 >N else now+i+1-N
    if N - cand + 1== cand - now:
        now = cand
        cand = now+i+1

    # pair = stack.pop(cand)
    stack.remove(cand)
    pair = cand
    
    # print(cand)
    # print("a")
    ans.append([now,pair])

for an in ans:
    print(an[0],an[1])

### FIXED CODE ###

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

num = list(range(1,N+1))
ans = []


if M % 2 == 0:
    for i in range(M // 2):
        ans.append([i+1,M+1-i])
    for i in range(M // 2):
        ans.append([i+2+M,2*M+1-i])


if M % 2 != 0:
    for i in range(M // 2):
        ans.append([i+1,M-i])
    for i in range(M - M//2):
        ans.append([i+1+M,2*M+1-i])


for an in ans:
    print(an[0],an[1])
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LLI(): return [int(x) for x in sys.stdin.readlines()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()
from bisect import bisect_left

def main():
    N, Q = LI()
    XST = []
    for _ in range(N):
        s, t, x = LI()
        XST.append([x, s, t])
    XST.sort()
    D = LLI()
    ans = [-1] * Q
    skip = [0] * Q
    for x, s, t in XST:
        i = bisect_left(D, s - x)
        end = bisect_left(D, t - x)
        while i < end:
            while skip[i] != 0:
                i += skip[i]
            if i >= end:
                break
            ans[i] = x
            skip[i] = end - i
            i += 1
    for y in ans:
        print(y)
    return

main()


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()
from bisect import bisect_left

def main():
    N, Q = LI()
    XST = []
    for _ in range(N):
        s, t, x = LI()
        s -= x
        t -= x
        XST.append([x, s, t])
    D = []
    for _ in range(Q):
        D.append(II())
    ans = [-1] * Q
    nexts = [-1] * Q
    XST.sort()
    for x, s, t in XST:
        i = bisect_left(D, s)
        end = bisect_left(D, t)
        while i < end:
            if nexts[i] == -1:
                ans[i] = x
                nexts[i] = end
                i += 1
            else:
                i = nexts[i]
    for y in ans:
        print(y)
    return

main()
d=[0,2,5,5,4,5,6,3,7,6]
N,M=map(int,input().split())
A=list(map(int,input().split()))
l=[]
for a in A:
    l.append([a,d[a]])
l.sort(key=lambda x:x[0],reverse=True)
l.sort(key=lambda x:x[1])
min_val,min_match=l[0]

ans=[]
if N%min_match==0:
    ans.append(int(str(min_val)*(N//min_match)))
from itertools import combinations
for i in range(1,M):
    for p in combinations(l[1:],i):
        v=[]
        m_sum=0
        for val,mat in p:
            v.append(str(val))
            m_sum+=mat
        if (N-m_sum)%min_match==0:
            ans.append(int(''.join(sorted(v+
                [str(min_val)]*((N-m_sum)//min_match),reverse=True))))
print(max(ans))



### FIXED CODE ###

d=[0,2,5,5,4,5,6,3,7,6]
N,M=map(int,input().split())
A=list(map(int,input().split()))

dp = [-1 for i in range(N+1)]
dp[0] = 0


for i in range(1,N+1):
    tmp = -1
    for a in A:
        if i-d[a]>=0 and dp[i-d[a]] != -1:
            tmp = max(tmp,dp[i-d[a]]+1)
    dp[i] = tmp


A.sort(reverse=True)
ans = ''
while N>0:
    for a in A:
        if N-d[a]>=0 and dp[N-d[a]] == dp[N]-1:
            ans += str(a)
            N -= d[a]
            break
print(ans)
N = input()
S = input()

def main(N,S):
    N = int(N)
    if N%2 == 1:
        print('No')
    else:
        l=int(N/2)

        S1 = S[:l]
        S2 = S[l:]

        if S1 == S2:
            print('Yes')
        else:
            print('No')

main(N,S)

### FIXED CODE ###

r = int(input())

print(r**2)
while True :
    a,b=input().split()
    h =int(a)
    w=int(b)
    if a==0 and b==0:
        break
    for i in range(h):
        if i %2==0:
            print(".#"*(w/2))
            if w==1:
                print(".")
        elif h ==1 :
            print("#")
        else:
            print("#."*((w+1)/2)-1))
            if w==1:
                print("#")

    print("")

### FIXED CODE ###

while True:
    a,b=input().split()
    h = int(a)
    w=int(b)
    if h==0 and w==0:
        break
    odd = "#."*300
    even= ".#"*300
    for i in range(h):
        if (i%2)==0:
            print(odd[:w])
        else:
            print(even[:w])
    print("")
S=input()
T=input()

output=0

for i in range(3):
    if int(S[0,i])==int(T[0,i]):
        output=output+1
    else :
        pass
    
print(output)

### FIXED CODE ###

S=input()
T=input()

output=0

for i in range(3):
    if S[i]==T[i]:
        output=output+1
    else :
        pass
    
print(output)
from collections import Counter as C
n = int(input())
l = sorted(map(int, input().split()), reverse = True)
c = C(l)
res = 0
for e in l:
    for p in range(32, 0, -1):
        e_ = (1 << p) - e
        if c.get(e_, 0) > 0:
            # print(e, e_, c)
            c[e_] -= 1
            c[e] -= 1
            res += 1
            break
print(res)

### FIXED CODE ###

s = input()
l = []
i = 0
n = len(s)
while i < n:
    j = 0
    while i < n and s[i] == 'B':
        j += 1
        i += 1
    l.append(j)

    j = 0
    while i < n and s[i] == 'W':
        j += 1
        i += 1
    l.append(j)
# print(l)
res = 0
for i in range(0, len(l), 2):
    if l[i] > 0:
        res += l[i] * l[i + 1]
    if i + 2 < len(l):
        l[i + 2] += l[i]
print(res)
d,t,s=list(map(int,input().split()))
if d//s<=t:
    print("Yes")
elif d=0 or t=0 or s=0:
    print("Yes")

    
else:
    print("No")



### FIXED CODE ###

d,t,s=list(map(int,input().split()))
if d/s<=t:
    print("Yes")
elif d==0 or t==0 or s==0:
    print("Yes")
else:
    print("No")
N=input()
N=int(N.split()[0])

if 1<=N,N<=9:
    output=N
elif 10<=N,N<=99:
    output=9
elif 100<=N,N<=999:
    output=N-99+9
elif 1000<=N,N<=9999:
    output=900+9
elif 10000<=N,N<=99999:
    output=N-9999+900+9
else:
    output=90000+900+9
print(output)

### FIXED CODE ###

N=input()
N=N.split()
N=int(N[0])

if 1<=N and N<=9:
    output=N
elif 10<=N and N<=99:
    output=9
elif 100<=N and N<=999:
    output=N-99+9
elif 1000<=N and N<=9999:
    output=900+9
elif 10000<=N and N<=99999:
    output=N-9999+900+9
else:
    output=90000+900+9
print(output)
impor math
A,B = map(float,input().split(" "))
A = int(A)
B = int(B * 100)
print(math.floor((A*B)/100))


### FIXED CODE ###

from decimal import Decimal
A,B = map(Decimal, input().split(" "))

print(int(A*B))
while True:
	a,b = map(int,raw_input().split())
   	print len(str(a+b))

### FIXED CODE ###

while True:
    try:
        a,b = map(int,raw_input().split())
        print len(str(a+b))
    except EOFError:
        break
n = int(input())
a = [tuple(map(int, input().split())) for _ in range(n)]

s = set(map(lambda x: sum(map(abs, x)) % 2, a))
if len(s) >= 2:
    print(-1)
    exit()

if next(iter(s)) == 1:
    m = 39
else:
    m = 40
d = [1] * m

print(m)
print(*d)

for x, y in a:
    c = []
    if x < 0:
        c.extend(['L'] * -x)
    elif x > 0:
        c.extend(['R'] * x)
    if y < 0:
        c.extend(['D'] * -y)
    elif y > 0:
        c.extend(['U'] * y)
    print(''.join(c + ['LR'] * m)[:m])


### FIXED CODE ###

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

s = set(map(lambda x: sum(map(abs, x)) % 2, a))
if len(s) >= 2:
    print(-1)
    exit()

if next(iter(s)) == 0:
    m = 33
else:
    m = 32

d = [2 ** i for i in range(32)]
if m > len(d):
    d.append(1)

print(m)
print(*d)

def fetch(x, y, i=31):
    if i == 0:
        return {(1, 0): 'R', (-1, 0): 'L', (0, 1): 'U', (0, -1): 'D'}[(x, y)]
    if abs(x - d[i]) + abs(y) < d[i]:
        return fetch(x - d[i], y, i - 1) + 'R'
    if abs(x + d[i]) + abs(y) < d[i]:
        return fetch(x + d[i], y, i - 1) + 'L'
    if abs(y - d[i]) + abs(x) < d[i]:
        return fetch(x, y - d[i], i - 1) + 'U'
    if abs(y + d[i]) + abs(x) < d[i]:
        return fetch(x, y + d[i], i - 1) + 'D'

for x, y in a:
    if m == 33:
        print(fetch(x + 1, y) + 'L')
    else:
        print(fetch(x, y))
x, n = map(int, input().split())
if n == 0:
    ans = x
else:
    p = list(map(int, input().split()))

d = float('inf')

for i in range(n):
    tmpx = x + n//2 - i
    if not tmpx in p:
        tmpd = abs(x -tmpx) 
        if d >= tmpd:
            d = tmpd
            ans = tmpx

print(ans)




### FIXED CODE ###

x, n = map(int, input().split())
p = list(map(int, input().split()))

if n == 0:
    ans = x
else:
    ans = float('inf')

d = float('inf')

for i in range(n+2):
    tmpx = x + 1 + n//2 - i
    if not tmpx in p:
        tmpd = abs(x -tmpx) 
        if d >= tmpd:
            d = tmpd
            if ans >= tmpx:
                ans = tmpx

print(ans)
a, b = input().split()
print(max(int(a*int(b)), int(b*int(a))

### FIXED CODE ###

a, b = input().split()
print(max(int(a*int(b)), int(b*int(a))))
data = [[[0 for r in range(10)] for f in range(3)] for b in range(4)]

count = int(input())

for c in range(count):
    (b, f, r, v) = [int(x) for x in input().split()]
    data[b - 1][f - 1][r - 1] += v

for b in range(4):
    for f in range(3):
        for r in range(10):
            print(data[b][f][r], end=' ')
        print()
    print('#' * 20) if b < 4 - 1 else pass

### FIXED CODE ###

data = [
    [[0 for r in range(10)] for f in range(3)] for b in range(4)
]

# ??\??????????????????????????§????????????????????????????????????
count = int(input())
for c in range(count):
    b, f, r, v = [int(i) for i in input().split()]
    data[b-1][f-1][r-1] += v

for bi, b in enumerate(data):
    for f in b:
        for r in f:
            print(' {0}'.format(r), end='')

        print()

    if bi < 3:
        print('#' * 20)
import sys
input = sys.stdin.readline
from collections import Counter
import math
M = 998244353
N = int(input())
# D = list(map(int, input().split()))
counter = Counter(map(int, input().split()))
ans = counter[1]
pre_c = 1
for i, (n, c) in enumerate(sorted(counter.items())):
    if i != n:
        ans = 0
        break
    elif n <= 1 or c == 1:
        pre_c = c
        continue
    elif pre_c == 1:
        ans *= c
        pre_c = c
        continue
    ans *= (math.factorial(c) ** 2 * (c+1)) // (math.factorial(c+2 - pre_c) * math.factorial(pre_c-1)) // pre_c
    pre_c = c
print(ans % M)

### FIXED CODE ###

import sys
input = sys.stdin.readline
from collections import Counter
M = 998244353
N = int(input())
D = list(map(int, input().split()))
counter = Counter(D)
ans = 1
pre_c = 1
if D[0] != 0 or counter[0] != 1:
    print(0)
else:
    for i, (k, c) in enumerate(sorted(counter.items(), key=lambda x: x[0])):
        if k == 0:
            continue
        elif i != k:
            ans = 0
            break
        ans *= pre_c ** c
        pre_c = c
    print(ans%M)
a = list(map(int,input().split("/"))

if a[0]>= 2019:
    print("Heisei")
else:
    print("TBD")



### FIXED CODE ###

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



if a[0]== 2019 and a[1]<5:
    print("Heisei")
elif a[0]<2019 and a[1]< 12:
    print("Heisei")
else:
    print("TBD")
N, X = map(int, input().split())

def f(a, b):
    if a == b:
        return a
    if a >= b:
        a, b = b, a
    return 2 * a + f(a, b - a)

print (N + f(N - X, X))

### FIXED CODE ###

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

ans = N
a = N - X
b = X
while a != b:
    if a >= b:
        a, b = b, a
    if b%a != 0:
        ans += 2 * a * (b//a)
        b = b%a
    else:
        ans += 2 * a * (b//a - 1)
        b = a
print (ans + a)
a=intput("enter")
if a=="ABC":
    print("ARC")
elif a=="ARC":
    print("ABC")

### FIXED CODE ###

a=input()
if a=="ABC":
    print("ARC")
elif a=="ARC":
    print("ABC")
n,l = map(int,input().split())
list = []

for i in range(n):
    word = input()
    list.append(word)

list_connect = "".join(sorted(list))


print(list_connect)


### FIXED CODE ###

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

if list == [5,5,7]:
    print("YES")
elif list == [5,7,5]:
    print("YES")
elif list == [7,5,5]:
    print("YES")
else:
    print("NO")
N = int(input())
result = 0
for i in (N+1):
  result += i
print(result)

### FIXED CODE ###

N = int(input())
cnt = 0
for i in range(N+1):
    cnt += i
print(cnt)
D = int(input())
a_dict={22:Christmas Eve Eve Eve,23:Christmas Eve Eve,24:Christmas Eve,25:Christmas}
print(a_dict[D])

### FIXED CODE ###

D = int(input())
a_dict={22:"Christmas Eve Eve Eve",23:"Christmas Eve Eve",24:"Christmas Eve",25:"Christmas"}
print(a_dict[D])
import sys

N = input()
S = input()

c = 0

for i in range(N-2):
    if S[i]=='A' and  S[i+1]=='B'and  S[i+2]=='C':
        c += 1

print(c)

### FIXED CODE ###

import sys

N = int(input())
S = input()

c = 0

for i in range(N-2):
    if S[i]=='A' and  S[i+1]=='B'and  S[i+2]=='C':
        c += 1

print(c)
import sys
input = sys.stdin.readline

S = input()
mod = 10 ** 9 + 7
N = len(S)
table = [[0] * 13 for _ in range(N + 1)]
table[0][0] = 1

dd = 1

for i, char in enumerate(reversed(S)):
    c = char != '?'
    for j in range(13):
        for k in range(10):
            if c and int(char) != k:
                continue
            table[i+1][(j + dd * k)  % 13] += table[i][j]
            table[i+1][(j + dd * k)  % 13] %= mod
    dd = (dd * 10) % 13

print(table[N][5])


### FIXED CODE ###

S = input()
mod = 10 ** 9 + 7
N = len(S)
table = [[0] * 13 for _ in range(N + 1)]
table[0][0] = 1

dd = 1

for i, char in enumerate(reversed(S)):
    c = char != '?'
    for j in range(13):
        for k in range(10):
            if c and int(char) != k:
                continue
            table[i+1][(j + dd * k)  % 13] += table[i][j]
            table[i+1][(j + dd * k)  % 13] %= mod
    dd = (dd * 10) % 13

print(table[N][5])
import math

a,b,C = map(int,raw_input())
c = math.sqrt(a*a+b*b-2*a*b*math.cos(math.radians(C)))
L = a+b+c
S = (a*b*math.sin(math.radians(C))) /2
h = (S*2)/a
print("%f" % (S, ))
print("%f" % (L, ))
print("%f" % (h, ))


### FIXED CODE ###

import math
e=map(float,raw_input().split())
a=e[0]
b=e[1]
C=math.radians(e[2])
c=(a**2+b**2-2*a*b*math.cos(C))**0.5
h=b*math.sin(C)
S=h*a*0.5
L=a+b+c
print S
print L
print h
import math

n = int(input())
c = -1
sum_ = 0
for i in range(n):
    a, b = map(int, input().split())
    sum_ += a
    if a > b:
        if c == -1:
            c = b
        if b > c:
            c = b
if c == -1:
    print("0")
else:
    print(s - c)


### FIXED CODE ###

import math

n = int(input())
c = -1
sum_ = 0
for i in range(n):
    a, b = map(int, input().split())
    sum_ += a
    if a > b:
        if c == -1:
            c = b
        if b < c:
            c = b
if c == -1:
    print(0)
else:
    print(sum_ - c)
n = input()
a = ""
for i in range(n):
  if i =="0":
    a.append(0)
  elif i =="1":
    a.append(1)
  elif i =="B":
    a.pop()
print(a)

### FIXED CODE ###

n = input()
a = ""
for i in n:
  if i =="0":
    a+=i
  elif i =="1":
    a+=i
  elif i =="B":
    a = a[:-1]
print(a)
n= int(input())
kk=set()
for i in range(n):
  s=input()
  kk.add()
print(len(kk))

### FIXED CODE ###

n=int(input())
d=dict()

for i in range(n):
  s="".join(input())
  #print(s)
  if s in d:
    d[s]+=1
  else:
    d[s]=1
ans=0
for x in d.values():
  ans+=1
print(ans)
S = input()
chars = list(map(lambda c: ord(c)-97, S))
if len(chars)!=26:
    chars = sorted(chars)
    i = 0
    while i==chars[i]:
        i += 1
    ans = S + chr(i+97)
else:
    prev = -1
    i = 0
    for c in reversed(chars):
        if prev < c:
            i += 1
            prev = c
        else:
            break
    if i==26:
        ans = -1
    else:
        max_s = chars[-i-1]
        min_c = 27
        for c in chars[-i:]:
            if c>max_s and c<min_c:
                min_c = c
        ans = S[:-i-1] + chr(min_c+97)

print(ans)



### FIXED CODE ###

S = input()
chars = list(map(lambda c: ord(c)-97, S))
if len(chars)!=26:
    chars = sorted(chars)
    i = 0
    while i==chars[i]:
        i += 1
        if i==len(chars):
            break
    ans = S + chr(i+97)
else:
    prev = -1
    i = 0
    for c in reversed(chars):
        if prev < c:
            i += 1
            prev = c
        else:
            break
    if i==26:
        ans = -1
    else:
        max_s = chars[-i-1]
        min_c = 27
        for c in chars[-i:]:
            if c>max_s and c<min_c:
                min_c = c
        ans = S[:-i-1] + chr(min_c+97)

print(ans)
import sys
input=sys.stdin.readline

f = open(sys.argv[1], "r")
input = f.readline

H,W = map(int, input().split())

b = {}
check = set()
i = 0
for h in range(H):
    for c in input().strip():
        if c == "#":
            b[i] = 1
            check.add(i)
        i += 1
t = 0

#import time
#t1 = time.time()

while len(b) != W*H:
    t += 1
    tb = set()
    #print(len(check))
    for i in check:
        if i-W >= 0:
            tb.add(i-W)
        if i%W > 0:
            tb.add(i-1)
        if i%W < W-1:
            tb.add(i+1)
        if i+W < H*W:
            tb.add(i+W)
    check.clear()
    for i in tb:
        if i not in b:
            check.add(i)
        b[i] = 1
print(t)

#print(time.time()-t1)


### FIXED CODE ###

import sys
input=sys.stdin.readline
H,W = map(int, input().split())

b = [[True]*(W+2)]
for _ in range(H):
    b.append([True] + [x == '#' for x in input().strip()] + [True])
b.append([True]*(W+2))

check = []
for i in range(1,H+1):
    for j in range(1,W+1):
        if b[i][j]:
            check.append((i,j))
t = 0
while check:
    tmp = []
    for i,j in check:
        if not b[i-1][j]:
            b[i-1][j] = True
            tmp.append((i-1,j))
        if not b[i][j-1]:
            b[i][j-1] = True
            tmp.append((i,j-1))
        if not b[i][j+1]:
            b[i][j+1] = True
            tmp.append((i,j+1))
        if not b[i+1][j]:
            b[i+1][j] = True
            tmp.append((i+1,j))
    check = tmp
    t += 1

print(t-1)
from functools import reduce
from functools import gcd

N = int(input())
A = [int(i) for i in input().split()]

print(reduce(gcd, A))


### FIXED CODE ###

def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)

N = int(input())
A = [int(i) for i in input().split()]

result = 0
for ai in A:
    result = gcd(result, ai)

print(result)
= int[int(i) for i in input().split()]

if a < b:
    print(a < b)
elif a > b:
    print(a > b)
else:
    print(a == b)

### FIXED CODE ###

a, b = [int(i) for i in input().split()]

if a < b:
    print("a < b")

elif a > b:
    print("a > b")

else:
    print("a == b")
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

l = [a, b, c, d, e]
l_times_ten = []
amari_list = []
for i in range(len(l)):
    amari = l[i] % 10
    if amari == 0:
        l_times_ten.append(l[i])
    elif amari != 0:
        amari_list.append(amari)
        l_tmp =  l[i] +(10 - amari)
        l_times_ten.append(l_tmp)
max_total_time = sum(l_times_ten)
adding = 10 - min(amari_list)
min_total_time = max_total_time - adding
print(min_total_time)

### FIXED CODE ###

a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

l = [a, b, c, d, e]
l_times_ten = []
amari_list = []
for i in range(len(l)):
    amari = l[i] % 10
    if amari == 0:
        l_times_ten.append(l[i])
    elif amari != 0:
        amari_list.append(amari)
        l_tmp =  l[i] +(10 - amari)
        l_times_ten.append(l_tmp)
# print(l_times_ten)
# print(amari_list)
max_total_time = sum(l_times_ten)
# print(min(amari_list))
if len(amari_list) != 0:
    adding = 10 - min(amari_list)
else:
    adding = 0
min_total_time = max_total_time - adding
print(min_total_time)
import collections
a = input().split()
M = int(a[2])
hidari = []
migi = []
c = []
 
for i in range(M):
  b = input().split()
  hidari.append(b[0])
  migi.append(b[1])
  c.append(b)
  
countleft = collections.Counter(hidari)
countright = collections.Counter(migi)
leftmax = countleft.most_common()[0][1]
rightmax = countright.most_common()[0][1]
tempmax = int(leftmax + rightmax)
 
leftkeys = [k for k, v in countleft.items() if v == leftmax]
rightkeys = [k for k, v in countright.items() if v == rightmax]
 
leftkeyN = int(len(leftkeys))
rightkeyN = int(len(rightkeys))
flag = int(0)
cnt = int(0)
#これで左右の最頻回数はOK
#左右の最頻奴も探した
#ここから最頻同志になってるやつを探す
 
for T in range(M):
    if c[T][0] in leftkeys:
      if c[T][1] in rightkeys:
        cnt = cnt + 1
      else:
        pass
    else:
      pass
 
 
if cnt == int(leftkeyN * rightkeyN):
    print(int(tempmax - 1))
else:
    print(int(tempmax)

### FIXED CODE ###

import collections
a = input().split()
M = int(a[2])
hidari = []
migi = []
c = []
 
for i in range(M):
  b = input().split()
  hidari.append(b[0])
  migi.append(b[1])
  c.append(b)
  
countleft = collections.Counter(hidari)
countright = collections.Counter(migi)
leftmax = countleft.most_common()[0][1]
rightmax = countright.most_common()[0][1]
tempmax = int(leftmax + rightmax)
 
leftkeys = [k for k, v in countleft.items() if v == leftmax]
rightkeys = [k for k, v in countright.items() if v == rightmax]
 
leftkeyN = int(len(leftkeys))
rightkeyN = int(len(rightkeys))
flag = int(0)
cnt = int(0)
#これで左右の最頻回数はOK
#左右の最頻奴も探した
#ここから最頻同志になってるやつを探す
 
for i in range(M):
    goukei = int(countleft.get(c[i][0])) + int(countright.get(c[i][1]))
    if goukei == tempmax:
        cnt += 1
    else:
        pass

if cnt == int(leftkeyN * rightkeyN):
    print(int(tempmax - 1))
else:
    print(int(tempmax))