Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02660 (python)

Fixed submission:
import numpy as np
import math

def fuctrization(n):
    arr = []
    tmp = n
    for i in range(2,math.ceil(n**(1/2))+1):
        if tmp%i==0:
            j = 0
            while tmp%i==0:
                j += 1
                tmp //= i
            arr.append([i,j])
    if tmp != 1:
        arr.append([tmp,1])
    if arr:
        pass
    else:
        arr.append([n,1])
            
    return arr
            
        
        
n = int(input())
if n == 1:
    print(0)
else:
    arr = fuctrization(n)
    nn = 0
    for i in range(len(arr)):
        k = arr[i][1]
        nnn = 1
        while k-nnn>=0:
            k -= nnn
            nnn += 1
            nn +=1
    print(nn)

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

def fuctrization(n):
    arr = []
    tmp = n
    for i in range(2,math.ceil(n**(1/2))+1):
        if tmp%i==0:
            j = 0
            while tmp%i==0:
                j += 1
                tmp //= i
            arr.append([i,j])
    if tmp != 1:
        arr.append([tmp,1])
    if arr:
        pass
    else:
        arr.append([n,1])
            
    return arr
            
        
        
n = int(input())
if n == 1:
    print(0)
else:
    arr = fuctrization(n)
    nn = 0
    for i in range(len(arr)):
        k = arr[i][1]
        nnn = 1
        while k-nnn>0:
            k -= nnn
            nnn += 1
            if k-nnn == 0:
                pass
            elif nnn != 1:
                nnn -= 1
        nn += nnn
print(nn)
Problem p02675 (python)

Fixed submission:
N=str(input())
N=N[-1]
  
if N in ["2","4","5","7","9"]:
  print("hon")
elif N == "3":
  print("bon")
else:
  print("pon")

Buggy submission (verdict: Runtime Error):
N=input()
if len(n)>1:
  N=N[1]
  
if N in ["2","4","5","7","9"]:
  print("hon")
elif N == "3":
  print("bon")
else:
  print("pon")
Problem p02630 (python)

Fixed submission:
import sys
n = int(input())
a = list(map(int,sys.stdin.readline().split()))
q = int(input())
s = sum(a)
cnt = [0]*(10**5+5)
for c in a:
  cnt[c] +=1
for i in range(q):
  b,c = map(int,sys.stdin.readline().split())
  bdif = c-b
  s += cnt[b]*bdif
  cnt[c] += cnt[b]
  cnt[b] = 0
  print(s)

Buggy submission (verdict: Runtime Error):
import sys
def Ii():return int(sys.stdin.readline())
def Mi():return map(int,sys.stdin.readline().split())
def Li():return list(map(int,sys.stdin.readline().split()))

n = Ii()
a = Li()
sa = sum(a)
af = [0]*(10**5)
for i in a: 
  af[i]+=1
q = Ii()
for i in range(q):
  b,c = Mi()
  sa = sa + (c-b)*af[b]
  af[c] += af[b]
  af[b] = 0;
  print(sa)

Buggy submission (verdict: Runtime Error):
import sys
def Ii():return int(sys.stdin.readline())
def Mi():return map(int,sys.stdin.readline().split())
def Li():return list(map(int,sys.stdin.readline().split()))

n = Ii()
a = Li()
sa = sum(a)
af = [0]*(10**5)
for i in a: 
  af[i]+=1
q = Ii()
for i in range(q):
  b,c = Mi()
  sa = sa + (c-b)*af[b]
  af[c] += af[b]
  af[b] = 0;
  print(sa)
Problem p02640 (python)

Fixed submission:
X,Y = map(int,input().split())
if Y%2 == 0:
  y = Y//2
else:
  print('No')
  exit(0)

if X <= y <=2*X:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
X,Y = map(int,input().split())
if y%2 == 0:
  y = Y//2
else:
  print('No')
  exit(0)

if x < y <2*x:
  print('Yes')
else:
  print('No')
Problem p02658 (python)

Fixed submission:
def Ii():return int(input())
def Mi():return map(int,input().split())
def Li():return list(map(int,input().split()))
n = Ii()
a = sorted(Li())

mx = 10**18
ans = 1
for i in a:
  
  ans *= i
  if ans > mx:
    ans = -1
    break
  elif ans == 0:
    break
    
print(ans)

Buggy submission (verdict: Runtime Error):
using System;
using System.Linq;
class program{
  static void Main(){
    int n = int.Parse(Console.ReadLine());
    long[] a = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
    long ans = 1;
    a.Sort();
    if(a[0] == 0){
      Console.Write(0);
      return;
    }
    for(int i = 0;i<n;i++){
      if(ans*a[i] > 1e18){
        Console.Write(-1);
      	return;
      }
      ans *= a[i];
    }
    Console.Write(ans);
  }
}
Problem p02675 (python)

Fixed submission:
def Ii():return int(input())
def Mi():return map(int,input().split())
def Li():return list(map(int,input().split()))
 
n = Ii()%10
if n == 3:
  print('bon')
elif n==2 or n == 4 or n == 5 or n==7 or n == 9:
  print('hon')
else:
  print('pon')

Buggy submission (verdict: Runtime Error):
def Ii():return int(input())
def Mi():return map(int,input().split())
def Li():return list(map(int,input().split()))

n = Ii()%10
if n == 3
  print('bon')
elif n==2 or n == 4 or n == 5 or n==7 or n == 9
  print('hon')
else
  print('pon')
Problem p02681 (python)

Fixed submission:
a = input()
b = input()
if a == b[:-1]:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
using System;
using System.Linq;

class program
{
    static void Main()
    {
        var abck = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        var a = abck[0];
      	var b = abck[1];
      	var k = abck[3];
        if (a+b > k)
        {
            Console.Write(a);
            return;
        }
        else
        {
            Console.Write(2*a+b-k);
        }
    }
}

Buggy submission (verdict: Runtime Error):
a = input()
b = input()
b.pop()
if a == b[:-1]:
  print('Yes')
else:
  print('No')
Problem p02694 (python)

Fixed submission:
import sys
import math
def Ii():return int(sys.stdin.buffer.readline())
def Mi():return map(int,sys.stdin.buffer.readline().split())
def Li():return list(map(int,sys.stdin.buffer.readline().split()))
 
x = Ii()
ans = 0
k = 100
while x > k:
  tax = k//100
  k += tax  
  ans += 1
  
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
import math
def Ii():return int(sys.stdin.buffer.readline())
def Mi():return map(int,sys.stdin.buffer.readline().split())
def Li():return list(map(int,sys.stdin.buffer.readline().split()))

x = Ii()
ans = (math.log10(x) - 2)math.log10(1.01)
k = 100
while x > k:
  tax = k//100
  k += tax  
  ans += 1
  
print(ans)
Problem p02583 (python)

Fixed submission:
n=int(input())
Ns=list(map(int, input().split() ) ) 
ans=0
for i in range(n):
  for j in range(i,n):
    for k in range(j,n):
      a , b , c = sorted([Ns[i] , Ns[j] , Ns[k]])
      if a+b>c and a!=b and b!=c:
        ans+=1
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
Ns=list(map(int, input().split() ) ) 
ans=0
for i in range(n):
  for j in range(i,j):
    for k in range(j,n):
      a , b , c = sorted([Ns[i] , Ns[j] , Ns[k]])
      if a+b>c and a!=b and b!=c:
        ans+=1
print(ans)
Problem p02642 (python)

Fixed submission:
import math , sys

N = int( input() )
A = list( map( int, input().split() ))
A.sort()
Cs = [0 for _ in range(10**6+1)]
M = A[-1]
#print(A)
i=0
M = max(A)
for i in range(N):
    e = A[i]
    if Cs[e]==1:
        Cs[e]=2
    elif Cs[e]==0:
        Cs[e]=1

for i in range(len(Cs)):
    Cs[i] = Cs[i]%2

for e in A:
    i = 2
    while e*i <= M:
        Cs[e*i] = 0
        i+=1
ans = sum(Cs)
print(ans)

Buggy submission (verdict: Runtime Error):
import math , sys

N = int( input() )
A = list( map( int, input().split() ))
A.sort()
Cs = [0 for _ in range(10**6+1)]
M = A[-1]
#print(A)
i=0
M = max(A)
for i in range(N):
    e = A[i]
    if Cs[e]==1:
        Cs[e]=2
    elif Cs[e]==0:
        Cs[e]=1

for i in range(len(Cs)):
    Cs[i] = Cs[i]%2

for e in A:
    i = 2
    while e*i <= 2*M+1:
        Cs[e*i] = 0
        i+=1
ans = sum(Cs)
print(ans)

Buggy submission (verdict: Runtime Error):
import math , sys

N = int( input() )
A = list( map( int, input().split() ))
A.sort()
Cs = [0 for _ in range(10**6+1)]
M = A[-1]
#print(A)
i=0
M = max(A)
for i in range(N):
    e = A[i]
    if Cs[e]==1:
        Cs[e]=2
    elif Cs[e]==0:
        Cs[e]=1

for i in range(len(Cs)):
    Cs[i] = Cs[i]%2

for e in A:
    i = 2
    while e*i <= M+1:
        Cs[e*i] = 0
        i+=1
ans = sum(Cs)
print(ans)

Buggy submission (verdict: Runtime Error):
import math , sys

N = int( input() )
A = list( map( int, input().split() ))
A.sort()
Cs = [0 for _ in range(10**6+1)]
M = A[-1]
#print(A)
i=0
while i < N:
    e = A[i]
    j=i+1
    if j < N:
        if A[j]==e:
            while A[j] == A[i] and j < N:
                j+=1
            i = j
        else:
            Cs[e] = 1
            i+=1
    else:
        Cs[e] = 1
        i+=1
#print(Cs[:30])
for e in A:
    i = 2
    while e*i < 10**6 +1:
        Cs[e*i] = 0
        i+=1
ans = sum(Cs)
print(ans)

Buggy submission (verdict: Runtime Error):
import math , sys

N = int( input() )
A = list( map( int, input().split() ))
A.sort()
Cs = [0 for _ in range(10**6+1)]
M = A[-1]
#print(A)
i=0
while i < N:
    e = A[i]
    j=i+1
    if j < N and A[j]==e:
        while A[j] == A[i]:
            i+=1
        i = j
    else:
        Cs[e] = 1
        i+=1
#print(Cs[:30])
for e in A:
    i = 2
    while e*i < 10**6 +1:
        Cs[e*i] = 0
        i+=1
ans = sum(Cs)
print(ans)

Buggy submission (verdict: Runtime Error):
import math , sys

N = int( input() )
A = list( map( int, input().split() ))
A.sort()
Cs = [0 for _ in range(10**6+1)]
M = A[-1]
#print(A)
i=0
while i < N:
    e = A[i]
    j=i+1
    if j < N and A[j]==e:
        while A[j] == A[i]:
            i+=1
        i = j
    else:
        Cs[e] = 1
        i+=1
#print(Cs[:30])
for e in A:
    i = 2
    while e*i < M+1:
        Cs[e*i] = 0
        i+=1
ans = sum(Cs)
print(ans)
Problem p02691 (python)

Fixed submission:
import math , sys

N  = int( input() )

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

def Prime(x):
    ub=int(math.sqrt(x))+2
    if x==2 or x==3 or x==5 or x==7:
        return True
    for i in range(2,ub):
        if x%i==0:
            return False
    return True

y = N
while not Prime(y):
    y+=1

def h1(x):
    return x % y
def h2(x):
    return 1+ x%(y-1)
def h(x,i):
    return (h1(x) + i*h2(x)) % y

def insert(T,x):
    i=0
    while True:
        j=h(x,i)
        if T[j][0]== -1:
            T[j][0]=x
            T[j][1]=1
            return j
        elif x ==T[j][0]:
            T[j][1]+=1
            return j
        else:
            i+=1

def search(T,x):
    i=0
    while True:
        j=h(x,i)
        if T[j][0] == x:
            return T[j][1]
        elif T[j][0] == -1:
            return -1
        else:
            i+=1

T = [[-1,0] for _ in range(y)]
for i in range(N):
    insert(T , i + A[i])
ans =0
        
for j in range(N):
    if j - A[j]>=0:
        s = search(T, j - A[j])
        if s >=0:
            ans+=s
print(ans)

Buggy submission (verdict: Runtime Error):
import math , sys

N  = int( input() )

A = list(map(int, input().split() ) )
M = max( [ i + A[i] for i in range(N) ])
B = [0] * (2*M)
ans = 0
for i in range(N):
    if i - A[i] >=0:
        ans += B[i - A[i]]
    B[i + A[i]]+=1
print(ans)

Buggy submission (verdict: Runtime Error):
import math , sys

N  = int( input() )

A = list(map(int, input().split() ) )
M = max( [ i + A[i] for i in range(N) ])
B = [0] * (M + 2)
ans = 0
for i in range(N):
    if i - A[i] >=0:
        ans += B[i - A[i]]
    B[i + A[i]]+=1
print(ans)
Problem p02741 (python)

Fixed submission:
print([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][int(input())-1])

Buggy submission (verdict: Runtime Error):
l=[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( l[int(input())+1])
Problem p02743 (python)

Fixed submission:
a, b, c=map(int, input().split())
left=(a+b-c)**2
right=4*a*b
print("Yes") if a+b<c and left> right else print("No")

Buggy submission (verdict: Runtime Error):
a,b,c=map(int, imput().split())
left=(a+b-c)**2
right=4*a*b
if a+b < c and left < right:
  print("Yes")
else:
  print("No")
Problem p02747 (python)

Fixed submission:
s=input()
while True:
  if len(s)==0:
    print("Yes")
    break
  elif len(s)==1:
    print("No")
    break
  elif s[:2]=="hi":
    s=s[2:]
  else:
    print("No")
    break

Buggy submission (verdict: Runtime Error):
def lin(t,i):
    return As[i]*t+Bs[i]
f=input().split(" ")
n,t=int(f[0]),int(f[1])
As=[]
Bs=[]
for i in range(n):
    f=input().split(" ")
    As.append(int(f[0]))
    Bs.append(int(f[1]))
time=0
count=0
shop_list=list(range(n))
while len(shop_list)>0:
    test=min(enumerate([lin(time+1,i) for i in shop_list]), key = lambda x:x[1])
    next_time,shop=test[1],shop_list[test[0]]
    if time+1+next_time>t:
        break
    else:
        time=time+1+next_time
        shop_list.remove(shop)
        count+=1
print(count)
Problem p02760 (python)

Fixed submission:
import itertools as it
dic={}
bing=[[0 for i in range(3)] for j in range(3)]
for i in range(3):
    f=list(map(int,input().split()))
    for each in f:
        dic.update({each:(i,f.index(each))})
n=int(input())
for i in range(n):
    m=int(input())
    if m in dic.keys():
        place=dic[m]
        bing[place[0]][place[1]]=1
flag=False
code="000102101112202122"
code=code+code[::-1]
code=code+"001122021120"

for i in range(8):
    code_sep=code[6*i:6*i+6]
    p=1
    for j in range(3):
        cords=code_sep[2*j:2*j+2]
        p*=bing[int(cords[0])][int(cords[1])]
    if p==1:
        flag=True
        break
    
print("Yes")if flag else print("No")

Buggy submission (verdict: Runtime Error):
import itertools as it
dic={}
bing=[[1 for i in range(3)] for j in range(3)]
for i in range(3):
    f=list(map(int,input().split()))
    for each in f:
        dic.update({each:(i,f.index(each))})
n=int(input())
for i in range(n):
    m=int(input())
    place=dic[m]
    bing[place[0]][place[1]]=0
flag=False
code="000102101112202122"
code=code+code[::-1]
code=code+"001122021120"

for i in range(8):
    code_sep=code[6*i:6*i+6]
    p=0
    for j in range(3):
        cords=code_sep[2*j:2*j+2]
        p+=bing[int(cords[0])][int(cords[1])]
    if p==0:
        flag=True
        break
    
print("Yes")if flag else print("No")

Buggy submission (verdict: Runtime Error):
import itertools as it
dic={}
bing=[[0 for i in range(3)] for j in range(3)]
for i in range(3):
    f=list(map(int,input().split()))
    for each in f:
        dic.update({each:(i,f.index(each))})
n=int(input())
for i in range(n):
    m=int(input())
    place=dic[m]
    bing[place[0]][place[1]]=1
flag=False
code="000102101112202122"
code=code+code[::-1]
code=code+"001122021120"

for i in range(8):
    code_sep=code[6*i:6*i+6]
    p=1
    for j in range(3):
        cords=code_sep[2*j:2*j+2]
        p*=bing[int(cords[0])][int(cords[1])]
    if p==1:
        flag=True
        break
    
print("Yes")if flag else print("No")

Buggy submission (verdict: Runtime Error):
bing=[]
for i in range(3):
  bing.append(list(map(int,input().aplit())))
import itertools as it
dic={}
bing=[[1 for i in range(3)] for j in range(3)]
for i in range(3):
    f=list(map(int,input().split()))
    for each in f:
        dic.update({each:(i,f.index(each))})
n=int(input())
for i in range(n):
    m=int(input())
    place=dic[m]
    bing[place[0]][place[1]]=0
flag=False
code="000102101112202122"
code=code+code[::-1]
code=code+"001122021120"

for i in range(8):
    code_sep=code[6*i:6*i+6]
    p=0
    for j in range(3):
        cords=code_sep[2*j:2*j+2]
        p+=bing[int(cords[0])][int(cords[1])]
    if p==0:
        flag=True
        break
    
print("yes")if flag else print("No")
Problem p02838 (python)

Fixed submission:
mod=10**9+7
N=int(input())
str_a = ''.join(['{:060b}'.format(a) for a in map(int, input().split())])

ans=0
for i in range(60):
    ones=str_a[59-i::60].count("1")
    ans+= pow( 2, i ,mod)* ones *(N-ones)
print(ans%mod)

Buggy submission (verdict: Runtime Error):
import math

N=int(input())
l=10**9+7
nums=list(map(int,input().split()))

#k=len(str(bin(max(nums))))-2
k=int(math.log2(max(nums)))+1

mat=[]
for each in nums:
    num=str(bin(each))[2:].zfill(k)
    mat.append(list(num))
 
mat=list(zip(*mat))
ans=0
 
for i in range(k):
    b=mat[i].count("1")
    ans+=b*(N-b)*pow(2,(k-i-1),l)
print(ans%l)

Buggy submission (verdict: Runtime Error):
import math

N=int(input())
l=10**9+7
nums=list(map(int,input().split()))
k=int(math.log2(max(nums)))+1
mat=[]
for each in nums:
    num=str(bin(each))[2:].zfill(k)
    mat.append(list(num))
 
mat=list(zip(*mat))
ans=0
 
for i in range(k):
    b=mat[i].count("1")
    ans+=b*(N-b)*pow(2,(k-i-1),l)
print(ans%l)

Buggy submission (verdict: Runtime Error):
import math

N=int(input())
l=10**9+7
nums=list(map(int,input().split()))
k=math.log2(max(nums))+1
mat=[]
for each in nums:
    num=str(bin(each))[2:].zfill(k)
    mat.append(list(num))
 
mat=list(zip(*mat))
ans=0
 
for i in range(k):
    b=mat[i].count("1")
    ans+=b*(N-b)*pow(2,(k-i-1),l)
print(ans%l)

Buggy submission (verdict: Runtime Error):
import math 

N=int(input())
l=10**9+7
nums=list(map(int,input().split()))
k=int(math.log2(max(nums)))+1
mat=[0]*k
for each in nums:
    num=str(bin(each))[2:].zfill(k)
    for i in range(k):
        if num[i]=="1":
            mat[i]+=1

ans=sum([ (N-mat[i])*mat[i]*pow(2,(k-i-1),l) for i in range(k)])
print(ans%l)

Buggy submission (verdict: Runtime Error):
import math 

N=int(input())
l=10**9+7
nums=list(map(int,input().split()))
k=int(math.log2(max(nums)))+1
mat=[0]*k
for each in nums:
    num=(str(bin(each))[2:])[::-1]
    kk=len(num)
    for i in range(kk):
        if num[i]=="1":
            mat[i]+=1

ans=sum([ (N-mat[i])*mat[i]*pow(2,i,l) for i in range(k)])
print(ans%l)

Buggy submission (verdict: Runtime Error):
=int(input())
l=10**9+7
nums=list(map(int,input().split()))
k=len(str(bin(max(nums))))-2
mat=[]
for each in nums:
    num=str(bin(each))[2:].zfill(k)
    mat.append(list(num))

mat=list(zip(*mat))
ans=0

for i in range(k):
    b=mat[i].count("1")
    
    ans+=b*(N-b)*(2**(k-i-1))
print(ans)
Problem p02744 (python)

Fixed submission:
from collections import defaultdict
n=int(input())
al=[chr(ord('a') + i) for i in range(26)]
norm=defaultdict(list)
def max_al(s):
  tmp=0
  for i in range(len(s)):
    tmp2=al.index(s[i])
    tmp=max(tmp,tmp2)
  return tmp

for i in range(11):
  if i==0:
    norm[1]=['a']
  else:
    for char in norm[i-1]:
      range_digit=max_al(char)+2
      for s in al[0:range_digit]:
        norm[i].append(char+s)

for char in norm[n]:
  print(char)

Buggy submission (verdict: Runtime Error):
from collections import deque
n=int(input())
al=[chr(ord('a') + i) for i in range(26)]
norm=defaultdict(list)
for i in range(11):
  if i==0:
    norm[1]=['a']
  else:
    for char in norm[i-1]:
      last=char[-1]
      range_digit=al.index(last)+2
      for s in al[0:range_digit]:
        norm[i].append(char+s)

for char in norm[n]:
  print(char)
Problem p02755 (python)

Fixed submission:
import sys
a,b=map(int,input().split())

if a%2==0:
  lower1=int(a*100/8)
  upper1=(a+1)*100/8
  upper1=max(lower1,int(upper1)-1)  
else:
  lower1=a*(100/8)
  upper1=int((a+1)*100/8)
  if (upper1)-int(lower1)<=1:
    print(-1)
    sys.exit()
  else:
    lower1=int(lower1)+1
    if lower1==upper1:
      print(-1)
      sys.exit()
    else:
      pass
  
lower2=(b)*10
upper2=(b+1)*10

lower=max(lower1,lower2)
upper=min(upper1,upper2)
if upper-lower<1:
  print(-1)
else:
  print(lower)

Buggy submission (verdict: Runtime Error):
import sys
a,b=map(int,input().split())

if a%2==0:
  lower1=int(a*100/8)
  upper1=(a+1)*100/8
  upper1=max(lower,int(upper1)-1)  
else:
  lower1=a*(100/8)
  upper1=int((a+1)*100/8)
  if (upper1)-int(lower1)<=1:
    print(-1)
    sys.exit()
  else:
    lower1=int(lower1)+1
    if lower1==upper1:
      print(-1)
      sys.exit()
    else:
      pass
  
lower2=(b)*10
upper2=(b+1)*10

lower=max(lower1,lower2)
upper=min(upper1,upper2)
if upper-lower<0:
  print(-1)
else:
  print(lower)

Buggy submission (verdict: Runtime Error):

import sys
a,b=map(int,input().split())

if a%2==0:
  lower1=int(a*100/8)
else:
  lower1=a*(100/8)
  upper1=int((a+1)*100/8)
  if (upper1)-int(lower1)<1:
    print(-1)
    sys.exit()
  else:
    lower1=int(lower1)+1
    if lower1=upper1:
      print(-1)
      sys.exit()
    else:
      pass
  
lower2=(b)*10
upper2=(b+1)*10

lower=max(lower1,lower2)
if lower=uppwer1:
  print(-1)
else:
  print(lower)
Problem p02756 (python)

Fixed submission:
s=str(input())

N=int(input())
cnt=0
f=''
b=''
for i in range(N):
  inp=str(input())
  if len(inp)==1:
    cnt+=1
  else:
    F,c=int(inp[2]),inp[4]
    if F==1:
      if cnt%2==0:
        f=c+f
      else:
        b+=c
    else:
      if cnt%2==0:
        b+=c
      else:
        f=c+f
if cnt%2==0:
  print(f+s+b)
else:
  ans=f+s+b
  L=len(ans)
  if L==1:
    print(ans)
  else:
    if L%2==1:
      f=ans[0:L//2]
      s=ans[L//2]
      b=ans[L//2+1:L]
      f_=''.join(list(reversed(b)))
      b_=''.join(list(reversed(f)))
      print(f_+s+b_)
    else:
      f=ans[0:L//2]
      b=ans[L//2:L]
      f_=''.join(list(reversed(b)))
      b_=''.join(list(reversed(f)))
      print(f_+b_)

Buggy submission (verdict: Runtime Error):
s=str(input())

N=int(input())
cnt=0
f=''
b=''
for i in range(N):
  inp=str(input())
  if len(inp)==1:
    cnt+=1
  else:
    F,c=int(inp[2]),inp[4]
    if F==1:
      if cnt%2==0:
        f=c+f
      else:
        b+=c
    else:
      if cnt%2==0:
        b+=c
      else:
        f=c+f
if cnt%2==0:
  print(f+s+b)
else:
  ans=f+s+b
  L=len(ans)
  if L==1:
    print(ans)
  else:
    if L%2==1:
      f=ans[0:L//2]
      s=ans[L//2]
      b=ans[L//2+1:L]
      print(''.join(list(reversed(b))))+s+''.join(list(reversed(f)))
    else:
      f=ans[0:L//2]
      b=ans[L//2:L]
      f_=''.join(list(reversed(b)))
      b_=''.join(list(reversed(f)))
      print(f_+b_)

Buggy submission (verdict: Runtime Error):
s=str(input())

N=int(input())
cnt=0
f=''
b=''
for i in range(N):
  inp=str(input())
  if len(inp)==1:
    cnt+=1
  else:
    F,c=int(inp[2]),inp[4]
    if F==1:
      if cnt%2==0:
        f=c+f
      else:
        b+=c
    else:
      if cnt%2==0:
        b+=c
      else:
        f=c+f
if cnt%2==0:
  print(f+s+b)
else:
  ans=f+s+b
  L=len(ans)
  if L%2==1:
    f=ans[0:L//2]
    s=ans[L//2]
    b=ans[L//2+1:L]
    print(''.join(list(reversed(b))))+s+''.join(list(reversed(f)))
  else:
    f=ans[0:L//2]
    b=ans[L//2:L]
    f_=''.join(list(reversed(b)))
    b_=''.join(list(reversed(f)))
    print(f_+b_)