Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
s = list(input())
se = (s)
k = int(input())
n = len(s)

se = set()
for i in range(n):
    for j in range(i+1,i+1+k):
#        print(i,j,s[i:j])
        se.add(s[i:j])
#print(se)
l = sorted(list(se))
print(l[k-1])
        










#TLE 
'''
se = set()
for i in range(n):
    for j in range(i+1,n+1):
#        print(i,j,s[i:j])
        se.add(s[i:j])
#print(se)
l = sorted(list(se))
print(l[k-1])
'''

Fixed submission:
s = input()
se = (s)
k = int(input())
n = len(s)

se = set()
for i in range(n):
    for j in range(i+1,i+1+k):
#        print(i,j,s[i:j])
        se.add(s[i:j])
#print(se)
l = sorted(list(se))
print(l[k-1])
        










#TLE 
'''
se = set()
for i in range(n):
    for j in range(i+1,n+1):
#        print(i,j,s[i:j])
        se.add(s[i:j])
#print(se)
l = sorted(list(se))
print(l[k-1])
'''

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
k = int(input())
n = len(s)

se = set()
for i in range(n):
    for j in range(i+1,n+1):
#        print(i,j,s[i:j])
        se.add(s[i:j])
#print(se)
l = sorted(list(se))
print(l[k-1])

Fixed submission:
s = input()
se = (s)
k = int(input())
n = len(s)

se = set()
for i in range(n):
    for j in range(i+1,i+1+k):
#        print(i,j,s[i:j])
        se.add(s[i:j])
#print(se)
l = sorted(list(se))
print(l[k-1])
        










#TLE 
'''
se = set()
for i in range(n):
    for j in range(i+1,n+1):
#        print(i,j,s[i:j])
        se.add(s[i:j])
#print(se)
l = sorted(list(se))
print(l[k-1])
'''
Buggy python submission (verdict: Runtime Error):
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

h,w = iim()

flag = True

l = []
dx = [0,0,1,-1]
dy = [1,-1,0,0]
for i in range(h):
    l.append(list(input()))

for i in range(h):
    for j in range(w):
        if l[i][j] == '#':
            check = False
            for k in range(4):
                if i+dx[k] < 0 or i+dx[k] >= w:
                    continue
                if j+dy[k] < 0 or j+dy[k] >= h:
                    continue
                if l[i+dx[k]][j+dy[k]] == '#':
                    check = True
            if not check:
                flag = False

print('Yes' if flag else 'No')

Fixed submission:
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

h,w = iim()

flag = True

l = []
dx = [0,0,1,-1]
dy = [1,-1,0,0]
for i in range(h):
    l.append(list(input()))

for i in range(h):
    for j in range(w):
        if l[i][j] == '#':
            check = False
            for k in range(4):
                if i+dx[k] < 0 or i+dx[k] >= h:
                    continue
                if j+dy[k] < 0 or j+dy[k] >= w:
                    continue
                if l[i+dx[k]][j+dy[k]] == '#':
                    check = True
            if not check:
                flag = False

print('Yes' if flag else 'No')
Buggy python submission (verdict: Runtime Error):
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n,m,x = iim()
before = 0
after = 0
for i in range(m):
    if ii() < x:
        before += 1
    else:
        after += 1

print(min(before,after))

Fixed submission:
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n,m,x = iim()
before = 0
after = 0
A = iil()
for i in A:
    if i < x:
        before += 1
    else:
        after += 1

print(min(before,after))
Buggy python submission (verdict: Runtime Error):
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))
n = ii()
A = set(sorted(iil()))
print(set[-1]-set[0])


Fixed submission:
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))
n = ii()
A = set(sorted(iil()))
print(max(A)-min(A))
Buggy python submission (verdict: Runtime Error):
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n = ii()
A = iil()

l = [0]*9
for i in A:
    l[max(i//400,8)] += 1

lf = l[:-1]
ans = 8-lf.count(0)
print(ans,ans+l[8])


Fixed submission:
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n = ii()
A = iil()

l = [0]*9
for i in A:
    l[min(i//400,8)] += 1

lf = l[:-1]
ans = 8-lf.count(0)
print(max(1,ans),ans+l[8])

Buggy python submission (verdict: Runtime Error):
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n = ii()
A = iil()

l = [0]*9
for i in A:
    l[i//400] += 1

lf = l[:-1]
ans = 8-lf.count(0)
print(ans,ans+l[8])


Fixed submission:
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n = ii()
A = iil()

l = [0]*9
for i in A:
    l[min(i//400,8)] += 1

lf = l[:-1]
ans = 8-lf.count(0)
print(max(1,ans),ans+l[8])
Buggy python submission (verdict: Runtime Error):
x = int(input())
num = 0
for i in range(1,1e6):
    num += i
    if num >= x:
        print(i)
        exit() 

Fixed submission:
x = int(input())
num = 0
for i in range(1,1000000):
    num += i
    if num >= x:
        print(i)
        exit()
Buggy python submission (verdict: Time Limit Exceeded):
n, x = map(int,input().split())
A = list(map(int,input().split()))
sum = []
ans = 0
for i in range(n-1):
    sum.append(A[i]+A[i+1])
for j in range(n-1):
    if j != n-2:
        while sum[j] > x:
            sum[j] -= 1
            sum[j+1] -= 1
            ans += 1
    else:
        while sum[j] > x:
            sum[j] -= 1
            ans += 1

print(ans)

Fixed submission:
n, x = map(int,input().split())
A = list(map(int,input().split()))
if A[0] > x:
    ans = A[0] - x
    A[0] -= ans
else:
    ans = 0
for j in range(n):
    if j != n-1:
        if A[j]+A[j+1]> x:
            diff = A[j+1]+A[j]-x
            ans += diff
            if A[j+1] - diff > 0:
                A[j+1] -= diff
            else:
                A[j+1] = 0
    else:
        if A[j]> x:
            diff = A[j]-x
            ans += diff
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):

n = int(input())
T = [0]*n
A = [0]*n
Tvote = [0]*n
Avote = [0]*n

for i in range(n):
    T[i], A[i] = map(int,input().split())

for k in range(n):
    if k == 0:
        Tvote[k] = T[k]
        Avote[k] = A[k]
    else:
        j = 1
        while Tvote[k-1]>j*T[k] or Avote[k-1]>j*A[k]:
            j += 1
        Tvote[k] = j*T[k]
        Avote[k] = j*A[k]

#print("---Tvote:{}".format(Tvote))
#print("---Avote:{}".format(Avote))
print(Tvote[n-1]+Avote[n-1])

Fixed submission:
import math
n = int(input())
T = [0]*n
A = [0]*n
Tvote = [0]*n
Avote = [0]*n

for i in range(n):
    T[i], A[i] = map(int,input().split())

for k in range(n):
    if k == 0:
        Tvote[k] = T[k]
        Avote[k] = A[k]
    else:
        '''
        j = math.ceil(max(Tvote[k-1]/T[k],Avote[k-1]/A[k]))
        print(Tvote[k-1]/T[k])
        print(Avote[k-1]/A[k])
        print(max(Tvote[k-1]/T[k],Avote[k-1]/A[k]))
        print(j)
        print(Avote[k-1], A[k]*j)
        print(bool(Avote[k-1]<A[k]*j))
        print(bool(j>Avote[k-1]/A[k]))
        '''
        j = int(min(Tvote[k-1]//(-T[k]),Avote[k-1]//(-A[k])))*-1
        #普通に割り算やると誤差で死ぬ（floatがむずい。）
        # // は整数の除算で常に負の無限大方向に丸められる
        #一度も float になることがないはずなので、正しい計算結果が出る
        #https://paiza.hatenablog.com/entry/2017/08/01/Python3%E3%81%A7%E5%B7%A8%E5%A4%A7%E3%81%AA%E6%B5%AE%E5%8B%95%E5%B0%8F%E6%95%B0%E8%A8%88%E7%AE%97%E3%81%AE%E7%B5%90%E6%9E%9C%E3%81%8C%E5%A4%89%E3%81%A0%E3%81%A3%E3%81%9F%E3%81%AE%E3%81%A7%E7%90%86
        #正の無限大方向に丸めたいので-1かけてから計算して（丸めて）あとで-1かける。その際Av/AとTv/Tの比較も逆をとるのに注意
#        j = 1
#        while Tvote[k-1]>j*T[k] or Avote[k-1]>j*A[k]:
#            j += 1
#これは投票数が多すぎるのでTLE
        Tvote[k] = j*T[k]
        Avote[k] = j*A[k]
#    print("---input:{}:{}--vote{}:{}--diff{}".format(T[k],A[k],Tvote[k],Avote[k],bool(T[k]/A[k]==Tvote[k]/Avote[k])))   

#print("---Tvote:{}".format(Tvote))
#print("---Avote:{}".format(Avote))
#print('hoge')
#for i in range(n):
#    print(Tvote[i],Avote[i])
print(Tvote[n-1]+Avote[n-1])
Buggy python submission (verdict: Runtime Error):
import math
import sys
sys.setrecursionlimit(10000000)

n = int(input())
s = int(input())

up = math.sqrt(n)

def colsum(num, base):
    if num < base:
        return num
    else:
        return num%base + colsum(num//base,base)

#s = n(n<b)
if s == n:
    print(n+1)
    exit()


#sqrt(n)まで探索
for i in range(2,int(up)+1):
    if s == colsum(n,i):
        print(i)
        exit()

#2桁しかあり得ない場合(sqrt(n)<b<n)
for j in range(1,int(up)+1):
    if (n-s)%j == 0:
        b = (n-s)/j + 1
        if s == colsum(n,b) and b > 1:
            print(i)
            exit()

print(-1)

Fixed submission:
n = int(input())
k = int(input())
x = int(input())
y = int(input())
if n > k:
    print(k*x+(n-k)*y)
else:
    print(n*x)
Buggy python submission (verdict: Time Limit Exceeded):
flg_stop = False
count = 1

K = int(input())

if K % 2 == 0:
    count = -1
    flg_stop = True
else:
    if K % 7 == 0:
        L = 9 * K / 7
    else:
        L = 9 * K

    mod_ = 1
    while not(flg_stop):
        mod_ = (mod_ * 10) % L
        if mod_ == 1:
            flg_stop = True
            continue
        count += 1

print(count)

Fixed submission:
k = int(input())
i = 1
a = 7
a = a % k
while a != 0:
  i += 1
  a = (10*a + 7) % k
  if i == 10**6:
    i = -1
    break
 
print(i)

Buggy python submission (verdict: Time Limit Exceeded):

num = 7
K = int(input())

flg_stop = False
count = 1

if K % 2 == 0:
    count = -1
    flg_stop = True


while not(flg_stop):
    mod_ = num % K
    if mod_ == 0:
        flg_stop = True
        continue
    num_2 = 7 * 10 ** count
    mod_2 = num_2 % K
    num = mod_ + mod_2
    count += 1

print(count)


Fixed submission:
k = int(input())
i = 1
a = 7
a = a % k
while a != 0:
  i += 1
  a = (10*a + 7) % k
  if i == 10**6:
    i = -1
    break
 
print(i)
Buggy python submission (verdict: Runtime Error):
n = int(input())  # nは入力回数
num_list = list(map(int, input().split()))
count = 0

if n//2 == 0:
  for i in range(n//2):
    if (num_list[2*i]%2) == 1:
      count += 1
else:
  for i in range((n//2) + 1):
    if (num_list[2*i]%2) == 1:
      count += 1
      
print(count)

Fixed submission:
n = int(input())  # nは入力回数
num_list = list(map(int, input().split()))
count = 0

if n%2 == 0:
  for i in range(n//2):
    if (num_list[2*i]%2) == 1:
      count += 1
else:
  for i in range((n//2) + 1):
    if (num_list[2*i]%2) == 1:
      count += 1
      
print(count)
Buggy python submission (verdict: Runtime Error):
import numpy as np
N = int(input())
A = list(map(int, input().split()))
if N > len(A):
  print(0)
else:
  tmp = 1
  for i in range(N):
    tmp *= A[i]
  if np.log10(tmp) > 18:
    print(-1)
  else:
    print(tmp)


Fixed submission:
s = input().split()
print(int(s[0]) * int(s[1]))

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = map(int, input().split())
if N > len(A):
  print(0)
else:
  tmp = 1
  for i in range(N):
    tmp *= A[i]
  if np.log(tmp) > 18:
    print(tmp)
  else:
    print(-1)


Fixed submission:
s = input().split()
print(int(s[0]) * int(s[1]))

Buggy python submission (verdict: Runtime Error):
s = input().split()
s[0] * s[1]

Fixed submission:
s = input().split()
print(int(s[0]) * int(s[1]))
Buggy python submission (verdict: Runtime Error):
A = list(map(int, input().split()))  # 入力のときに N を使う必要はありません
i_max = 0
i_count = 0
j_count = 0

for x in range(1, A[2]+1):
  if i_max < ((A[0]*x)//A[1]-A[0]*(x//A[1])):
    i_max = ((A[0]*x)//A[1]-A[0]*(x//A[1]))
    i_count = x
  if (x - i_count) == 1:
    j_count = j_count + 1
  if (j_count == 2):
    break
    
print(i_count)


Fixed submission:
N = int(input())
A = list(map(int, input().split()))  # 入力のときに N を使う必要はありません
icount = 0
if A[1] - A[0] >= N:
  print('OK')
  icount = icount + 1
else:
  for i in range(A[0], A[1]+1):
    if i % N == 0:
      print('OK')
      icount = icount + 1
      if icount == 1:
        break
      
if icount == 0:
  print('NG')

Buggy python submission (verdict: Runtime Error):
A = list(map(int, input().split()))
icount = 0
if A[2] - A[1] >= A[0]:
  print('OK')
  icount = icount + 1
else:
  for i in range(A[1]:A[2]+1):
    if i % A[0] == 0:
      print('OK')
      icount = icount + 1
      if icount == 1:
        break
      
if icount == 0:
  print('NG')
    


Fixed submission:
N = int(input())
A = list(map(int, input().split()))  # 入力のときに N を使う必要はありません
icount = 0
if A[1] - A[0] >= N:
  print('OK')
  icount = icount + 1
else:
  for i in range(A[0], A[1]+1):
    if i % N == 0:
      print('OK')
      icount = icount + 1
      if icount == 1:
        break
      
if icount == 0:
  print('NG')
Buggy python submission (verdict: Runtime Error):
X = int(input())
N = 100
for i in range(1:10000000000):
  N = int(N*1.01)
  if N >= X:
    print(i)
    break

Fixed submission:
X = int(input())
N = 100
for i in range(1,10000000000):
  N = int(N*1.01)
  if N >= X:
    print(i)
    break
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
fruits = list(map(int, input().split()))

mix = []

for mix in range(k):
    mix.append(min(fruits))
    fruits.remove(min(fruits))

print(sum(mix))

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

mix = []
a = 0

while a < k:
    mix.append(min(fruits))
    fruits.remove(min(fruits))
    a += 1

print(sum(mix))
Buggy python submission (verdict: Runtime Error):
n = input()

def num2alpha(num):
    if num<=26:
        return chr(96+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(122)
    else:
        return num2alpha(num//26)+chr(96+num%26)


print(num2alpha(n))

Fixed submission:
n = int(input())

def num2alpha(num):
    if num <= 26:
        return chr(96 + num)
    elif num % 26 == 0:
        return num2alpha(num // 26 - 1) + chr(122)
    else:
        return num2alpha(num // 26) + chr(96 + num % 26)

print(num2alpha(n))

Buggy python submission (verdict: Runtime Error):
n = input()

def num2alpha(num):
    if num<=26:
        return chr(64+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(64+num%26)
    
print(num2alpha(n))

Fixed submission:
n = int(input())

def num2alpha(num):
    if num <= 26:
        return chr(96 + num)
    elif num % 26 == 0:
        return num2alpha(num // 26 - 1) + chr(122)
    else:
        return num2alpha(num // 26) + chr(96 + num % 26)

print(num2alpha(n))
Buggy python submission (verdict: Runtime Error):
x, y = map(int, input().split())

c = 0

while x >= 0 :
    if c * 2 + x * 4 == y :
        break 
    c += 1
    x -= 1
else :
    print(No)

print(Yes)

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

c = 0

while x >= 0:
    if c * 2 + x * 4 == y:
        break
    c += 1
    x += -1
else:
    print("No")
    exit()

print("Yes")

Buggy python submission (verdict: Runtime Error):
x, y = map(int, input().split())

c = 0
t = x

while t >= 0 :
    if c * 2 + t * 4 == y :
        break 
    c += 1
    t += -1
else :
    print(No)

print(Yes)

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

c = 0

while x >= 0:
    if c * 2 + x * 4 == y:
        break
    c += 1
    x += -1
else:
    print("No")
    exit()

print("Yes")

Buggy python submission (verdict: Runtime Error):
x , y = map(int, input().split())

c = 0
t = x

while t >= 0 :
    if c * 2 + t * 4 = y :
        break 
    c += 1
    t += -1
else :
    print(No)

print(Yes)

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

c = 0

while x >= 0:
    if c * 2 + x * 4 == y:
        break
    c += 1
    x += -1
else:
    print("No")
    exit()

print("Yes")

Buggy python submission (verdict: Runtime Error):
x , y = map(int, input().split()))

ans = False
c = 0
t = x

while ans = False :
    if t = -1 :
        break 
        elif c*2+t*4 == y :
            ans = True
        elif : 
            c += 1
            t += -1

if ans :
    print(Yes)
    elif :
      print(No)
    

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

c = 0

while x >= 0:
    if c * 2 + x * 4 == y:
        break
    c += 1
    x += -1
else:
    print("No")
    exit()

print("Yes")
Buggy python submission (verdict: Runtime Error):
text = input()
if text[1] == "S":
	if text[0] == "R" or text[2] == "R":
    	print(1)
    else:
        print(0)
else:
    if text[0] == "R" and text[2] == "R":
    	print(3)
    elif text[0] == "R" or text[2] == "R":
        print(2)

Fixed submission:
text = input()
if text[1] == "S":
    if text[0] == "R" or text[2] == "R":
        print(1)
    else:
        print(0)
else:
    if text[0] == "R" and text[2] == "R":
        print(3)
    elif text[0] == "R" or text[2] == "R":
        print(2)
    else:
        print(1)

Buggy python submission (verdict: Runtime Error):
    text = input()
    if text[1] == "S":
        if text[0] == "R" or text[2] == "R":
            print(1)
        else:
            print(0)
    else:
        if text[0] == "R" and text[2] == "R":
            print(3)
        elif text[0] == "R" or text[2] == "R":
            print(2)

Fixed submission:
text = input()
if text[1] == "S":
    if text[0] == "R" or text[2] == "R":
        print(1)
    else:
        print(0)
else:
    if text[0] == "R" and text[2] == "R":
        print(3)
    elif text[0] == "R" or text[2] == "R":
        print(2)
    else:
        print(1)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = list(input())

min = n
for i in range(n):
    count = 0
    for j in range(n):
        if j == i:
            continue
        elif ((j < i and s[j] != "E")
            or (j > i and s[j] != "W")):
            count += 1
        if count > min:
            break
    if count < min:
        min = count

print(min)


Fixed submission:
n = int(input())
s = list(input())

min = n
count = 0
for i in range(1, n):
    if s[i] == "E":
        count += 1
min = count

for i in range(1, n):
    if s[i] == "E":
        count -= 1
    if s[i-1] == "W":
        count += 1

    if count < min:
        min = count

print(min)

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

min = n
for i in range(n):
    count = 0
    for j in range(n):
        if j == i:
            continue
        elif ((j < i and s[j] != "E")
            or (j > i and s[j] != "W")):
            count += 1
    if count < min:
        min = count

print(min)


Fixed submission:
n = int(input())
s = list(input())

min = n
count = 0
for i in range(1, n):
    if s[i] == "E":
        count += 1
min = count

for i in range(1, n):
    if s[i] == "E":
        count -= 1
    if s[i-1] == "W":
        count += 1

    if count < min:
        min = count

print(min)
Buggy python submission (verdict: Runtime Error):

if w_count >= r_count:
    print(w_count)
else:
    print(w_count - right_w_count)


Fixed submission:
n = int(input())

c = list(input())

w_count = c.count("W")
r_count = c.count("R")

right_center = c[r_count:]
right_w_count = right_center.count("W")

print(w_count - right_w_count)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split(" "))
a = list(map(int, input().split(" ")))

score: list = []
for i in range(k - 1, n):
    tmp_score = 1
    for j in range(k):
        tmp_score *= a[i - j]
    score.append(tmp_score)

for i in range(len(score) - 1):
    # print(score[i], score[i + 1])
    if score[i + 1] > score[i]:
        print("Yes")
    else:
        print("No")


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

for i in range(k, n):
    if a[i - k] < a[i]:
        print("Yes")
    else:
        print("No")
Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
q = int(input())

rev_flag = False
for i in range(q):
    tmp_in = list(input().split())

    if tmp_in[0] == '1':
        if rev_flag:
            rev_flag = False
        else:
            rev_flag = True
    else:
        if rev_flag:
            if tmp_in[1] == '1':
                s.append(tmp_in[2])
            else:
                s.insert(0, (tmp_in[2]))
        else:
            if tmp_in[1] == '1':
                s.insert(0, tmp_in[2])
            else:
                s.append(tmp_in[2])

if rev_flag:
    s.reverse()

ans = "".join(s)
print(ans)



Fixed submission:
from collections import deque

s = deque(input())
q = int(input())

rev_flag = False
for i in range(q):
    tmp_in = list(input().split())

    if tmp_in[0] == '1':
        if rev_flag:
            rev_flag = False
        else:
            rev_flag = True
    else:
        if rev_flag:
            if tmp_in[1] == '1':
                s.append(tmp_in[2])
            else:
                s.appendleft(tmp_in[2])
        else:
            if tmp_in[1] == '1':
                s.appendleft(tmp_in[2])
            else:
                s.append(tmp_in[2])

if rev_flag:
    s.reverse()

ans = "".join(s)
print(ans)

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

for i in range(q):
    tmp_in = list(input().split())

    if tmp_in[0] == '1':
        s.reverse()
    else:
        if tmp_in[1] == '1':
            s.insert(0, tmp_in[2])
        else:
            s.append(tmp_in[2])

ans = "".join(s)
print(ans)



Fixed submission:
from collections import deque

s = deque(input())
q = int(input())

rev_flag = False
for i in range(q):
    tmp_in = list(input().split())

    if tmp_in[0] == '1':
        if rev_flag:
            rev_flag = False
        else:
            rev_flag = True
    else:
        if rev_flag:
            if tmp_in[1] == '1':
                s.append(tmp_in[2])
            else:
                s.appendleft(tmp_in[2])
        else:
            if tmp_in[1] == '1':
                s.appendleft(tmp_in[2])
            else:
                s.append(tmp_in[2])

if rev_flag:
    s.reverse()

ans = "".join(s)
print(ans)