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

# 1-index
def segfunc(x, y):
    return max(x, y)

ide_ele = 0

class segtree:

    def __init__(self, init_val, segfunc, ide_ele):
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num

        for i in range(n):
            self.tree[self.num + i] = init_val[i]

        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, k, x):
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, l, r):
        """
        [l, r)のsegfuncしたものを得る
        """
        res = self.ide_ele

        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res


N, K = map(int, input().split())
T = []
for i in range(N):
    a = int(input())
    T.append(a)

A = [0]*(max(T)+1)
s_tree = segtree(A, segfunc, ide_ele)
for i in range(N):
    a = T[i]
    p = s_tree.query(max(a - K, 0), min(a + K + 1, max(T)+1))
    s_tree.update(a, p + 1)

print(s_tree.query(0, max(T)+1))

### FIXED CODE ###

# 1-index
def segfunc(x, y):
    return max(x, y)

ide_ele = 0

class segtree:

    def __init__(self, init_val, segfunc, ide_ele):
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num

        for i in range(n):
            self.tree[self.num + i] = init_val[i]

        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, k, x):
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, l, r):
        """
        [l, r)のsegfuncしたものを得る
        """
        res = self.ide_ele

        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res


N, K = map(int, input().split())
T = []
for i in range(N):
    a = int(input())
    T.append(a)

M = max(T)+1
A = [0]*M
s_tree = segtree(A, segfunc, ide_ele)
for i in range(N):
    a = T[i]
    p = s_tree.query(max(a - K, 0), min(a + K + 1, M))
    s_tree.update(a, p + 1)

print(s_tree.query(0, M))
### BUGGY CODE ###

from collections import deque


H, W = map(int, input().split())
A, white = [], []
for i in range(H):
    A.append(list(input()))
    if '.' in A[i]:
        for j in range(W):
            if A[i][j] == '.':
                white.append([i, j])

dy = [0, 1, 0, -1]
dx = [1, 0, -1, 0]
cnt = 0

# 各白マスから黒マスまでの最短距離を探索し，その最大値を出力
for sy, sx in white:
    dis = [[float('inf')] * W for _ in range(H)]
    dis[sy][sx] = 0
    q = deque([(sy, sx)])
    update = False
    while q:
        y, x = q.popleft()
        for i in range(4):
            ny = y + dy[i]
            nx = x + dx[i]
            if (1
                    and 0 <= ny < H
                    and 0 <= nx < W
                    and dis[ny][nx] == float('inf')):
                dis[ny][nx] = dis[y][x] + 1
                q.append((ny, nx))
                if A[ny][nx] == '#':
                    cnt = max(dis[ny][nx], cnt)
                    update = True
        if update:
            break
print(cnt)

### FIXED CODE ###

from collections import deque


def resolve():
    H, W = map(int, input().split())
    A, q = [], deque([])
    for i in range(H):
        A.append(list(input()))
        if '#' in A[i]:
            for j in range(W):
                if A[i][j] == '#':
                    q.append((i, j))

    dy = [0, 1, 0, -1]
    dx = [1, 0, -1, 0]
    cnt = -1

    # 1回目で各黒マスを拡張して，2回目以降は拡張した黒マスから拡張してく
    nq = deque([])
    while q:
        y, x = q.popleft()
        for i in range(4):
            ny = y + dy[i]
            nx = x + dx[i]
            if 0 <= ny < H and 0 <= nx < W and A[ny][nx] == '.':
                nq.append((ny, nx))
                A[ny][nx] = '#'
        if q == deque([]):
            q = nq
            nq = deque([])
            cnt += 1
    print(cnt)


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

# input here
_INPUT = """\
10 2
4
5
"""
"""
K = int(input())
H, W, K = map(int, input().split())
a = list(map(int, input().split()))
xy = [list(map(int, input().split())) for i in range(N)]
p = tuple(map(int,input().split()))
"""
def main():
    N, M = map(int, input().split())
    a = [int(input()) for i in range(M)]

    #動的計画法問題
    dp = [0] * (N+1)
    dp[0] = 1
    if 1 not in a:
        dp[1] = 1
    else:
        dp[1] = 0

    for i in range(2,N+1):
        if i in a:
            continue
        else:
            dp[i] = dp[i-1] + dp[i-2]

    print(dp[N]%(10**9+7)) 




            
if __name__ == '__main__':
    import io
    import sys
    import math
    import itertools
    from collections import deque

    # sys.stdin = io.StringIO(_INPUT)
    main()

### FIXED CODE ###

N, M = map(int, input().split())
a = set([int(input()) for _ in range(M)])
INF = 1000000007

dp = [0] * (N + 1)
dp[0] = 1
if 1 not in a:
	dp[1] = 1
else:
	dp[1] = 0
for i in range(2, N + 1):
	if i in a:
		continue
	dp[i] = dp[i - 1] + dp[i - 2]
	dp[i] %= INF

print(dp[N])
### BUGGY CODE ###

from collections import deque
import copy

H, W = map(int, input().split())
maps2 = deque([deque(["#" for _ in range(W + 2)])])
MAX = 0

for _ in range(H):
    temp = deque(input())
    temp.appendleft("#")
    temp.append("#")
    maps2.append(temp)
maps2.append(deque(["#" for _ in range(W + 2)]))

for i in range(1, H + 1):
    for l in range(1, W + 1):
        maps = copy.deepcopy(maps2)
        if maps2[i][l] != "#":
            pos = [[i, l, 0]]
            while len(pos) > 0:

                y, x, depth = pos.pop(0)
                if depth > MAX:
                    MAX = depth
                maps[y][x] = "$"

                if maps[y + 1][x] == ".":
                    pos.append([y + 1, x, depth + 1])
                if maps[y][x + 1] == ".":
                    pos.append([y, x + 1, depth + 1])
                if maps[y - 1][x] == ".":
                    pos.append([y - 1, x, depth + 1])
                if maps[y][x - 1] == ".":
                    pos.append([y, x - 1, depth + 1])
print(MAX)


### FIXED CODE ###

import sys
import math
from collections import deque
import copy

H, W = map(int, input().split())
maps2 = deque([deque(["#" for _ in range(W + 2)])])
MAX = 0

for _ in range(H):
    temp = deque(input())
    temp.appendleft("#")
    temp.append("#")
    maps2.append(temp)
maps2.append(deque(["#" for _ in range(W + 2)]))

for i in range(1, H + 1):
    for l in range(1, W + 1):
        if maps2[i][l] != "#":
            maps = copy.deepcopy(maps2)
            pos = [[i, l, 0]]
            maps[i][l] = "a"
            while len(pos) > 0:

                y, x, depth = pos.pop(0)
                if depth > MAX:
                    MAX = depth

                if maps[y + 1][x] == ".":
                    pos.append([y + 1, x, depth + 1])
                    maps[y + 1][x] = "a"
                if maps[y][x + 1] == ".":
                    pos.append([y, x + 1, depth + 1])
                    maps[y][x + 1] = "a"
                if maps[y - 1][x] == ".":
                    pos.append([y - 1, x, depth + 1])
                    maps[y - 1][x] = "a"
                if maps[y][x - 1] == ".":
                    pos.append([y, x - 1, depth + 1])
                    maps[y][x - 1] = "a"
print(MAX)
### BUGGY CODE ###

import math
A,B,N=map(int,input().split())
max=0
if N<B:
  print(math.floor(A*N/B)-A*math.floor(N/B))
  exit()
for i in range(1,B):
  tmp=math.floor(A*i/B)-A*math.floor(i/B)
  if tmp>max:
    max=tmp
print(max)

### FIXED CODE ###

import math
A,B,N=map(int,input().split())
max=0
if N<B:
  print(math.floor(A*N/B)-A*math.floor(N/B))
  exit()
tmp=math.floor(A*(B-1)/B)-A*math.floor((B-1)/B)
print(tmp)
### BUGGY CODE ###

# D - Integer Cards

from operator import itemgetter
from collections import deque

N, M = map(int, input().split())
A = sorted([int(a) for a in input().split()])

BC = []
for i in range(M):
    b, c = map(int, input().split())
    BC.append((b, c))

BC = sorted(BC, key=itemgetter(1), reverse=True)

D = deque()
for _ in range(M):
    bc = BC.pop()
    for _ in range(bc[0]):
        D.append(bc[1])

for i in range(N):
    if len(D) != 0 and A[i] <= D[-1]:
        A[i] = D.pop()

print(sum(A))


### FIXED CODE ###

# D - Integer Cards

from operator import itemgetter

N, M = map(int, input().split())
A = sorted([int(a) for a in input().split()])

BC = []
for i in range(M):
    b, c = map(int, input().split())
    BC.append([b, c])

BC = sorted(BC, key=itemgetter(1), reverse=True)

ans = 0
for i in range(N):
    if len(BC) != 0 and A[i] <= BC[0][1]:
        ans += BC[0][1]
        BC[0][0] -= 1
        if BC[0][0] == 0:
            BC.pop(0)
    else:
        ans += A[i]

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

import sys
input = sys.stdin.readline

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

SC=[0,0,0,0]#0個,1個,2個,3個

for a in A:
    SC[a]+=1
SC=tuple(SC)

DP=dict()
DP[SC]=[1,0]#遷移確率0,経過日数

def plus(A,B):
    xa,ya=A
    xb,yb=B

    return [xa+xb,(xa*ya+xb*yb)/(xa+xb)]
#print(DP)

for test in range(sum(A)):
    
    NEXT=dict()
    
    for a,b,c,d in DP:
        x,y=DP[(a,b,c,d)]
        

        #print(a,b,c,d,x,y)
        #print(NEXT.get((a+1,b-1,c,d),[0,0]),[x*b/(b+c+d),y+N/(b+c+d)])

        if b>0:
            NEXT[(a+1,b-1,c,d)]=plus(NEXT.get((a+1,b-1,c,d),[0,0]),[x*b/(b+c+d),y+N/(b+c+d)])

        if c>0:
            NEXT[(a,b+1,c-1,d)]=plus(NEXT.get((a,b+1,c-1,d),[0,0]),[x*c/(b+c+d),y+N/(b+c+d)])

        if d>0:
            NEXT[(a,b,c+1,d-1)]=plus(NEXT.get((a,b,c+1,d-1),[0,0]),[x*d/(b+c+d),y+N/(b+c+d)])

        #print(NEXT)

    DP=NEXT

print(list(DP.values())[0][1])


### FIXED CODE ###

import sys
input = sys.stdin.readline

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

SC=[0,0,0]#1個,2個,3個

for a in A:
    SC[a-1]+=1
one,two,three=SC

DAYSDICT=[[[0.0]*301 for j in range(301)] for k in range(301)]
DAYSDICT[0][0][0]=0
def days(one,two,three):
    ANS=N
    if one>0:
        ANS+=DAYSDICT[one-1][two][three]*one
    if two>0:
        ANS+=DAYSDICT[one+1][two-1][three]*two
    if three>0:
        ANS+=DAYSDICT[one][two+1][three-1]*three
        
    DAYSDICT[one][two][three]=ANS/(one+two+three)


for k in range(three+1):
    for j in range(two+three+1-k):
        for i in range(one+two+three+1-j-k):
            if i==j==k==0:
                continue
            days(i,j,k)

print(DAYSDICT[one][two][three])
### BUGGY CODE ###

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

min_list = [[a[i] for i in range(n)] for _ in range(n)]
for i in range(1, n):
	for j in range(n):
		min_list[i][j] = min(min_list[i-1][j], a[(j-i) % n])

ans = float("inf")
for i in range(n):
	ans = min(ans, x * i + sum(min_list[i]))

print(ans)

### FIXED CODE ###

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

min_list = [[a[i] for i in range(n)] for _ in range(n)]
for i in range(1, n):
	for j in range(n):
		min_list[i][j] = min(min_list[i-1][j], a[(j-i) % n])

ans = float("inf")
for i in range(n):
	ans = min(ans, x * i + sum(min_list[i]))

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

L, R = map(int, input().split())

P = 2019

R = min(R, L+4038)

tmp = 3000
for i in range(L, R):
    for j in range(L+1, R+1):
        tmp = min((i*j)%P, tmp)
        
print(tmp)

### FIXED CODE ###

L, R = map(int, input().split())

P = 2019

R = min(R, L+673)

tmp = 2018
for i in range(L, R):
    for j in range(L+1, R+1):
        tmp = min((i*j)%P, tmp)
        
print(tmp)
### BUGGY CODE ###

N = int(input())
s = input()
l = []
c = 0
ans = 10**6

if s.count("#")==0:
    print(0)
else:
    for i in range(N):
        if s[i] == "#":
            k = i
            aaa = s[i:N+1].count(".")
            ans = min(c + aaa, ans)
            c += 1
    print(ans)

        



### FIXED CODE ###

N = int(input())
s = input()
l = []
b = 0
w = s.count(".")

for i in range(N):
    if s[i] == "#":
        l.append(b+w)
        b += 1
    else:
        w -= 1
        l.append(b+w)
print(min(l))
### BUGGY CODE ###

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

A=[list(map(int,input().split())) for _ in range(H)]
B=[list(map(int,input().split())) for _ in range(H)]
num=(H+W)*80+1
#dp[i][j]=マス(i,j)における可能なポイントのリスト
dp=[[[False]*(num) for _ in range(W)] for _ in range(H)]
dp[0][0][0]=True

for i in range(W+H-1):
  I,J=0,0
  if i < H:
    I=i
    J=0
  else:
    I=H-1
    J=i-H+1
  while I>=0 and J<W:
    sa = abs(A[I][J] - B[I][J])
    for n in range(num):
      if not dp[I][J][n]:
        continue
      if I!=H-1:
        dp[I+1][J][n+sa]=True
        dp[I+1][J][abs(n-sa)]=True
      if J!=W-1:
        dp[I][J+1][n+sa]=True
        dp[I][J+1][abs(n-sa)]=True
    I-=1
    J+=1

sa = abs(A[H-1][W-1] - B[H-1][W-1])
ans=float("inf")
for n in range(num):
  if not dp[-1][-1][n]:
    continue
  ans = min(ans,abs(n-sa),n+sa)
print(ans)

### FIXED CODE ###

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

A=[list(map(int,input().split())) for _ in range(H)]
B=[list(map(int,input().split())) for _ in range(H)]

#dp[i][j]=マス(i,j)における可能なポイントのリスト
dp=[[set() for _ in range(W)] for _ in range(H)]
dp[0][0].add(0)

for i in range(W+H-1):
  I,J=0,0
  if i < H:
    I=i
    J=0
  else:
    I=H-1
    J=i-H+1
  while I>=0 and J<W:
    sa = abs(A[I][J] - B[I][J])
    for point in dp[I][J]:
      if I!=H-1:
        dp[I+1][J].add(point+sa)
        dp[I+1][J].add(abs(point-sa))
      if J!=W-1:
        dp[I][J+1].add(point+sa)
        dp[I][J+1].add(abs(point-sa))
    I-=1
    J+=1

ans=dp[H-1][W-1]
sa = abs(A[H-1][W-1] - B[H-1][W-1])
res=float("inf")
for p in ans:
  res=min(res,abs(p+sa),abs(p-sa))
print(res)
### BUGGY CODE ###

s = list(input())
k = int(input())

substring = []
for i in range(len(s)):
    for j in range(i,len(s)):
        if not("".join(s[i:j+1]) in substring):
            substring.append("".join(s[i:j+1]))

substring.sort()
print(substring[k-1])

### FIXED CODE ###

s = list(input())
k = int(input())

substring = []
for i in range(len(s)):
    for j in range(i,min(len(s),i+k)):
        if not("".join(s[i:j+1]) in substring):
            substring.append("".join(s[i:j+1]))

substring.sort()
print(substring[k-1])
### BUGGY CODE ###

from collections import deque
n, m = map(int, input().split())
rode = []
for _ in range(m):
    rode.append(list(map(int, input().split())))

l= deque([1])
unvisit= [True]*(n+1)
unvisit[1] = False
anslis = [0]*(n+1)
while len(l) != 0:
    now = l.popleft()
    for r in rode:
        if r[0] == now:
            if unvisit[r[1]]:
                unvisit[r[1]] = False
                l.append(r[1])
                anslis[r[1]] = now
        if r[1] == now:
            if unvisit[r[0]]:
                unvisit[r[0]] = False
                l.append(r[0])
                anslis[r[0]] = now
print("Yes")
for i in range(2,len(anslis)):
    print(anslis[i])

### FIXED CODE ###

from collections import deque
n, m = map(int, input().split())
rinsetsu_lis = [[] for _ in range(n+1)]
for _ in range(m):
    a,b = map(int, input().split())
    rinsetsu_lis[a].append(b)
    rinsetsu_lis[b].append(a)
l= deque([1])
unvisit= [True]*(n+1)
unvisit[1] = False
anslis = [0]*(n+1)
while len(l) != 0:
    now = l.popleft()
    for r in rinsetsu_lis[now]:
        if unvisit[r]:
            unvisit[r] = False
            l.append(r)
            anslis[r] = now
print("Yes")
for i in range(2,len(anslis)):
    print(anslis[i])
### BUGGY CODE ###

from collections import deque
import sys
input=sys.stdin.readline


def solve():
    H, W = map(int, input().split())
    dp = [[False]*W for _ in range(H)]
    candidate = []

    for i in range(H):
        for j, s in enumerate(input()):
            if s=="#":
                dp[i][j] = True
                candidate.append((i, j))

    q = deque([(c, 0) for c in candidate])
    while q:
        (y, x), cost = q.popleft()
        dp[y][x] = True

        for y1, x1 in [(y+1, x), (y-1, x), (y, x-1), (y, x+1)]:
            if not (0<=y1<H and 0<=x1<W):
                continue
            if dp[y1][x1]:continue
            q.append(((y1, x1), cost+1))

    print(cost)


if __name__ == "__main__":
    solve()


### FIXED CODE ###

from collections import deque


def solve():
    H, W = map(int, input().split())
    m = [[-1]*W for _ in range(H)]
    l = [list(input()) for _ in range(H)]
    dx = [-1, 1, 0, 0]
    dy = [0, 0, -1, 1]
    q = deque([])

    for i in range(H):
        for j in range(W):
            if l[i][j]=="#":
                q.append((i, j))
                m[i][j] = 0
    
    while q:
        y, x = q.popleft()

        for px, py in zip(dx, dy):
            x1, y1 = x + px, y + py
            if not (0<=x1<W and 0<=y1<H):
                continue
            if m[y1][x1] == -1:
                q.append((y1, x1))
                m[y1][x1] = m[y][x] + 1

    print(max(map(max, m)))


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

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

ans = round(n*(n-1)*(n-2)/6)
b=0

l.sort()

for i in range(n):
    for j in range(i+1,n):
        b = l[i] + l[j]
        for k in range(n):
            if b<=l[n-k-1]:
                ans-=1
            else:
                break

if ans<0:
    ans=0

print(ans)

### FIXED CODE ###

import bisect
n = int(input())
li = list(map(int, input().split()))

li.sort()
ans = 0

for i in range(n-2):
    for j in range(i+1,n-1):
        ans += bisect.bisect_left(li, li[i]+li[j]) - j - 1

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

from collections import deque
h,w = map(int,input().split())
map_input = [list(input()) for i in range(h)]

queue = deque([])
for i in range(h):
    for j in range(w):
        if map_input[i][j]=='#':
            queue.append([j,i])

mx = [0,0,1,-1]
my = [1,-1,0,0]

ans = -1
def bfs(map_input,queue,ans):
    while queue:
        queue2 = deque([])
        ans+=1
        for x,y in queue:
            for i in range(4):
                nx = x+mx[i]
                ny = y+my[i]
                if 0<=nx<w and 0<=ny<h:
                    if map_input[ny][nx]=='#':
                        continue
                    map_input[ny][nx]='#'
                    queue2.append([nx,ny])

        queue = queue2
    return ans

ans = bfs(map_input,queue,ans)
print(ans)

### FIXED CODE ###

from collections import deque
h,w = map(int,input().split())
map_input = [list(input()) for i in range(h)]

queue = deque([])
for i in range(h):
    for j in range(w):
        if map_input[i][j]=='#':
            queue.append([j,i])

mx = [0,0,1,-1]
my = [1,-1,0,0]

ans = -1
def bfs(map_input,queue,ans):
    while queue:
        queue2 = deque([])
        ans+=1
        for x,y in queue:
            for i in range(4):
                nx = x+mx[i]
                ny = y+my[i]
                if 0<=nx<w and 0<=ny<h:
                    if map_input[ny][nx]=='#':
                        continue
                    map_input[ny][nx]='#'
                    queue2.append([nx,ny])

        queue = queue2
    return ans

ans = bfs(map_input,queue,ans)
print(ans)
### BUGGY CODE ###

h, n = map(int, input().split())
f_inf = float("inf")
dp = [f_inf] * (h + 1)
dp[0] = 0
for i in range(n):
    a, b = map(int, input().split())
    for j in range(h):
        next_j = min(j + a, h)
        dp[next_j] = min(dp[next_j], dp[j] + b)
print(dp[h])

### FIXED CODE ###

h, n = map(int, input().split())
a = []
b = []
for i in range(n):
    a_, b_ = map(int, input().split())
    a.append(a_)
    b.append(b_)

f_inf = float("inf")
dp = [f_inf] * (h + max(a))
dp[0] = 0
for i in range(n):
    for j in range(h):
        if dp[j] != f_inf:
            if dp[j + a[i]] > dp[j] + b[i]:
                dp[j + a[i]] = dp[j] + b[i]

print(min(dp[h:]))
### BUGGY CODE ###

import numpy as np
n=input()
data=list(map(int,input().split()))
is_i=0
num=sorted(data)
count=num[1]
if 2<len(data):
    while num[0]<count and any([x%count!=0 for x in num[1::]]):
        count=int(count/2)+1
for i in range(count+1)[::-1]:
    is_i=0
    if all([x%i==0 for x in data]):
        print(i)
        break
    else:
        for j in range(len(data)):
            if data[j]%i!=0:
                is_i+=1
        if is_i==1:
            print(i)
            break

### FIXED CODE ###

from fractions import gcd
import numpy as np
n=int(input())
data=list(map(int,input().split()))
left=np.zeros(n+1,dtype=np.int)
right=np.zeros(n+1,dtype=np.int)
kotae=1
for i in range(n):
    left[i+1]=gcd(left[i],data[i])
    right[n-i-1]=gcd(right[n-i],data[n-i-1])
for j in range(n):
    num=gcd(left[j],right[j+1])
    kotae=max(num,kotae)
print(kotae)
### BUGGY CODE ###

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

targets = []
n_target_h = [0] * H
n_target_w = [0] * W

for i in range(M):
    h, w = map(int, input().split())
    targets.append((h, w))
    n_target_h[h - 1] += 1
    n_target_w[w - 1] += 1

h_max = max(n_target_h)
w_max = max(n_target_w)

bomb_h = [i + 1 for i, h in enumerate(n_target_h) if h == h_max]
bomb_w = [i + 1 for i, w in enumerate(n_target_w) if w == w_max]

ans = h_max + w_max - 1
for h in bomb_h:
    for w in bomb_w:
        if not (h, w) in targets:
            ans = h_max + w_max
            break
    else:
        continue
    break

print(ans)

### FIXED CODE ###

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

targets = []
n_target_h = [0] * H
n_target_w = [0] * W

for i in range(M):
    h, w = map(int, input().split())
    targets.append((h, w))
    n_target_h[h - 1] += 1
    n_target_w[w - 1] += 1

h_max = max(n_target_h)
w_max = max(n_target_w)

bomb_h = [i + 1 for i, h in enumerate(n_target_h) if h == h_max]
bomb_w = [i + 1 for i, w in enumerate(n_target_w) if w == w_max]

count = len(bomb_h) * len(bomb_w)
for target in targets:
    if (n_target_h[target[0] - 1] == h_max) and (n_target_w[target[1] - 1] == w_max):
        count -= 1

if count > 0:
    ans = h_max + w_max
else:
    ans = h_max + w_max - 1

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

n=int(input())
import math
a=[0]*3
sum=0
for i in range(n):
  for j in range(n):
    for k in range(n):
      a[0]=i+1
      a[1]=j+1
      a[2]=k+1
      ans=a[2]
      for l in range(2):
        ans = math.gcd(ans, a[l])
      sum+=ans
print(int(sum))
  

### FIXED CODE ###

n=int(input())
import math
a=[0]*3
sum=0
for i in range(n):
  for j in range(n):
    for k in range(n):
      a[0]=i+1
      a[1]=j+1
      a[2]=k+1
      ans=a[2]
      for l in range(2):
        ans = math.gcd(ans, a[l])
      sum+=ans
print(int(sum))