Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
#s=raw_input()
l=list(input())
q=int(input())

r=False
for i in range(0, q):
    t=input()
    if t[0] == "1":
        r = not r
        #s = s[::-1]
    else:
        if t[2] == "1" and r is False or t[2] == "2" and r is True:
            #s = t[4] + s
            l.insert(0,t[4])
        else:
            #s = s + t[4]
            l.append(t[4])

if r is True:
    #s = s[::-1]
    l = l[::-1]

#print s
print("".join(l))


Fixed submission:
from collections import deque
#s=raw_input()

l=deque(list(input()))
q=int(input())

r=False
for i in range(0, q):
    t=input()
    if t[0] == "1":
        r = not r
        #s = s[::-1]
    else:
        if t[2] == "1" and r is False or t[2] == "2" and r is True:
            #s = t[4] + s
            l.appendleft(t[4])
        else:
            #s = s + t[4]
            l.append(t[4])

if r is True:
    #s = s[::-1]
    l = list(l)[::-1]

#print s
print("".join(l))

Buggy python submission (verdict: Time Limit Exceeded):
s=raw_input()
q=int(raw_input())

r=False
for i in range(0, q):
    t=raw_input()
    if t[0] == "1":
        r = not r
        #s = s[::-1]
    else:
        if t[2] == "1" and r is False or t[2] == "2" and r is True:
            s = t[4] + s
        else:
            s = s + t[4]

if r is True:
    s = s[::-1]
print s


Fixed submission:
from collections import deque
#s=raw_input()

l=deque(list(input()))
q=int(input())

r=False
for i in range(0, q):
    t=input()
    if t[0] == "1":
        r = not r
        #s = s[::-1]
    else:
        if t[2] == "1" and r is False or t[2] == "2" and r is True:
            #s = t[4] + s
            l.appendleft(t[4])
        else:
            #s = s + t[4]
            l.append(t[4])

if r is True:
    #s = s[::-1]
    l = list(l)[::-1]

#print s
print("".join(l))

Buggy python submission (verdict: Time Limit Exceeded):
s=raw_input()
q=int(raw_input())

for i in range(0, q):
    t=raw_input()
    if t[0] == "1":
        s = s[::-1]
    else:
        if t[2] == "1":
            s = t[4] + s
        else:
            s = s + t[4]

print s


Fixed submission:
from collections import deque
#s=raw_input()

l=deque(list(input()))
q=int(input())

r=False
for i in range(0, q):
    t=input()
    if t[0] == "1":
        r = not r
        #s = s[::-1]
    else:
        if t[2] == "1" and r is False or t[2] == "2" and r is True:
            #s = t[4] + s
            l.appendleft(t[4])
        else:
            #s = s + t[4]
            l.append(t[4])

if r is True:
    #s = s[::-1]
    l = list(l)[::-1]

#print s
print("".join(l))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(raw_input())
a=[]
for i in range(n):
    a.append(int(raw_input()))

for i in range(n):
    m=0
    for j in range(n):
        if i == j:
            continue
        m=max(m,a[j])
    print m



Fixed submission:
n=int(raw_input())
a=[]
for i in range(n):
    a.append(int(raw_input()))

m=max(a)
c=a.count(m)

if c > 1:
    for i in range(n):
        print m
else:
    s=sorted(a)[-2]
    for i in range(n):
        if a[i] != m:
            print m
        else:
            print s
Buggy python submission (verdict: Runtime Error):
s=input()
for i in range(0:len(s)):
  if i%2==0:
    if s[i]=='L':
      print('No')
    else:
      print('Yes')
  else:
    if s[i]=='R':
      print('No')
    else:
      print('Yes')

Fixed submission:
s=input()
a=0
for i in range(0,len(s)):
  if i%2==0:
    if s[i]=='L':
      a=a-1
  else:
    if s[i]=='R':
      a=a-1
if a<0:
  print('No')
else:
  print('Yes')
Buggy python submission (verdict: Runtime Error):
list = input().split()

jack = list[0] + list[1] + list[2]

if jack >= 22:
  print("bust")
else:
  print("win")


Fixed submission:
list = input().split()
 
jack = int(list[0]) + int(list[1]) + int(list[2])
 
if jack >= 22:
  print("bust")
else:
  print("win")
Buggy python submission (verdict: Runtime Error):
n, q = map(int, input().split())
s = list(input())

for i in range(q):
    count = 0
    l, r = map(int, input().split())
    # ss = s[l:r]
    for j in range(l-1,r):
        if s[j] == 'A':
            if j+1 < r:
                if s[j+1] == 'C':
                    count += 1
                j += 1
    print(count)

Fixed submission:

b = input()
if b == 'A':
    print('T')
elif b == 'T':
    print('A')
elif b == 'C':
    print('G')
else:
    print('C')

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

for i in range(q):
    count = 0
    l, r = map(int, input().split())
    for j in range(l-1,r):
        if s[j] == 'A':
            if j+1 < r:
                if s[j+1] == 'C':
                    count += 1
                j += 1
    print(count)

Fixed submission:

b = input()
if b == 'A':
    print('T')
elif b == 'T':
    print('A')
elif b == 'C':
    print('G')
else:
    print('C')

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

for i in range(q):
    count = 0
    l, r = map(int, input().split())
    for j in range(l-1,r):
        if s[j] == 'A':
            if j+1 < r:
                if s[j+1] == 'C':
                    count += 1
                j += 1
    print(count)

Fixed submission:

b = input()
if b == 'A':
    print('T')
elif b == 'T':
    print('A')
elif b == 'C':
    print('G')
else:
    print('C')
Buggy python submission (verdict: Time Limit Exceeded):
N = input()
A = list(map(int, input().split()))

ans = 1#np.prod(A)
for i in A:
  ans = ans * i
print(ans if ans <= 10**18 else -1)

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

if A.count(0) > 0:
  print(0)
else:
  ans = 1
  for i in A:
    ans = ans * i
    if ans > 10 ** 18:
      ans = -1
      break
  
  print(ans)
Buggy python submission (verdict: Runtime Error):
N = input()

if N[0] == 7:
  print("Yes")
else if N[1] == 7:
  print("Yes")
else if N[2] == 7:
  print("Yes")
else:
  print("No")

Fixed submission:
N = input()

if N[0] == "7":
  print("Yes")
elif N[1] == "7":
  print("Yes")
elif N[2] == "7":
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
X = list(map(int, input().split()))

x = 1

for i in range(N):
  x = x * X[i]

if x > 10 ** 18: print("-1")
else: print(x)

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

x = 1

if min(X) == 0:
  print(0)
  x = -1
else:
  for i in range(N):
    x = x * X[i]
    if x > 10 ** 18:
      print(-1)
      x = -1
      break
    
if x > 0: print(x)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
X = list(map(int, input().split()))

x = 1

for i in range(N):
  x = x * X[i]

if x > 10 ** 18: print("-1")
else: print(x)

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

x = 1

if min(X) == 0:
  print(0)
  x = -1
else:
  for i in range(N):
    x = x * X[i]
    if x > 10 ** 18:
      print(-1)
      x = -1
      break
    
if x > 0: print(x)
Buggy python submission (verdict: Time Limit Exceeded):
import math as m

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

if N >= B:
  print(m.floor(A * -1 / B) - A * m.floor(-1 / B))

else:
  list = []
  flag = 0
 
  list += [m.floor(A * 0 / B) - A * m.floor(0 / B)]
  
  for x in range(1, N + 1):
    list += [m.floor(A * x / B) - A * m.floor(x / B)]
    if list[x] < list[x - 1]:
      print(list[x - 1])
      flag = 1
      break
      
  if flag == 0: print(max(list))

Fixed submission:
import math as m
A, B, N = map(int, input().split())
if N >= B: print(m.floor(A * -1 / B) - A * m.floor(-1 / B))
else: print(m.floor(A * N / B) - A * m.floor(N / B))

Buggy python submission (verdict: Time Limit Exceeded):
import math as m

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

list = []
flag = 0

list += [m.floor(A * 0 / B) - A * m.floor(0 / B)]

for x in range(1, N + 1):
  list += [m.floor(A * x / B) - A * m.floor(x / B)]
  if list[x] < list[x - 1]:
    print(list[x - 1])
    flag = 1
    break

if flag == 0: print(max(list))

Fixed submission:
import math as m
A, B, N = map(int, input().split())
if N >= B: print(m.floor(A * -1 / B) - A * m.floor(-1 / B))
else: print(m.floor(A * N / B) - A * m.floor(N / B))

Buggy python submission (verdict: Time Limit Exceeded):
import math as m

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

list = []

for x in range(N + 1):
  list += [m.floor(A * x / B) - A * m.floor(x / B)]

print(max(list))

Fixed submission:
import math as m
A, B, N = map(int, input().split())
if N >= B: print(m.floor(A * -1 / B) - A * m.floor(-1 / B))
else: print(m.floor(A * N / B) - A * m.floor(N / B))
Buggy python submission (verdict: Time Limit Exceeded):
###############################################################################
#Imports
import collections
import itertools
from functools import lru_cache
import sys
import math
###############################################################################
#Constants
MOD = int(1e9)+7
###############################################################################
#Helper
def helper():
	pass
###############################################################################
#Solver
def solve():
	n = int(input())
	arr = list(map(int, input().split(' ')))
	sm = 1
	for num in arr:
		sm *= num
	if sm > int(1e18):
		print(-1)
		return
	print(sm)

###############################################################################
#Driver
t = 1
for _ in range(t):
	solve()
###############################################################################


Fixed submission:
###############################################################################
#Imports
import collections
import itertools
from functools import lru_cache
import sys
import math
###############################################################################
#Constants
MOD = int(1e9)+7
###############################################################################
#Helper
def helper():
	pass
###############################################################################
#Solver
def solve():
	n = int(input())
	arr = list(map(int, input().split(' ')))
	sm = 1
	if 0 in arr:
		print(0)
		return
	for num in arr:
		sm *= num
		if sm > int(1e18):
			print(-1)
			return
	print(sm)

###############################################################################
#Driver
t = 1
for _ in range(t):
	solve()
###############################################################################
Buggy python submission (verdict: Runtime Error):

X,N=map(int,input().split())
p=list(map(int,input().split()))
for i in range(102):
    if i in p:
        p.remove(i)
    else:
        p.append(i)
for i in range(102-N):
    if abs(X-p[i])<abs(X-ans):
        ans=p[i]
print(ans)

Fixed submission:
ans=0
X,N=map(int,input().split())
p=list(map(int,input().split()))
for i in range(102):
    if i in p:
        p.remove(i)
    else:
        p.append(i)
for i in range(102-N):
    if abs(X-p[i])<abs(X-ans):
        ans=p[i]
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
M=N
ans=0

for i in range(2,int(N**(1/4))+1):
    e=1
    while N%(i**e)==0:
        N=N//(i**e)
        ans+=1
        e+=1
    if N<i:
        break
if M==1:
    ans=0
elif ans==0:
#    x = int(N**(1/5))
    y = int(N**(1/4))
    z = int(N**(1/3))
    a = int(N**(1/2))
#    if x**5==M:
#        ans = 2
    if y**4==M:
        ans = 2
    elif z**3==M:
        ans = 2
    elif a**2==M:
        ans = 1
    else:
        ans=1
print(ans)

Fixed submission:
A,B=map(int,input().split())
print(A*B)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
ans=1
for i in range(N):
    ans = ans * A[i]
if ans>1000000000000000000:
    ans = -1
print(ans)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
ans=1
for i in range(N):
    if A[i] == 0:
        ans = 0
for i in range(N):
    ans = ans * A[i]
    if ans>1000000000000000000:
        ans = -1
        break
print(ans)
Buggy python submission (verdict: Runtime Error):
A,B=map(int,input().split())
print((A*B*100)//100)

Fixed submission:
A,B=input().split()
A = int(A)
B = B.replace('.','')
B = int(B)
ans = int(A*B//100)
print(ans)
Buggy python submission (verdict: Runtime Error):
import math
N , M , X =  map(int,input().split())
A = {}
B = {}
ANS = 100000000000
for i in range(1,N+1):
    A[i]=list(map(int,input().split()))
for i in range(1,2**N):
    l = str(bin(i))
    n = len(l)
    ans=0
    for s in range(1,M+1):
        B[s]=0
    for k in range(1,n+1):
        if l[-k] == "1":
            ans = ans + A[k][0]
            for s in range(1,M+1):
                B[s] += A[k][s]
    if all((B[l] >= X for l in range(1,M+1))):
        ANS = min(ans,ANS)
if ANS == 100000000000:
    print("-1")
else:
    print(ANS)

Fixed submission:
S = input()
T = input()
s = list(S)
t = list(T)
n = len(t)
t.pop(n-1)
if s == t:
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Runtime Error):
N , K = map(int,input().split())
B = {}
C = {}
D = {0}
A = list(map(int,input().split()))
place = 0
num = 0
C[0] = 0
while True:
    place = int(A[place]) - 1
    num += 1   
    if place in D:
        Y = int(num) - int(C[place])
        break
    elif num == K:
        break
    else:
        B[num] = place
        C[place] = num
        D.add(place)
try:
    X = (K - num) % Y
    print(B[C[place] + X] + 1)
except:
    print(A[place])

    

Fixed submission:
S = input()
T = input()
s = list(S)
t = list(T)
n = len(t)
t.pop(n-1)
if s == t:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
N , K = map(int,input().split())
B = {}
C = {}
D = {0}
A = list(map(int,input().split()))
place = 0
num = 0
C[0] = 0
while True:
    place = int(A[place]) - 1
    num += 1   
    if place in D:
        Y = int(num) - int(C[place])
        break
    else:
        B[num] = place
        C[place] = num
        D.add(place)
X = (K - num) % Y
print(B[C[place] + X] + 1)


Fixed submission:
N , K = map(int,input().split())
B = {}
C = {}
D = {0}
A = list(map(int,input().split()))
place = 0
num = 0
C[0] = 0
while True:
    place = int(A[place]) - 1
    num += 1   
    if place in D:
        Y = int(num) - int(C[place])
        break
    elif num == K:
        break
    else:
        B[num] = place
        C[place] = num
        D.add(place)
try:
    X = (K - num) % Y
    print(B[C[place] + X] + 1)
except:
    print(place+1)

Buggy python submission (verdict: Runtime Error):
N , K = map(int,input().split())
B = {}
C = {}
D = {0}
A = list(map(int,input().split()))
place = 0
num = 0
C[0] = 0
while True:
    place = int(A[place]) - 1
    num += 1   
    if place in D:
        Y = int(num) - int(C[place])
        break
    else:
        B[num] = place
        C[place] = num
        D.add(place)
if Y == 0:
    print(1)
else:
    X = (K - num) % Y
    print(B[int(C[place]) + X] + 1)

Fixed submission:
N , K = map(int,input().split())
B = {}
C = {}
D = {0}
A = list(map(int,input().split()))
place = 0
num = 0
C[0] = 0
while True:
    place = int(A[place]) - 1
    num += 1   
    if place in D:
        Y = int(num) - int(C[place])
        break
    elif num == K:
        break
    else:
        B[num] = place
        C[place] = num
        D.add(place)
try:
    X = (K - num) % Y
    print(B[C[place] + X] + 1)
except:
    print(place+1)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
l=0

for i in range(N):
    if A[i]>2*100000:
        A.remove(A[i])
N=len(A)
for i in range(N):
        for k in range(i+1 , N):
            if A[i]+A[k]==k-i or A[i]+A[k]==i-k:
                l+=1
print(l)

Fixed submission:
name = input()
if name == "ARC":
    print("ABC")
else:
    print("ARC")
Buggy python submission (verdict: Time Limit Exceeded):
N , M =map(int , input().split())
S = [k for k in range(0,N)]
H = list(map(int , input().split()))
for i in range(M):
    f , g =map(int , input().split())
    x=f-1
    y=g-1
    if H[x]<=H[y]:
        if x in S:
            S.remove(x)
    if H[x]>=H[y]:
        if y in S:
            S.remove(y)
print(len(S))


Fixed submission:
N , M =map(int , input().split())
S = set(k for k in range(0,N))
H = list(map(int , input().split()))
for i in range(M):
    f , g =map(int , input().split())
    x=f-1
    y=g-1
    if H[x]<=H[y]:
            S.discard(x)
    if H[x]>=H[y]:
            S.discard(y)
print(len(S))

Buggy python submission (verdict: Time Limit Exceeded):
N , M =map(int , input().split())
S = [k for k in range(0,N)]
H = list(map(int , input().split()))
for i in range(M):
    f , g =map(int , input().split())
    x=f-1
    y=g-1
    if H[x]<=H[y]:
        if x in S:
            S.remove(x)
    if H[x]>=H[y]:
        if y in S:
            S.remove(y)
print(len(S))

Fixed submission:
N , M =map(int , input().split())
S = set(k for k in range(0,N))
H = list(map(int , input().split()))
for i in range(M):
    f , g =map(int , input().split())
    x=f-1
    y=g-1
    if H[x]<=H[y]:
            S.discard(x)
    if H[x]>=H[y]:
            S.discard(y)
print(len(S))
Buggy python submission (verdict: Time Limit Exceeded):
A , B , N = map(int , input().split())
max = 0
for i in range(1,N+1):
    if int(A*i/B) - A*(int(i/B)) > max:
        max = int(A*i/B)-A*(int(i/B))
print(max)

Fixed submission:
A , B , N = map(int , input().split())
x = min (int(B-1) , int(N))
y = int(A * x / B) - A * (int(x / B))
print(y)
Buggy python submission (verdict: Runtime Error):
s = input()
w = input()
if s <= w:
    print("unsafe")
else:
    print("safe")

Fixed submission:
s , w =map(int , input() . split())
if s <= w:
    print("unsafe")
else:
    print("safe")
Buggy python submission (verdict: Time Limit Exceeded):
# ABC172c


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    # 再帰関数を使わない限りPypyで出すこと

    def dump(*args):
        sys.stderr.write(str(args))

    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    memo = dict()

    def dfs(i, j, s):
        if memo.get((i, j, s)) != None:
            return memo[(i, j, s)]
        t = 0
        if i < n and s + a[i] <= k:
            t = dfs(i + 1, j, s + a[i])+1
        if j < m and s + b[j] <= k:
            t = max(t, dfs(i, j + 1, s + b[j]) + 1)
        memo[(i, j, s)] = t
        return t

    print(dfs(0, 0, 0))


if __name__ == '__main__':
    main()


Fixed submission:
# ABC172c


def main():
    import sys
    import bisect
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    # 再帰関数を使わない限りPypyで出すこと

    def dump(*args):
        sys.stderr.write(str(args))

    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    def cum(array):  # result[i]=i番目まで（1-indexed）の累積和
        result = [0]
        for i in range(len(array)):
            result.append(array[i]+result[i])
        return result

    bc = cum(b)
    ac = cum(a)
    ans = 0
    for i in range(n + 1):
        if ac[i] <= k:
            #print(i, bisect.bisect_left(bc, k - ac[i])-1)
            ans = max(ans, i + bisect.bisect_right(bc, k - ac[i])-1)
    print(ans)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
# ABC172c


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    # 再帰関数を使わない限りPypyで出すこと

    def dump(*args):
        sys.stderr.write(str(args))

    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    def dfs(i, j, s):
        t = 0
        if i < n and s + a[i] <= k:
            t = dfs(i + 1, j, s + a[i])+1
        if j < m and s + b[j] <= k:
            t = max(t, dfs(i, j + 1, s + b[j])+1)
        return t

    print(dfs(0, 0, 0))


if __name__ == '__main__':
    main()


Fixed submission:
# ABC172c


def main():
    import sys
    import bisect
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    # 再帰関数を使わない限りPypyで出すこと

    def dump(*args):
        sys.stderr.write(str(args))

    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    def cum(array):  # result[i]=i番目まで（1-indexed）の累積和
        result = [0]
        for i in range(len(array)):
            result.append(array[i]+result[i])
        return result

    bc = cum(b)
    ac = cum(a)
    ans = 0
    for i in range(n + 1):
        if ac[i] <= k:
            #print(i, bisect.bisect_left(bc, k - ac[i])-1)
            ans = max(ans, i + bisect.bisect_right(bc, k - ac[i])-1)
    print(ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
# ABC159d


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    # 再帰関数を使わない限りPypyで出すこと

    def dump(*args):
        sys.stderr.write(str(args))

    from collections import Counter
    import math

    def c_count(n, r):  # 組み合わせ
        if n - r < 0:
            return 0
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

    class Combination:  # メモ化組み合わせ
        def __init__(self):
            super().__init__()
            self.dp = dict()

        def count(self, n, r):
            if self.dp.get((n, r)) != None:
                return self.dp[(n, r)]
            self.dp[(n, r)] = c_count(n, r)
            return self.dp[(n, r)]

    n = int(input())
    a = list(map(int, input().split()))
    c = Counter(a)
    d = Combination()
    e = dict()

    ss = 0

    for i in c:
        #print(i, c[i])
        e[i] = d.count(c[i], 2)
        # print(e[i])
        ss += e[i]

    for i in range(n):

        print(ss-d.count(c[a[i]], 2) + d.count(c[a[i]]-1, 2))


if __name__ == '__main__':
    main()


Fixed submission:
# ABC159d


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    # 再帰関数を使わない限りPypyで出すこと

    def dump(*args):
        sys.stderr.write(str(args))

    from collections import Counter
    import math

    def c_count(n, r):  # 組み合わせ
        if n - r < 0:
            return 0
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

    class Combination:  # メモ化組み合わせ
        def __init__(self):
            super().__init__()
            self.dp = dict()

        def count(self, n, r):
            if self.dp.get((n, r)) != None:
                return self.dp[(n, r)]
            self.dp[(n, r)] = c_count(n, r)
            return self.dp[(n, r)]

    n = int(input())
    a = list(map(int, input().split()))
    c = Counter(a)
    d = Combination()
    e = dict()

    ss = 0

    for i in c:
        #print(i, c[i])
        e[i] = d.count(c[i], 2)
        # print(e[i])
        ss += e[i]

    for i in range(n):
        t = e[a[i]]
        w = t * (c[a[i]] - 2) // c[a[i]]
        #print(a[i], t, w)
        w = w if w >= 0 else 0
        print(ss-t+w)


if __name__ == '__main__':
    main()