Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from collections import Counter, defaultdict

N = int(input())
D = list(map(int, input().split()))
M = int(input())
T = list(map(int, input().split()))

memo = defaultdict(int)
for d in D:
    memo[d] += 1

for i in range(m):
    ti = T[i]
    if ti not in memo:
        print("NO")
        exit()
    if memo[ti] == 0:
        print("NO")
        exit()
    memo[ti] -= 1

print("YES")

Fixed submission:
from collections import Counter, defaultdict

N = int(input())
D = list(map(int, input().split()))
M = int(input())
T = list(map(int, input().split()))

memo = defaultdict(int)
for d in D:
    memo[d] += 1

for i in range(M):
    ti = T[i]
    if ti not in memo:
        print("NO")
        exit()
    if memo[ti] == 0:
        print("NO")
        exit()
    memo[ti] -= 1

print("YES")

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

N = int(input())
D = list(map(int, input().split()))
M = int(input())
T = list(map(int, input().split()))

Dnew = [elem for elem in D if elem in T]

c1 = Counter(Dnew)
c2 = Counter(T)

flag = True
for key in c2:
    if c2[key] > c1[key]:
        flag = False
        break

if flag:
    print("YES")
else:
    print("NO")

Fixed submission:
from collections import Counter, defaultdict

N = int(input())
D = list(map(int, input().split()))
M = int(input())
T = list(map(int, input().split()))

memo = defaultdict(int)
for d in D:
    memo[d] += 1

for i in range(M):
    ti = T[i]
    if ti not in memo:
        print("NO")
        exit()
    if memo[ti] == 0:
        print("NO")
        exit()
    memo[ti] -= 1

print("YES")
Buggy python submission (verdict: Runtime Error):
print((n // 2) * min(8 * q, 4 * h, 2 * s, d) + (n % 2) * min(4 * q, 2 * h, s))

Fixed submission:
q, h, s, d = map(int, input().split())
n = int(input())
print((n // 2) * min(8 * q, 4 * h, 2 * s, d) + (n % 2) * min(4 * q, 2 * h, s))
Buggy python submission (verdict: Time Limit Exceeded):
# https://atcoder.jp/contests/agc019/tasks/agc019_b
A = input()

ans = set({A})
n = len(A)
for i in range(n):
    for j in range(i + 1, n):
        new_A = A[:i] + A[i:j+1][::-1] + A[j+1:]
        # print(i, j, A, A[i:j+1], new_A)
        ans.add(new_A)

print(len(ans))

Fixed submission:
# https://atcoder.jp/contests/agc019/tasks/agc019_b
from collections import defaultdict

A = input()
n = len(A)
cA = defaultdict(int)

for ch in A:
    cA[ch] += 1

all_num = 1 + n * (n - 1) // 2

for _, v in cA.items():
    all_num -= v * (v - 1) // 2

print(all_num)
Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heapify, heappush, heappop

import sys
sys.setrecursionlimit(100000000)

n = int(input())
G = [[] for _ in range(n + 1)]

for _ in range(n - 1):
    ai, bi, ci = map(int, input().split())
    G[ai].append((bi, ci))
    G[bi].append((ai, ci))

Q, K = map(int, input().split())

# 頂点KからDFSする
d = [None for _ in range(n + 1)]
d[K] = 0

def dfs(v, dist):
    for (u, cvu) in G[v]:
        if d[u] is None:
            d[u] = dist + cvu
            dfs(u, dist + cvu)

dfs(K, 0)

for _ in range(Q):
    xi, yi = map(int, input().split())
    print(d[xi] + d[yi])


Fixed submission:
from heapq import heapify, heappush, heappop

import sys
sys.setrecursionlimit(100000000)

n = int(input())
G = [[] for _ in range(n + 1)]

for _ in range(n - 1):
    ai, bi, ci = map(int, input().split())
    G[ai].append((bi, ci))
    G[bi].append((ai, ci))

Q, K = map(int, input().split())

# # 頂点KからDFSする
# d = [None for _ in range(n + 1)]
# d[K] = 0

# def dfs(v, dist):
#     for (u, cvu) in G[v]:
#         if d[u] is None:
#             d[u] = dist + cvu
#             dfs(u, dist + cvu)

# dfs(K, 0)

# 頂点KからDFSする (heap ver.)
queue = []
d = [None for _ in range(n + 1)]
heappush(queue, (0, K, -1))
while len(queue) > 0:
    dist, index, parent = heappop(queue)
    if d[index] is not None:
        continue
    d[index] = dist
    for (u, cvu) in G[index]:
        if u == parent:
            continue
        heappush(queue, (dist + cvu, u, index))

for _ in range(Q):
    xi, yi = map(int, input().split())
    print(d[xi] + d[yi])

Buggy python submission (verdict: Runtime Error):
from heapq import heapify, heappush, heappop

n = int(input())
G = [[] for _ in range(n + 1)]

for _ in range(n - 1):
    ai, bi, ci = map(int, input().split())
    G[ai].append((bi, ci))
    G[bi].append((ai, ci))

Q, K = map(int, input().split())

# 頂点KからDFSする
d = [None for _ in range(n + 1)]

def dfs(v, dist):
    for (u, cvu) in G[v]:
        if d[u] is None:
            d[u] = dist + cvu
            dfs(u, dist + cvu)

d[K] = 0
dfs(K, 0)

for _ in range(Q):
    xi, yi = map(int, input().split())
    print(d[xi] + d[yi])


Fixed submission:
from heapq import heapify, heappush, heappop

import sys
sys.setrecursionlimit(100000000)

n = int(input())
G = [[] for _ in range(n + 1)]

for _ in range(n - 1):
    ai, bi, ci = map(int, input().split())
    G[ai].append((bi, ci))
    G[bi].append((ai, ci))

Q, K = map(int, input().split())

# # 頂点KからDFSする
# d = [None for _ in range(n + 1)]
# d[K] = 0

# def dfs(v, dist):
#     for (u, cvu) in G[v]:
#         if d[u] is None:
#             d[u] = dist + cvu
#             dfs(u, dist + cvu)

# dfs(K, 0)

# 頂点KからDFSする (heap ver.)
queue = []
d = [None for _ in range(n + 1)]
heappush(queue, (0, K, -1))
while len(queue) > 0:
    dist, index, parent = heappop(queue)
    if d[index] is not None:
        continue
    d[index] = dist
    for (u, cvu) in G[index]:
        if u == parent:
            continue
        heappush(queue, (dist + cvu, u, index))

for _ in range(Q):
    xi, yi = map(int, input().split())
    print(d[xi] + d[yi])
Buggy python submission (verdict: Runtime Error):
from fractions import gcd

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

M = max(A)
G = gcd(A[0], A[1])
for i in range(2, N):
    G = gcd(G, A[i])
# print(M, G)

if K <= M and K % G == 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Fixed submission:
from fractions import gcd

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

M = max(A)
G = A[0]
for i in range(1, N):
    G = gcd(G, A[i])

if K <= M and K % G == 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Buggy python submission (verdict: Runtime Error):
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

if K in A:
    print("POSSIBLE")
    exit(0)

An = A.copy()
for i in range(len(A)):
    for j in range(i + 1, len(A)):
        aij = abs(A[i] - A[j])
        if aij not in An:
            An.append(aij)

if K in A:
    print("POSSIBLE")
    exit(0)

while A != An:
    A = An.copy()
    for i in range(len(A)):
        for j in range(i + 1, len(A)):
            aij = abs(A[i] - A[j])
            if aij not in An:
                An.append(aij)

    # print(A)
    # print(An)

    if K in A:
        print("POSSIBLE")
        exit(0)

if K in An:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Fixed submission:
from fractions import gcd

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

M = max(A)
G = A[0]
for i in range(1, N):
    G = gcd(G, A[i])

if K <= M and K % G == 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
Buggy python submission (verdict: Runtime Error):
n, A, B = map(int, input().split())
if A > B:
  print(0)
elif n == 1:
  if A != B:
    print(0)
  else:
    print(1)
else:
  print((B - A) * (N - 2) + 1)

Fixed submission:
n, A, B = map(int, input().split())
if A > B:
  print(0)
elif n == 1:
  if A != B:
    print(0)
  else:
    print(1)
else:
  print((B - A) * (n - 2) + 1)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int, input().split()))
A.sort()


# print(A)
t = 0
for k in range(1, n):
    # print("A[0:{}]={}".format(k, A[:k]))
    # print("{} <? {}".format(2 * sum(A[:k]), A[k]))
    if 2 * sum(A[:k]) < A[k]:
        t = max(t, k)

print(n - t)



Fixed submission:
n = int(input())
A = list(map(int, input().split()))
A.sort()


# print(A)
# t = 0
# for k in range(1, n):
#     # print("A[0:{}]={}".format(k, A[:k]))
#     # print("{} <? {}".format(2 * sum(A[:k]), A[k]))
#     if 2 * sum(A[:k]) < A[k]:
#         t = max(t, k)

t = 0
value = A[0]
for k in range(1, n):
    # print("A[0:{}]={}".format(k, A[:k]))
    # print("{} <? {}".format(2 * sum(A[:k]), A[k]))
    if 2 * value < A[k]:
        t = max(t, k)
    value += A[k]


print(n - t)
Buggy python submission (verdict: Time Limit Exceeded):
from math import ceil
N = int(input())
A, B = [], []
for _ in range(N):
    ai, bi = map(int, input().split())
    A.append(ai)
    B.append(bi)

# print(" ", A, B)

# 後ろから順番にすれば良い気がする (iのボタンは1からiまでしか作用しないので)
count = 0
for j in range(N - 1, -1, -1):
    # j番目の足りない回数を決定
    if A[j] % B[j] == 0:
        continue
    if A[j] < B[j]:
        cj = B[j] - A[j]
    else:
        cj = ((A[j] + B[j] - 1) // B[j]) * B[j] - A[j]
    count += cj

    # cj回押した回数，数値を反映
    for k in range(j, -1, -1):
        A[k] += cj

    # print(j, cj, A, B)
print(count)

Fixed submission:
from math import ceil
N = int(input())
A, B = [], []
for _ in range(N):
    ai, bi = map(int, input().split())
    A.append(ai)
    B.append(bi)

# 回数だけ確定する
# 後ろから順番にすれば良い気がする (iのボタンは1からiまでしか作用しないので)
count = 0
for j in range(N - 1, -1, -1):
    if (count + A[j]) % B[j] == 0:
        continue
    else:
        # 足りない分をカウントする
        count += B[j] - (count + A[j]) % B[j]
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
# https://atcoder.jp/contests/agc005/tasks/agc005_a
# 半分はS, 半分はTからなる文字列
# STを取り除く，どうなるか (無限回)

X = input()
j = len(X) - 1
i = X.find("ST")

while i >= 0:
    X = X[:i] + X[i + 2:]
    i = X.find("ST")

print(len(X))

Fixed submission:
# https://atcoder.jp/contests/agc005/tasks/agc005_a
#
# Stackでやる

from collections import deque

stack = deque([])
X = input()

for ch in X:
    if ch == 'S':
        stack.append(ch)
    elif ch == 'T':
        if len(stack) == 0:
            stack.append(ch)
        elif stack[-1] == 'T':
            stack.append(ch)
        elif stack[-1] == 'S':
            stack.pop()

print(len(stack))
Buggy python submission (verdict: Runtime Error):
s = input()
print("{} {}".format(s[:4], s[4:])

Fixed submission:
s = input()
print("{} {}".format(s[:4], s[4:]))
Buggy python submission (verdict: Time Limit Exceeded):
# https://atcoder.jp/contests/abc044/tasks/arc060_a

from itertools import combinations


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

# print(n, a)
# print(x)
ans = 0
for k in range(1, n + 1):
    for comb in combinations(range(n), k):
        avg = 0
        for c in comb:
            avg += x[c]
        avg /= len(comb)
        if avg == a:
            ans += 1
print(ans)

Fixed submission:
# DP

# https://atcoder.jp/contests/abc044/tasks/arc060_a

from itertools import combinations


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


# dp[j][k][s] (0 <= j <= N, 0 <= k <= N, 0 <= s <= NX)
# dp[j][k][s] = x1,...,xjまでからk枚使って，合計をsにする選び方の総数
# dp[0][0][0] = 1
# j >= 1, s < xjのとき，dp[j][k][s] = dp[j-1][k][s] (xjは使わない)
# j >= 1, k >= 1, s >= xjのとき，dp[j][k][s] = dp[j-1][k][s] + dp[j-1][k-1][s-xj]
# ... 1枚少なく使ってxjを入れる + 使わない
# それ以外 0

dp = [
    [[0 for _ in range(n * X + 1)] for _ in range(n + 2)]
    for _ in range(n + 2)
]

dp[0][0][0] = 1
for i in range(n):
    for j in range(n+1):
        for k in range(n * X + 1):
            if k < x[i]:
                dp[i + 1][j][k] = dp[i][j][k]
            else:
                dp[i + 1][j][k] = dp[i][j][k] + dp[i][j-1][k-x[i]]
ans = 0
for i in range(1, n + 1):
    ans += dp[n][i][i*a]
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys

inp = [int(x) for x in sys.stdin.read().split()]; ii = 0

rows, cols, k = inp[ii:ii+3]; ii += 3
items = [[] for _ in range(rows+1)]
best = [0]*(cols+1)
for _ in range(k):
	inp[ii:ii+3]; ii += 3
	items[r].append([c, v])
for i in range(rows+1):
	items[i].sort()
ans = 0
for r in range(1, rows+1):
	dp = []
	best1, best2 = 0, 0
	Row = items[r]
	for c, v in Row:
		v1 = best[c] + v
		v2 = best1 + v
		v3 = best2 + v
		V = v1
		if V < v2:
			V = v2
		if V < v3:
			V = v3
		dp.append(V)
		if v1 > best1:
			best1 = v1
		if v2 > best2:
			best2 = v2
		if ans < V:
			ans = V
	for j in range(len(dp)):
		if best[Row[j][0]] < dp[j]:
			best[Row[j][0]] = dp[j]
	for j in range(2, cols+1):
		if best[j] < best[j-1]:
			best[j] = best[j-1]
print(ans)


Fixed submission:
rows, cols, k = map(int, input().split())
items = [[] for _ in range(rows+1)]
best = [0]*(cols+1)
for _ in range(k):
	r, c, v = map(int, input().split())
	items[r].append([c, v])
for i in range(rows+1):
	items[i].sort()
ans = 0
for r in range(1, rows+1):
	dp = []
	best1, best2 = 0, 0
	Row = items[r]
	for c, v in Row:
		v1 = best[c] + v
		v2 = best1 + v
		v3 = best2 + v
		V = max(v1, v2, v3)
		dp.append(V)
		if v1 > best1:
			best1 = v1
		if v2 > best2:
			best2 = v2
		if ans < V:
			ans = V
	for j in range(len(dp)):
		if best[Row[j][0]] < dp[j]:
			best[Row[j][0]] = dp[j]
	for j in range(2, cols+1):
		if best[j] < best[j-1]:
			best[j] = best[j-1]
print(ans)

Buggy python submission (verdict: Runtime Error):
import sys

inp = [int(x) for x in sys.stdin.readline()]; ii = 0

rows, cols, k = inp[ii:ii+3]; ii += 3
items = [[] for _ in range(rows+1)]
best = [0]*(cols+1)
for _ in range(k):
	inp[ii:ii+3]; ii += 3
	items[r].append([c, v])
for i in range(rows+1):
	items[i].sort()
ans = 0
for r in range(1, rows+1):
	dp = []
	best1, best2 = 0, 0
	Row = items[r]
	for c, v in Row:
		v1 = best[c] + v
		v2 = best1 + v
		v3 = best2 + v
		V = v1
		if V < v2:
			V = v2
		if V < v3:
			V = v3
		dp.append(V)
		if v1 > best1:
			best1 = v1
		if v2 > best2:
			best2 = v2
		if ans < V:
			ans = V
	for j in range(len(dp)):
		if best[Row[j][0]] < dp[j]:
			best[Row[j][0]] = dp[j]
	for j in range(2, cols+1):
		if best[j] < best[j-1]:
			best[j] = best[j-1]
print(ans)


Fixed submission:
rows, cols, k = map(int, input().split())
items = [[] for _ in range(rows+1)]
best = [0]*(cols+1)
for _ in range(k):
	r, c, v = map(int, input().split())
	items[r].append([c, v])
for i in range(rows+1):
	items[i].sort()
ans = 0
for r in range(1, rows+1):
	dp = []
	best1, best2 = 0, 0
	Row = items[r]
	for c, v in Row:
		v1 = best[c] + v
		v2 = best1 + v
		v3 = best2 + v
		V = max(v1, v2, v3)
		dp.append(V)
		if v1 > best1:
			best1 = v1
		if v2 > best2:
			best2 = v2
		if ans < V:
			ans = V
	for j in range(len(dp)):
		if best[Row[j][0]] < dp[j]:
			best[Row[j][0]] = dp[j]
	for j in range(2, cols+1):
		if best[j] < best[j-1]:
			best[j] = best[j-1]
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())

z_vec = [0] * n
w_vec = [0] * n


for i in range(0, n + 1):
    line = input()
    tmp = line.split()
    z_vec[i] = int(tmp[0]) + int(tmp[1])
    w_vec[i] = int(tmp[0]) - int(tmp[1])

z_ans = max(z_vec) - min(z_vec)
w_ans = max(w_vec) - min(w_vec)


print(f'{max(z_ans, w_ans)}')

Fixed submission:
n = int(input())

p_one = input()
p_one_list = p_one.split(' ')

zmax = int(p_one_list[0]) + int(p_one_list[1])
zmin = int(p_one_list[0]) + int(p_one_list[1])
wmax = int(p_one_list[0]) - int(p_one_list[1])
wmin = int(p_one_list[0]) - int(p_one_list[1])


for i in range(1, n):
    line = input()
    tmp = line.split(' ')
    z = int(tmp[0]) + int(tmp[1])
    w = int(tmp[0]) - int(tmp[1])
    zmax = max(zmax, z)
    wmax = max(wmax, w)
    zmin = min(zmin, z)
    wmin = min(wmin, w)


z_ans = zmax - zmin
w_ans = wmax - wmin


print(f'{max(z_ans, w_ans)}')

Buggy python submission (verdict: Runtime Error):
n = int(input())

z_vec = [0] * n
w_vec = [0] * n


for i in range(0, n + 1):
    tmp = input().split()
    z_vec[i] = int(tmp[0]) + int(tmp[1])
    w_vec[i] = int(tmp[0]) - int(tmp[1])

z_ans = max(z_vec) - min(z_vec)
w_ans = max(w_vec) - min(w_vec)


print(f'{max(z_ans, w_ans)}')

Fixed submission:
n = int(input())

p_one = input()
p_one_list = p_one.split(' ')

zmax = int(p_one_list[0]) + int(p_one_list[1])
zmin = int(p_one_list[0]) + int(p_one_list[1])
wmax = int(p_one_list[0]) - int(p_one_list[1])
wmin = int(p_one_list[0]) - int(p_one_list[1])


for i in range(1, n):
    line = input()
    tmp = line.split(' ')
    z = int(tmp[0]) + int(tmp[1])
    w = int(tmp[0]) - int(tmp[1])
    zmax = max(zmax, z)
    wmax = max(wmax, w)
    zmin = min(zmin, z)
    wmin = min(wmin, w)


z_ans = zmax - zmin
w_ans = wmax - wmin


print(f'{max(z_ans, w_ans)}')
Buggy python submission (verdict: Time Limit Exceeded):
n = eval(input())
a = input().split()
prod = 1
for i in range(0, n):
    prod *= int(a[i])
if prod > 1e18:
    print(-1)
else:
    print(prod)

Fixed submission:
n = eval(input())
a = input().split()
prod = 1
for i in range(0, n):
    a[i] = int(a[i])
a = sorted(a)
for i in range(0, n):
    prod *= int(a[i])
    if prod > 1e18:
        break
if prod > 1e18:
    print(-1)
else:
    print(prod)
Buggy python submission (verdict: Runtime Error):
n=int(input())
h=[int(i) for i in input().split()]

dp=[10000 for i in range(n+1)]
dp[0]=0
for i in range(n-1):
    dp[i+1]=min(dp[i+1],dp[i]+abs(h[i]-h[i+1]))
    dp[i+2]=min(dp[i+2],dp[i]+abs(h[i]-h[i+2]))
print(dp[n-1])

Fixed submission:
n=int(input())
h=[int(i) for i in input().split()]
dp=[0,abs(h[1]-h[0])]

for ind in range(2,len(h)):
    a=abs(h[ind-1]-h[ind])
    b=abs(h[ind-2]-h[ind])
    if(a+dp[ind-1]>b+dp[ind-2]):
        dp.append(b+dp[ind-2])
    else:
        dp.append(a+dp[ind-1])
print(dp[len(dp)-1])

Buggy python submission (verdict: Runtime Error):
n=int(input())
h=[int(i) for i in input().split()]
dp=[10000 for i in range(n)]
dp[0]=0
dp[1]=abs(h[1]-h[0])
dp[2]=abs(h[2]-h[0])

for i in range(1,len(h)-2):
    x=abs(h[i+1]-h[i])+dp[i]
    y=abs(h[i+2]-h[i])+dp[i]
    if(dp[i+1]>x):
      dp[i+1]=x
    if(dp[i+2]>y):
      dp[i+2]=y

if(dp[n-1]>abs(h[n-1]-h[n-2])+dp[n-2]):
	dp[n-1]=abs(h[n-1]-h[n-2])+dp[n-2]
print(dp[n-1])
    


Fixed submission:
n=int(input())
h=[int(i) for i in input().split()]
dp=[0,abs(h[1]-h[0])]

for ind in range(2,len(h)):
    a=abs(h[ind-1]-h[ind])
    b=abs(h[ind-2]-h[ind])
    if(a+dp[ind-1]>b+dp[ind-2]):
        dp.append(b+dp[ind-2])
    else:
        dp.append(a+dp[ind-1])
print(dp[len(dp)-1])
Buggy python submission (verdict: Runtime Error):
import math

def lcm(a,b):
    return a*b //math.gcd(a,b)

n=int(input())
t=[]
for i in range(n):
    t.append(int(input()))
t.sort()
if(n==1):
    print(t[0])
    exit()
ans=lcm(t[0],t[1])
if(n==2):
    print(ans)
    exit()
for i in range(2,n):
    ans=lcm(ans,t[i])
print(ans)



Fixed submission:
def gcd(x,y):
  if x>y: x,y = y,x
  while x:
    x,y = y%x, x
  return y

def lcm(a,b):
    return a*b //gcd(a,b)

n=int(input())
t=[]
for i in range(n):
    t.append(int(input()))
t.sort()
if(n==1):
    print(t[0])
    exit()
ans=lcm(t[0],t[1])
if(n==2):
    print(ans)
    exit()
for i in range(2,n):
    ans=lcm(ans,t[i])
print(ans)

Buggy python submission (verdict: Runtime Error):

def gcd(x,y):
  if x>y: x,y = y,x
  while x:
    x,y = y%x, x
  return y

def lcm(a,b):
    return int(a*b /gcd(a,b))

n=int(input())
t=[]
for i in range(n):
    t.append(int(input()))
t.sort()
if(n==1):
    print(t[0])
    exit()
ans=lcm(t[0],t[1])
if(n==2):
    print(ans)
    exit()
for i in range(2,n):
    ans=lcm(ans,t[i])
print(ans)



Fixed submission:
def gcd(x,y):
  if x>y: x,y = y,x
  while x:
    x,y = y%x, x
  return y

def lcm(a,b):
    return a*b //gcd(a,b)

n=int(input())
t=[]
for i in range(n):
    t.append(int(input()))
t.sort()
if(n==1):
    print(t[0])
    exit()
ans=lcm(t[0],t[1])
if(n==2):
    print(ans)
    exit()
for i in range(2,n):
    ans=lcm(ans,t[i])
print(ans)

Buggy python submission (verdict: Runtime Error):
import math
def lcm(a,b):
    return int(a*b /math.gcd(a,b))

n=int(input())
t=[]
for i in range(n):
    t.append(int(input()))
t.sort()
if(n==1):
    print(t[0])
    exit()
ans=lcm(t[0],t[1])
if(n==2):
    print(ans)
    exit()
for i in range(2,n):
    ans=lcm(ans,t[i])
print(ans)



Fixed submission:
def gcd(x,y):
  if x>y: x,y = y,x
  while x:
    x,y = y%x, x
  return y

def lcm(a,b):
    return a*b //gcd(a,b)

n=int(input())
t=[]
for i in range(n):
    t.append(int(input()))
t.sort()
if(n==1):
    print(t[0])
    exit()
ans=lcm(t[0],t[1])
if(n==2):
    print(ans)
    exit()
for i in range(2,n):
    ans=lcm(ans,t[i])
print(ans)

Buggy python submission (verdict: Runtime Error):
import math
def lcm(a,b):
    return int(a*b /math.gcd(a,b))

n=int(input())
t=[]
for i in range(n):
    t.append(int(input()))
t.sort()
ans=lcm(t[0],t[1])
for i in range(2,n-1):
    ans=lcm(ans,t[i])
print(ans)



Fixed submission:
def gcd(x,y):
  if x>y: x,y = y,x
  while x:
    x,y = y%x, x
  return y

def lcm(a,b):
    return a*b //gcd(a,b)

n=int(input())
t=[]
for i in range(n):
    t.append(int(input()))
t.sort()
if(n==1):
    print(t[0])
    exit()
ans=lcm(t[0],t[1])
if(n==2):
    print(ans)
    exit()
for i in range(2,n):
    ans=lcm(ans,t[i])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import math
n,m=[int(i) for i in input().split()]
if(abs(n-m)>1):
    print(0)
    exit()

def is_even(n):
    if(n%2==0):
        return True
    else:
        return False
if(is_even(n) and is_even(m) or not is_even(n) and not is_even(m)):
    print(math.factorial(n)*math.factorial(m)*2)
    exit()
else:
    print(math.factorial(n)*math.factorial(m))
    exit()
# if(is_even(n) and is_even(m)):
#     print(math.factorial(n)*math.factorial(m)*2)
#     exit()
# elif(is_even(n) and not is_even(m)):
#     print(math.factorial(n)*math.factorial(m))
#     exit()
# elif(not is_even(n) and is_even(m)):
#     print(math.factorial(m)*math.factorial(n))
#     exit()
# elif(not is_even(n) and not is_even(m)):
#     print(math.factorial(m)*math.factorial(n)*2)
#     exit()

Fixed submission:
import math
n,m=[int(i) for i in input().split()]
if(abs(n-m)>1):
    print(0)
    exit()

def is_even(n):
    if(n%2==0):
        return True
    else:
        return False
if(is_even(n) and is_even(m) or not is_even(n) and not is_even(m)):
    print(math.factorial(n)*math.factorial(m)*2%(10**9+7))
    exit()
else:
    print(math.factorial(n)*math.factorial(m)%(10**9+7))
    exit()
# if(is_even(n) and is_even(m)):
#     print(math.factorial(n)*math.factorial(m)*2)
#     exit()
# elif(is_even(n) and not is_even(m)):
#     print(math.factorial(n)*math.factorial(m))
#     exit()
# elif(not is_even(n) and is_even(m)):
#     print(math.factorial(m)*math.factorial(n))
#     exit()
# elif(not is_even(n) and not is_even(m)):
#     print(math.factorial(m)*math.factorial(n)*2)
#     exit()

Buggy python submission (verdict: Time Limit Exceeded):
import math
n,m=[int(i) for i in input().split()]
if(abs(n-m)>1):
    print(0)
    exit()
    
def is_even(n):
    if(n%2==0):
        return True
    else:
        return False

if(is_even(n) and is_even(m)):
    print(math.factorial(n)*math.factorial(m)*2)
    exit()
elif(is_even(n) and not is_even(m)):
    print(math.factorial(n)*math.factorial(m))
    exit()
elif(not is_even(n) and is_even(m)):
    print(math.factorial(m)*math.factorial(n))
    exit()
elif(not is_even(n) and not is_even(m)):
    print(math.factorial(m)*math.factorial(n)*2)
    exit()

Fixed submission:
import math
n,m=[int(i) for i in input().split()]
if(abs(n-m)>1):
    print(0)
    exit()

def is_even(n):
    if(n%2==0):
        return True
    else:
        return False
if(is_even(n) and is_even(m) or not is_even(n) and not is_even(m)):
    print(math.factorial(n)*math.factorial(m)*2%(10**9+7))
    exit()
else:
    print(math.factorial(n)*math.factorial(m)%(10**9+7))
    exit()
# if(is_even(n) and is_even(m)):
#     print(math.factorial(n)*math.factorial(m)*2)
#     exit()
# elif(is_even(n) and not is_even(m)):
#     print(math.factorial(n)*math.factorial(m))
#     exit()
# elif(not is_even(n) and is_even(m)):
#     print(math.factorial(m)*math.factorial(n))
#     exit()
# elif(not is_even(n) and not is_even(m)):
#     print(math.factorial(m)*math.factorial(n)*2)
#     exit()