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

class Node:
	elm = None
	next = None
	prev = None

class MyList:
	head = tail = None

	def insert(self, x):
		n = Node()
		n.elm = x
		if self.head == None:
			self.head = self.tail = n
		else:
			n.next = self.head
			self.head.prev = n
			self.head = n

	def delete(self, x):
		n = self.head
		while n and n.elm != x:
			n = n.next
		if n: 
			self.__delete_node(n)

	def deleteFirst(self):
		self.__delete_node(self.head)

	def deleteLast(self):
		self.__delete_node(self.tail)

	def __delete_node(self, n):
		if n == self.head:
			self.head = n.next
		if n == self.tail:
			self.tail = n.prev
		if n.prev:
			n.prev.next = n.next
		if n.next:
			n.next.prev = n.prev

	def __traverse(self):
		n = self.head
		while n:
			yield n.elm
			n = n.next

	def print_all(self):
		n = self.head
		while n:
			print n.elm,
			n = n.next

	def __str__(self):
		return " ".join([s for s in self.__traverse()])

myList = MyList()
n = int(raw_input())
for _ in xrange(n):
	line = raw_input()
	if line[0]=='i':
		myList.insert(line[7:])
	elif line[6]=='F':
		myList.deleteFirst()
	elif line[6]=='L':
		myList.deleteLast()
	else:
		myList.delete(line[7:])
#print myList
myList.print_all()

### FIXED CODE ###

class MyList:
	head = tail = None

	def insert(self, x):
		n = [x, None, None]
		if self.head == None:
			self.head = self.tail = n
		else:
			n[2] = self.head
			self.head[1] = n
			self.head = n

	def delete(self, x):
		n = self.head
		while n and n[0] != x:
			n = n[2]
		if n: 
			self.__delete_node(n)

	def deleteFirst(self):
		self.__delete_node(self.head)

	def deleteLast(self):
		self.__delete_node(self.tail)

	def __delete_node(self, n):
		if n == self.head:
			self.head = n[2]
		if n == self.tail:
			self.tail = n[1]
		if n[1]:
			n[1][2] = n[2]
		if n[2]:
			n[2][1] = n[1]

	def print_all(self):
		n = self.head
		while n:
			print n[0],
			n = n[2]

myList = MyList()
n = int(raw_input())
for _ in xrange(n):
	line = raw_input()
	if line[0]=='i':
		myList.insert(line[7:])
	elif line[6]=='F':
		myList.deleteFirst()
	elif line[6]=='L':
		myList.deleteLast()
	else:
		myList.delete(line[7:])
myList.print_all()
### BUGGY CODE ###

n= int(input())
ninesix = [9**i for i in range(1,6) if 9**i <= n]+[6**i for i in range(1,7) if 6**i <= n]
ninesix.sort(reverse=True)

def coin(ns,max_res):
  if not ns:
    return max_res
  remainder = max_res//ns[0]
  if remainder > 0:
    count = 0
    c = 10000
    for i in range(1,remainder+1):
      nnss = ns[1:]
      c = min(coin(nnss,max_res-ns[0]*i)+i,c)
    count += c
    return count
  else:
    nnss = ns[1:]
    return coin(nnss,max_res)
  return count
   
print(coin(ninesix,n))
  

### FIXED CODE ###

N=int(input())
ans=N
for i in range(N+1): 
    cnt=0
    t=i
    while t>0:
        cnt+=t%6
        t//=6
    s=N-i
    while s>0:
        cnt+=s%9
        s//=9
    ans=min(ans,cnt)
print(ans)
### BUGGY CODE ###

from collections import Counter

while True:
    N, M = map(int, input().split())
    if N == 0 and M == 0:
        break
    H = [int(input()) for _ in range(N)]
    W = [int(input()) for _ in range(M)]
    all_H = Counter(
        sorted([sum(H[i:j]) for i in range(N) for j in range(i + 1, N + 1)])
    )
    all_W = Counter(
        sorted([sum(W[i:j]) for i in range(M) for j in range(i + 1, M + 1)])
    )
    ans = 0
    for k, v in all_H.items():
        if k in all_H:
            ans += v * all_W[k]
    print(ans)


### FIXED CODE ###

from collections import Counter

while True:
    N, M = map(int, input().split())
    if N == 0 and M == 0:
        break
    H = [int(input()) for _ in range(N)]
    W = [int(input()) for _ in range(M)]

    all_H = []
    for i in range(N):
        s = 0
        for j in range(i, N):
            s += H[j]
            all_H.append(s)

    all_W = []
    for i in range(M):
        s = 0
        for j in range(i, M):
            s += W[j]
            all_W.append(s)

    all_H = Counter(all_H)
    all_W = Counter(all_W)
    ans = 0
    for k, v in all_H.items():
        if k in all_H:
            ans += v * all_W[k]
    print(ans)
### BUGGY CODE ###

H, W, K = map(int, input().split())
s = []
for _ in range(H):
    *row, = map(int, input())
    s.append(row)

ret = H * W
for bits in range(1 << (H - 1)):
    # 水平カットで生成される2枚目以降の開始行
    # 0行目は確定で, 残りのカットを調べる
    # 次の変換が必要
    # [0,H) -> [1,H]

    group = [0] * H
    for j in range(H - 1):
        group[j + 1] = group[j] + (1 if (bits >> j) & 1 else 0)
    # group = [0,0,1,1,1,2,...]

    ctr = [0] * H
    add_v = [0] * H
    c = 0
    cut = bin(bits).count('1')
    while c < W:
        need_cut = False
        for r in range(H):
            g = group[r]
            add_v[g] += s[r][c]
            if ctr[g] + add_v[g] > K:
                need_cut = True
                break

        if need_cut:
            ctr = [0] * H
            add_v = [0] * H
            cut += 1
            if cut >= ret:
                break
            continue

        for g, _add_v in enumerate(add_v):
            ctr[g] += _add_v
        add_v = [0] * H
        c += 1

    ret = min(ret, cut)

print(ret)


### FIXED CODE ###

H, W, K = map(int, input().split())
s = []
for _ in range(H):
    *row, = map(int, input())
    s.append(row)

ret = H * W
for bits in range(1 << (H - 1)):
    # 水平カットで生成される2枚目以降の開始行
    # 0行目は確定で, 残りのカットを調べる
    # 次の変換が必要
    # [0,H) -> [1,H]

    group = [0] * H
    for j in range(H - 1):
        group[j + 1] = group[j] + (1 if (bits >> j) & 1 else 0)
    # group = [0,0,1,1,1,2,...]

    ctr = [0] * H
    add_v = [0] * H
    c, pc = 0, -1
    cut = bin(bits).count('1')
    while c < W:
        need_cut = False
        for r in range(H):
            g = group[r]
            add_v[g] += s[r][c]
            if ctr[g] + add_v[g] > K:
                need_cut = True
                break

        if need_cut:
            if pc == c:
                cut = H * W
                break
            ctr = [0] * H
            add_v = [0] * H
            cut += 1
            pc = c
            if cut >= ret:
                break
            continue

        for g, _add_v in enumerate(add_v):
            ctr[g] += _add_v
        add_v = [0] * H
        pc = c
        c += 1

    ret = min(ret, cut)

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

H, W = list(map(int, input().split(' ')))
xs = []
for i in range(H):
    xs.append(list(map(int, input().split(' '))))
# best でなくても良い？
ans = []  # x,y -> p, q
seeds = []
for i in range(H):  # 500
    for j in range(W):  # 500
        if xs[i][j] % 2 != 0:
            seeds.append((i, j))
used = {}
def f(st, ed):
    res = []
    while(st != ed):
        while(st[0] > ed[0]):
            if (st[0]-1, st[1]) in used:
                break
            res.append('%d %d %d %d' % (st[0]+1, st[1]+1, st[0]+1-1, st[1]+1))
            st = (st[0]-1, st[1])
            used[st] = True
        while(st[0] < ed[0]):
            if (st[0]+1, st[1]) in used:
                break
            res.append('%d %d %d %d' % (st[0]+1, st[1]+1, st[0]+1+1, st[1]+1))
            st = (st[0]+1, st[1])
            used[st] = True
        while(st[1] > ed[1]):
            if (st[0], st[1]-1) in used:
                break
            res.append('%d %d %d %d' % (st[0]+1, st[1]+1, st[0]+1, st[1]+1-1))
            st = (st[0], st[1]-1)
            used[st] = True
        while(st[1] < ed[1]):
            if (st[0], st[1]-1) in used:
                break
            res.append('%d %d %d %d' % (st[0]+1, st[1]+1, st[0]+1, st[1]+1+1))
            st = (st[0], st[1]+1)
            used[st] = True
    return res

ans = []
for i in range(0, len(seeds)-1, 2):
    st = seeds[i]
    ed = seeds[i+1]
    ans += f(st, ed)
print(len(ans))
print('\n'.join(ans))


### FIXED CODE ###

H, W = list(map(int, input().split(' ')))
xs = []
for i in range(H):
    xs.append(list(map(int, input().split(' '))))
# best でなくても良い？
ans = []  # x,y -> p, q
seeds = []
for i in range(H):  # 500
    for j in range(W):  # 500
        if xs[i][j] % 2 != 0:
            seeds.append((i, j))
used = {}
def f(st, ed):
    res = []
    while(st != ed):
        old = st
        if (st[0] % 2 == 0):
            if st[1] < W - 1:
                st = (st[0], st[1] + 1)
            else:
                st = (st[0]+1, st[1])
        else:
            if st[1] > 0:
                st = (st[0], st[1] - 1)
            else:
                st = (st[0]+1, st[1])
        res.append('%d %d %d %d' % (old[0]+1, old[1]+1, st[0]+1, st[1]+1))
    return res

ans = []
# print (seeds)
seeds = sorted(seeds, key=lambda x:(x[0] * 9999999 + x[1] * (-1 if x[0]%2 == 1 else 1)))
# print (seeds)
for i in range(0, len(seeds)-1, 2):
    st = seeds[i]
    ed = seeds[i+1]
    ans += f(st, ed)
print(len(ans))
print('\n'.join(ans))
### BUGGY CODE ###

N, A, B = map(int, input().split())
result = 0
current = "b"

while(N > 0):
  if current == "b":
    if N - A > 0:
      result += A
      N = N - A
    else:
      result += N
      N = 0
    current = "r"
  else:
    if N - B > 0:
      N = N - B
    else:
      N = 0
    current = "b"
print(result)

### FIXED CODE ###

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

x = N // (A+B) 
result = A * x

N = N - ((A + B) * x)
if N < A:
  result += N
else:
  result += A
print(result)
### BUGGY CODE ###

# coding: utf-8

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

def f2(n):
    dp = [[0] * n for _ in range(n)]

    def dfs(i, j):  # from i to j
        if dp[i][j]:
            return(dp[i][j])
        dpij = 1
        for u in U[i]:
            if u != j:
                dpij = dpij * (dfs(u, i) + 1) % M
        dp[i][j] = dpij
        return(dpij)

    for i in range(n):
        ans = 1
        for u in U[i]:
            ans = ans * (dfs(u, i) + 1) % M
            if not ans:
              break
        print(ans)

N, M = map(int, input().split()) # 1 <= N <= 10^5, 2 <= M <= 10^9
U = [set() for _ in range(N)]
for x, y in [map(int, input().split()) for _ in range(N - 1)]:
    U[x - 1].add(y - 1)
    U[y - 1].add(x - 1)
f2(N)


### FIXED CODE ###

# coding: utf-8

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

def dfs(v, p = -1):
    deg[v] = len(U[v])
    dp[v] = [0] * deg[v]
    ans = 1
    for i in range(deg[v]):
        u = U[v][i]
        if u == p:
            par[v] = i
            continue
        dp[v][i] = dfs(u, v)
        ans *= dp[v][i] + 1
        ans %= M
    return(ans)

def bfs(v, ans_p = 0, p = -1):
    if p != -1:
        dp[v][par[v]] = ans_p
    lmul = [1] * (deg[v] + 1)
    rmul = [1] * (deg[v] + 1)
    for i in range(1, deg[v] + 1):
        lmul[i] = lmul[i - 1] * (dp[v][i - 1] + 1) % M
        rmul[-i - 1] = rmul[-i] * (dp[v][-i] + 1) % M
    ans[v] = rmul[0]
    for i in range(deg[v]):
        u = U[v][i]
        if u == p:
            continue
        bfs(u, lmul[i] * rmul[i + 1] % M, v)

N, M = map(int, input().split()) # 1 <= N <= 10^5, 2 <= M <= 10^9
U = [list() for _ in range(N)]
for x, y in [map(int, input().split()) for _ in range(N - 1)]:
    U[x - 1].append(y - 1)
    U[y - 1].append(x - 1)
deg = [0] * N
par = [0] * N
dp = [None] * N
ans = [0] * N
dfs(0)
bfs(0)
print("\n".join([str(x) for x in ans]))
### BUGGY CODE ###

#!/usr/bin/env python3

s = input()
N = int(s.split()[0])
A = int(s.split()[1])
B = int(s.split()[2])

h = []
for i in range(N):
    h.append(int(input()))

i = 0
while True:
    h.sort()
    if h[-1] <= 0:
        print(i)
        break
    else:
        i += 1
        h[-1] -= (A-B)
        for j in range(len(h)):
            h[j] -= B

### FIXED CODE ###

import math
 
def check(x):
    k = 0
    global h, a, b
    for i in h:
        if x * b < i:
            k += math.ceil((i - x * b) / (a - b))
    return k <= x
 
 
n, a, b = map(int, input().split())
h = []
for i in range(n):
    h.append(int(input()))
l = -1
r = max(h) // b + 1
while r - l > 1:
    m = (l + r) // 2
    if check(m):
        r = m
    else:
        l = m
print(r)
### BUGGY CODE ###

N, K = [int(x) for x in input().split(" ")]

if N ==0 or K==1:
  print(0)
else:
  while N>abs(N-K):
    N = abs(N%K-K)
  print(N)


### FIXED CODE ###

N, K = [int(x) for x in input().split(" ")]

if N ==0 or K==1 or N == K:
  print(0)
else:
  while N>abs(N-K):
    N = abs(N%K-K)
  print(N)
### BUGGY CODE ###

from heapq import*
h,w=map(int,input().split())
grid=[["#"]*(w+2)]+[list("#"+input()+"#") for x in range(h)]+[["#"]*(w+2)]

stack=[]
for y in range(1,h+1):
    for x in range(1,w+1):
        if grid[y][x]=="#":
            grid[y][x]=0
            heappush(stack,(y,x))

for i in range(h*w):
    tmp=[]
    for my,mx in stack:
        for y,x in ([0,1],[1,0],[-1,0],[0,-1]):
            if grid[my+y][mx+x]==".":
                grid[my+y][mx+x]=i+1
                tmp.append([my+y,mx+x])
    if all(all(j!="." for j in i)for i in grid):
        print(max(max(i[1:-1])for i in grid[1:-1]))
        exit()
    stack=tmp

### FIXED CODE ###

from heapq import*
h,w=map(int,input().split())
grid=[["#"]*(w+2)]+[list("#"+input()+"#")for x in range(h)]+[["#"]*(w+2)]

stack=[]
for y in range(1,h+1):
    for x in range(1,w+1):
        if grid[y][x]=="#":
            grid[y][x]=0
            stack.append((y,x))

for i in range(h*w):
    tmp=[]
    for my,mx in stack:
        for y,x in ([0,1],[1,0],[-1,0],[0,-1]):
            if grid[my+y][mx+x]==".":
                grid[my+y][mx+x]=i+1
                tmp.append([my+y,mx+x])
    stack=tmp
    if len(tmp)==0:
        print(i)
        break
### BUGGY CODE ###

N = int(input()) #マスの数
Hlist = list(map(int, input().split())) #マスの高さのリスト
sortHlist = sorted(Hlist, reverse=True)
ilist = []
nlist = []

for i in range(N):
    for j in range(N):
        if Hlist[j] == sortHlist[i]:
            ilist.append(j)

for j in range(len(sortHlist)):
    i = ilist[j]
    
    n = 0
    while i <= N-2: #最大の高さのマスから右方向に探索
        if Hlist[i+1] <= Hlist[i]:
            n += 1
            i += 1
        else:
            break
    nlist.append(n)

#    n = 0
#    while i >= 1: #最大の高さのマスから左方向に探索
#        if Hlist[i-1] <= Hlist[i]:
#            n += 1
#            i -= 1
#        else:
#            break
#    nlist.append(n)

print(max(nlist))

### FIXED CODE ###

n = int(input())
h = list(map(int,input().split()))
 
t = 0
result =0
 
for i in range(n-1):
  if h[i] >= h[i+1]:
    t += 1
  else:
    result = max(t,result)
    t = 0
 
result = max(t, result)
 
print(result)
### BUGGY CODE ###

'''input
10 2
7 6 18 6 16 18 1 17 17
6 9 3 10 9 1 10 1 5
'''
# A coding delight
from sys import stdin, stdout
import gc
gc.disable()
 
import sys, time, threading


	
# main starts
string = stdin.readline().strip()
i = 0
j = len(string) - 1
count = 0
while i < j:	
	if string[i] != string[j]:
		count += 1
print(count)

### FIXED CODE ###

'''input
10 2
7 6 18 6 16 18 1 17 17
6 9 3 10 9 1 10 1 5
'''
# A coding delight
from sys import stdin, stdout
import gc
gc.disable()
 
import sys, time, threading


	
# main starts
string = stdin.readline().strip()
i = 0
j = len(string) - 1
count = 0
while i < j:	
	if string[i] != string[j]:
		count += 1
	i += 1
	j -= 1
print(count)
### BUGGY CODE ###

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

l = [1]
for i in range(1, n+1):
  if i in a:
    if l[i-1] != 0:
      l.append(0)
    else:
      print(0)
      exit()
  else:
    if i != 1:
      l.append(l[i-2] + l[i-1])
    else:
      l.append(1)

print(l[-1] % 1000000007)

### FIXED CODE ###

n, m = map(int, input().split())
a = set([int(input()) for x in range(m)])

l = [0]*(n+1)
l[0] = 1

for i in range(1, n+1):
  if i in a:
    l[i] = 0
    continue
  else:
    l[i] = l[i-2] + l[i-1]

print(l[-1] % 1000000007)
### BUGGY CODE ###

def check(m,g,A,n):
    
    for i in range(n):
        gg = g + A[n-i-1]
        if m == gg:
            return True
        elif n == 0 or m < gg:
            continue
        if check(m,gg,A,n-i-1) == True:
            return True
    return False
        

n=int(input())
A=list(map(int,str.split(input())))
q = int(input())
m=list(map(int,str.split(input())))

for mi in m:
    if check(mi,0,A,n):
        print("yes")
    else:
        print("no")

### FIXED CODE ###

def check(m,g,A,n):
    
    for i in range(n):
        gg = g + A[n-i-1]
        if m == gg:
            return True
        elif n == 0 or m < gg:
            continue
        if check(m,gg,A,n-i-1) == True:
            return True
    return False
        

    

n=int(input())
A=list(map(int,str.split(input())))
q = int(input())
m=list(map(int,str.split(input())))




mini = min(A)
nor = sum(A)

for mi in m:
    if mi < mini or mi > nor:
        print("no")
        continue
    if check(mi,0,A,n):
        print("yes")
    else:
        print("no")
### BUGGY CODE ###

N = int(input())
A = list()
for i in range(N):
  A.append(int(input()))
for i in range(N):
  X = A[i]
  A[i] = 0
  print(max(A))
  A[i] = X


### FIXED CODE ###

N = int(input())
A = list()
for i in range(N):
  A.append(int(input()))
ma = max(A)
am = sorted(A,reverse = True)
for i in range(N):
  if ma != A[i]:
    print(ma)
  else:
    print(am[1])
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10 ** 5)


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def main():
    H, W = LI()
    S = [0 for _ in range(H)]
    for i in range(H):
        str = input()
        for j, s in enumerate(str):
            if s == '#':
                S[i] |= 1 << j
    ans = 1
    tate = 0
    yoko = 0
    for i in range(H):
        yoko = 0
        for j in range(W):
            if (S[i] >> j) & 1:
                yoko = 0
                continue
            if yoko == 0:
                for k in range(j+1, W):
                    if (S[i] >> k) & 1:
                        break
                    yoko += 1
            tate = 0
            for k in range(i+1, H):
                if (S[k] >> j) & 1:
                    break
                tate += 1
            for k in range(i-1, -1, -1):
                if (S[k] >> j) & 1:
                    break
                tate += 1
            ans = max(ans, tate + yoko + 1)
    print(ans)


main()


### FIXED CODE ###

import sys
import numpy as np
sys.setrecursionlimit(10 ** 5)


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def main():
    H, W = LI()
    S = np.ones((H, W), dtype=int)
    for i in range(H):
        str = input()
        for j, s in enumerate(str):
            if s == '#':
                S[i][j] = 0

    L = S.copy()
    R = S.copy()
    U = S.copy()
    D = S.copy()
    for j in range(1, W):
        L[:, j] = (L[:, j-1] + 1)*S[:, j]
        R[:, W-j-1] = (R[:, W-j] + 1) * S[:, W-j-1]

    for i in range(1, H):
        U[i][:] = (U[i-1][:] + 1)*S[i][:]
        D[H-i-1][:] = (D[H-i][:] + 1)*S[H-i-1][:]

    ans = (L+R+U+D).max() - 3
    print(ans)


main()
### BUGGY CODE ###

n = int(input())
lst = []
pair = 0
for i in range(n):
	st = sorted(list(input()))
	for j in lst:
		if st == j:
			pair += 1
	lst.append(st)
print (pair)

### FIXED CODE ###

n = int(input())
lst = []
pair = 0
for i in range(n):
	st = ''.join(sorted(list(input())))
	lst.append(st)
lst = sorted(lst)
lst += ['end']
pre = ''
tmp_cnt = 0
cnt = 0
for i in lst:
	if i == pre:
		tmp_cnt += 1
	else:
		cnt += sum([j for j in range(tmp_cnt + 1)])
		tmp_cnt = 0
	pre = i
print (cnt)
### BUGGY CODE ###

import queue

h, w = map(int, input().split())
s = [list(input()) for i in range(h)]

que = queue.Queue()
class stgo:
    def __init__(self):
        self.x = 0
        self.y = 0
        self.depth = 0
y_dist = (0, 0, -1, +1)
x_dist = (-1, +1, 0, 0)
g_y = 0
g_x = 0

def bfs():
    dist = [[-1] * (w) for i in range(h)]
    maxdepth = 0
    while not que.empty():
        now = que.get()
        y = now.y
        x = now.x
        depth = now.depth
        dist[now.y][now.x] = depth
        maxdepth = max(maxdepth, depth)

        for z in range(4):
            next = stgo()
            next.y = y + y_dist[z]
            next.x = x + x_dist[z]
            next.depth = depth + 1

            if next.y >= 0 and next.y <= h - 1 and next.x >= 0 and next.x <= w - 1 and s[next.y][next.x] == "." and dist[next.y][next.x] == -1:
                que.put(next)
    return maxdepth

ans = 0
for i in range(h):
    for j in range(w):
        if s[i][j] != "#":
            start = stgo()
            start.x = j
            start.y = i
            start.depth = 0
            que.put(start)
            ans = max(ans,bfs())
print(ans)

### FIXED CODE ###

import queue

H, W = map(int, input().split())
S = [input() for i in range(H)]
q = queue.Queue()
longest_path = 0
for i in range(H):
    for j in range(W):
        if S[i][j] == '.':
            g = [[0 if S[k][l] == '.' else -1 for l in range(W)] for k in range(H)]
            q.put((i,j))
            g[i][j] = 0
            while not(q.empty()):
                x, y = q.get()
                for nx, ny in [(x+1, y),(x-1, y),(x, y+1),(x, y-1)]:
                    if nx < 0 or nx > H-1 or ny < 0 or ny > W-1: continue
                    if g[nx][ny] != 0: continue
                    if nx == i and ny == j: continue
                    g[nx][ny] = g[x][y] + 1
                    q.put((nx,ny))
            longest_path = max(longest_path, max(map(max, g)))
print(longest_path)
### BUGGY CODE ###

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

#初期値が0の辞書
from collections import defaultdict
xyz = defaultdict(lambda: set([]))
for _ in range(m):
    x,y,z=map(int,input().split())
    xyz[x].add(y)
    xyz[y].add(x)

no_checked=set([i for i in range(1,n+1)])

cnt=0
while no_checked != set([]):
    cnt+=1
    i=no_checked.pop()
    temp=set([i])
    while len(list(temp))>0:
        v=temp.pop()
        for item in xyz[v]:
            if item in no_checked:
                no_checked.remove(item)
                temp.add(item)
                xyz[item].remove(v)

print(cnt)



### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000)

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

#初期値が0の辞書
from collections import defaultdict
xyz = defaultdict(lambda: set([]))
for _ in range(m):
    x,y,z=map(int,input().split())
    xyz[x].add(y)
    xyz[y].add(x)

no_checked=[0]*n

def DFS(x):
    global no_checked
    global xyz
    no_checked[x-1]=1
    for item in xyz[x]:
        if no_checked[item-1]==0:
            DFS(item)

cnt=0
for i in range(1,n+1):
    if no_checked[i-1]==0:
        cnt+=1
        DFS(i)

    #print(i,no_checked)
print(cnt)
### BUGGY CODE ###

def gcd(a,b):
    while b != 0:
        a, b = b, a % b
    return a

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

if N == 2:
    print(max(A))
else:
    for i in range(N):
        B = A[:]
        B.pop(i)
        element =gcd(B[0], B[1])
        if N == 3:
            ans = max(ans, element)
        else:
            for j in range(2, N-1):
                element = gcd(element, B[j])
            ans = max(ans, element)
    print(ans)


### FIXED CODE ###

def gcd(a, b):
	while b != 0:
		a, b = b, a % b
	return a

N = int(input())
A = list(map(int, input().split()))
L = [0]*(N+2)
R = [0]*(N+2)
ans = 0
for i in range(N):
	L[i+1] = (gcd(L[i],A[i]))
	R[N-i] = (gcd(R[N-i+1],A[N-1-i]))
for i in range(N):
	ans = max(ans,(gcd(L[i], R[i+2])))
print(ans)