Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys

input = sys.stdin.readline

def main():
    n, m = [int(e) for e in input().split()]
    A = [int(e) for e in input().split()]
    A.sort()

    M = []
    max_c = 0
    for l in sys.stdin:
        b, c = [int(e) for e in l.strip().split()]
        max_c = max(max_c, c)
        M.append([b, c])
    last_idx = len(A)
    for i in range(len(A)):
        if max_c < A[i]:
            last_idx = i + 1
            break

    M.sort(key=lambda x: x[1], reverse=True)

    idx = 0
    for m in M:
        b, c = m[0], m[1]
        b_cnt = 0
        for i in range(idx, last_idx):
            if A[i] < c:
                A[i] = c
                b_cnt += 1
                idx += 1
            if b_cnt == b:
                break
    print(sum(A))

main()


Fixed submission:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys

input = sys.stdin.readline

def main():
    n, m = [int(e) for e in input().split()]
    A = [int(e) for e in input().split()]
    A.sort()

    M = []
    max_c = 0
    for l in sys.stdin:
        b, c = [int(e) for e in l.strip().split()]
        max_c = max(max_c, c)
        M.append([b, c])
    last_idx = len(A)
    for i in range(len(A)):
        if max_c < A[i]:
            last_idx = i + 1
            break

    M.sort(key=lambda x: x[1], reverse=True)


    idx = 0
    for m in M:
        b, c = m[0], m[1]
        b_cnt = 0
        for i in range(idx, last_idx):
            if A[i] > c:
                break
            if A[i] < c:
                A[i] = c
                b_cnt += 1
                idx += 1
            if b_cnt == b:
                break

    print(sum(A))

main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys

input = sys.stdin.readline

def main():
    n, m = [int(e) for e in input().split()]
    A = [int(e) for e in input().split()]
    A.sort()
    for l in sys.stdin:
        b, c = [int(e) for e in l.strip().split()]
        b_cnt = 0
        for i in range(len(A)):
            if A[i] < c:
                A[i] = c
                b_cnt += 1
            if b_cnt == b:
                break
        A.sort()
    print(sum(A))

main()


Fixed submission:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys

input = sys.stdin.readline

def main():
    n, m = [int(e) for e in input().split()]
    A = [int(e) for e in input().split()]
    A.sort()

    M = []
    max_c = 0
    for l in sys.stdin:
        b, c = [int(e) for e in l.strip().split()]
        max_c = max(max_c, c)
        M.append([b, c])
    last_idx = len(A)
    for i in range(len(A)):
        if max_c < A[i]:
            last_idx = i + 1
            break

    M.sort(key=lambda x: x[1], reverse=True)


    idx = 0
    for m in M:
        b, c = m[0], m[1]
        b_cnt = 0
        for i in range(idx, last_idx):
            if A[i] > c:
                break
            if A[i] < c:
                A[i] = c
                b_cnt += 1
                idx += 1
            if b_cnt == b:
                break

    print(sum(A))

main()
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

def main():
    s = input().split(" ")

    sl = list(s[0])
    prev = -1
    n = 0

    i = 0
    while True:
        if len(sl) <= i:
            break

        if (prev == 0 and sl[i] == '1') or (prev == 1 and sl[i] == '0'):
            # print(str(sl))
            # print("remove", i, prev, sl[i])
            del sl[i]
            del sl[i-1]
            n += 2
            if len(sl) <= i:
                break
            else:
                prev = int(sl[i-2])
                i = i-1
        else:
            prev = int(sl[i])
            i += 1

    print(n)

main()


Fixed submission:
# -*- coding: utf-8 -*-

def main():
    s = input().split(" ")

    sl = list(s[0])
    prev = -1
    n = 0

    i = 0
    while True:
        if len(sl) <= i:
            break

        if (prev == 0 and sl[i] == '1') or (prev == 1 and sl[i] == '0'):
            # print(str(sl))
            # print("remove", i, prev, sl[i])
            del sl[i]
            del sl[i-1]
            n += 2
            if i-2 < 0:
                prev = -1
                i = 0
            else:
                prev = int(sl[i-2])
                i = i-1
        else:
            prev = int(sl[i])
            i += 1

    print(n)

main()

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

def main():
    s = input().split(" ")

    sl = list(s[0])
    prev = -1
    n = 0
    while True:
        # print(str(sl))
        if len(sl) < 1:
            break
        kita = False
        for i, c in enumerate(sl):
            if i == 0 and prev != -1:
                break
            if (prev == 0 and c == '1') or (prev == 1 and c == '0'):
                kita = True
                # print("remove", i, prev, c)
                del sl[i]
                del sl[i-1]
                n += 2
                prev = -1
                break
            else:
                kita = True
                prev = int(c)

        if not kita:
            break

    print(n)

main()


Fixed submission:
# -*- coding: utf-8 -*-

def main():
    s = input().split(" ")

    sl = list(s[0])
    prev = -1
    n = 0

    i = 0
    while True:
        if len(sl) <= i:
            break

        if (prev == 0 and sl[i] == '1') or (prev == 1 and sl[i] == '0'):
            # print(str(sl))
            # print("remove", i, prev, sl[i])
            del sl[i]
            del sl[i-1]
            n += 2
            if i-2 < 0:
                prev = -1
                i = 0
            else:
                prev = int(sl[i-2])
                i = i-1
        else:
            prev = int(sl[i])
            i += 1

    print(n)

main()
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys

input = sys.stdin.readline

def main():
    S = input().strip()
    T = input().strip()

    T2 = T[:]
    for i in range(len(S)):
        if S[i] == T2[i]:
            continue
        from_c = T2[i]
        to_c = S[i]
        T2 = T2.translate(str.maketrans({from_c: to_c, to_c: from_c}))

    if S != T2:
        print("No")
    else:
        print("Yes")

main()


Fixed submission:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys

input = sys.stdin.readline

def main():
    S = input().strip()
    T = input().strip()
    m = {}
    for i in range(len(T)):
        if T[i] in m:
            if m[T[i]] != S[i]:
                print("No")
                return
        m[T[i]] = S[i]

    T2 = T[:]
    for i in range(len(S)):
        if S[i] == T2[i]:
            continue
        from_c = T2[i]
        to_c = S[i]
        T2 = T2.translate(str.maketrans({from_c: to_c, to_c: from_c}))

    if S != T2:
        print("No")
    else:
        print("Yes")

main()

Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys

input = sys.stdin.readline

def main():
    T2 = T[:]
    for i in range(len(S)):
        if S[i] == T2[i]:
            continue
        from_c = T2[i]
        to_c = S[i]
        T2 = T2.translate(str.maketrans({from_c: to_c, to_c: from_c}))

    if S != T2:
        print("No")
    else:
        print("Yes")

main()


Fixed submission:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys

input = sys.stdin.readline

def main():
    S = input().strip()
    T = input().strip()
    m = {}
    for i in range(len(T)):
        if T[i] in m:
            if m[T[i]] != S[i]:
                print("No")
                return
        m[T[i]] = S[i]

    T2 = T[:]
    for i in range(len(S)):
        if S[i] == T2[i]:
            continue
        from_c = T2[i]
        to_c = S[i]
        T2 = T2.translate(str.maketrans({from_c: to_c, to_c: from_c}))

    if S != T2:
        print("No")
    else:
        print("Yes")

main()
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys

input = sys.stdin.readline

def main():
    s = list(input().strip())
    t = list(input().strip())
    s.sort()
    t.sort(reverse=True)

    min_len = min(len(s), len(s))
    same = True
    for i in range(min_len):
        if s[i] < t[i]:
            print("Yes")
            return
        if s[i] != t[i]:
            same = False
    if same and len(s) < len(t):
        print("Yes")
    else:
        print("No")

main()


Fixed submission:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys

input = sys.stdin.readline

def main():
    s = list(input().strip())
    t = list(input().strip())
    s.sort()
    t.sort(reverse=True)

    min_len = min(len(s), len(t))
    same = True
    for i in range(min_len):
        if s[i] < t[i]:
            print("Yes")
            return
        if s[i] != t[i]:
            same = False
    if same and len(s) < len(t):
        print("Yes")
    else:
        print("No")

main()
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()) for _ in range(N))
B = sorted(A)
for i in range(N):
  if A[i-1] == B[0]:
    print(B[1])
  else:
    print(B[0])


Fixed submission:
N = int(input())
A = []
for i in range(N):
  A.append(int(input()))
B = sorted(A, reverse=True)
for i in range(N):
  if A[i] == B[0]:
    print(B[1])
  else:
    print(B[0])
Buggy python submission (verdict: Runtime Error):
N = int(input())
X = [list(map(int, input().split())) for _ in range(N)]
X.sort(key = lambda X:X[1])
time = 0
ans = 'Yes'
for i in range(N):
  time += X[0][i]
  line = X[i][1]
  if line < time :
    ans = 'No'
print(ans)

Fixed submission:
N = int(input())
X = [list(map(int, input().split())) for _ in range(N)]
X.sort(key = lambda X:X[1])
time = 0
ans = 'Yes'
for i in range(N):
  time += X[i][0]
  line = X[i][1]
  if line < time :
    ans = 'No'
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
W = list(map(int, input().split()))
V = []
for T in range(N-1):
  A = 0
  B = 0
  for i in range(N):
    while i <= T:
      A = A + W[i]
    else:
      B = B + W[i]
    V.append(abs(A-B))
  
V = min(str(V[T]))


Fixed submission:
N = int(input())
W = list(map(int, input().split()))
V = []
for i in range(N):
    A = sum(W[0:i])
    B = sum(W[i:N])
    V.append(abs(A-B))
print(min(V))
Buggy python submission (verdict: Runtime Error):
pie=int("3*A+P")
if pie//2:
 (3*A+P)/2
else :
 (3*A+P-1)/2

Fixed submission:
a, p = map(int, input().split())
print((a*3+p) // 2)
Buggy python submission (verdict: Runtime Error):
def gcd(a,b):
  if b==0:
    return a
  else:
    return gcd(b,a%b)

N = int(input())
A = list(map(int, input().split()))
A.sort()
B = []
C = []
for i in range(1,N):
  B.append(gcd(A[0],A[i]))
  C.append(gcd(A[1],A[i]))
B.sort()
C.sort()
print(B[1],C[1])


Fixed submission:
def gcd(a,b):
  if b==0:
    return a
  else:
    return gcd(b,a%b)

N = int(input())
A = list(map(int, input().split()))
B = [A[0]]
C = [A[N-1]]
for i in range(1,N):
  B.append(gcd(A[i],B[i-1]))
  C.append(gcd(A[N-i-1],C[i-1]))
D = [C[N-2]]
for j in range(N-2):
  D.append(gcd(B[j],C[N-j-3]))
D.append(B[N-2])
print(max(D))
Buggy python submission (verdict: Runtime Error):
A = str(input())
B = str(input())
C = str(input())
D = str(input())
E = str(input())
a = int(A[-1:])
b = int(B[-1:])
c = int(C[-1:])
d = int(D[-1:])
e = int(E[-1:])
F = [a,b,c,d,e]
G = F.count(0)
H = (10-a)+(10-b)+(10-c)+(10-d)+(10-e)
p = 9 if a == 0 else a
q = 9 if b == 0 else b
r = 9 if c == 0 else c
s = 9 if d == 0 else d
t = 9 if e == 0 else e
I = min([p,q,r,s,t])
J = int(A) +int(B) +int(C) + int(D) + int(E)
K = -10*G + I -10
if G==5:
  print(J)
else:


Fixed submission:
A = str(input())
B = str(input())
C = str(input())
D = str(input())
E = str(input())
a = int(A[-1:])
b = int(B[-1:])
c = int(C[-1:])
d = int(D[-1:])
e = int(E[-1:])
F = [a,b,c,d,e]
G = F.count(0)
H = (10-a)+(10-b)+(10-c)+(10-d)+(10-e)
p = 9 if a == 0 else a
q = 9 if b == 0 else b
r = 9 if c == 0 else c
s = 9 if d == 0 else d
t = 9 if e == 0 else e
I = min([p,q,r,s,t])
J = int(A) +int(B) +int(C) + int(D) + int(E)
K = I -10*G -10
if G==5:
  print(J)
else:
  print(H+J+K)
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    s = [-1 if c == '?' else int(c) for c in list(input())]
    MOD = 10 ** 9 + 7
    n = len(s)
    dp = [[0] * 13 for _ in range(n)]

    if s[n-1] == -1:
        for j in range(10):
            dp[0][j] = 1
    else:
        dp[0][s[n-1]] = 1
    for i in range(1, n):
        i10 = 10 ** i % 13
        c = s[n-i-1]
        for k in range(13):
            if c == -1:
                for j in range(10):
                    m = (i10 * j + k) % 13
                    dp[i][m] += dp[i-1][k]
                    dp[i][m] %= MOD
            else:
                m = (i10 * c + k) % 13
                dp[i][m] += dp[i-1][k]
                dp[i][m] %= MOD
    print(dp[n-1][5])


main()


Fixed submission:
def main():
    s = [-1 if c == '?' else int(c) for c in list(input())]
    MOD = 10 ** 9 + 7
    n = len(s)
    dp = [[0] * 13 for _ in range(n)]

    if s[n-1] == -1:
        for j in range(10):
            dp[0][j] = 1
    else:
        dp[0][s[n-1]] = 1
    i10 = 1
    for i in range(1, n):
        i10 = (10 * i10) % 13
        c = s[n-i-1]
        for k in range(13):
            if c == -1:
                for j in range(10):
                    m = (i10 * j + k) % 13
                    dp[i][m] += dp[i-1][k]
                    dp[i][m] %= MOD
            else:
                m = (i10 * c + k) % 13
                dp[i][m] += dp[i-1][k]
                dp[i][m] %= MOD
    print(dp[n-1][5])


main()
Buggy python submission (verdict: Runtime Error):
def main():
    n, k = map(int, input().split())
    MOD = 10 ** 9 + 7
    t = [{} for _ in range(n)]
    for _ in range(n-1):
        a, b = map(int, input().split())
        t[a-1][b-1] = 1
        t[b-1][a-1] = 1
    values = [1] * n

    def dfs(x):
        colors = k - 2
        for y in t[x]:
            del t[y][x]
            values[y] = colors
            colors -= 1
            dfs(y)

    values[0] = k
    colors = k - 1
    for x in t[0]:
        del t[x][0]
        values[x] = colors
        colors -= 1
        dfs(x)

    ans = 1
    for v in values:
        ans *= v
        ans %= MOD
    print(ans)


main()


Fixed submission:
import sys

sys.setrecursionlimit(10 ** 6)


def main():
    n, k = map(int, input().split())
    MOD = 10 ** 9 + 7
    t = [{} for _ in range(n)]
    for _ in range(n-1):
        a, b = map(int, input().split())
        t[a-1][b-1] = 1
        t[b-1][a-1] = 1
    values = [1] * n

    def dfs(x):
        colors = k - 2
        for y in t[x]:
            del t[y][x]
            values[y] = colors
            colors -= 1
            dfs(y)

    values[0] = k
    colors = k - 1
    for x in t[0]:
        del t[x][0]
        values[x] = colors
        colors -= 1
        dfs(x)

    ans = 1
    for v in values:
        ans *= v
        ans %= MOD
    print(ans)


main()
Buggy python submission (verdict: Time Limit Exceeded):
from scipy.misc import comb
# from scipy.special import comb


MOD = 10 ** 9 + 7

def main():
    N, K = map(int, input().split())

    note = [[-1 for i in range(N)] for j in range(N)]

    def calc_comb(n, r):
        if note[n][r] != -1:
            return note[n][r]
        a = comb(n, r, exact=True)
        note[n][r] = a
        return a

    def print_patterns(i, N, K):
        m = N - K
        if i - 1 > m:
            print(0)
            return
        if i == 1:
            p = 1 * (m+1) % MOD
            print(p)
            return
        p_red = 0
        for l in range(i-1, m+1):
            p_red += calc_comb(l-1, i-2) * (m-l+1)
            p_red %= MOD
        p = calc_comb(K-1, i-1) * p_red % MOD
        print(p)

    for i in range(1, K+1):
        print_patterns(i, N, K)


main()

Fixed submission:
from scipy.misc import comb
# from scipy.special import comb


MOD = 10 ** 9 + 7

def main():
    N, K = map(int, input().split())

    note = [[-1 for i in range(N)] for j in range(N)]

    def calc_comb(n, r):
        if note[n][r] != -1:
            return note[n][r]
        a = comb(n, r, exact=True)
        note[n][r] = a
        return a

    def print_patterns(i, N, K):
        m = N - K
        if i - 1 > m:
            print(0)
            return
        if i == 1:
            p = 1 * (m+1) % MOD
            print(p)
            return
        p = calc_comb(K-1, i-1) * calc_comb(m+1, i) % MOD
        print(p)

    for i in range(1, K+1):
        print_patterns(i, N, K)


main()

Buggy python submission (verdict: Runtime Error):
# from scipy.misc import comb
from scipy.special import comb


MOD = 10 ** 9 + 7

def main():
    N, K = map(int, input().split())

    note = [[-1 for i in range(N)] for j in range(N)]

    def calc_comb(n, r):
        if note[n][r] != -1:
            return note[n][r]
        a = comb(n, r, exact=True)
        note[n][r] = a
        return a

    def print_patterns(i, N, K):
        m = N - K
        if i - 1 > m:
            print(0)
            return
        if i == 1:
            p = 1 * (m+1) % MOD
            print(p)
            return
        p_red = 0
        for l in range(i-1, m+1):
            p_red += calc_comb(l-1, i-2) * (m-l+1)
            p_red %= MOD
        p = calc_comb(K-1, i-1) * p_red % MOD
        print(p)

    for i in range(1, K+1):
        print_patterns(i, N, K)


main()

Fixed submission:
from scipy.misc import comb
# from scipy.special import comb


MOD = 10 ** 9 + 7

def main():
    N, K = map(int, input().split())

    note = [[-1 for i in range(N)] for j in range(N)]

    def calc_comb(n, r):
        if note[n][r] != -1:
            return note[n][r]
        a = comb(n, r, exact=True)
        note[n][r] = a
        return a

    def print_patterns(i, N, K):
        m = N - K
        if i - 1 > m:
            print(0)
            return
        if i == 1:
            p = 1 * (m+1) % MOD
            print(p)
            return
        p = calc_comb(K-1, i-1) * calc_comb(m+1, i) % MOD
        print(p)

    for i in range(1, K+1):
        print_patterns(i, N, K)


main()
Buggy python submission (verdict: Runtime Error):
import math


def main():
    A, B, C, D = map(int, input().split())

    def num_of_multiples(st, ed, m):
        a = st % m
        a0 = st + (m - a)
        if a0 > ed:
            return 0
        if a == 0:
            a0 = st
        b = ed % m
        b0 = ed - b
        num = (b0 - a0)
        if num % m != 0:
            raise Exception()
        return (b0 - a0) // m + 1
    
    nc = num_of_multiples(A, B, C)
    nd = num_of_multiples(A, B, D)
    ncd = num_of_multiples(A, B, C * D // math.gcd(C, D))
    print(B - A + 1 - (nc + nd - ncd))


main()

Fixed submission:
import fractions

def main():
    A, B, C, D = map(int, input().split())

    def num_of_multiples(st, ed, m):
        a = st % m
        a0 = st + (m - a)
        if a == 0:
            a0 = st
        if a0 > ed:
            return 0
        b = ed % m
        b0 = ed - b
        num = (b0 - a0)
        if num % m != 0:
            raise Exception()
        return (b0 - a0) // m + 1
    
    nc = num_of_multiples(A, B, C)
    nd = num_of_multiples(A, B, D)
    ncd = num_of_multiples(A, B, C * D // fractions.gcd(C, D))
    print(B - A + 1 - (nc + nd - ncd))


main()
Buggy python submission (verdict: Runtime Error):
H, W = map(int, input().split())
s = [[c for c in input()] for i in range(H)]
s_vrt = [[s[i][j] for i in range(H)] for j in range(W)]

dp_l = [[0 for j in range(W)] for i in range(H)]
dp_r = [[0 for j in range(W)] for i in range(H)]
dp_u = [[0 for i in range(H)] for j in range(W)]
dp_d = [[0 for i in range(H)] for j in range(W)]


def mark_table_for_dp():
    for i in range(H):
        mark_line_for_dp(s[i], dp_l[i], False)
        mark_line_for_dp(s[i], dp_r[i], True)
    for j in range(W):
        mark_line_for_dp(s_vrt[j], dp_u[j], True)
        mark_line_for_dp(s_vrt[j], dp_d[j], False)



def mark_line_for_dp(line, dp, is_reverse):
    cnt = 0
    r = list(range(len(line)))
    if is_reverse:
        r.reverse()
    for i in r:
        if line[i] == '#':
            cnt = 0
            continue
        dp[i] = cnt
        cnt += 1


mark_table_for_dp()


def count_light_cross(i, j):
    return dp_l[i][j] + dp_r[i][j] + dp_u[j][i] + dp_d[j][i] + 1


count_max = 0
for i in range(H):
    for j in range(W):
        if s[i][j] == '#':
            continue
        count = count_light_cross(i, j)
        if count_max < count:
            count_max = count

print(count_max)

Fixed submission:
p, q, r = map(int, input().split())

route = min(p+q, q+r, r+p)
print(route)
Buggy python submission (verdict: Runtime Error):
class UnionFind(object):
    def __init__(self, N):
        self.parent = [i for i in range(N)]

    def merge(self, a, b):
        pa = self.root(a)
        pb = self.root(b)
        self.parent[pa] = pb
    
    def root(self, x):
        p = self.parent[x]
        if p == x:
            return x
        else:
            r = self.root(p)
            self.parent[x] = r
            return r


def main():
    N, M = map(int, input().split())

    uf = UnionFind(N)
    for _ in range(M):
        x, y, _ = map(int, input().split())
        uf.merge(x-1, y-1)

    print(len(list(filter(lambda x: x == uf.root(x), range(N)))))


main()

Fixed submission:
import sys


sys.setrecursionlimit(10**5)


class UnionFind(object):
    def __init__(self, N):
        self.parent = [i for i in range(N)]

    def merge(self, a, b):
        pa = self.root(a)
        pb = self.root(b)
        self.parent[pa] = pb
    
    def root(self, x):
        p = self.parent[x]
        if p == x:
            return x
        else:
            r = self.root(p)
            self.parent[x] = r
            return r


def main():
    N, M = map(int, input().split())

    uf = UnionFind(N)
    for _ in range(M):
        x, y, _ = map(int, input().split())
        uf.merge(x-1, y-1)

    print(len(list(filter(lambda x: x == uf.root(x), range(N)))))


main()
Buggy python submission (verdict: Runtime Error):
from math import gcd


def main():
    N = int(input())
    A = [0] + list(map(int, input().split()))

    L = [0] * (N+2)
    R = [0] * (N+2)
    G = [0] * (N+1)
    L[1] = A[1]
    R[N] = A[N]
    for i in range(2, N+1):
        L[i] = gcd(L[i-1], A[i])
    for i in range(1, N):
        R[i] = gcd(R[i+1], A[i])
    for i in range(1, N+1):
        if i == 1:
            G[i] = R[2]
        elif i == N:
            G[i] = L[N-1]
        else:
            G[i] = gcd(L[i-1], R[i+1])
    print(max(G[1:]))


main()


Fixed submission:
from fractions import gcd


def main():
    N = int(input())
    A = [0] + list(map(int, input().split()))

    L = [0] * (N+2)
    R = [0] * (N+2)
    G = [0] * (N+1)
    L[1] = A[1]
    R[N] = A[N]
    for i in range(2, N+1):
        L[i] = gcd(L[i-1], A[i])
    for i in range(1, N)[::-1]:
        R[i] = gcd(R[i+1], A[i])
    for i in range(1, N+1):
        if i == 1:
            G[i] = R[2]
        elif i == N:
            G[i] = L[N-1]
        else:
            G[i] = gcd(L[i-1], R[i+1])
    print(max(G[1:]))


main()