Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from math import ceil
N, M = map(int, input().split())
A = list(map(int, input().split()))

# 2で割ったものに置き換え
A = [a // 2 for a in A]

# 各要素について、2で割り切れる回数が等しいかチェック
count_div_2 = None
for a in A:
    cnt = 0
    while a % 2 == 0:
        a //= 2
        cnt += 1

    if count_div_2 is None:
        count_div_2 = cnt
    elif cnt != count_div_2:
        print(0)
        exit()

# LCM計算
while len(A) > 1:
    a, b = A.pop(), A.pop()
    my_lcm = lcm(a, b)

    # Mを超えたlcmは意味がない
    if my_lcm > M:
        print(0)
        exit()

    A.append(my_lcm)


print(ceil(M // A[0] / 2))


Fixed submission:
from math import ceil
from fractions import gcd

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

# 2で割ったものに置き換え
A = [a // 2 for a in A]


def lcm(x, y):
    return x*(y//gcd(x, y))


# 各要素について、2で割り切れる回数が等しいかチェック
count_div_2 = None
for a in A:
    cnt = 0
    while a % 2 == 0:
        a //= 2
        cnt += 1

    if count_div_2 is None:
        count_div_2 = cnt
    elif cnt != count_div_2:
        print(0)
        exit()

# LCM計算
while len(A) > 1:
    a, b = A.pop(), A.pop()
    my_lcm = lcm(a, b)

    # Mを超えたlcmは意味がない
    if my_lcm > M:
        print(0)
        exit()

    A.append(my_lcm)


print(ceil(M // A[0] / 2))
Buggy python submission (verdict: Runtime Error):
import math

A, B = map(int, input().split())

print(A*B//math.gcd(A, B))


Fixed submission:
import fractions

A, B = map(int, input().split())

print(A*B//fractions.gcd(A, B))

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

A, B = map(int, input().split())

print(int(A*B/math.gcd(A, B)))


Fixed submission:
import fractions

A, B = map(int, input().split())

print(A*B//fractions.gcd(A, B))
Buggy python submission (verdict: Runtime Error):
def div_with_mod(x, y, mod):
    # Fermat's little theorem
    return x*pow(y, mod - 2, mod)


def comb(n, r, mod):
    # calculates C(n,r) with mod (assuming mod is prime)
    nc = n
    for rc in range(1, r):
        nc -= 1
        n = n*nc % mod
        r = r*rc % mod

    return div_with_mod(n, r, mod)


x, y = map(int, input().split())

j = 2*x-y
if j % 3:
    print(0)
    exit()
j //= 3
i = x - 2*j
if i < 0 or j < 0:
    print(0)
    exit()

ans = comb(i+j, i)
print(ans)


Fixed submission:
def comb(n, m, p=10**9+7):
    if n < m:
        return 0
    if n < 0 or m < 0:
        return 0
    m = min(m, n-m)
    top = bot = 1
    for i in range(m):
        top = top*(n-i) % p
        bot = bot*(i+1) % p
    bot = pow(bot, p-2, p)
    return top*bot % p


x, y = map(int, input().split())

j = 2*x-y
if j % 3:
    print(0)
    exit()
j //= 3
i = x - 2*j
if i < 0 or j < 0:
    print(0)
    exit()

ans = comb(i+j, i)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

Alist = [int(input()) for i in range(N)]

for i in range(N):
    print(max(Alist[:i]+Alist[i+1:]))


Fixed submission:
N = int(input())

Alist = [int(input()) for i in range(N)]

Blist = sorted(Alist, reverse=True)

for i in range(N):
    if Alist[i] == Blist[0]:
        print(Blist[1])
    else:
        print(Blist[0])
Buggy python submission (verdict: Runtime Error):
import math


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


def count(X, C, D):
    ret = X - (X//C + X//D - X//lcm(C, D))
    return ret


def main():
    A, B, C, D = map(int, input().split())
    ans = count(B, C, D) - count(A-1, C, D)
    print(ans)


if __name__ == "__main__":
    main()


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


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


def count(X, C, D):
    ret = X - (X//C + X//D - X//lcm(C, D))
    return ret


def main():
    A, B, C, D = map(int, input().split())
    ans = count(B, C, D) - count(A-1, C, D)
    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
C - GCD on Blackboard。
累積和を使ういい問題だが、難しい。

```python

from fractions import gcd

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

left = [0]*n
right = [0]*n

# 取り除く点を除いたGCDの累積
# 引き算できないので、両端から求めてそれぞれのgcdを取る
for i in range(n-1):
    left[i+1] = gcd(left[i], A[i])
    right[n-i-2] = gcd(right[n-i-1], A[n-i-1])

ans = 0
for i in range(n):
    ans = max(ans, gcd(left[i], right[i]))
print(ans)


```

N**2分の計算量がかかる解法は比較的すぐに思いつく。

Fixed submission:
from fractions import gcd

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

left = [0]*n
right = [0]*n

for i in range(n-1):
    left[i+1] = gcd(left[i], A[i])
    right[n-i-2] = gcd(right[n-i-1], A[n-i-1])

ans = 0
for i in range(n):
    ans = max(ans, gcd(left[i], right[i]))
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
Hlist = list(map(int, input().split()))

H1 = Hlist[0]
H2 = Hlist[1]

ans = 1
if H2 >= H1:
    ans += 1

for i in range(2, N):
    if Hlist[i] >= H1 and Hlist[i] >= H2 and Hlist[i] >= Hlist[i-1]:
        ans += 1

print(ans)


Fixed submission:
N = int(input())
H = list(map(int, (input().split())))
c = 0
nax = 0
for i in range(N):
    nax = max(nax, H[i])
    if H[i] == nax:
        c += 1
print(c)
Buggy python submission (verdict: Runtime Error):


def solve():

    D = int(input())

    if D == 25:
        print(`Christmas`)
    else if D == 24:
        print(`Christmas Eve`)
    else if D == 23:
        print(`Christmas Eve Eve`)
    else if D == 22:
        print(`Christmas Eve Eve Eve`)


if __name__ == "__main__":
    solve()


Fixed submission:

def solve():

    D = int(input())

    if D == 25:
        print("Christmas")
    elif D == 24:
        print("Christmas Eve")
    elif D == 23:
        print("Christmas Eve Eve")
    elif D == 22:
        print("Christmas Eve Eve Eve")


if __name__ == "__main__":
    solve()
Buggy python submission (verdict: Runtime Error):


def solve():

    N, K = map(int, input().split())
    hlist = [int(input()) for i in range(N)]

    # sortして走破？
    hlist.sort()
    l = []

    for i in range(N-K+1):
        l.append(hlist(i+K-1)-hlist(i))

    print(min(l))


if __name__ == "__main__":
    solve()


Fixed submission:


def solve():

    N, K = map(int, input().split())
    hlist = [int(input()) for i in range(N)]

    # sortして走破？
    hlist.sort()
    l = []

    for i in range(N-K+1):
        l.append(hlist[i+K-1]-hlist[i])

    print(min(l))


if __name__ == "__main__":
    solve()
Buggy python submission (verdict: Runtime Error):


import collections


def solve():

    S = list(input())
    K = int(input())

    passed = 5000000000000000

    if K < passed:
        if S[0] != "1":
            print(S[0])
        else:
            print(S[1])
        exit()

    for s in S:
        if K < int(s) * passed:
            print(s)
            break
        K = K - (int(s) * passed)


if __name__ == "__main__":
    solve()


Fixed submission:


import collections


def solve():

    S = list(input())
    K = int(input())

    for i in range(K):
        if S[i] != "1":
            print(S[i])
            break
    else:
        print(1)


if __name__ == "__main__":
    solve()
Buggy python submission (verdict: Runtime Error):
import math

N = int(input())

print(2*N//math.gcd(2, N))


Fixed submission:


def solve():
    N = int(input())

    if N % 2 == 0:
        print(N)
    else:
        print(N*2)


# Solve
if __name__ == "__main__":
    solve()
Buggy python submission (verdict: Runtime Error):
print(f"Christmas {' '.join(['Eve'] * (25 - int(input())))}".strip())


Fixed submission:
print("Christmas {}".format(" ".join(['Eve'] * (25 - int(input())))).strip())
Buggy python submission (verdict: Runtime Error):
print(int(input()) + int(input()) / 2)

Fixed submission:
X, Y = [int(x) for x in input().split()]
print(X + Y // 2)
Buggy python submission (verdict: Runtime Error):
print("Hello World" if input() == "1" int(input()) + int(input()))


Fixed submission:
print("Hello World" if input() == "1" else int(input()) + int(input()))
Buggy python submission (verdict: Runtime Error):
N = int(input())
print(min([x for x in [int(str(i) * 3) - N for i in range(1, 10)] if x > 0]) + N)


Fixed submission:
N = int(input())
print(min([x for x in [int(str(i) * 3) - N for i in range(1, 10)] if x >= 0]) + N)

Buggy python submission (verdict: Runtime Error):
N = int(input())
print(min([x for x in [int(x * 3) for x in list(str(N))] if x - N > 0], key=lambda x: x - N))


Fixed submission:
N = int(input())
print(min([x for x in [int(str(i) * 3) - N for i in range(1, 10)] if x >= 0]) + N)
Buggy python submission (verdict: Runtime Error):
a=input()

if a == ABC:
    print("ARC")
else:
    print("ABC")

Fixed submission:
a=input()
 
if a == "ABC":
    print("ARC")
else:
    print("ABC")
Buggy python submission (verdict: Runtime Error):
import math
A,B,N= map(int,input().split())
x=[]
AB=A/B
if N<=B:
    #x.append(math.floor(AB*N-1)-A*(N//B)
    print(math.floor(AB*N-1)-A*(N//B)
else:
    print(math.floor(AB*B-1)

Fixed submission:
import math
A,B,N= map(int,input().split())
x=[]
AB=A/B
if B==1:
    print("0")
elif N<B:
    #x.append(math.floor(AB*N-1)-A*(N//B)
    print(math.floor(AB*N))
else:
    x=[math.floor(AB*N)-A*(N//B)]
    for i in range(N//B):
        x.append(math.floor(AB*((i+1)*B-1))-i)
    print(max(x))

Buggy python submission (verdict: Time Limit Exceeded):
import math
A,B,N= map(int,input().split())
x=[]
AB=A/B
for i in range(1,N+1):
    x.append(math.floor(AB*i)-A*(i//B))
x.sort()
print(x.pop(N-1))

Fixed submission:
import math
A,B,N= map(int,input().split())
x=[]
AB=A/B
if B==1:
    print("0")
elif N<B:
    #x.append(math.floor(AB*N-1)-A*(N//B)
    print(math.floor(AB*N))
else:
    x=[math.floor(AB*N)-A*(N//B)]
    for i in range(N//B):
        x.append(math.floor(AB*((i+1)*B-1))-i)
    print(max(x))
Buggy python submission (verdict: Runtime Error):
N=int(input())
S=[]
for i in range(N):
    S.append(int(input()))
print(len(set(S)))

Fixed submission:
N=int(input())
S=[]
for i in range(N):
    S.append(input())
print(len(set(S)))

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
S=[]
for i in range(N):
    a = input()
    if not a in S:
        S.append(a)
print(len(S))

Fixed submission:
N=int(input())
S=[]
for i in range(N):
    S.append(input())
print(len(set(S)))

Buggy python submission (verdict: Runtime Error):
a,b,c,d=map(int,input().split())

e=a//d
f=c//b

if a == d:
    e -= 1
if c == b:
    f -= 1

if e >= f:
    print("Yes")
else:
    print("No")

Fixed submission:
N=int(input())
S=[]
for i in range(N):
    S.append(input())
print(len(set(S)))

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
S=[]
for i in range(N):
    a = input()
    if not a in S:
        S.append(a)
print(len(S))

Fixed submission:
N=int(input())
S=[]
for i in range(N):
    S.append(input())
print(len(set(S)))

Buggy python submission (verdict: Runtime Error):
N=int(input())
S=[]
for i in range(N):
    a = int(input())
    if not a in S:
        S.append(a)
print(len(S))

Fixed submission:
N=int(input())
S=[]
for i in range(N):
    S.append(input())
print(len(set(S)))
Buggy python submission (verdict: Time Limit Exceeded):
import math

K=int(input())

ans=0
for i in range(K):
    for j in range(K):
        for k in range(K):
            ans+=math.gcd(math.gcd(j+1,k+1),i+1)

print(ans)

Fixed submission:
import math

K=int(input())

ans=0
for i in range(K):
    for j in range(K):
        for k in range(K):
            ans+=math.gcd(math.gcd(j+1,k+1),i+1)

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

su=sum(A)
i=0
while max(A)*4*M>=su:
    i+=1
    A.remove(max(A))
else:
    if i>=M:
        print("Yes")
    else:
        print("No")

Fixed submission:
N,M=map(int,input().split())
A=list(map(int,input().split()))

su=sum(A)
i=0
while max(A)*4*M>=su:
    i+=1
    A.remove(max(A))
    if i>=M:
        print("Yes")
        break
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
def INT(): x = int(input()) return x
def LIST(): x = list(map(int, input().split())) return x

S = input()
if S[2]==S[3] and S[4] == S[5]:
    print("Yes")
else:
    print("No")

Fixed submission:


S = str(input())
if S[2] == S[3] and S[4] == S[5]:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
def INT(): x = int(input()) return x
def LIST(): x = list(map(int, input().split())) return x

X =INT()

p = X//500
q= (X%500)//5

print(p*1000+q*5)


Fixed submission:
X = int(input())

p = X//500
q= (X%500)//5

print(p*1000+q*5)
Buggy python submission (verdict: Runtime Error):
import numpy as np

K,N=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
x=np.array(A[1:])
y=np.array(A[:-1])
B=x-y
B.append(K+A[0]-A[N-1])
print(K-int(max(B))

Fixed submission:
import numpy as np

K,N=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
x=np.array(A[1:])
y=np.array(A[:-1])
B=x-y
C=B.tolist()
C.append(K+A[0]-A[N-1])
print(K-int(max(C)))

Buggy python submission (verdict: Runtime Error):
import numpy as np

K,N=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
x=np.array(A[1:])
y=np.array(A[:-1])
B=list(map(x-y))
B.append(K+A[0]-A[N-1])
print(K-max(B))

Fixed submission:
import numpy as np

K,N=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
x=np.array(A[1:])
y=np.array(A[:-1])
B=x-y
C=B.tolist()
C.append(K+A[0]-A[N-1])
print(K-int(max(C)))

Buggy python submission (verdict: Runtime Error):
import numpy as np

K,N=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
x=np.array(A[1:])
y=np.array(A[:-1])
B=x-y
B.append(K+A[0]-A[N-1])
print(K-max(B))

Fixed submission:
import numpy as np

K,N=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
x=np.array(A[1:])
y=np.array(A[:-1])
B=x-y
C=B.tolist()
C.append(K+A[0]-A[N-1])
print(K-int(max(C)))

Buggy python submission (verdict: Runtime Error):
K,N=map(int,input().split())
A=list(map(int,input().split()))
C = A.sort()
B=C[1:]-C[:-1]
B.append(K+C[0]-C[N-1])
print(K-max(B))

Fixed submission:
import numpy as np

K,N=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
x=np.array(A[1:])
y=np.array(A[:-1])
B=x-y
C=B.tolist()
C.append(K+A[0]-A[N-1])
print(K-int(max(C)))

Buggy python submission (verdict: Runtime Error):
K,N=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
B=A[1:]-A[:-1]
B.append(K+A[0]-A[N-1])
print(K-max(B))

Fixed submission:
import numpy as np

K,N=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
x=np.array(A[1:])
y=np.array(A[:-1])
B=x-y
C=B.tolist()
C.append(K+A[0]-A[N-1])
print(K-int(max(C)))

Buggy python submission (verdict: Runtime Error):
K,N=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
B=A[1:]-x[:-1]
B.append(K+A[0]-A[N-1])
print(K-max(B))

Fixed submission:
import numpy as np

K,N=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
x=np.array(A[1:])
y=np.array(A[:-1])
B=x-y
C=B.tolist()
C.append(K+A[0]-A[N-1])
print(K-int(max(C)))

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

def distance(x):
    q=x[1:]-x[:-1]
    return q

B=distance(A)
B.append(K+A[0]-A[N-1])
print(K-max(B))

Fixed submission:
import numpy as np

K,N=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
x=np.array(A[1:])
y=np.array(A[:-1])
B=x-y
C=B.tolist()
C.append(K+A[0]-A[N-1])
print(K-int(max(C)))
Buggy python submission (verdict: Runtime Error):
N = int(input())
alp = ["b","c","d","e","f","g","h","i","j","a"]
a = "a"
A = "a"
for i in range(N):
    word = [a]
    a = a + "a"
for i in range(N):
    word = [A]
    A = A + alp.pop(0)
word.pop(0)
word.sort()
s = "\n".join(word)
print(s)

Fixed submission:
K = int(input())
alist = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(alist[K-1])

Buggy python submission (verdict: Runtime Error):
H , W = map(int, input().split())
S = H * W

if S % 2 == 0:
    print(S//2)
else:
    print(S//2+1)


Fixed submission:
K = int(input())
alist = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(alist[K-1])
Buggy python submission (verdict: Runtime Error):
H , W = map(int, input().split())
S = H * W

if S % 2 = 0:
    print(S//2)
else:
    print(S//2+1)

Fixed submission:
H , W = map(int, input().split())
S = H * W
s = S//2

if H == 1 or W ==1:
    print("1")
elif S % 2 == 0:
    print(s)
else:
    print(s+1)

Buggy python submission (verdict: Runtime Error):
H , W = map(int,input().split())
S = H * W

if S % 2 = 0:
    print(S//2)
else:
    print(S//2+1)


Fixed submission:
H , W = map(int, input().split())
S = H * W
s = S//2

if H == 1 or W ==1:
    print("1")
elif S % 2 == 0:
    print(s)
else:
    print(s+1)

Buggy python submission (verdict: Runtime Error):
a , b = map(int,input().split())
S = a * b

if S % 2 = 0:
    print(S//2)
else:
    print(S//2 + 1)


Fixed submission:
H , W = map(int, input().split())
S = H * W
s = S//2

if H == 1 or W ==1:
    print("1")
elif S % 2 == 0:
    print(s)
else:
    print(s+1)
Buggy python submission (verdict: Runtime Error):
sta = input()

s1 = sta[0]
s2 = sta[1]
s3 = sta[2]

if :
    pass
if s1 == s2 and s2 == s3:
    print("Yes")
else:
    print("No")

Fixed submission:
sta = input()

s1 = sta[0]
s2 = sta[1]
s3 = sta[2]

if s1 == s2 and s2 == s3:
    print("No")
else:
    print("Yes")
Buggy python submission (verdict: Runtime Error):
N , A , B = int(input().split())
a = N // ( A + B )
b = N % ( A + B )

if b >> A:
    print( a * A + A )
else:
    print( a * A + b ) 

Fixed submission:
N , A , B = map(int, input().split())
AB = A + B
a = N // AB
b = N % AB



if b > A:
    print( a * A + A )
else:
    print( a * A + b )
Buggy python submission (verdict: Runtime Error):
a,b = (int(x) for x in input().split

if a == b:
       print ("Yes")
else:
       print ("No")

Fixed submission:
a,b=(int(x) for x in input().split())
if a == b:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
a,b=(int(x) for x in input().split())
if a > b:
  while i < b:
    print(str(a))
else:
  while i < a:
    print(str(b))

Fixed submission:
a,b=(int(x) for x in input().split())
i = 0
if a > b:
  while i < a:
    print(str(b), end="")
    i += 1
else:
  while i < b:
    print(str(a), end="")
    i += 1

Buggy python submission (verdict: Runtime Error):
a,b=(int(x) for x in input().split())
if a > b:
  while i < b:
    print(count(a))
else:
  while i < a:
    print(count(b))

Fixed submission:
a,b=(int(x) for x in input().split())
i = 0
if a > b:
  while i < a:
    print(str(b), end="")
    i += 1
else:
  while i < b:
    print(str(a), end="")
    i += 1

Buggy python submission (verdict: Runtime Error):
a,b=(int(x) for x in input().split())
if a > b:
  while i == b:
    print(count(a))
else:
  while i == a:
    print(count(b))

Fixed submission:
a,b=(int(x) for x in input().split())
i = 0
if a > b:
  while i < a:
    print(str(b), end="")
    i += 1
else:
  while i < b:
    print(str(a), end="")
    i += 1

Buggy python submission (verdict: Runtime Error):
a,b=(int(x) for x in input().split())
if a > b:
  print(count(a)).while i == b
else:
  print(count(b)).while i == a

Fixed submission:
a,b=(int(x) for x in input().split())
i = 0
if a > b:
  while i < a:
    print(str(b), end="")
    i += 1
else:
  while i < b:
    print(str(a), end="")
    i += 1
Buggy python submission (verdict: Runtime Error):
a = input()
count0 = 0
count1 = 0
a = int(a)
while(a > 0):
    if(a%2 ==0):
        count0 = count0 + 1
        a = a/10
    else:
        count1 = count1 + 1
        a = (a-1)/10

print(min(count0,count1)*2)


Fixed submission:
a = input()
count0 = 0
count1 = 0
b = len(a)
for i in range(b):
    if(a[i] == "0") :
        count0 = count0 + 1
    else:
        count1 = count1 + 1

print(min(count0,count1)*2)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

s=input()

d=deque()
for i in s:
  d.append(i)
  
v=1

q=int(input())

for i in range(q):
  a=input()
  if len(a)==1:
    if v:
      v=0
    else:
      v=1
  else:
    b,f,c=a.split()
    if f=="1":
      if v:
        d.appendleft(c)
      else:
        d.append(c)
    else:
      if v:
        d.append(c)
      else:
        d.appendleft(c)
        
ans=""
if v:
  for i in range(len(d)):
    ans+=d[i]
else:
  for i in range(len(d)):
    ans+=d.pop()
    
print(ans)

Fixed submission:
from collections import deque

s=input()

d=deque()
for i in s: #10**5
  d.append(i)
  
v=1

q=int(input())

for i in range(q): #2*10**5
  a=input()
  if len(a)==1:
    if v:
      v=0
    else:
      v=1
  else:
    b,f,c=a.split()
    if f=="1":
      if v:
        d.appendleft(c)
      else:
        d.append(c)
    else:
      if v:
        d.append(c)
      else:
        d.appendleft(c)
        
if v:
  for i in range(len(d)):
    print(d[i],end="")
else:
  for i in range(len(d)):
    print(d[len(d)-1-i],end="")
    
print()
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))

ans=99999999
for i in range(1,101):
  d=0
  for x in a:
    d+=(a-i)*(a-i)
  ans=min(ans,d)
print(ans)
    
  

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

ans=99999999
for i in range(1,101):
  d=0
  for x in a:
    d+=(x-i)*(x-i)
  ans=min(ans,d)
print(ans)

Buggy python submission (verdict: Runtime Error):
n=int(iinput())
a=list(map(int,input().split()))

ans=99999999
for i in range(1,101):
  d=0
  for x in a:
    d+=(a-i)*(a-i)
  ans=min(ans,d)
print(ans)
    
  

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

ans=99999999
for i in range(1,101):
  d=0
  for x in a:
    d+=(x-i)*(x-i)
  ans=min(ans,d)
print(ans)
Buggy python submission (verdict: Runtime Error):
def f(h):
  if h==1:
    return 1
  else:
    return f[h//2]*2+1
  
print(f(int(input())))

Fixed submission:
def f(h):
  if h==1:
    return 1
  else:
    return f(h//2)*2+1
  
print(f(int(input())))
Buggy python submission (verdict: Runtime Error):
x=input()
while 1:
  k=1
  for i in range(2,x**0.5+1):
    if x%i==0:
      k=0
      break
  if k:
    print(x)
    break
  x+=1

Fixed submission:
import math

x=int(input())
while 1:
  k=1
  for i in range(2,int(math.sqrt(x))+1):
    if x%i==0:
      k=0
      break
  if k:
    print(x)
    break
  x+=1

Buggy python submission (verdict: Runtime Error):
x=input()
while 1:
  k=1
  for i in range(2,x**2+1):
    if x%i==0:
      k=0
      break
  if k:
    print(x)
    break
  x+=1

Fixed submission:
import math

x=int(input())
while 1:
  k=1
  for i in range(2,int(math.sqrt(x))+1):
    if x%i==0:
      k=0
      break
  if k:
    print(x)
    break
  x+=1
Buggy python submission (verdict: Runtime Error):
n,t=map(int,input().split())
times=[]
values=[]
for i in range(n):
  time,value=map(int,input().split())
  times.append(time)
  values.append(value)
  
def knapsack(i,w):
  if i >= n:
    return 0
  elif w < 0:
    return 0
  else:
    p1 = knapsack(i+1, w)
    p2 = knapsack(i+1, w - times[i]) + values[i]
    return max(p1,p2)

  
print(knapsack(0,t-1))

Fixed submission:
import numpy as np

N,T = map(int, input().split())
item = [None]*N
for i in range(N):
  w,v = map(int,input().split())
  item[i] = [w,v]
item.sort(key=lambda x:x[0])

dp = np.zeros(T, dtype=int)
ans=0
for i in range(N):
    w,v=item[i]
    ans=max(ans,dp.max()+v)
    dp[w:] = np.maximum(dp[w:], dp[:-w] + v)
print(ans)

Buggy python submission (verdict: Runtime Error):
n,t=map(int,input().split())
times=[]
values=[]
for i in range(n):
  time,value=map(int,input().split())
  times.append(time)
  values.append(value)
  
def knapsack(i,w):
  if i >= n:
    return 0
  elif w < 0:
    return 0
  else:
    p1 = knapsack(i+1, w)
    p2 = knapsack(i+1, w - times[i]) + values[i]
    if p1>p2:
        return p1
    else:
        return p2

  
print(knapsack(0,t))

Fixed submission:
import numpy as np

N,T = map(int, input().split())
item = [None]*N
for i in range(N):
  w,v = map(int,input().split())
  item[i] = [w,v]
item.sort(key=lambda x:x[0])

dp = np.zeros(T, dtype=int)
ans=0
for i in range(N):
    w,v=item[i]
    ans=max(ans,dp.max()+v)
    dp[w:] = np.maximum(dp[w:], dp[:-w] + v)
print(ans)