Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=1
f=0
x=[int(x) for x in input().split()]
if x.count(0)>0:
    print(0)
else:
    for i in range(len(x)):
        s=s*x[i]
    if s>10**18:
        print(-1)
    else:print(s)

Fixed submission:
n=int(input())
s=1
f=0
x=[int(x) for x in input().split()]
if x.count(0)>0:
    print(0)
else:
    for i in range(len(x)):
        s=s*x[i]
        if s>10**18:
            f=1
            break
    if f:
        print(-1)
    else:print(s)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=1
f=0
x=[int(x) for x in input().split()]
for i in range(len(x)):
    s=s*x[i]
if s>10**18:
    print(-1)
else:print(s)

Fixed submission:
n=int(input())
s=1
f=0
x=[int(x) for x in input().split()]
if x.count(0)>0:
    print(0)
else:
    for i in range(len(x)):
        s=s*x[i]
        if s>10**18:
            f=1
            break
    if f:
        print(-1)
    else:print(s)
Buggy python submission (verdict: Runtime Error):
a,b=map(float,input().split())
a=int(a)
z=list(str(b-int(b)))
t=''
for i in range(4):
    t+=z[i]
t=float(t)
print(int(int(a*int(b))+int(t*a)))

Fixed submission:
a,b=input().split()
a = int(a)
b = list(b.split("."))
b = ''.join(b)
b = int(b)
print(a*b//100)
Buggy python submission (verdict: Runtime Error):
m=map(int,input().split())
a=[int(x) for x  in input().split()]
if sum(a)-n<0:
  print(-1)
else:
  print(sum(a)-n)

Fixed submission:
n,m=map(int,input().split())
a=[int(x) for x in input().split()]
if n-sum(a)<0:
  print(-1)
else:
  print(n-sum(a))

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=[int(x) for x i in input().split()]
if sum(a)-n<0:
  print(-1)
else:
  print(sum(a)-n)

Fixed submission:
n,m=map(int,input().split())
a=[int(x) for x in input().split()]
if n-sum(a)<0:
  print(-1)
else:
  print(n-sum(a))
Buggy python submission (verdict: Time Limit Exceeded):
import sys

X, K, D=list(map(int, input().split()))

if X < 0:
    X = -X

if X-K*D>=0:
    print(X-K*D)
    sys.exit()

temp_X = X
temp_K = K

while temp_X-D >= 0:
    temp_X -= D
    temp_K -= 1

if temp_K%2==0:
    print(temp_X)
else:
    print( abs(temp_X-D) )


Fixed submission:
import sys

X, K, D=list(map(int, input().split()))

if X < 0:
    X = -X

if X-K*D>=0:
    print(X-K*D)
    sys.exit()

temp_X = X
temp_K = K

#while temp_X-D >= 0:
#    temp_X -= D
#    temp_K -= 1

k = X//D

temp_X = X-k*D
temp_K = K-k

if temp_K%2==0:
    print(temp_X)
else:
    print( abs(temp_X-D) )
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())

c_list = []
for i in range(10):
    temp_list = []
    for j in range(10):
        temp_count = 0
        for n in range(1, N+1):
            if n%10==j and n//(10**(len(str(n))-1) )==i:
                temp_count += 1
        temp_list.append(temp_count)
    c_list.append(temp_list)
sum=0
for i in range(10):
    for j in range(10):
        sum += c_list[i][j]*c_list[j][i]
print(sum)


Fixed submission:
N=int(input())

N_digit = len(str(N))
if N_digit==1:
    print(N)
    exit()

N_head = N//(10**(N_digit-1))
N_tail = N%10

count = 0
for A in range(1, N+1):
    A_digit = len(str(A))
    A_head  = A//(10**(A_digit-1))
    A_tail  = A%10

    if A_tail==0:
        continue

    if A_head==A_tail:
        count += 1

    for digit in range(2, N_digit+1):
        if digit==N_digit:
            if A_tail < N_head:
                count += 10**(digit-2)
            elif A_tail == N_head:
                if A_head <= N_tail:
                    count += N//10-N_head*(10**(N_digit-2))+1
                else:
                    count += N//10-N_head*(10**(N_digit-2))
            else:
                pass
        else:
            count += 10**(digit-2)
print(count)
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
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under
"""

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

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

# min
min_ = 0
for n in range(N-K+1):
    min_ += A[n]*cmb(N-1-n, K-1)

# max
max_ = 0
for n in reversed( range(K-1, N) ):
    max_ += A[n]*cmb(n, K-1)

mod = 10**9+7
print( (max_-min_)%mod )


Fixed submission:
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N_ = 10**5+1
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N_ + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

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

# min
min_ = 0
for n in range(N-K+1):
    min_ += A[n]*cmb(N-1-n, K-1, mod)

# max
max_ = 0
for n in reversed( range(K-1, N) ):
    max_ += A[n]*cmb(n, K-1, mod)

#mod = 10**9+7
print( (max_-min_)%mod )

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
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

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

# min
min_ = 0
for n in range(N-K+1):
    min_ += A[n]*cmb(N-1-n, K-1)

# max
max_ = 0
for n in reversed( range(K-1, N) ):
    max_ += A[n]*cmb(n, K-1)

mod = 10**9+7
print( (max_-min_)%mod )


Fixed submission:
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N_ = 10**5+1
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N_ + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

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

# min
min_ = 0
for n in range(N-K+1):
    min_ += A[n]*cmb(N-1-n, K-1, mod)

# max
max_ = 0
for n in reversed( range(K-1, N) ):
    max_ += A[n]*cmb(n, K-1, mod)

#mod = 10**9+7
print( (max_-min_)%mod )
Buggy python submission (verdict: Runtime Error):
import math

str_list = input().split(' ')
int_list = [int(x) for x in str_list]
A, B = int_list[0], int_list[1]

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


Fixed submission:
import fractions

str_list = input().split(' ')
int_list = [int(x) for x in str_list]
A, B = int_list[0], int_list[1]

print( (A*B)//fractions.gcd(A, B) )
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int, input().split()))

divider = 10**9+7

ans = 0
for shift in range(0, 60+1):
    one_num = 0
    for a in A:
        one_num += (a>>shift) & 1
    ans += (2**shift)*one_num*(N-one_num)
print(ans%divider)


Fixed submission:
import numpy as np

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

divider = 10**9+7

ans = 0
for shift in range(0, 60):
    one_num = np.count_nonzero(A & 1)
    ans += (2**shift)*one_num*(N-one_num)
    A >>= 1
print(ans%divider)
Buggy python submission (verdict: Time Limit Exceeded):
str_list = input().split(' ')
int_list = [int(x) for x in str_list]
A, B = int_list[0], int_list[1]

def cf(x1,x2):
    cf=[]
    for i in range(2,min(x1,x2)+1):
        if x1 % i == 0 and x2 % i == 0:
            cf.append(i)
    return cf

cf = cf(A, B)

count = 0

import numpy as np
cf = np.array(cf)

count = 0
while len(cf) > 0:
    count += 1
    if len(cf)==1:
        break
    x = int( cf[0] )
    cf = cf[np.where( cf%x!=0 )]
print(count+1)


Fixed submission:
str_list = input().split(' ')
int_list = [int(x) for x in str_list]
A, B = int_list[0], int_list[1]

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

a_div = make_divisors(A)
b_div = make_divisors(B)

cf = list( set(a_div) & set(b_div) )
cf.remove(1)
cf.sort()

count = 0

import numpy as np
cf = np.array(cf)

count = 0
while len(cf) > 0:
    count += 1
    if len(cf)==1:
        break
    x = int( cf[0] )
    cf = cf[np.where( cf%x!=0 )]
print(count+1)
Buggy python submission (verdict: Runtime Error):
str_list = input().split(' ')
int_list = [int(x) for x in str_list]
N, K, Q = int_list[0], int_list[1], int_list[2]
A = []
for _ in range(Q):
    A.append( int(input()) )
point = [int(K)]*N
import numpy as np
point = np.array(point)
for ii in range(Q):
    point[A[ii]-1] += 1
point -= Q
for ii in range(N):
    if point[ii] <= 0:
        print('No')
    else:
        print('Yes')


Fixed submission:
w = input()

if w=='Sunny':
    print('Cloudy')
elif w=='Rainy':
    print('Sunny')
elif w=='Cloudy':
    print('Rainy')
Buggy python submission (verdict: Time Limit Exceeded):
str_list = input().split(' ')
int_list = [int(x) for x in str_list]
N, K, Q = int_list[0], int_list[1], int_list[2]
A = []
for _ in range(Q):
    A.append( int(input()) )
point = [int(K)]*N
import numpy as np
point = np.array(point)
for ii in range(Q):
    point -= 1
    point[A[ii]-1] += 1
for ii in range(N):
    if point[ii] <= 0:
        print('No')
    else:
        print('Yes')


Fixed submission:
str_list = input().split(' ')
int_list = [int(x) for x in str_list]
N, K, Q = int_list[0], int_list[1], int_list[2]
A = []
for _ in range(Q):
    A.append( int(input()) )
point = [int(K)]*N
import numpy as np
point = np.array(point)
for ii in range(Q):
    point[A[ii]-1] += 1
point -= Q
for ii in range(N):
    if point[ii] <= 0:
        print('No')
    else:
        print('Yes')
Buggy python submission (verdict: Time Limit Exceeded):
import heapq

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

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

for _ in range(M):
    A.sort(reverse=True)
    A[0] //= 2
print(sum(A))


Fixed submission:
import heapq

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

A=list(map(lambda x: int(x)*(-1), input().split()))

heapq.heapify(A)

for _ in range(M):
    temp_min = heapq.heappop(A)
    heapq.heappush(A, (-1)*(-temp_min//2))
print(-sum(A))
Buggy python submission (verdict: Runtime Error):
N=int(input())
return 2**N

Fixed submission:
import numpy as np
N=int(input())
print(N**3)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
str_list = input().split(' ')
H = [int(x) for x in str_list]
max_count = 0
for ii in range(len(H)-1):
    count=0
    while H[ii+count]>=H[ii+count+1]:
        count += 1
        if ii+count>=len(H)-1:
            break
    if max_count < count:
        max_count = count
print(max_count)


Fixed submission:
N=int(input())
str_list = input().split(' ')
H = [int(x) for x in str_list]
max_count = 0
count=0
for ii in range(len(H)-1):
    if H[ii] >= H[ii+1]:
        count += 1
    else:
        count = 0
    if max_count < count:
        max_count = count
    #if max_count + ii > len(H):
    #    break
print(max_count)
Buggy python submission (verdict: Runtime Error):
import os

def main():
  args = list(map(int, input().split()))
  nb = args[0]
  nl = args[1]
  if nb == 0 or (nl % 2 == 1):
    print('No')
    return
  if (nl / 4.0) > nb:
    print('No')
    return
  if (nl % ((nb - 1) * 2)) % 2 == 0:
    print('Yes')
  else:
    print('No')

if __name__ == '__main__':
  main()


Fixed submission:
import os

def main():
  args = list(map(int, input().split()))
  nb = args[0]
  nl = args[1]
  if nb == 0 or (nl % 2 == 1) or nl == 0 or nb > nl or (nl / 4.0) > nb:
    print('No')
    return
  for i in range(nb + 1):
    if ((nb - i) * 4 + i * 2) == nl:
      print('Yes')
      return
  print('No')

if __name__ == '__main__':
  main()
Buggy python submission (verdict: Runtime Error):
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("name")
arg = parser.parse_args()
print(arg.name[:3])

Fixed submission:
import sys

args = input()
print(args[:3])

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

parser = argparse.ArgumentParser()
parser.add_argument("name")
arg = parser.parse_args()
print(arg.name[:3])

Fixed submission:
import sys

args = input()
print(args[:3])

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

parser = argparse.ArgumentParser()
parser.add_argument("name")
arg = parser.parse_args()
print(arg[:3])

Fixed submission:
import sys

args = input()
print(args[:3])
Buggy python submission (verdict: Runtime Error):
S = input()
num = len(S)

pair = 0

if num < 5:
    print(0)
else:
    for i in range(5,num):
        for j in range(num-i+1):
            temp = int(S[j:j+i+1])
            if temp % 2019 == 0:
                pair += 1

    print(pair)


Fixed submission:
S,W = map(int, input().split())

if W>=S:
    print('unsafe')
else:
    print('safe')
Buggy python submission (verdict: Runtime Error):
N, X, Y = map(int, input().split(' '))

dct = {X : Y}
short = Y - X - 1

dist_list = [0] * N

for i in range(1,N):
    for j in range(i+1,N+1):
        d1 = abs(X - i) + 1 + abs(Y - j)
        d2 = j - i
        dist = min(d1,d2)
        dist_list[dist] += 1

for k in range(1,N):
    print(dist[k])

Fixed submission:
S = list(input())

if S[2] == S[3] and S[4]==S[5]:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
from collections import Counter
from math import factorial

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

for k in range(N):
  sum_k = 0
  temp_c = c.copy()
  temp_c[A[k]] -= 1
  for v in temp_c.values():
    if v > 1:
      sum_k += factorial(v) / 2 / factorial(v - 2)
  print(int(sum_k))

Fixed submission:
from math import factorial

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

if N <= 1:
  a = 0
else:
  a = factorial(N) / 2 / factorial(N - 2)
  
if M <= 1:
  b = 0
else:
  b = factorial(M) / 2 / factorial(M - 2)
  
print(int(a+b))
Buggy python submission (verdict: Runtime Error):
S = input().split()
S_rev = list(reversed(S))
N = len(S)

if S != S_rev:
  print('No')
else:
  S1 = S[:(N-3)/2]
  S2 = S[(N-3)/2:]
  S1_rev = list(reversed(S1_rev))
  S2_rev = list(reversed(S2_rev))
  
  if S1==S1_rev and S2 == S2_rev:
    print('Yes')
  else:
    print('No')
  


Fixed submission:
S = list(input())
S_rev = list(reversed(S))
N = len(S)
if S != S_rev:
  print('No')
else:
  S1 = S[:int((N-1)/2)]
  S2 = S[int((N+1)/2):]
  S1_rev = list(reversed(S1))
  S2_rev = list(reversed(S2))
  if S1==S1_rev and S2 == S2_rev:
    print('Yes')
  else:
    print('No')
Buggy python submission (verdict: Runtime Error):
from collections import Counter

N = int(input())
alpha = [chr(i) for i in range(97, 97+26)]

temp = []
for n in range(N):
  result = []
	for i in temp:
    	temp_list = list(i)
  		type = len(Counter(temp_list))
  
  			for j in range(type):
    			result.append(i + alpha[j])
	temp = result.copy()
    
print('\n'.join(result))

Fixed submission:
from collections import Counter

N = int(input())
alpha = [chr(i) for i in range(97, 97+26)]
temp = ['a']
result = ['a']
if N >= 2:
  for n in range(2,N+1):
    result = []
    for i in temp:
      temp_list = list(i)
      type = len(Counter(temp_list))
      for j in range(type+1):
        a = i + alpha[j]
        result.append(a)
    temp = result.copy()
print('\n'.join(result))
Buggy python submission (verdict: Runtime Error):
import re
 
if re.match(r'^(hi)+$',S):
  print('Yes')

else:
  print('No')

Fixed submission:
import re

S = input() 

if re.match(r'^(hi)+$',S):
  print('Yes')

else:
  print('No')

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

if re.match(r'^(hi)+$'):
  print('Yes')

else:
  print('No')

Fixed submission:
import re

S = input() 

if re.match(r'^(hi)+$',S):
  print('Yes')

else:
  print('No')
Buggy python submission (verdict: Runtime Error):
import sys
N = int(input())
A = list(map(int, input().split()))

money = 1000
urine = 0
kabu = 0 
n = 0
mode = ""

if N == 2 and A[0] == A[1] :
  print("1000")
  sys.exit()

if A[0] < A[1] :
  mode = "up"
  urine = A[0]
  kabu = money // urine
  money = money - kabu*urine
elif A[0] > A[1] :
  mode = "down"
else :
  while A[n] == A[n + 1]:
    if n + 2 > N :
      print("1000")
      sys.exit()
      
    if A[n + 1] < A[n + 2]:
      mode = "up"
      urine = A[n + 1]
      kabu = money // urine
      money = money - kabu*urine
      break
    elif A[n + 1] > A[n + 2]:
      mode ="down"
      break
    
    n += 1  

for i in range(N-1):
  if mode == "up" :
    if A[i] <= A[i + 1] :
      next
    elif A[i] > A[i +1] :
      mode = "down"
      money = money + kabu*A[i]

  elif mode == "down":
    if A[i] >= A[i + 1] :
      next
    elif A[i] < A[i +1] :
      mode = "up"
      urine = A[i]
      kabu = money // urine
      money = money - kabu * urine
      
if mode == "up" :
  print(money + A[N-1]*kabu)
else :
  print(money)


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

money = 1000
kabu = 0 

for i in range(N-1):
  if A [i] < A[i + 1] and kabu == 0 :
    kabu = money // A[i]
    money = money - kabu*A[i]
  elif A[i] > A[i + 1] and kabu > 0:
    money = money + kabu*A[i]
    kabu = 0
    
if kabu > 0 :
  print(money + kabu*A[N-1])
else :
  print(money)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

ans = 1
for i in A :
  ans *= i
  
if ans > 1000000000000000000 :
  print("-1")
else :
  print(ans)

Fixed submission:
import sys

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

if 0 in set(A):
  print("0")
  sys.exit()  

ans = 1
for i in A :
  ans *= i
  if ans > 1000000000000000000 :
    print("-1")
    sys.exit()

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
N = int(input())
num = []
nn = -1

while nn ** 5 < N :
  nn += 1
  A = str(nn ** 5 - N)
  if A in num:
    print(nn, A.index(A))
    exit()
  num.append(str(nn ** 5)) 
  
An = -1
Bn = -1
A = 0
B = 0
while True :
  An += 1
  Bn = An
  A = 0
  B = 0
  while A + B < N :
    Bn += 1
    A = An ** 5
    B = Bn ** 5
    if A + B == N:
      print(An, Bn * -1)
      sys.exit()

Fixed submission:
import sys
N = int(input())

for A in range(-118, 120) :
  for B in range(-119, 119) :
    if A ** 5 - B ** 5 == N :
      print(A, B)
      sys.exit()

Buggy python submission (verdict: Runtime Error):
import sys
N = int(input())
num = []
nn = -1

while nn ** 5 < N :
  nn += 1
  A = nn ** 5 - N
  if A in num:
    print(nn, index(A))
    exit()
  num.append(nn ** 5) 
  
An = -1
Bn = -1
A = 0
B = 0
while True :
  An += 1
  Bn = An
  A = 0
  B = 0
  while A + B < N :
    Bn += 1
    A = An ** 5
    B = Bn ** 5
    if A + B == N:
      print(An, Bn * -1)
      sys.exit()

Fixed submission:
import sys
N = int(input())

for A in range(-118, 120) :
  for B in range(-119, 119) :
    if A ** 5 - B ** 5 == N :
      print(A, B)
      sys.exit()
Buggy python submission (verdict: Runtime Error):
import sys
A, B, N = map(int, input().split())

if N < B :
  print(int(N * A // B) - A * int(N // B))
  sys.exit()
else :
  print(((B-1) * A // B) - A * ((B-1) // B))


Fixed submission:
K = int(input())
A, B = map(int, input().split())

dist = A % K + B - A

if dist >= K :
  print("OK")
elif A % K == 0 or B % K == 0:
  print("OK")
else :
  print("NG")
Buggy python submission (verdict: Time Limit Exceeded):
A, B, N = map(int, input().split())

ans = set()

for i in range(N + 1):
  ans.add(int(i * A / B) - A * int(i / B))
  
print(max(ans))

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

if N < B :
  print(N * A // B - A * (N // B))
else :
  print((B-1) * A // B - A * ((B-1) // B))
Buggy python submission (verdict: Time Limit Exceeded):
from math import gcd

K = int(input())
ans = 0

for a in range(1, K+1) :
  for b in range(1, K+1) :
    for c in range(1, K+1) :
      ans += gcd(gcd(a, b), c)
      
print(ans)

Fixed submission:
from math import gcd
K = int(input())
ans = 0
for a in range(1, K+1) :
  for b in range(1, K+1) :
    for c in range(1, K+1) :
      ans += gcd(gcd(a, b), c)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
S = str(input())
Q = int(input())

ans = S

for i in range(Q) :
  Qn = list(map(str, input().split()))
  
  if Qn == ["1"] :
    ans = ans[::-1]
  else :
    if Qn[1] == "1" :
      ans = Qn[2] + ans
    if Qn[1] == "2" :
      ans = ans + Qn[2]

print(ans)

Fixed submission:
S = str(input())
Q = int(input())

fwd = ""
rev = ""
now = 1

for i in range(Q) :
  Qn = list(map(str, input().split()))
  
  if Qn == ["1"] :
    now *=-1
  else :
    if now == 1 :
      if Qn[1] == "1" :
        fwd = Qn[2] + fwd
      if Qn[1] == "2" :
        rev = rev + Qn[2]
    else : 
      if Qn[1] == "1" :
        rev = rev + Qn[2]
      if Qn[1] == "2" :
        fwd = Qn[2] + fwd

ans = fwd + S + rev
if now == -1 :
  ans = ans[::-1]
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
N, M = map(int, input().split())

num = []
for i in range(N) :
  num.append([0])

sc = []
for i in range(M) :
  sc.append(list(map(int, input().split()))) 

ans = ""

for n in sc :
  if n[1] not in num[n[0]-1] :
    num[n[0]-1].append(n[1])

if N >= and [1, 0] in sc :
  print('-1')
  sys.exit()
elif N >= 2 and num[0] == [0] :
  num[0].append(1)

for m in num :
  if len(m) >= 3 :
    print('-1')
    sys.exit()

if len(num[0]) == 1 :
  print('-1')
  sys.exit()
else :
  for l in range(N) :
    ans = ans + str(max(num[l]))

print(ans)

Fixed submission:
import sys
N, M = map(int, input().split())

num = []
for i in range(N) :
  num.append([0])

sc = []
for i in range(M) :
  sc.append(list(map(int, input().split()))) 

ans = ""

for n in sc :
  if n[1] not in num[n[0]-1] :
    num[n[0]-1].append(n[1])

if N >= 2 and [1, 0] in sc :
  print('-1')
  sys.exit()
elif N == 1 and num[0] == [0] :
  print('0')
  sys.exit()  
elif N >= 2 and num[0] == [0] :
  num[0].append(1)

for m in num :
  if len(m) >= 3 :
    print('-1')
    sys.exit()

if len(num[0]) == 1 :
  print('-1')
  sys.exit()
else :
  for l in range(N) :
    ans = ans + str(max(num[l]))

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
print(sum(range(N)))

Fixed submission:
N = int(input())
ans = N * (N - 1) // 2
 
print(int(ans))
Buggy python submission (verdict: Runtime Error):
W, H, x, y = map(int, input().split())

print(W * H / 2, end="")
print("" end="")

if x == W / 2 :
  if y == H / 2 :
    ans = 1
  else : 
    ans = 0
else :
  ans = 0
  
print(ans)

Fixed submission:
W, H, x, y = map(int, input().split())

S = W * H / 2

if x == W / 2 :
  if y == H / 2 :
    n = 1
  else : 
    n = 0
else :
  n = 0
  
ans = str(S) + " " + str(n)
print(ans)
Buggy python submission (verdict: Runtime Error):
time = T + 0.5
bisckets = (time //   A) * B

print(bisckets)

Fixed submission:
str = input().split()
A = int(str[0])
B = int(str[1])
T = int(str[2])

time = T + 0.5
biscuits = (time //   A) * B

print(int(biscuits))