Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
K = int(input())
ans = 0

T = ""
for _ in range(K):
    T += S

for ti in range(1, len(T)):
    if T[ti] == T[ti - 1]:
        T = T[: ti] + "?" + T[ti + 1:]
        ans += 1

print(ans)


Fixed submission:
S = input()
K = int(input())
ans_s2, ans_s3 = 0, 0

# 例外処理
if len(S) == 1:
    print(K // 2)
    exit()
elif len(set(S)) == 1:
    print(len(S) * K // 2)
    exit()

S_double = S + S
for i in range(1, len(S_double)):
    if S_double[i] == S_double[i - 1]:
        S_double = S_double[: i] + "?" + S_double[i + 1:]
        ans_s2 += 1

S_triple = S + S + S
for j in range(1, len(S_triple)):
    if S_triple[j] == S_triple[j - 1]:
        S_triple = S_triple[: j] + "?" + S_triple[j + 1:]
        ans_s3 += 1

ans_increase = ans_s3 - ans_s2  #K>=3のときの増分

ans = ans_s2 + max(0, ans_increase * (K - 2))
print(ans)

Buggy python submission (verdict: Runtime Error):
S = input()
K = int(input())
ans = 0

T = ""
for _ in range(K):
    T += S

for ti in range(1, len(T)):
    if T[i] == T[i - 1]:
        T = T[: i] + "?" + T[i + 1:]
        ans += 1

print(ans)


Fixed submission:
S = input()
K = int(input())
ans_s2, ans_s3 = 0, 0

# 例外処理
if len(S) == 1:
    print(K // 2)
    exit()
elif len(set(S)) == 1:
    print(len(S) * K // 2)
    exit()

S_double = S + S
for i in range(1, len(S_double)):
    if S_double[i] == S_double[i - 1]:
        S_double = S_double[: i] + "?" + S_double[i + 1:]
        ans_s2 += 1

S_triple = S + S + S
for j in range(1, len(S_triple)):
    if S_triple[j] == S_triple[j - 1]:
        S_triple = S_triple[: j] + "?" + S_triple[j + 1:]
        ans_s3 += 1

ans_increase = ans_s3 - ans_s2  #K>=3のときの増分

ans = ans_s2 + max(0, ans_increase * (K - 2))
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(list, input().split()))
for i in range(N):
    A[i].append(i + 1)  # 出席番号をそれぞれ追加している
A = sorted(A)  # 人数でソート
ans = []
for ai in range(N):
    ans.append(A[ai][1])  # 人数順に出席番号で出力
print(" ".join(map(str, ans)))


Fixed submission:
N = int(input())
A = list(map(int, input().split()))
B = []
for i in range(N):
    B.append([A[i]])
    B[i].append(i + 1)  # 出席番号をそれぞれ追加している
B = sorted(B)  # 人数でソート
ans = []
for ai in range(N):
    ans.append(B[ai][1])  # 人数順に出席番号で出力
print(" ".join(map(str, ans)))
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))
for i in range(M):
    A[-1] //= 2
    A = sorted(A)
print(sum(A))


Fixed submission:
import heapq

N, M = map(int, input().split())
A = [-i for i in list(map(int, input().split()))]
heapq.heapify(A)
for m in range(M):
    A_max = -heapq.heappop(A)  # Aの最大値を削除して取り出す
    heapq.heappush(A, -(A_max // 2))
print(-sum(A))
Buggy python submission (verdict: Time Limit Exceeded):
def verify_anagrams(w1, w2):
    f = lambda y: "".join(sorted(map(lambda x: x.replace(" ", ""), y)))
    return f(w1) == f(w2)


N = int(input())
s = [input() for _ in range(N)]
ans = 0
for i in range(N):
    for j in range(i + 1, N):
        if verify_anagrams(s[i], s[j]):
            ans += 1
print(ans)


Fixed submission:
from operator import mul
from functools import reduce
import collections


def cmb(n, r):
    r = min(n - r, r)
    if r == 0:
        return 1
    elif r < 0:
        return 0
    numer = reduce(mul, range(n, n - r, -1))
    denom = reduce(mul, range(1, r + 1))
    return numer // denom


N = int(input())
s = ["".join(sorted(input())) for _ in range(N)]
c = collections.Counter(s)
ans = 0
for si in set(s):
    n = c[si]
    ans += cmb(n, 2)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from operator import mul
from functools import reduce


def cmb(n, r):
        r = min(n - r, r)
        if r == 0:
                return 1
        elif r < 0:
                return 0
        numer = reduce(mul, range(n, n - r, -1))
        denom = reduce(mul, range(1, r + 1))
        return numer // denom


N = int(input())
s = ["".join(sorted(input())) for _ in range(N)]
ans = 0
for si in set(s):
        n = s.count(si)
        ans += cmb(n, 2)
print(ans)


Fixed submission:
from operator import mul
from functools import reduce
import collections


def cmb(n, r):
    r = min(n - r, r)
    if r == 0:
        return 1
    elif r < 0:
        return 0
    numer = reduce(mul, range(n, n - r, -1))
    denom = reduce(mul, range(1, r + 1))
    return numer // denom


N = int(input())
s = ["".join(sorted(input())) for _ in range(N)]
c = collections.Counter(s)
ans = 0
for si in set(s):
    n = c[si]
    ans += cmb(n, 2)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
s = []
ans = 0
for i in range(N):
        si = sorted(input())
        if si in s:
                ans += s.count(si)
        s.append(si)
print(ans)


Fixed submission:
from operator import mul
from functools import reduce
import collections


def cmb(n, r):
    r = min(n - r, r)
    if r == 0:
        return 1
    elif r < 0:
        return 0
    numer = reduce(mul, range(n, n - r, -1))
    denom = reduce(mul, range(1, r + 1))
    return numer // denom


N = int(input())
s = ["".join(sorted(input())) for _ in range(N)]
c = collections.Counter(s)
ans = 0
for si in set(s):
    n = c[si]
    ans += cmb(n, 2)
print(ans)
Buggy python submission (verdict: Runtime Error):
import heapq
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
for _ in range(N):
    A, B = map(int, input().split())

hq = []
ans = 0

for i in range(1, M + 1):
    while j < N and A[j] <= i:
        heapq.heappush(hq, -B[j])
        j += 1
    if len(hq):
        ans -= heapq.heappop(hq)

print(ans)


Fixed submission:
import heapq
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
X = sorted([list(map(int, input().split())) for _ in range(N)], key = lambda x: x[0])

hq = []
ans, j = 0, 0

for i in range(1, M + 1):
    while (j < N) and (X[j][0] <= i):
        heapq.heappush(hq, -X[j][1])
        j += 1
    if len(hq):
        ans -= heapq.heappop(hq)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
X = sorted([list(map(int, input().split())) for _ in range(N)], key = lambda x: (x[0], x[1]))
A, B = [0], [0]
for i in range(N):
    A.append(X[i][0])
    B.append(X[i][1])

ans = 0
index_upper = 1
for k in range(1, M + 1):
    Ak = [a for a in A if a <= k]
    index_upper = len(Ak)
    res = max(B[:index_upper])
    if res != 0:
        A.remove(A[B.index(res)])
        B.remove(res)
    ans += res
print(ans)


Fixed submission:
import heapq
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
X = sorted([list(map(int, input().split())) for _ in range(N)], key = lambda x: x[0])

hq = []
ans, j = 0, 0

for i in range(1, M + 1):
    while (j < N) and (X[j][0] <= i):
        heapq.heappush(hq, -X[j][1])
        j += 1
    if len(hq):
        ans -= heapq.heappop(hq)

print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
ans = 0
for i in range(1, N + 1):
    if len(i) % 2 == 1:
        ans += 1
print(ans)


Fixed submission:
N = int(input())
ans = 0
for i in range(1, N + 1):
    if len(str(i)) % 2 == 1:
        ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
H = list(map(int, input().split()))
for i in range(1, N):
    M = max(M, H[i - 1])
    if H[i] < M - 1:
        print("No")
        exit()
print("Yes")


Fixed submission:
N = int(input())
H = list(map(int, input().split()))
M = 0
for i in range(1, N):
    M = max(M, H[i - 1])
    if H[i] < M - 1:
        print("No")
        exit()
print("Yes")

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
H = list(map(int, input().split()))
for i in range(1, N):
    if H[i] < max(H[:i]) - 1:
        print("No")
        exit()
print("Yes")


Fixed submission:
N = int(input())
H = list(map(int, input().split()))
M = 0
for i in range(1, N):
    M = max(M, H[i - 1])
    if H[i] < M - 1:
        print("No")
        exit()
print("Yes")

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
H = list(map(int, input().split()))
for i in range(N):
    if H[i] > H[min(N - 1, i + 1)] + 1:
        print("No")
        exit()
    if i > 0:
        if H[i] < max(H[:i]) - 1:
            print("No")
            exit()
print("Yes")


Fixed submission:
N = int(input())
H = list(map(int, input().split()))
M = 0
for i in range(1, N):
    M = max(M, H[i - 1])
    if H[i] < M - 1:
        print("No")
        exit()
print("Yes")

Buggy python submission (verdict: Runtime Error):
N = int(input())
H = list(map(int, input().split()))
for i in range(N):
    if H[i] > H[max(N - 1, i + 1)] + 1:
        print("No")
        exit()
    if i > 0:
        if H[i] < max(H[:i]) - 1:
            print("No")
            exit()
print("Yes")


Fixed submission:
N = int(input())
H = list(map(int, input().split()))
M = 0
for i in range(1, N):
    M = max(M, H[i - 1])
    if H[i] < M - 1:
        print("No")
        exit()
print("Yes")

Buggy python submission (verdict: Runtime Error):
N = int(input())
H = list(map(int, input().split()))
for i in range(N):
    if i < N - 2:
        elif H[i] > H[i + 1] > H[i + 2]:
            print("No")
            exit()
    elif i < N - 1:
        if H[i] > H[i + 1] + 1:
            print("No")
            exit()
print("Yes")


Fixed submission:
N = int(input())
H = list(map(int, input().split()))
M = 0
for i in range(1, N):
    M = max(M, H[i - 1])
    if H[i] < M - 1:
        print("No")
        exit()
print("Yes")
Buggy python submission (verdict: Time Limit Exceeded):
import copy

def continue_cnt(A):
	Datas, Cnts = [A[0]], [1]
	index = 0
	for i in range(1, len(A)):
		if A[i] == Datas[index]:
			Cnts[index] += 1
		else:
			Datas.append(A[i])
			Cnts.append(1)
			index += 1
	return Datas, Cnts

def nums_child(S, Cnts):
    res = [1] * len(S)
    if max(Cnts) % 2 == 0:
        cnts = max(Cnts)
    else:
        cnts = max(Cnts) - 1

    for _ in range(cnts):
        num = copy.deepcopy(res)
        for i in range(len(S)):
            if num[i] > 0:
                res[i] -= num[i]
                if S[i] == "R":
                    res[i + 1] += num[i]
                else:
                    res[i - 1] += num[i]

    return res


S = input()
Datas, Cnts = continue_cnt(S)  # 実は Datas の情報は明らかなので要らない

print(" ".join(map(str, nums_child(S, Cnts))))


Fixed submission:
def runLength(str):
    """文字列strをランレングス圧縮して返す関数
    ex: "0000111101" => [(0,4), (1,4), (0,1), (1,1)]
    """
    res = []
    data, count = str[0], 1
    for i in range(1, len(str)):
        if str[i] == data:
            count += 1
        else:
            res.append((data, count))
            data, count = str[i], 1
    res.append((data, count))
    return res

S = input()  # S[0] == "R", S[-1] == "L"

ans = [0] * len(S)
ind = -1
for rl in runLength(S):
    if rl[0] == "R":
        ind += rl[1]
        ans[ind] += rl[1] - rl[1] // 2
        ans[ind+1] += rl[1] // 2
        #print("now", rl, *ans)
    else:
        ans[ind] += rl[1] // 2
        ans[ind+1] += rl[1] - rl[1] // 2
        ind += rl[1]
        #print("now", rl, *ans)

print(*ans)
Buggy python submission (verdict: Runtime Error):
INF = 10 ** 9 + 7

S = input()
# dp[i][j]はうしろからi桁を13で割った余りがjであるものの個数
dp = [[0] * 13 for _ in range(len(S) + 1)]
dp[0][0] = 1
mul = 1

for i in range(len(S)):
    x = S[-(i + 1)]
    if x == "?":
        for k in range(10):
            for j in range(13):
                dp[i + 1][(mul * k + j) % 13] += dp[i][j]
                dp[i + 1][(mul * k + j) % 13] %= INF
    else:
        k = int(x)
        for j in range(13):
            dp[i + 1][(mul * k + j) % 13] += dp[i][j]
            dp[i + 1][(mul * k + j) % 13] %= INF
    mul = mul * 10 % 13  # 計算量削減のためここで13で割っている

print(dp[len(S)][5])


Fixed submission:
A, B = map(int, input().split())
if (A + B) % 2 == 0:
    print((A + B) // 2)
else:
    print("IMPOSSIBLE")
Buggy python submission (verdict: Runtime Error):
import numpy as np
N = int(input())
A = list(map(int, input().split()))

# solve "mat * x = b" about x
x, y = np.identity(N), np.identity(N)
y0 = y[0]
y = np.reshape(np.append(np.delete(y, 0, 0), y0), (N, N))
mat = (x + y) / 2

b = np.array(A)

for i in range(len(mat) - 1):
    for j in range(i + 1, len(mat)):
        coef = mat[j][i] / mat[i][i]
        mat[j] -= mat[i] * coef
        b[j] -= b[i] * coef

for i in range(len(mat) - 1, 0, -1):
    b[i] /= mat[i][i]
    mat[i] /= mat[i][i]
    for j in range(i):
        b[j] -= b[i] * mat[j][i]
        mat[j][i] = 0

b = [int(n) for n in b]
b[0] += 1
print(" ".join(map(str, b)))


Fixed submission:
N = int(input())
A = list(map(int, input().split()))
X = [0] * N

X[0] = sum(A) - 2 * (sum([A[i] for i in range(N) if i % 2 == 1]))

for i in range(N - 1):
	X[i + 1] = 2 * A[i] - X[i]

print(" ".join(map(str, X)))

Buggy python submission (verdict: Runtime Error):
import numpy as np
N = int(input())
A = list(map(int, input().split()))

x = np.identity(N)
y = np.identity(N)
y0 = y[0]
y = np.reshape(np.append(np.delete(y, 0, 0), y0), (N, N))
a = (x + y) / 2

b = np.array(A)
b = b.reshape((1, N))
b = b.transpose()

ans = np.linalg.solve(a, b)
ans = [int(n) for n in ans]

print(" ".join(map(str, ans)))


Fixed submission:
N = int(input())
A = list(map(int, input().split()))
X = [0] * N

X[0] = sum(A) - 2 * (sum([A[i] for i in range(N) if i % 2 == 1]))

for i in range(N - 1):
	X[i + 1] = 2 * A[i] - X[i]

print(" ".join(map(str, X)))

Buggy python submission (verdict: Runtime Error):
import numpy as np
N = int(input())
A = list(map(int, input().split()))

x = np.identity(N)
y = np.identity(N)
y0 = y[0]
y = np.delete(y, 0, 0)
y = np.append(y, y0)
y = np.reshape(y, (N, N))
a = x + y
b = np.array(A)

ans = np.linalg.solve(a, b)
ans = [int(n * 2) for n in ans]

print(" ".join(map(str, ans)))


Fixed submission:
N = int(input())
A = list(map(int, input().split()))
X = [0] * N

X[0] = sum(A) - 2 * (sum([A[i] for i in range(N) if i % 2 == 1]))

for i in range(N - 1):
	X[i + 1] = 2 * A[i] - X[i]

print(" ".join(map(str, X)))
Buggy python submission (verdict: Runtime Error):
from operator import mul
from functools import reduce


def cmb(n, r):
	r = min(n - r, r)
	if r == 0:
		return 1
	numer = reduce(mul, range(n, n - r, -1))
	denom = reduce(mul, range(1, r + 1))
	return numer // denom % INF


N, K = map(int, input().split())
INF = 10 ** 9 + 7

for i in range(1, K + 1):
	print(cmb(K - 1, i - 1) * cmb(N - K + 1, i) % INF)


Fixed submission:
from operator import mul
from functools import reduce


def cmb(n, r):
	r = min(n - r, r)
	if r == 0:
		return 1
	numer = reduce(mul, range(n, n - r, -1))
	denom = reduce(mul, range(1, r + 1))
	return numer // denom % INF


N, K = map(int, input().split())
INF = 10 ** 9 + 7

for i in range(1, K + 1):
	if N - K + 1 >= i:
		print(cmb(K - 1, i - 1) * cmb(N - K + 1, i) % INF)
	else:
		print(0)
Buggy python submission (verdict: Runtime Error):
# 締切の早いものから順番に見ていくのが最適戦略
N = int(input())
X = [list(map(int, input().split())) for _ in range(N)]
X = sorted(X, key=lambda x: x[1])  # B (締切の早い順にソート)

res = 0
for i in range(N):
    res += A[i]
    if res > B[i]:
        print("No")
        exit()
print("Yes")


Fixed submission:
N = int(input())
X = sorted([list(map(int, input().split())) for _ in range(N)], key = lambda x: x[1])
a = [0] * N
a[0] = X[0][0]
for i in range(1, N):
	a[i] = a[i - 1] + X[i][0]
for j in range(N):
	if a[j] > X[j][1]:
		print("No")
		exit()
print("Yes")

Buggy python submission (verdict: Runtime Error):
# 締切の早いものから順番に見ていくのが最適戦略
N = int(input())
X = [list(map(int, input().split())) for _ in range(N)]
X = sorted(X, key=lambda x: x[1])  # B (締切の早い順にソート)
diff = 0
for i in range(N):
    diff += B[i] - A[i]
    if diff < 0:
        print("No")
        exit()
print("Yes")


Fixed submission:
N = int(input())
X = sorted([list(map(int, input().split())) for _ in range(N)], key = lambda x: x[1])
a = [0] * N
a[0] = X[0][0]
for i in range(1, N):
	a[i] = a[i - 1] + X[i][0]
for j in range(N):
	if a[j] > X[j][1]:
		print("No")
		exit()
print("Yes")
Buggy python submission (verdict: Time Limit Exceeded):
s = input().replace("BC", "X")
indA = [i for i in range(len(s)) if s[i] == "A"]

ans = 0
for i in indA:
    while s[i] != "B" and s[i] != "C":
        ans += (s[i] == "X")
print(ans)


Fixed submission:
s = input()
ans = 0
s = s.replace("BC", "D")
cnt = 0
for i in range(len(s)):
	if s[i] == "A":
		cnt += 1
	elif s[i] == "D":
		ans += cnt
	else:
		cnt = 0
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
ans = 0
for i in range(len(s) - 2):
	if s[i] == "A" and s[i + 1] == "B" and s[i + 2] == "C":
		s[i], s[i + 1], s[i + 2] = "B", "C", "A"
		# print("".join(s))
		ans += 1
		j = 1
		if i > 0:
			while s[i - j] == "A":
				s[i - j], s[i - j + 1], s[i - j + 2] = "B", "C", "A"
				ans += 1
				# print("".join(s))
				if i - j == 0:
					break
				j += 1
		k = 3
		if i < len(s) - 4:
			while s[i + k] == "B" and s[i + k + 1] == "C":
				s[i + k - 1], s[i + k], s[i + k + 1] = "B", "C", "A"
				ans += 1
				# print("".join(s))
				if i + k + 2 > len(s) - 1:
					break
				k += 2
print(ans)


Fixed submission:
s = input()
ans = 0
s = s.replace("BC", "D")
cnt = 0
for i in range(len(s)):
	if s[i] == "A":
		cnt += 1
	elif s[i] == "D":
		ans += cnt
	else:
		cnt = 0
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
ans = 0
while "ABC" in s:
	ans += s.count("ABC")
	s = s.replace("ABC", "BCA")
print(ans)


Fixed submission:
s = input()
ans = 0
s = s.replace("BC", "D")
cnt = 0
for i in range(len(s)):
	if s[i] == "A":
		cnt += 1
	elif s[i] == "D":
		ans += cnt
	else:
		cnt = 0
print(ans)
Buggy python submission (verdict: Runtime Error):
R, G, B, N = map(int, input().split())
ans = 0
for x in range(N // R + 1):
	for y in range(N // G + 1):
		if (N - R * x - G * y) % B == 0 and 0 <= (N - R * x - G * y) // B <= N // B:
			ans += 1
print(ans)


Fixed submission:
N, K = map(int, input().split())
print(N - K + 1)
Buggy python submission (verdict: Time Limit Exceeded):
R, G, B, N = map(int, input().split())
ans = 0
for x in range(N // R + 1):
	for y in range(N // G + 1):
		if (N - R * x - G * y) % B == 0 and 0 <= (N - R * x - G * y) // B <= N // B:
			ans += 1
print(ans)


Fixed submission:
R ,G, B, N = map(int, input().split())
ans = 0
for r in range(N // R + 1):
	for g in range(N // G + 1):
		if (N - R * r - G * g) % B == 0 and 0 <= (N - R * r - G * g) // B <= N // B:
			ans += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
R ,G, B, N = map(int, input().split())
ans = 0
for r in range(N // R + 1):
	for g in range(N // G + 1):
		if (N - R * r - G * g) % B == 0 and 0 <= (N - R * r - G * g) // B <= N // B:
			ans += 1
print(ans)


Fixed submission:
R ,G, B, N = map(int, input().split())
ans = 0
for r in range(N // R + 1):
	for g in range(N // G + 1):
		if (N - R * r - G * g) % B == 0 and 0 <= (N - R * r - G * g) // B <= N // B:
			ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
import fractions
N = int(input())
A = list(map(int, input().split()))
# まずはA[0]以外のgcdをansとしておく
ans = A[1]
for i in range(2, N):
	ans = fractions.gcd(ans, A[i])
# つぎにA[0]と他の要素の2数のgcdをリストアップし、それが一番小さくなるindexをkとする
G = [A[0]]
for j in range(1, N):
	G.append(fractions.gcd(A[0], A[j]))
k = G.index(min(G))
# A[k]以外のgcdをtmpとしておく
if k == N - 1:
	B = A[: N - 1]
elif K == 0:
	B = A[1:]
else:
	B = A[: k] + A[k + 1:]
tmp = B[0]
for l in range(1, N - 1):
	tmp = fractions.gcd(tmp, B[l])
# ansとtmpの大きい方を出力
print(max(ans, tmp))


Fixed submission:
from fractions import gcd
N = int(input())
A = list(map(int, input().split()))
Asort = sorted(A)[:: -1]
L = [0] * N  #左からi番目までのgcdをメモった配列
R = [0] * N  #右からi番目までのgcdをメモった配列
L[0] = A[0]
R[0] = A[N - 1]
for i in range(1, N):
	L[i] = gcd(L[i - 1], A[i])
	R[i] = gcd(R[i - 1], A[N - 1 - i])
ans = max(L[N - 2], R[N - 2])
for j in range(1, N - 1):
	ans = max(ans, gcd(L[j - 1], R[N - j - 2]))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import fractions
import copy
N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(N):
	B = copy.copy(A)
	del B[i]
	tmp = B[0]
	for j in range(1, N - 1):
		tmp = fractions.gcd(tmp, B[j])
	ans = max(ans, tmp)
print(ans)


Fixed submission:
from fractions import gcd
N = int(input())
A = list(map(int, input().split()))
Asort = sorted(A)[:: -1]
L = [0] * N  #左からi番目までのgcdをメモった配列
R = [0] * N  #右からi番目までのgcdをメモった配列
L[0] = A[0]
R[0] = A[N - 1]
for i in range(1, N):
	L[i] = gcd(L[i - 1], A[i])
	R[i] = gcd(R[i - 1], A[N - 1 - i])
ans = max(L[N - 2], R[N - 2])
for j in range(1, N - 1):
	ans = max(ans, gcd(L[j - 1], R[N - j - 2]))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import fractions
N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(N):
	if i == N - 1:
		B = A[: N - 1]
	else:
		B = A[: i] + A[i + 1:]
	g = B[0]
	for j in range(1, N - 1):
		g = fractions.gcd(g, B[j])
	ans = max(ans, g)
print(ans)


Fixed submission:
from fractions import gcd
N = int(input())
A = list(map(int, input().split()))
Asort = sorted(A)[:: -1]
L = [0] * N  #左からi番目までのgcdをメモった配列
R = [0] * N  #右からi番目までのgcdをメモった配列
L[0] = A[0]
R[0] = A[N - 1]
for i in range(1, N):
	L[i] = gcd(L[i - 1], A[i])
	R[i] = gcd(R[i - 1], A[N - 1 - i])
ans = max(L[N - 2], R[N - 2])
for j in range(1, N - 1):
	ans = max(ans, gcd(L[j - 1], R[N - j - 2]))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
ans = N
for i in range(N + 1):
	ans = min(ans, S[: i].count("#") + S[i:].count("."))
print(ans)


Fixed submission:
N = int(input())
S = input()
A = [S.count(".")]
for i in range(N):
	if S[i] == "#":
		A.append(A[i] + 1)
	else:
		A.append(A[i] - 1)
print(min(A))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
A = []
for i in range(N + 1):
	A.append(S[: i].count("#") + S[i:].count("."))
print(min(A))


Fixed submission:
N = int(input())
S = input()
A = [S.count(".")]
for i in range(N):
	if S[i] == "#":
		A.append(A[i] + 1)
	else:
		A.append(A[i] - 1)
print(min(A))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
ans = min(S.count("#"), S.count("."))
for i in range(N):
	tmp = S[: i].count("#") + S[i:].count(".")
	if ans > tmp:
		ans = tmp
print(ans)


Fixed submission:
N = int(input())
S = input()
A = [S.count(".")]
for i in range(N):
	if S[i] == "#":
		A.append(A[i] + 1)
	else:
		A.append(A[i] - 1)
print(min(A))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
count1 = S.count("#")  #すべて白にする
count2 = S.count(".")  #すべて黒にする
A = []
for i in range(N):
	A.append(S[: i].count("#") + S[i:].count("."))
count = min(A)
print(min(count1, count2, count))


Fixed submission:
N = int(input())
S = input()
A = [S.count(".")]
for i in range(N):
	if S[i] == "#":
		A.append(A[i] + 1)
	else:
		A.append(A[i] - 1)
print(min(A))
Buggy python submission (verdict: Runtime Error):
S = input()
acgt = ["A", "C", "G", "T"]
cnts = []
cnt = 0
for i in range(len(S)):
	if S[i] in acgt:
		cnt += 1
		cnts.append(cnt)
	else:
		cnt = 0
print(max(cnts))


Fixed submission:
S = input()
acgt = ["A", "C", "G", "T"]
cnts = []
cnt = 0
for i in range(len(S)):
	if S[i] in acgt:
		cnt += 1
		cnts.append(cnt)
	else:
		cnts.append(cnt)
		cnt = 0
print(max(cnts))

Buggy python submission (verdict: Runtime Error):
S = input()
acgt = ["A", "C", "G", "T"]
cnts = []
tmp = 0
for i in range(len(S)):
	if S[i] in acgt:
		tmp += 1
	else:
		cnts.append(tmp)
		tmp = 0
print(max(cnts))


Fixed submission:
S = input()
acgt = ["A", "C", "G", "T"]
cnts = []
cnt = 0
for i in range(len(S)):
	if S[i] in acgt:
		cnt += 1
		cnts.append(cnt)
	else:
		cnts.append(cnt)
		cnt = 0
print(max(cnts))