Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys, math, heapq
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans=count=0


ans = -inf
n = int(input())
A = list(map(int, input().split()))
AL, AR = A[:n], A[2*n:]
al,ar=AL.copy(),AR.copy()
AN = A[n:2*n]
LS, RS = sum(AL), sum(AR)
AR = list(map(lambda ddd: -ddd, AR))
heapq.heapify(AL)
heapq.heapify(AR)
tmp=LS
ANSR=[0]*n
ANSL=[0]*n

for i in range(n):
    if AN[i]-AL[0] >0:
        LS = LS-heapq.heappop(AL)+AN[i]
        heapq.heappush(AL,AN[i])
    ANSL[i] = LS

LS=tmp
for j in range(n-1,-1,-1):
    if 0 < -AR[0]-AN[j]:
        RS = RS+heapq.heappop(AR)+AN[j]
        heapq.heappush(AR,-AN[j])
    ANSR[j] = RS
ANSR=ANSR+[sum(ar)]
ANSL=[sum(al)]+ANSL
for i in range(n+1):
    ans=max(ans,ANSL[i]-ANSR[i])
print(ans)
# print(ANSL,ANSR)

Fixed submission:
#!/usr/bin/env python3
import sys, math, heapq,copy
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans=count=0


ans = -inf
n = int(input())
A = list(map(int, input().split()))
AL, AR = A[:n], A[2*n:]
al,ar=copy.copy(AL),copy.copy(AR)
AN = A[n:2*n]
LS, RS = sum(AL), sum(AR)
AR = list(map(lambda ddd: -ddd, AR))
heapq.heapify(AL)
heapq.heapify(AR)
tmp=LS
ANSR=[0]*n
ANSL=[0]*n

for i in range(n):
    if AN[i]-AL[0] >0:
        LS = LS-heapq.heappop(AL)+AN[i]
        heapq.heappush(AL,AN[i])
    ANSL[i] = LS

LS=tmp
for j in range(n-1,-1,-1):
    if 0 < -AR[0]-AN[j]:
        RS = RS+heapq.heappop(AR)+AN[j]
        heapq.heappush(AR,-AN[j])
    ANSR[j] = RS
ANSR=ANSR+[sum(ar)]
ANSL=[sum(al)]+ANSL
for i in range(n+1):
    ans=max(ans,ANSL[i]-ANSR[i])
print(ans)
# print(ANSL,ANSR)
Buggy python submission (verdict: Runtime Error):
n,t=map(int,input().split())
T=list(map(int,input().split()))
count=0
if t>T[1]:
    count+=t-T[1]
pre=T[1]
for i in range(2,n):
    sa=T[i]-pre
    if t>sa:
        count+=t-sa
    pre=T[i]
print(n*t-count)

Fixed submission:
n,t=map(int,input().split())
T=list(map(int,input().split()))
if n==1:
	print(t)
	exit()
count=0
if t>T[1]:
    count+=t-T[1]
pre=T[1]
for i in range(2,n):
    sa=T[i]-pre
    if t>sa:
        count+=t-sa
    pre=T[i]
print(n*t-count)
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf')
ans = 0 ;count = 0 ;pro = 1

n,m=map(int,input().split())
ab=[tuple(map(int,input().split())) for i in range(n)]
cd=[tuple(map(int,input().split())) for i in range(m)]
for a,b in ab:
    tmp=inf
    candi=0
    for j in range(n):
        c=cd[j][0]
        d=cd[j][1]
        k=abs(a-c)+abs(b-d)
        if tmp>k:
            tmp=k
            candi=j
    print(candi+1)
    



Fixed submission:
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf')
ans = 0 ;count = 0 ;pro = 1

n,m=map(int,input().split())
ab=[tuple(map(int,input().split())) for i in range(n)]
cd=[tuple(map(int,input().split())) for i in range(m)]
for a,b in ab:
    tmp=inf
    candi=0
    for j in range(m):
        c=cd[j][0]
        d=cd[j][1]
        k=abs(a-c)+abs(b-d)
        if tmp>k:
            tmp=k
            candi=j
    print(candi+1)
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys, itertools
from math import gcd
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans = count = 0



a, b, c = map(int, input().split())
for i in itertools.permutations([a, b, c], 3):
    if i[0] == sum(i[1:]) or sum(i[:2]) == i[2]:
        print("Yes")
        exit()

print("No")


Fixed submission:
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect, fractions
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans = count = 0

a,b,c=map(int,input().split())
for i in itertools.permutations([a,b,c],3):
    if i[0]==sum(i[1:]) or sum(i[:2])==i[2]:
        print("Yes")
        exit()

print("No")

Buggy python submission (verdict: Runtime Error):
!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect, fractions
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans = count = 0

a,b,c=map(int,input().split())
print(0)
for i in itertools.permutations([a,b,c],3):
    if i[0]==sum(i[1:]) or sum(i[:2])==i[2]:
        print("Yes")
        exit()

print("No")

Fixed submission:
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect, fractions
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans = count = 0

a,b,c=map(int,input().split())
for i in itertools.permutations([a,b,c],3):
    if i[0]==sum(i[1:]) or sum(i[:2])==i[2]:
        print("Yes")
        exit()

print("No")

Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
# import sys, math, itertools, heapq, collections, bisect, fractions
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans = count = 0

# a,b,c=map(int,input().split())
# for i in itertools.permutations([a,b,c],3):
#     if i[0]==sum(i[1:]) or sum(i[:2])==i[2]:
#         print("Yes")
#         exit()

# print("No")

Fixed submission:
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect, fractions
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans = count = 0

a,b,c=map(int,input().split())
for i in itertools.permutations([a,b,c],3):
    if i[0]==sum(i[1:]) or sum(i[:2])==i[2]:
        print("Yes")
        exit()

print("No")
Buggy python submission (verdict: Runtime Error):
def ceil(x,y):
    return x//y+(not( not x%y))
n=int(input())
a,b=1,1
for i in range(n):
    t,s = map(int,input().split())
    i = max( ceil(a/t), ceil(b/s) )
    a=t*i;b=s*i
print(a+b)

Fixed submission:
def ceil(x,y):
  return (x-1)//y+1
N = int(input())
TA = [list(map(int, input().split())) for _ in range(N)]
t, a = 1, 1
for T, A in TA:
  rate = max(ceil(t, T), ceil(a, A))
  t = T * rate
  a = A * rate
print(t + a)

Buggy python submission (verdict: Runtime Error):
from math import ceil
# def ceil(x,y):
#   return (x-1)//y+1
N = int(input())
TA = [list(map(int, input().split())) for _ in range(N)]
t, a = 1, 1
for T, A in TA:
  rate = max(ceil(t, T), ceil(a, A))
  t = T * rate
  a = A * rate
print(t + a)    
    


Fixed submission:
def ceil(x,y):
  return (x-1)//y+1
N = int(input())
TA = [list(map(int, input().split())) for _ in range(N)]
t, a = 1, 1
for T, A in TA:
  rate = max(ceil(t, T), ceil(a, A))
  t = T * rate
  a = A * rate
print(t + a)

Buggy python submission (verdict: Runtime Error):
from math import ceil
N = int(input())
TA = [list(map(int, input().split())) for _ in range(N)]
t, a = 1, 1
for T, A in TA:
  rate = max(ceil(t, T), ceil(a, A))
  t = T * rate
  a = A * rate
print(t + a)    
    


Fixed submission:
def ceil(x,y):
  return (x-1)//y+1
N = int(input())
TA = [list(map(int, input().split())) for _ in range(N)]
t, a = 1, 1
for T, A in TA:
  rate = max(ceil(t, T), ceil(a, A))
  t = T * rate
  a = A * rate
print(t + a)
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect, fractions
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans = count = 0

n,k=map(int,input().split())
D=set(input().split())
while True:
    ns=str(n)
    for ni in ns:
        if ni in D:
            break
    else:
        print(n)
        exit()
    n+=1
    continue

    

Fixed submission:
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect, fractions
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans = count = 0

A=list(map(int,input().split()))
a=b=0
for ai in A:
    if ai==5:
        a+=1
    elif ai==7:
        b+=1
if a==2 and b==1:
    print("YES")
else:
    print("NO")
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))

sum=0
tmp=0
for i in range(n):
    o = i+1
    tmp = 0
    while (o<n):
        tmp=a[o]+tmp
        o=o+1
    sum=(a[i]%1000000007*tmp%1000000007)%1000000007+sum%1000000007

print(sum%1000000007)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
mod=1000000007
sum=0
tmp=0
o=0
while(o<n):
    tmp = (a[o]%mod + tmp%mod)%mod
    o += 1

for i in range(n):
    tmp=(tmp%mod-a[i]%mod)%mod
    sum=((a[i]%mod)*tmp)%mod+sum%mod



print(sum%mod)

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

sum=0
tmp=0
for i in range(n):
    o = i+1
    tmp = 0
    while (o<n):
        tmp=((a[o]%1000000007)+(tmp%1000000007))%1000000007
        o=o+1
    sum=(a[i]*tmp)%1000000007+sum%1000000007

print(sum%1000000007)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
mod=1000000007
sum=0
tmp=0
o=0
while(o<n):
    tmp = (a[o]%mod + tmp%mod)%mod
    o += 1

for i in range(n):
    tmp=(tmp%mod-a[i]%mod)%mod
    sum=((a[i]%mod)*tmp)%mod+sum%mod



print(sum%mod)

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

sum=0
tmp=0
for i in range(n):
    o = i+1
    tmp = 0
    while (o<n):
        tmp=a[o]+tmp
        o=o+1
    sum=(a[i]*tmp)+sum

print(sum%1000000007)


Fixed submission:
n=int(input())
a=list(map(int,input().split()))
mod=1000000007
sum=0
tmp=0
o=0
while(o<n):
    tmp = (a[o]%mod + tmp%mod)%mod
    o += 1

for i in range(n):
    tmp=(tmp%mod-a[i]%mod)%mod
    sum=((a[i]%mod)*tmp)%mod+sum%mod



print(sum%mod)

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

sum=0
for i in range(n):
    o = i+1
    while (o<n):
        sum=(a[i]%1000000007*a[o]%1000000007+sum)%1000000007
        o=o+1

print(sum)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
mod=1000000007
sum=0
tmp=0
o=0
while(o<n):
    tmp = (a[o]%mod + tmp%mod)%mod
    o += 1

for i in range(n):
    tmp=(tmp%mod-a[i]%mod)%mod
    sum=((a[i]%mod)*tmp)%mod+sum%mod



print(sum%mod)

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

sum=0
for i in range(n):
    o = i+1
    while (o<n):
        sum=(a[i]*a[o]+sum)%1000000007
        o=o+1

print(sum)


Fixed submission:
n=int(input())
a=list(map(int,input().split()))
mod=1000000007
sum=0
tmp=0
o=0
while(o<n):
    tmp = (a[o]%mod + tmp%mod)%mod
    o += 1

for i in range(n):
    tmp=(tmp%mod-a[i]%mod)%mod
    sum=((a[i]%mod)*tmp)%mod+sum%mod



print(sum%mod)

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

sum=0
for i in range(n):
    o = i+1
    while (o<n):
        sum=a[i]*a[o]+sum
        o=o+1

print(sum%1000000007)


Fixed submission:
n=int(input())
a=list(map(int,input().split()))
mod=1000000007
sum=0
tmp=0
o=0
while(o<n):
    tmp = (a[o]%mod + tmp%mod)%mod
    o += 1

for i in range(n):
    tmp=(tmp%mod-a[i]%mod)%mod
    sum=((a[i]%mod)*tmp)%mod+sum%mod



print(sum%mod)
Buggy python submission (verdict: Runtime Error):
D = input()
T = input()
S = input()

if(D/S <= T):
	print("Yes")
else:
	print("No")

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

if(D/S <= T):
	print("Yes")
else:
	print("No")

Buggy python submission (verdict: Runtime Error):
D = input()
T = input()
S = input()

if(D/S <= T) print("Yes")
else print("No")

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

if(D/S <= T):
	print("Yes")
else:
	print("No")
Buggy python submission (verdict: Runtime Error):
a,b=map(int, input().split())
if (a<=9 && b<=9):
  print(a*b)
else:
  print("-1")


Fixed submission:
a,b=map(int, input().split())
if (a<=9 and b<=9):
  print(a*b)
else:
  print("-1")

Buggy python submission (verdict: Runtime Error):
a,b=map(int, input())
if (a<=9 & b<=9):
  print(a*b)
else:
  print("-1")

Fixed submission:
a,b=map(int, input().split())
if (a<=9 and b<=9):
  print(a*b)
else:
  print("-1")
Buggy python submission (verdict: Time Limit Exceeded):
n,m=[int(x) for x in input().split()]
l=[[] for i in range(n)]
for i in range(m):
  a,b=map(int,input().split())
  l[a-1].append(b-1)
  l[b-1].append(a-1)
# print(l)

done=[0]*n


def dfs(j):
  que=[j]
  cnt=1
  done[j]=1
  while(que):
    now=que.pop(0)

    for i in l[now]:
      if done[i]!=1:
        que.append(i)
        done[i]=1
        cnt+=1

  return cnt

ma=0
for j in range(n):
  if done[j]!=1:
    now=dfs(j)
  else:
    now=0
  ma=max(now,ma)
  
print(ma)


Fixed submission:
n,m=[int(x) for x in input().split()]
l=[[] for i in range(n)]
for i in range(m):
  a,b=map(int,input().split())
  l[a-1].append(b-1)
  l[b-1].append(a-1)
# print(l)

done=[0]*n


def dfs(j):
  que=[j]
  cnt=1
  done[j]=1
  while(que):
    now=que.pop(0)

    for i in l[now]:
      if done[i]!=1:
        que.append(i)
        done[i]=1
        cnt+=1

  return cnt

ma=0
for j in range(n):
  if done[j]!=1:
    now=dfs(j)
  else:
    now=0
  ma=max(now,ma)
  
print(ma)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=[int(x) for x in input().split()]
ma=max(a)
memo=[0]*ma

def gcd(a,b):#最大公約数
  while b!=0:
    a,b=b,a%b
  return a

for i in a:
  memo[i-1]+=1

pair=True
for i in range(2,ma+1):
  cnt=0
  for j in range(i,ma+1,i):
    if 0<memo[j-1]:
      cnt+=1
  if 1<cnt:
    pair=False


g=a[0]
for i in range(1,n):
  g=gcd(g,a[i])

if pair == False and g==1:
  print("setwise coprime")
elif pair == True and g==1:
  print("pairwise coprime")
else:
  print("not coprime")
    

Fixed submission:
n=int(input())
a=[int(x) for x in input().split()]
ma=max(a)
memo=[0]*ma

def gcd(a,b):#最大公約数
  while b!=0:
    a,b=b,a%b
  return a

for i in a:
  memo[i-1]+=1

pair=True
for i in range(2,ma+1):
  cnt=0
  for j in range(i,ma+1,i):
    if 0<memo[j-1]:
      cnt+=1
  if 1<cnt:
    pair=False


g=a[0]
for i in range(1,n):
  g=gcd(g,a[i])

if pair == False and g==1:
  print("setwise coprime")
elif pair == True and g==1:
  print("pairwise coprime")
else:
  print("not coprime")
Buggy python submission (verdict: Runtime Error):
import sys

n=int(input())
l=[int(x) for x in input().rstrip().split()]
l.sort()
num=[0]*max(l)
for i in l:
  num[i-1]+=1

ans=0
for i in range(n):
  for j in range(i+1,n):
    for s in range(j+1,n):
      if l[i]!=l[j] and l[j]!=l[s] and l[i]!=l[s]:
        if l[i]<l[j]+l[s] and l[j]<l[i]+l[s] and l[s]<l[i]+l[j]:
          ans+=1
print(ans)




Fixed submission:
import sys

n=int(input())
l=[int(x) for x in input().rstrip().split()]
l.sort()


ans=0
for i in range(n):
  for j in range(i+1,n):
    for s in range(j+1,n):
      if l[i]!=l[j] and l[j]!=l[s] and l[i]!=l[s]:
        if l[i]<l[j]+l[s] and l[j]<l[i]+l[s] and l[s]<l[i]+l[j]:
          ans+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys


x,k,d=map(int,input().split())

x=abs(x)
syou = x//d
if k<=syou:
  print(x-k*d)
else:
  if (k//syou)%2 == 0:
    if syou%2==0:
      print(x%d)
    else:
      print(min(abs(x%d+d), abs(x%d-d)))
  else:
    if syou%2==0:
      print(min(abs(x%d+d), abs(x%d-d)))
    else:
      print(x%d)



Fixed submission:
x,k,d=map(int,input().split())
x=abs(x)
syou=x//d
if k<=syou:
  print(x-k*d)
else:
  k=k-syou
  x=x%d
  if k%2==0:
    print(x)
  else:
    print(abs(x-d))
Buggy python submission (verdict: Time Limit Exceeded):
s=input()
s=s[::-1]
l=[0]*2019
l[0]=1
prev=0
ans=0

for i in range(len(s)):
  mul=(10**i)%2019
  now=(int(s[i])*mul)%2019
  ans+=l[(prev+now)%2019]
  l[(prev+now)%2019]+=1
  prev=(prev+now)%2019

print(ans)

Fixed submission:
s=input()


s=s[::-1]
l=[0]*2019
l[0]=1
prev=0
ans=0
mul=1

for i in range(len(s)):
  now=(int(s[i])*mul)%2019
  ans+=l[(prev+now)%2019]
  l[(prev+now)%2019]+=1
  prev=(prev+now)%2019
  mul=(mul*10)%2019

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=[int(x) for x in input().rstrip().split()]
cnt=[0 for i in range(n)]
for i in a:
  cnt[i-1]+=1

nc2=[]
for i in cnt:
  nc2.append(((i)*(i-1))//2)
  
for i in range(n):
  print(sum(nc2)-nc2[a[i]-1]+((cnt[a[i]-1]-1)*(cnt[a[i]-1]-2))//2)


Fixed submission:
n=int(input())
a=[int(x) for x in input().rstrip().split()]
cnt=[0 for i in range(n)]
for i in a:
  cnt[i-1]+=1

nc2=[]
for i in cnt:
  nc2.append(((i)*(i-1))//2)

All=sum(nc2)
for i in range(n):
  now=cnt[a[i]-1]-1
  print(All-nc2[a[i]-1]+((now)*(now-1))//2)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=[int(x) for x in input().rstrip().split()]
cnt=[0 for i in range(n)]
nc2=[0 for i in range(n)]
for i in a:
  cnt[i-1]+=1
  nc2[i-1]=((cnt[i-1])*(cnt[i-1]-1))//2

for i in a:
  print(sum(nc2)-nc2[i-1]+((cnt[i-1]-1)*(cnt[i-1]-2))//2)

Fixed submission:
n=int(input())
a=[int(x) for x in input().rstrip().split()]
cnt=[0 for i in range(n)]
for i in a:
  cnt[i-1]+=1

nc2=[]
for i in cnt:
  nc2.append(((i)*(i-1))//2)

All=sum(nc2)
for i in range(n):
  now=cnt[a[i]-1]-1
  print(All-nc2[a[i]-1]+((now)*(now-1))//2)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=[int(x) for x in input().rstrip().split()]
cnt=[0 for i in range(n)]
nc2=[0 for i in range(n)]
for i in a:
  cnt[i-1]+=1

for i in a:
  nc2[i-1]=((cnt[i-1])*(cnt[i-1]-1))//2
for i in a:
  print(sum(nc2)-nc2[i-1]+((cnt[i-1]-1)*(cnt[i-1]-2))//2)

Fixed submission:
n=int(input())
a=[int(x) for x in input().rstrip().split()]
cnt=[0 for i in range(n)]
for i in a:
  cnt[i-1]+=1

nc2=[]
for i in cnt:
  nc2.append(((i)*(i-1))//2)

All=sum(nc2)
for i in range(n):
  now=cnt[a[i]-1]-1
  print(All-nc2[a[i]-1]+((now)*(now-1))//2)
Buggy python submission (verdict: Time Limit Exceeded):
s=input()
q=int(input())

cnt=0
left=""
right=""

for i in range(q):
  qq=[x for x in input().rstrip().split()]

  if qq[0]=="2":
    t=int(qq[0])
    f=int(qq[1])
    c=qq[2]
    
    if cnt%2==1 and f==1:
      s=s+c
    elif cnt%2==1 and f==2:
      s=c+s
    elif cnt%2==0 and f==2:
      s=s+c
    elif cnt%2==0 and f==1:
      s=c+s

  else:
    cnt+=1


if cnt%2==1:
  print(s[::-1])
else:
  print(s)

Fixed submission:
s=input()
q=int(input())

cnt=0
left=""
right=""

for i in range(q):
  qq=[x for x in input().rstrip().split()]

  if qq[0]=="2":
    t=int(qq[0])
    f=int(qq[1])
    c=qq[2]
    
    if cnt%2==1 and f==1:
      right=right+c
    
    elif cnt%2==1 and f==2:

      left=c+left
    elif cnt%2==0 and f==2:
  
      right=right+c
    elif cnt%2==0 and f==1:

      left=c+left

  else:
    cnt+=1

s=left+s+right
if cnt%2==1:
  print(s[::-1])
else:
  print(s)

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

cnt=0

for i in range(q):
  qq=[x for x in input().rstrip().split()]
  # print(len(qq))
  if len(qq)==3:
    t=int(qq[0])
    f=int(qq[1])
    c=qq[2]
    
    if cnt%2==1 and f==1:
      s=s+c
    elif cnt%2==1 and f==2:
      s=c+s
    elif cnt%2==0 and f==2:
      s=s+c
    elif cnt%2==0 and f==1:
      s=c+s

  else:
    cnt+=1


if cnt%2==1:
  print(s[::-1])
else:
  print(s)

Fixed submission:
s=input()
q=int(input())

cnt=0
left=""
right=""

for i in range(q):
  qq=[x for x in input().rstrip().split()]

  if qq[0]=="2":
    t=int(qq[0])
    f=int(qq[1])
    c=qq[2]
    
    if cnt%2==1 and f==1:
      right=right+c
    
    elif cnt%2==1 and f==2:

      left=c+left
    elif cnt%2==0 and f==2:
  
      right=right+c
    elif cnt%2==0 and f==1:

      left=c+left

  else:
    cnt+=1

s=left+s+right
if cnt%2==1:
  print(s[::-1])
else:
  print(s)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
S=[str(i) for i in input()]
l=[]
for i in range(10):
  for j in range(10):
    for k in range(10):
      l.append(str(i)+str(j)+str(k))

ans=0
for i in range(len(l)):
  now=l[i]
  j=0
  for s in range(N):
    if S[s]==now[j]:
      j+=1

    if j==3:
      ans+=1
      break
print(ans)


Fixed submission:
n=int(input())
s=input()
ans=0

for i in range(10):
  x=s.find(str(i))
  if x!=-1:
    for j in range(10):
      y=s.find(str(j),x+1,n)
      if y!=-1:
        for k in range(10):
          z=s.find(str(k),y+1,n)
          if z!=-1:
            ans+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input())
if 1<=a<=9 and 1<=b<=9:
    print(a*b)
else:
    print(-1)

Fixed submission:
a,b=map(int,input().split())
if 1<=a<=9 and 1<=b<=9:
    print(a*b)
else:
    print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
A=[int(x) for x in input().rstrip().split()]
ans=[]
for i in range(1,n+1):
  ans.append(A.index(i)+1)
print(*ans)

Fixed submission:
n=int(input())
A=[int(x) for x in input().rstrip().split()]
ans=[0 for i in range(n)]
for i in range(n):
  ans[A[i]-1]=i+1
print(*ans)
Buggy python submission (verdict: Runtime Error):
from heapq import heappush,heappop

n,m=[int(x) for x in input().rstrip().split()]
ab=[[] for i in range(10**5)]

for i in range(n):
  a,b=[int(x) for x in input().rstrip().split()]
  if a<=m:
    ab[m-a].append(-b)

ans=0
time=0
l=[]
for i in range(m,-1,-1):
  for b in ab[i]:
    heappush(l,b)

  if l:
    ans-=heappop(l)

print(ans)


Fixed submission:
from heapq import heappush,heappop

n,m=[int(x) for x in input().rstrip().split()]
ab=[[] for i in range(10**5)]

for i in range(n):
  a,b=[int(x) for x in input().rstrip().split()]
  ab[a-1].append(-b)

ans=0
time=0
l=[]
for i in range(m):
  for b in ab[i]:
    heappush(l,b)
  if l:
    ans-=heappop(l)

print(ans)

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

n,m=[int(x) for x in input().rstrip().split()]
ab=[[] for i in range(10**5)]

for i in range(n):
  a,b=[int(x) for x in input().rstrip().split()]
  ab[m-a].append(-b)


ans=0
time=0
l=[]
for i in range(m,-1,-1):
  for b in ab[i]:
    heappush(l,b)

  if l:
    ans-=heappop(l)

print(ans)


Fixed submission:
from heapq import heappush,heappop

n,m=[int(x) for x in input().rstrip().split()]
ab=[[] for i in range(10**5)]

for i in range(n):
  a,b=[int(x) for x in input().rstrip().split()]
  ab[a-1].append(-b)

ans=0
time=0
l=[]
for i in range(m):
  for b in ab[i]:
    heappush(l,b)
  if l:
    ans-=heappop(l)

print(ans)
Buggy python submission (verdict: Runtime Error):
n,m=[int(x) for x in input().rstrip().split()]
a=[int(input()) for i in range(m)]
oks=[True for i in range(n+1)]

mod=10**9+7
dp=[0 for i in range(n+1)]
for i in a:
  oks[i]=False

if oks[1]==True:
  dp[1]=1
if oks[2]==True:
  dp[2]=dp[1]+1

for i in range(3,n+1):
  if oks[i]==True:
    dp[i]=dp[i-2]+dp[i-1]
print(dp[n]%mod)

Fixed submission:
n,m=[int(x) for x in input().rstrip().split()]
a=[int(input()) for i in range(m)]
oks=[True for i in range(n+1)]

mod=10**9+7
dp=[0 for i in range(n+1)]
for i in a:
  oks[i]=False

if oks[1]==True:
  dp[1]=1
dp[0]=1
for i in range(2,n+1):
  if oks[i]==True:
    dp[i]=dp[i-2]+dp[i-1]
print(dp[n]%mod)