Harryxun/stf_run huggingface dataset:
def gcd(x, y):
    """
    ユークリッドの互除法を用いて最大公約数を求める
    """
    if not x:
        return y
    return gcd(y % x, x)

def dfs(L, A):
    if not len(L):
        return A
    return gcd(dfs(L[:-1], L[-1]), A)

def get_M_i(A, i):
    """
    i番目のAを取り除いて得られる最大公約数を返す
    """
    L = dfs(A[:i-1], A[i-1]) if i > 0 else 0
    R = dfs(A[i+1:-1], A[-1]) if i < len(A) else 0
    return gcd(L, R)

if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))

    # i番目のMの値はi番目のAを取り除いて得られるN-1個の整数の最大公約数
    M = [0 for _ in range(N)]

    for i in range(N):
        M[i] = get_M_i(A, i)

    print(max(M))

### FIXED CODE ###

from fractions import gcd 

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

# Lを埋める
L = [0 for _ in range(N+1)]
for i in range(1, N+1):
    if not L[i-1]:
        L[i] = A[i-1]
    else: 
        L[i] = gcd(L[i-1], A[i-1])

# Rを埋める
R = [0 for _ in range(N+1)]
for i in range(1, N+1)[::-1]:
    if not R[i]:
        R[i-1] = A[i-1] 
    else:
        R[i-1] = gcd(R[i], A[i-1])

# Mを埋める
M = [0 for _ in range(N)]
for i in range(N):
    if not L[i]:
        M[i] = R[i+1]
    elif not R[i]:
        M[i] = L[i]
    else: 
        M[i] = gcd(L[i], R[i+1])

print(max(M))
n, m = map(int, input().split())

la = [0] * (m+2)
li = [0] + [1]*m + [0]

lall = [la]
for i in range(n):
    lall.append(li)
lall.append(la)

# print(lall)
lcnt = [[0]*(m+2)]
for i in range(n+1):
    lcnt.append([0]*(m+2))
#nprint("lcnt =", lcnt)
 
for i in range(1, n+1):
    for j in range(1, m+1):
#        if lall[i-1][j-1:j+2] == [1,1,1] and lall[i][j-1] == 1 and lall[i][j+1] == 1 and lall[i+1][j-1:j+2] == [1,1,1]:
        for p in range(3):
            for q in range(3):
                lcnt[i-1+p][j-1+q] += 1
#                 print(i-1+p,j-1+q, lcnt[i-1+p][j-1+q], lcnt)

ans = 0
for i in range(1, n+1):
    for j in range(1, m+1):
        if lcnt[i][j] % 2 == 1:
            ans += 1

print(ans)

### FIXED CODE ###

n, m = map(int, input().split())

if min(n, m) == 1:
    if max(n, m) == 1:
        print(1)
    else:
        print(max(n, m)-2)
elif min(n, m) == 2:
    print(0)
else:
    print((n-2)*(m-2))
counter = 0
for i in S:
	if i == 'S':
		counter = 0
	elif i == 'R':
      	counter += 1

return counter


### FIXED CODE ###

S = input()
max_count = 0
counter = 0
for i in S:
  if i == 'S':
    if max_count < counter:
      max_count = counter
      counter = 0
  elif i == 'R':
    counter += 1

if max_count < counter:
  max_count = counter

print(max_count)
import sys

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

if k == 0:
    print(max(a))
    sys.exit()

def check(t):
    ans = 0
    for ai in a:
        if ai > t:
            ans += ai // t
    return ans <= k

l = 0
r = 10 ** 9 + 1

while r - l > 1:
    mid = (r + l) // 2
    if check(mid):
        r = mid
    else:
        l = mid

if check(l):
    print(l)
else:
    print(r)



### FIXED CODE ###

import sys

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

if k == 0:
    print(max(a))
    sys.exit()

def check(t):
    if t == 0:
        return False
    ans = 0
    for ai in a:
        if ai > t:
            ans += ai // t
    return ans <= k

l = 0
r = 10 ** 9 + 1

while r - l > 1:
    mid = (r + l) // 2
    if check(mid):
        r = mid
    else:
        l = mid

if check(l):
    print(l)
else:
    print(r)
# -*- coding: utf-8 -*-

s = list(input())

l = len(s)

goodFlag = False
for i in range(l-1):
    if s[i] == s[i+1]:
        ggoodFlag = True

if goodFlag == True:
    print ("Good")
else:
    print ("Bad")

### FIXED CODE ###

# -*- coding: utf-8 -*-

s = list(raw_input())

l = len(s)

badFlag = False
for i in range(l-1):
    if s[i] == s[i+1]:
        badFlag = True

if badFlag == True:
    print ("Bad")
else:
    print ("Good")
N,K=map(int,input().split())
A=list(map(int,input().split()))
As=list(set(A))
sa=max(0,len(As)-K)
if sa==0:
    print(0)
    break
else:
    count=[]
    for i in As:
        count.append(A.count(i))
    num=sorted(count)
    ans=0
    for i in range(sa):
        ans+=num[i]
    print(ans)

### FIXED CODE ###

N,K=map(int,input().split())
A=list(map(int,input().split()))
sa=len(set(A))-K
if sa>0:
    As={}
    for i in range(N):
        if A[i] in As:
            As[A[i]]+=1
        else:
            As[A[i]]=1
    Ass=sorted(As.values())
    print(sum(Ass[:sa]))
else:
    print(0)
a,b,c = input().split()
a = int(a)
b= int(b)
c=int(c)
for x in range(a,b)




### FIXED CODE ###

a,b,c = input().split()
a = int(a)
b= int(b)
c=int(c)
aaa = 0
for x in range(a,b+1):
    if c%x == 0:
        aaa+=1
print(aaa)
nums = list(map(int, input.split(" ")))
if len(set(nums)) == 2:
    print("Yes")
else:
    print("No")


### FIXED CODE ###

nums = list(map(int, input().split(" ")))
if len(set(nums)) == 2:
    print("Yes")
else:
    print("No")
N = int(input())
A = list(map(int, input()))

rev = []
for a in A:
    rev.append(1/float(a))

print(1/float(sum(rev)))

### FIXED CODE ###

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

rev = []
for a in A:
  rev.append(1.0/float(a))
  
print(1.0/float(sum(rev)))
N = int(input())
T = list(map(int,input().split()))
M = int(input())
P = []
X = []
for _ in range(M):
  p,x = map(int,input().split())
  P.append(p)
  X.append(x)

sumT = sum(T)

for i,p,x in enumerate(zip(P,X)):
  print(sumT - (T[p]-x))

### FIXED CODE ###

N = int(input())
T = list(map(int,input().split()))
M = int(input())
P = []
X = []
for _ in range(M):
  p,x = map(int,input().split())
  P.append(p)
  X.append(x)

sumT = sum(T)

for p,x in zip(P,X):
  print(sumT - (T[p-1]-x))
import math

a, b, c, d = map(int, input().split())

a -= 1

lcm = (c * d) // math.gcd(c, d)

b_sum = b - (b // c) - (b // d) + (b // lcm)
a_sum = a - (a // c) - (a // d) + (a // lcm)

print(b_sum - a_sum)

### FIXED CODE ###

import fractions

a, b, c, d = map(int, input().split())

a -= 1

lcm = c * d // fractions.gcd(c, d)

b_sum = b - (b // c) - (b // d) + (b // lcm)
a_sum = a - (a // c) - (a // d) + (a // lcm)

print(b_sum - a_sum)
S = input()

ans = 0
if len(S) % 2 == 0:
    ans = len(S)//2
    c = ans
    t = S[ans]
    for i in range(len(S)//2-1,-1,-1):
        if S[i] == S[c] and S[i] == t:
            ans += 1
            c += 1
        else:
            break
else:
    ans = len(S)//2
    c = ans+1
    t = S[ans+1]
    for i in range(len(S)//2-1,-1,-1):
        if S[i] == S[c] and S[i] == t:
            ans += 1
            c += 1
        else:
            break
print(ans)


### FIXED CODE ###

S = input()

ans = 0
if len(S) % 2 == 0:
    ans = len(S)//2
    c = ans
    t = S[ans]
    for i in range(len(S)//2-1,-1,-1):
        if S[i] == S[c] and S[i] == t:
            ans += 1
            c += 1
        else:
            break
else:
    ans = len(S)//2+1
    c = ans
    t = S[ans-1]
    for i in range(len(S)//2-1,-1,-1):
        if S[i] == S[c] and S[i] == t:
            ans += 1
            c += 1
        else:
            break

    ans = max(len(S)//2,ans)

print(ans)
(W, H, x, y, r) = [int)(i) for i in input().split()]

nums = input().split()
W = int(nums[0])
H = int(nums[1])
x = int(nums[2])
y = int(nums[3])
r = int(nums[4])

### FIXED CODE ###

x = list(map(lambda k : int(k),input().split(" ")))
if x[4] <= x[2] <= x[0]-x[4] and x[4] <= x[3] <= x[1] - x[4]:
    print("Yes")
else:
    print("No")
if 1 <= N <= 100 and 0 <= R <= 4111:
    if N > 10:
        print(R)
    else:
        K = 100 * (10 - N)
        M = R + K
        print(M)
else:
    False

### FIXED CODE ###

N,R=input().split()
n,r=int(N),int(R)

if n>=10:
    print(r)
else:
    print(r+100*(10-n))
N = int(input())
print("YES" if N[0]==N[-1] else "NO")

### FIXED CODE ###

N = input()
print("Yes" if N[0]==N[-1] else "No")
a, b = list(map(int, input().split()))
print(int((a+b)/2 + 1)

### FIXED CODE ###

import math

a, b = list(map(int, input().split()))
ans = math.ceil((a+b)/2)
print(ans)
# -*- coding: utf-8 -*-
a = int(input())
judge = True
for i in range(a):
  b = int(input())
  if (b % 2 == 0) & ((b % 3 == 0) or (b % 5 == 0)):
    judge = False
# 出力
if judge:
  print("APPROVED")
else:
  print("DENIED")

### FIXED CODE ###

# -*- coding: utf-8 -*-
a = int(input())
lis = list(map(int, input().split()))
for i in range(a):
  judge = True
  if (lis[i] % 2 == 0):
    if (lis[i] % 3 != 0) and (lis[i] % 5 != 0):
      judge = False
      break
# 出力
if judge:
  print("APPROVED")
else:
  print("DENIED")
n = int(input())

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

su = 0

co = 0

for i in range(max(a)):
    for j in range(n):
        if a[j] > 0 and co == 0:
            co += 1
            su += 1
        if co  >=  1:
            if a[j] == 0:
                co = 0
            else:
                a[j] -= 1
    co = 0

print(su)



### FIXED CODE ###

d = input()
a = int(input())
p = []
k = len(d)
for i in range(k):
  for j in range(min({6,k-i+1})):
    p.append(d[i:i+j])
    
x = list(set(p))
x.sort()
del x[0]
 
print(x[a-1])
x, n = map(int, input().split())
if n <= 0:
    print(x)
else:
    tbl = [0 for i in range(101)]
    data_in = input().split()
    for num in data_in:
        tbl[int(num)] = 1
    for i in range(1, 101, 1):
        if (x-i >= 0) and (tbl[x-i] == 0):
            print(x-i)
            break
        if (x+i <= 101) and (tbl[x+i] == 0):
            print(x+i)
            break

### FIXED CODE ###

x, n = map(int, input().split())
p = list(map(int, input().split()))
for base in range(x+1):
    if p.count(x+base*-1) == 0:
        print(x+base*-1)
        break
    if p.count(x+base) == 0:
        print(x+base)
        break
def main():
    S = input()
    k = int(input())

    array = []
    for i in range(len(S)):
        for j in range(i+1,len(S)+1):
            if j-i < k:
                array.append(S[i:j])
    array = list(set(array))
    array.sort()
    print(array[k-1])


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    S = input()
    k = int(input())

    array = []
    for i in range(len(S)):
        for j in range(i+1,len(S)+1):
            if j-i <= k:
                array.append(S[i:j])
    array = list(set(array))
    array.sort()
    print(array[k-1])


if __name__ == '__main__':
    main()
n = int(input())
t = [[0, 0, 0]]
for i in range(n):
    t.append(list(map(int, input().split())))
for i in range(0, n+1):
    time = t[i+1][0] - t[i][0]
    move = t[i+1][1] + t[i+1][2] - (t[i][1] + t[i][2])
    if(move > time or move%2 != time%2):
        print("No")
        exit()
print("Yes")

### FIXED CODE ###

n = int(input())
t = [[0, 0, 0]]
for i in range(n):
    t.append(list(map(int, input().split())))
for i in range(0, n):
    time = t[i+1][0] - t[i][0]
    move = t[i+1][1] + t[i+1][2] - (t[i][1] + t[i][2])
    if(move > time or move%2 != time%2):
        print("No")
        exit()
print("Yes")
#!/usr/bin/env python3
import sys

inf = float('inf')

def solve(H: int, W: int, A: "List[str]"):
    dist = [[inf] * W for h in range(H)]
    for h in range(1, H):
        for w in range(1, W):
            if A[h][w] == '#':
                dist[h][w] = 0
            else:
                dist[h][w] = min(dist[h-1][w], dist[h][w-1]) + 1
    
    dmax = 0
    for h in range(H-1, -1, -1):
        for w in range(W-1, -1, -1):
            if A[h][w] == '#':
                dist[h][w] = 0
            elif h+1 <= H-1 and w+1 <= W-1:
                dist[h][w] = min(dist[h][w], min(dist[h+1][w], dist[h][w+1]) + 1)
            elif w+1 == W and h+1 <= H-1:
                dist[h][w] = min(dist[h][w], dist[h+1][w] + 1)
            elif h+1 == H and w+1 <= W-1:
                dist[h][w] = min(dist[h][w], dist[h][w+1] + 1)
            else:
                dist[h][w] = dist[h][w]
            dmax = max(dist[h][w], dmax)
    print(dmax) 
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    A = [ next(tokens) for _ in range(W) ]  # type: "List[str]"
    solve(H, W, A)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys

inf = float('inf')

def solve(H: int, W: int, A: "List[str]"):
    dist = [[inf] * W for h in range(H)]
    for h in range(1, H):
        for w in range(1, W):
            if A[h][w] == '#':
                dist[h][w] = 0
            else:
                dist[h][w] = min(dist[h-1][w], dist[h][w-1]) + 1
    
    dmax = 0
    for h in range(H-1, -1, -1):
        for w in range(W-1, -1, -1):
            if A[h][w] == '#':
                dist[h][w] = 0
            elif h+1 <= H-1 and w+1 <= W-1:
                dist[h][w] = min(dist[h][w], min(dist[h+1][w], dist[h][w+1]) + 1)
            elif w+1 == W and h+1 <= H-1:
                dist[h][w] = min(dist[h][w], dist[h+1][w] + 1)
            elif h+1 == H and w+1 <= W-1:
                dist[h][w] = min(dist[h][w], dist[h][w+1] + 1)
            dmax = max(dist[h][w], dmax)
    print(dmax) 
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    A = [ next(tokens) for _ in range(H) ]  # type: "List[str]"
    solve(H, W, A)

if __name__ == '__main__':
    main()
n = 10
i = 1
while n != 0:
 n = raw_input()
 i = i + 1
 print "Case " + str(i) + ": " +str(n)

### FIXED CODE ###

n = 10
i = 1
while n != 0:
 n = input()
 if n == 0:
     break
 print "Case " + str(i) + ": " +str(n)
 i = i + 1
#coding:utf-8
import bisect,math
import multiprocessing
A,B,Q=map(int,raw_input().split())
s=[]
t=[]
for a in range(A):
    s.append(input())
for a in range(B):
    t.append(input())
buf=[]    
def f(x):
    sl=bisect.bisect_left(s,x)-1
    sr=bisect.bisect_left(s,x)
    tl=bisect.bisect_left(t,x)-1
    tr=bisect.bisect_left(t,x)
    ans=float("inf")
    if sl!=-1 and tl!=-1:
        A=max(s[sl],t[tl])
        B=min(s[sl],t[tl])
        L=abs(x-A)+abs(A-B)
        ans=min(ans,L)
    if sl!=-1 and tr!=len(t):
        L=abs(x-s[sl])*2 + abs(t[tr]-x)        
        ans=min(ans,L)
        ans=min(ans,abs(x-s[sl])+abs(t[tr]-x)*2)
    if tl!=-1 and sr!=len(s):
        ans=min(ans,abs(x-t[tl])*2+abs(s[sr]-x))
        ans=min(ans,abs(x-t[tl])+abs(s[sr]-x)*2)
    if tr!=len(t) and sr!=len(s):
        A=min(s[sr],t[tr])
        B=max(s[sr],t[tr])
        L=abs(A-x)+abs(B-A)
        ans=min(ans,L)
    return str(ans)

p=multiprocessing.Pool(8)
I=[]
for _ in xrange(Q):
    I.append(input())
r=p.map(f,I)
print("\n".join(r))
    
    




### FIXED CODE ###

#coding:utf-8
import bisect,sys
A,B,Q=map(int,raw_input().split())
s=[0]*A
t=[0]*B
for i in range(A):    
    s[i]=int(sys.stdin.readline())
for i in range(B):
    t[i]=int(sys.stdin.readline())
buf=[]
def f(x):
    sl=bisect.bisect_left(s,x)-1
    sr=sl+1
    tl=bisect.bisect_left(t,x)-1
    tr=tl+1
    ans=float("inf")
    if sl!=-1 and tl!=-1:
        A=max(s[sl],t[tl])
        B=min(s[sl],t[tl])
        L=abs(x-A)+abs(A-B)
        ans=min(ans,L)
    if sl!=-1 and tr!=len(t):
        L=abs(x-s[sl])*2 + abs(t[tr]-x)        
        ans=min(ans,L)
        ans=min(ans,abs(x-s[sl])+abs(t[tr]-x)*2)
    if tl!=-1 and sr!=len(s):
        ans=min(ans,abs(x-t[tl])*2+abs(s[sr]-x))
        ans=min(ans,abs(x-t[tl])+abs(s[sr]-x)*2)
    if tr!=len(t) and sr!=len(s):
        A=min(s[sr],t[tr])
        B=max(s[sr],t[tr])
        L=abs(A-x)+abs(B-A)
        ans=min(ans,L)
    return str(ans)

I=[0]*Q
for i in xrange(Q):
    I[i]=int(sys.stdin.readline())
r=map(f,I)
print("\n".join(r))
import math
import sys
n, m = map(int, input().split())

def combinations_count(n, r):
    C = math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
    return C

if n <= 1 and m >= 2:
    print(combinations_count(m, 2))
    sys.exit()
elif n >= 2 and m <= 1@:
    print(combinations_count(n, 2))
    sys.exit()
elif n == m == 1:
    print(1)
    sys.exit()
elif n == m == 0:
    print(0)
    sys.exit()
else:
    print(combinations_count(n, 2) + combinations_count(m, 2))

### FIXED CODE ###

import math
import sys
n, m = map(int, input().split())

def combinations_count(n, r):
    C = math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
    return C

if n <= 1 and m >= 2:
    print(combinations_count(m, 2))
    sys.exit()
elif n >= 2 and m <= 1:
    print(combinations_count(n, 2))
    sys.exit()
elif n == m == 1:
    print(0)
    sys.exit()
elif n == m == 0:
    print(0)
    sys.exit()
else:
    print(combinations_count(n, 2) + combinations_count(m, 2))
n = int(input())
l0 = [int(i) for i in input().split()]
l = sorted(l0, reverse = True)
ans = 0

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


print(ans)

### FIXED CODE ###

a,b = (int(i) for i in input().split())
s = a-2*b
if s<0:
    s = 0
print(s)
L,A,B,M=map(int,input().split())
mod=M
C=A+B*(L-1)
ans=0
def S(x,l,r,mod):
    if l==r:
        return pow(x,l,mod)
    rev=pow(x-1,mod-2,mod)
    return (pow(x,r+1,mod)-pow(x,l,mod))*rev%mod
def SS(x,l,r,mod):
    if l==r:
        return l*pow(x,l,mod)%mod
    rev=pow(x-1,mod-2,mod)
    return rev*(r*pow(x,r+1,mod)-l*pow(x,l,mod)-S(x,l+1,r,mod))%mod
now=0
Sx=1
times=len(str(C))
for dL in range(times,0,-1):
    if len(str(C))==1:
        r=C//B
    else:
        r=(C%pow(10,len(str(C))-1))//B
    if r==0:
        ans=(ans+C)%mod
    else:
        if now+r>=L:
            r=L-now-1
        x=pow(10,len(str(C)),mod)
        y=Sx*(C*(S(x,1,r,mod)+1)-B*SS(x,1,r,mod))%mod
        ans=(ans+y)%mod
    Sx=Sx*pow(10,(r+1)*len(str(C)),mod)%mod
    C-=(r+1)*B
    now+=r+1
print(ans)

### FIXED CODE ###

L,A,B,M=map(int,input().split())
C=(L-1)*B+A
mod=M
X,s=0,A
now=A
data=[0]*19
ruiseki=[0]*19
Ami=(A-1)//B
Cmi=C//B
for i in range(19):
    now=10**i-1
    if now<A:
        ruiseki[i]=0
    elif now>=C:
        ruiseki[i]=L
    else:
        ruiseki[i]=(now-A)//B+1
def mul33(A,B):
    global mod
    res=[[0]*3 for i in range(3)]
    for i in range(3):
        for j in range(3):
            res[i][j]=sum([A[i][k]*B[k][j]%mod for k in range(3)])
    return res
def ruijou(vec,Cd):
    rui=dict()
    if Cd==0:
        return [[1,0,0],[0,1,0],[0,0,1]]
    now=vec
    ans=[[1,0,0],[0,1,0],[0,0,1]]
    Cds=bin(Cd)[2:][::-1]
    for i in range(len(Cds)):
        if Cds[i]=="1":
            ans=mul33(ans,now)
        now=mul33(now,now)
    return ans
def mul(X,s,Cd,d):
    global mod
    global B
    vec=[[pow(10,d,mod),0,0],[1,1,0],[0,B,1]]
    vec=ruijou(vec,Cd)
    Xc=X
    sc=s
    X=(Xc*vec[0][0]+sc*vec[1][0]+vec[2][0])%mod
    s=(Xc*vec[0][1]+sc*vec[1][1]+vec[2][1])%mod
    return X,s
for d in range(1,19):
    Cd=ruiseki[d]-ruiseki[d-1]
    X,s=mul(X,s,Cd,d)
print(X)
# -*- coding: utf-8 -*-
import sys
from collections import defaultdict, deque

H,W=map(int, sys.stdin.readline().split())
CH,CW=map(int, sys.stdin.readline().split())
CH-=1
CW-=1
DH,DW=map(int, sys.stdin.readline().split())
DH-=1
DW-=1
S=[ sys.stdin.readline().strip() for _ in range(W) ]

D=[(0,1),(0,-1),(1,0),(-1,0)]
WARP=[]
for dh in range(-2,3):
    for dw in range(-2,3):
        if abs(dh)+abs(dw)<=1: continue
        WARP.append((dh,dw))

d=defaultdict(lambda: float("inf")) #スタート地点から各マスまでの距離

q=deque()
q.append((0,CH,CW))
d[(CH,CW)]=0

while q:
    kyori, fro_h, fro_w=q.popleft()
    if d[(fro_h, fro_w)]<kyori: continue
    #歩いて移動
    for dh,dw in D:
        to_h, to_w=fro_h+dh, fro_w+dw
        if 0<=to_h<H and 0<=to_w<W and S[to_h][to_w]==".":
            if kyori < d[(to_h, to_w)]:
                d[(to_h, to_w)]=kyori
                q.appendleft((kyori, to_h, to_w))

    try:
        #ワープ
        for dh,dw in WARP:
            to_h, to_w=fro_h+dh, fro_w+dw
            if 0<=to_h<H and 0<=to_w<W and S[to_h][to_w]==".":
                if kyori+1 < d[(to_h, to_w)]:
                    d[(to_h, to_w)]=kyori+1
                    q.append((kyori+1, to_h, to_w))
    except:
        pass

if d[(DH,DW)]==float("inf"):
    print -1
else:
    print d[(DH,DW)]


### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys
from collections import defaultdict, deque

H,W=map(int, sys.stdin.readline().split())
CH,CW=map(int, sys.stdin.readline().split())
CH-=1
CW-=1
DH,DW=map(int, sys.stdin.readline().split())
DH-=1
DW-=1
S=[ sys.stdin.readline().strip() for _ in range(H) ]

D=[(0,1),(0,-1),(1,0),(-1,0)]
WARP=[]
for dh in range(-2,3):
    for dw in range(-2,3):
        if abs(dh)+abs(dw)<=1: continue
        WARP.append((dh,dw))

d=defaultdict(lambda: float("inf")) #スタート地点から各マスまでの距離

q=deque()
q.append((0,CH,CW))
d[(CH,CW)]=0

while q:
    kyori, fro_h, fro_w=q.popleft()
    if d[(fro_h, fro_w)]<kyori: continue
    #歩いて移動
    for dh,dw in D:
        to_h, to_w=fro_h+dh, fro_w+dw
        if 0<=to_h<H and 0<=to_w<W and S[to_h][to_w]==".":
            if kyori < d[(to_h, to_w)]:
                d[(to_h, to_w)]=kyori
                q.appendleft((kyori, to_h, to_w))
    #ワープ
    for dh,dw in WARP:
        to_h, to_w=fro_h+dh, fro_w+dw
        if 0<=to_h<H and 0<=to_w<W and S[to_h][to_w]==".":
            if kyori+1 < d[(to_h, to_w)]:
                d[(to_h, to_w)]=kyori+1
                q.append((kyori+1, to_h, to_w))

if d[(DH,DW)]==float("inf"):
    print -1
else:
    print d[(DH,DW)]
m=int(input("縦の長さ:"))
n=int(input("横の長さ:"))
multi=(m-1)*(n-1)
print(multi)


### FIXED CODE ###

n,m=input().split(" ")
m=int(m)
n=int(n)
multi=(m*n)-(m+n)+1
print(multi)
print()
# coding: utf-8


def solve(*args: str) -> str:
    n, m, k = map(int, args[0].split())
    mod = 998244353

    P = [1]*(k+1)
    p = pow(m-1, n-2-k, mod)
    for i in range(k+1):
        p = p*(m-1) % mod
        P[-1-i] = p

    ret = m*P[0] % mod
    ncr = 1
    for i in range(1, k+1):
        ncr = ncr*(n-i)//i
        ret += m*P[i]*ncr % mod

    return str(ret % mod)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


### FIXED CODE ###

# coding: utf-8


def bpow(x, y, z):
    a = 1
    for b in format(y, 'b'):
        a = (a*a) % z
        if b == '1':
            a = (a*x) % z
    return a


def solve(*args: str) -> str:
    n, m, k = map(int, args[0].split())
    mod = 998244353

    if m == 1 and n-1 == k:
        return str(1)

    ncr = 1
    p = m*bpow(m-1, n-1, mod) % mod
    ret = p
    inv = bpow(m-1, mod-2, mod)
    for i in range(1, k+1):
        ncr = (ncr * (n-i)*bpow(i, mod-2, mod)) % mod
        p = (p*inv) % mod
        ret += p*ncr % mod

    return str(ret % mod)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))
N,M = map(int,input().split())
f = []
for i in range(M):
    A,B = map(int,input().split())
    a = {A,B}
    for j in range(len(f)):
        if f[j] & a != set():
            f[j] = f[j] | a
            a = set()
    if a != set():
        f.append(a)
count = 1
while count > 0:
    count = 0
    for i in range(len(f)-1):
        for j in range(i+1,len(f)):
            if f[i] & f[j] != set():
                count += 1
                f[i] = f[i] | f[j]
                f.remove(f[j])
for i in range(len(f)):
    f[i] = len(f[i])
print(max(f))

### FIXED CODE ###

N,M = map(int,input().split())
f = [[] for i in range(N)]
for i in range(M):
    A,B = map(int,input().split())
    f[A-1].append(B-1)
    f[B-1].append(A-1)
from collections import deque
d = deque()
x = [-1]*N
for i in range(N):
    if x[i] == -1:
        x[i] = i
        d.append(f[i])
    while len(d) > 0:
        z = d.popleft()
        for j in z:
            if x[j] == -1:
                x[j] = i
                d.append(f[j])
import collections
ans = collections.Counter(x)
print(ans.most_common()[0][1])