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

Fixed submission:
S = input()
k = int(input())
n = len(S)

orders = set()

for i in range(n):
    for j in range(1, 6):
        if i + j < n + 1:
            orders.add(S[i:i + j])

print(sorted(list(orders))[k - 1])

Buggy submission (verdict: Runtime Error):
S = input()
k = int(input())
n = len(S)

orders = set()

for i in range(n):
    for j in range(1, 6):
        if i + j < n:
            orders.add(S[i:i + j])

print(sorted(list(orders))[k - 1])
Problem p03379 (python)

Fixed submission:
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def main():
    N = int(input().strip())
    X_list = [int(i) for i in input().strip().split()]
    sorted_x = sorted(X_list)

    left = sorted_x[(N // 2)-1]
    right = sorted_x[N // 2]
    for x in X_list:
        if x <= left:
            print(right)
        else:
            print(left)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    N = int(input().strip())
    X_list = [int(i) for i in input().strip().split()]
    sorted_x = sorted(X_list)

    left = sorted_x[(N // 2)-1]
    right = sorted_x[N // 2]
    for x in X_list:
        if X_list[x-1] <= left:
            print(right)
        else:
            print(left)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def main():
    N = int(input().strip())
    X_list = [int(i) for i in input().strip().split()]
    sorted_x = sorted(X_list)

    left = sorted_x[(N // 2)-1]
    right = sorted_x[N // 2]
    print(left, right)
    for x in X_list:
        if X_list[x-1] <= left:
            print(right)
        else:
            print(left)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def median():
    l = sorted(l)
    if len(l) % 2 == 1:
        return l[len(l) // 2]
    else:
        return (l[len(l) // 2] + l[(len(l) // 2) - 1]) // 2


def main():
    N = int(input().strip())
    X_list = [int(i) for i in input().strip().split()]
    num = 0
    sorted_x = sorted(X_list)

    left = sorted_x[N // 2 - 1]
    right = sorted_x[N // 2]
    for x in X_list:
        if X_list[x-1] >= right:
            print(right)
        else:
            print(left)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def median():
    l = sorted(l)
    if len(l) % 2 == 1:
        return l[len(l) // 2]
    else:
        return (l[len(l) // 2] + l[(len(l) // 2) - 1]) // 2


def main():
    N = int(input().strip())
    X_list = [int(i) for i in input().strip().split()]
    num = 0
    sorted_x = sorted(X_list)

    left = sorted_x[N // 2 - 1]
    right = sorted_x[N // 2 + 1]
    for x in X_list:
        idx = sorted_x.index(x)
        if idx >= N / 2:
            print(right)
        else:
            print(left)


if __name__ == "__main__":
    main()
Problem p03386 (python)

Fixed submission:
a, b, k = [int(i) for i in input().split()]

lim_1 = min(a + k, b)
lim_2 = max(b - k + 1, a)
ans = set(list(range(a, lim_1)) + list(range(lim_2, b + 1)))

for n in ans:
    print(n)

Buggy submission (verdict: Runtime Error):
import numpy as np
 
def main():
    numbers=[]
    a,b,k = map(int,input().split())
    numbers=np.arange(a,b+1)
    A=set(numbers[:k])
    B=set(numbers[-k:])
    answer = A|B
    
    for i in sorted(answer):
        print("{}".format(i))
 
 
if __name__=="__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
import numpy as np
 
def main():
    numbers=[]
    a,b,k = map(int,input().rstrip().split())
    numbers=np.arange(a,b+1)
    #A=set(numbers[:k])
    #B=set(numbers[-k:])
    #answer = A|B
    
    #for i in sorted(answer):
    #    print("{}".format(i))
 
 
if __name__=="__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
import numpy as np
 
def main():
    numbers=[]
    a,b,k = map(int,input().rstrip().split())
    numbers=np.arange(a,b+1)
    A=set(numbers[:min(k,b+1)])
    B=set(numbers[max(b-k,a):])
    answer = A.union(B)
    
    for i in sorted(answer):
        print("{}".format(i))
 
 
if __name__=="__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
import numpy as np
 
def main():
    numbers=[]
    a,b,k = map(int,input().rstrip().split())
    numbers=np.arange(a,b+1)
    A=set(numbers[:k])
    B=set(numbers[-k:])
    answers = A|B
    
    for i in sorted(answers):
        print("{}".format(i))
 
 
if __name__=="__main__":
    main()
Problem p03583 (python)

Fixed submission:
import sys
# sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    n = input_int()
    for a in range(1, 3501):
        for b in range(1, 3501):
            if 4 * a * b - n * b - n * a == 0:
                continue
            c = (n * a * b) // (4 * a * b - n * b - n * a)
            if c < 1:
                continue
            if 4 * a * b * c == n * (a * b + b * c + c * a):
                print(a, b, c)
                return
    return


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys
# sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    n = input_int()
    for a in range(1, 3501):
        for b in range(1, 3501):
            numerator = a * b * n
            denominator = 4 * a * b - a * n - b * n
            if denominator == 0:
                continue
            c = numerator // denominator
            if n / 4 == 1 / a + 1 / b + 1 / c:
                print(a, b, c)
                return
    return


if __name__ == "__main__":
    main()
Problem p03611 (python)

Fixed submission:
import numpy as np
N = int(input())
A = np.array(input().split(), dtype = np.int32)
 
counter = np.bincount(A)
if len(counter) <= 2:
  answer = counter.sum()
else:
  answer = (counter[2:] + counter[1:-1] + counter[:-2]).max()
print(answer)

Buggy submission (verdict: Runtime Error):
import numpy as np
N = int(input())
A = np.array(input().split(), dtype = np.int32)
 
counter = np.bincount(A)
if len(counter) <= 2:
  answer = counter.sum()
else:
  answer = (counter[2:] + counter[1:-1] + counter[:-2]).max()
print(answer)
Problem p03672 (python)

Fixed submission:
S = input()
while len(S) > 0:
  S = S[:-1]
  mid = len(S)//2
  if S[:mid] == S[mid:]:
    print(len(S))
    break

Buggy submission (verdict: Runtime Error):
S = input()
while True:
  S = S[:-1]
  mid = len(S)//2
  if S[:mid] == S[mid:]:
    print(len(S))
    break
  elif S = "":
    break
Problem p03818 (python)

Fixed submission:
import sys
# sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    from collections import Counter
    n = input_int()
    A = input_int_list()
    A_cnt = Counter(A).most_common()
    A_cnt = [list(a) for a in A_cnt]
    cnt = 0
    for i in range(len(A_cnt)):
        if A_cnt[i][1] > 2:
            if A_cnt[i][1] % 2 == 1:
                cnt += A_cnt[i][1] // 2
                A_cnt[i][1] = 1
            elif A_cnt[i][1] % 2 == 0:
                cnt += (A_cnt[i][1] // 2) - 1
                A_cnt[i][1] = 2
        if A_cnt[i][1] == 2:
            if i + 1 < len(A_cnt):
                A_cnt[i + 1][1] -= 1
            A_cnt[i][1] = 1
            cnt += 1
    print(n - cnt * 2)
    return


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys
# sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    from collections import Counter
    n = input_int()
    A = input_int_list()
    A_cnt = Counter(A).most_common()
    A_cnt = [list(a) for a in A_cnt]
    cnt = 0
    for i in range(len(A_cnt)):
        if A_cnt[i][1] > 2:
            if A_cnt[i][1] % 2 == 1:
                cnt += A_cnt[i][1] // 2
                A_cnt[i][1] = 1
            elif A_cnt[i][1] % 2 == 0:
                cnt += (A_cnt[i][1] // 2) - 1
                A_cnt[i][1] = 2
        if A_cnt[i][1] == 2:
            if i + 1 < n:
                A_cnt[i + 1][1] -= 1
            A_cnt[i][1] = 1
            cnt += 1
    print(n - cnt * 2)
    return


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys
# sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    from collections import Counter
    n = input_int()
    A = input_int_list()
    A_cnt = Counter(A).most_common()
    A_cnt = [list(a) for a in A_cnt]
    cnt = 0
    for i in range(len(A_cnt)):
        if A_cnt[i][1] > 2:
            if A_cnt[i][1] % 2 == 1:
                cnt += A_cnt[i][1] // 2
                A_cnt[i][1] = 1
            elif A_cnt[i][1] % 2 == 0:
                cnt += (A_cnt[i][1] // 2) - 1
                A_cnt[i][1] = 2
        if A_cnt[i][1] == 2:
            A_cnt[i + 1][1] -= 1
            A_cnt[i][1] = 1
            cnt += 1
    print(n - cnt * 2)
    return


if __name__ == "__main__":
    main()
Problem p03830 (python)

Fixed submission:
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def get_prime(N):
    prime = dict()
    prime[1] = 1
    i = 2
    while i * i <= N:
        while N % i == 0:
            if i in prime.keys():
                prime[i] += 1
            else:
                prime[i] = 1
            N = N // i
        i += 1
    if N != 1:
        prime[N] = 1
    return prime


def main():
    N = int(input().strip())
    div_table = [0] * (N + 1)
    MOD = 10**9 + 7
    ans = 1
    for i in range(2, N + 1):
        for j in range(i, N + 1, i):
            div_table[j] += 1

    prime = dict()
    for i in range(2, N + 1):
        if div_table[i] == 1:
            prime[i] = 0

    for i in range(2, N + 1):
        _prime = get_prime(i)
        for k, v in _prime.items():
            if k == 1:
                continue
            prime[k] += v

    for k, v in prime.items():
        ans *= v + 1
        ans %= MOD

    print(ans)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def get_prime(N, prime):
    if N < 2:
        return {1: 1}

    i = 2
    while i * i <= N:
        while N % i == 0:
            if i in prime.keys():
                prime[i] += 1
            else:
                prime[i] = 1
            N = N // i
        i += 1
    if N != 1:
        prime[N] = 1
    return prime


def main():
    N = int(input().strip())
    div_table = [1] * (N + 1)
    MOD = 10**9 + 7
    ans = 0
    for i in range(2, N + 1):
        for j in range(i, N + 1, i):
            div_table[j] += 1

    prime = dict()
    prime[1] = 1

    for i in range(1, N + 1):
        if div_table[i] == 2:
            prime = get_prime(i, prime)
    ans = 1
    for k, v in prime:
        ans *= v
        ans %= MOD

    print(ans)


if __name__ == "__main__":
    main()
Problem p03854 (python)

Fixed submission:
import sys
sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    S = input()
    # 後ろから貪欲に評価すればよい
    while True:
        if S[-5:] == "dream" or S[-5:] == "erase":
            S = S[:-5]
            continue
        elif S[-6:] == "eraser":
            S = S[:-6]
            continue
        elif S[-7:] == "dreamer":
            S = S[:-7]
            continue
        else:
            break
    if S == "":
        print("YES")
    else:
        print("NO")
    return


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def solver(T):
    if T == "":
        print("YES")
        quit()
    if len(T) >= 5:
        if T[:5] == "dream" or T[:5] == "erase":
            solver(T[5:])
    if len(T) >= 6:
        if T[:6] == "eraser":
            solver(T[6:])
    if len(T) >= 7:
        if T[:7] == "dreamer":
            solver(T[7:])
    return


def main():
    S = input()
    # 再帰的に解いて解く

    solver(S)
    print("NO")
    return


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    S = input()
    # 再帰的に解いて解く

    def solver(T):
        if T == "":
            print("YES")
            quit()
        if len(T) >= 5:
            if T[:5] == "dream" or T[:5] == "erase":
                solver(T[5:])
        if len(T) >= 6:
            if T[:6] == "eraser":
                solver(T[6:])
        if len(T) >= 7:
            if T[:7] == "dreamer":
                solver(T[7:])
        return

    solver(S)
    print("NO")
    return


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys
# sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    S = input()
    # 再帰的に解いて解く

    def solver(T):
        if T == "":
            print("YES")
            quit()
        if len(T) >= 5:
            if T[:5] == "dream" or T[:5] == "erase":
                solver(T[5:])
        if len(T) >= 6:
            if T[:6] == "eraser":
                solver(T[6:])
        if len(T) >= 7:
            if T[:7] == "dreamer":
                solver(T[7:])
        return

    solver(S)
    print("NO")
    return


if __name__ == "__main__":
    main()
Problem p02612 (python)

Fixed submission:
N=int(input())
if N%1000==0:
    print(0)
else:
    print(1000-N%1000)

Buggy submission (verdict: Runtime Error):
from collections import deque

N,K=map(int,input().split())
A=list(map(int,input().split()))
A.sort(key=lambda x:abs(x),reverse=True)
MOD=10**9+7

P=[]
M=[]
for num in A:
    if num>=0:
        P.append(num)
    else:
        M.append(num)
       
#print(P,M)
       
if len(M)==N and K%2==1:
    ans= M[-1]
    for j in range(1,K):
        ans = (ans*M[-1-j])%MOD
       
else:
    Q=deque(P)
    R=deque(M)
    cnt=0
    ans_list=[]

    while cnt<K:

        if Q:
            tmp_p=Q.popleft()
        else:
            tmp_p=0

        if len(R)>=2 and K-cnt>=2:
            x= R.popleft()
            y= R.popleft()
            tmp_q= x*y
        else:
            tmp_q=0

        if tmp_p>=tmp_q:
            ans_list.append(tmp_p)
            if tmp_q>0:
                R.appendleft(y)
                R.appendleft(x)
            cnt +=1
        else:
            ans_list.append(x)
            ans_list.append(y)
            Q.appendleft(tmp_p)
            cnt +=2

    #print(cnt, tmp_p, tmp_q,Q,R,ans_list)
       
    ans=ans_list[0]
    for j in range(1,len(ans_list)):
        ans = (ans*ans_list[j])%MOD
       
       
print(ans)
Problem p02615 (python)

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

ans=A[0]
if N>2:
    p = (N-2)//2
    q = (N-2)%2
    ans += 2*sum(A[1:1+p])
    if q==1:
        ans += A[1+p]

print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)

ans=A[0]
if N>2:
    p = (N-2)//2
    q = (N-2)%2
#print(p,q)

ans += 2*sum(A[1:1+p])
if q==1:
    ans += A[1+p]

print(ans)
Problem p02642 (python)

Fixed submission:
# D 

from collections import Counter
N=int(input())
A=list(map(int,input().split()))
A.sort()
maxi=A[-1]
real=set()
forbid=set()
#print(A[0],maxi)
d=dict(Counter(A))
#print(d)

cnt=0
for i in range(N):
    if A[i] not in forbid:
        if d[A[i]]==1:
            cnt +=1
        p=maxi//A[i]
        for j in range(1,p+1):
            forbid.add(j*A[i])
        
        
#print(forbid)
print(cnt)

Buggy submission (verdict: Runtime Error):
# D 

from collections import deque
N=int(input())
A=list(map(int,input().split()))
A.sort()
B=deque(A)
#print(B)

cnt=0
tmp=[]
while B:
    i = B.popleft()
    for j in B:
        flag=True
        if j==i:
            flag=False
        elif j%i==0:
            pass
        else:
            tmp.append(j)
    else:
        if flag:
            cnt += 1
        #print(i,tmp,cnt)
        B=deque(tmp)
        tmp=[]
        continue

print(cnt)
Problem p02713 (python)

Fixed submission:
from math import gcd

K=int(input())
sum=0

for i in range(1,K+1):
  for j in range(1,K+1):
    tmp= gcd(i,j)
    for k in range(1,K+1):      
      sum += gcd(tmp,k)
      
print(sum)

Buggy submission (verdict: Runtime Error):
from math import gcd

K=int(input())
sum=0

for i in range(1,K+1):
  for j in range(1,K+1):
    for k in range(1,K+1):
      sum += gcd(i,j,k)
      
print(sum)
Problem p02720 (python)

Fixed submission:
K=int(input())
x=[[0] for _ in range(11)]
y=[ 0 for _ in range(11)]

x[1]=[1,2,3,4,5,6,7,8,9]
y[1]=9

for i in range(2,11):
  x[i].pop()
  for num in x[i-1]:
    last = num%10
    if last==0:
      x[i].append(10*num)
      x[i].append(10*num+1)
      y[i] +=2
    elif last==9:
      x[i].append(10*num+8)
      x[i].append(10*num+9)
      y[i] +=2
    else:
      x[i].append(10*num+(last-1))
      x[i].append(10*num+last)
      x[i].append(10*num+(last+1))
      y[i] +=3
      
#print(y)
#print(sum(y))

z=[0,y[1]]
for i in range(2,11):
 z.append(z[-1]+y[i])
#print(z)

keta=0
for i,num in enumerate(z):
  if num<=K:
    keta=i+1

s= K-z[keta-1]
#print(s)
print(x[keta][s-1])

Buggy submission (verdict: Runtime Error):
K=int(input())
x=[[0] for _ in range(11)]
y=[ 0 for _ in range(11)]

x[1]=[1,2,3,4,5,6,7,8,9]
y[1]=9

for i in range(2,11):
  x[i].pop()
  for num in x[i-1]:
    last = num%10
    if last==0:
      x[i].append(10*num)
      x[i].append(10*num+1)
      y[i] +=2
    elif last==9:
      x[i].append(10*num+8)
      x[i].append(10*num+9)
      y[i] +=2
    else:
      x[i].append(10*num+(last-1))
      x[i].append(10*num+last)
      x[i].append(10*num+(last+1))
      y[i] +=3
      
#print(y)
#print(sum(y))

z=[0,y[1]]
for i in range(2,11):
 z.append(z[-1]+y[i])
#print(z)

maxi=0
for r in range(11):
  if z[r]<=K:
    maxi=max(maxi,r)
    
keta=maxi+1
#print(K-y[maxi])
print(x[keta][K-y[maxi-1]])
Problem p02732 (python)

Fixed submission:
N=int(input())
A=list(map(int,input().split() ))
from collections import Counter
d=dict(Counter(A))
#print(d)
cnt=0
for item in d:
    cnt += (d[item])*(d[item]-1)//2

#print("cnt",cnt)
   
for num in A:
    new = max(0, (d[num]-1)*(d[num]-2)//2)
    print(cnt- d[num]*(d[num]-1)//2 + new)

Buggy submission (verdict: Runtime Error):
import copy
from collections import Counter
from math import factorial

def comb(n,r):
  a = factorial(n) / factorial(r) // factorial(n - r)
  return float(a)

N=int(input())
A=list(map(int,input().split() ))
B=[-1]*N   #メモ化。iの時の方法の総数

f_cnt=Counter(A)
f_dic=dict(f_cnt)

for i,item in enumerate(A):
  if B[item-1]>-1:
    print(B[item-1])
  else:
    D=copy.deepcopy(f_dic)
    D[item] -= 1
    opt=0
    for item3 in D:
      if D[item3]>=2:
        opt += comb(D[item3],2)
    B[item-1]=opt
    print(opt)

Buggy submission (verdict: Runtime Error):
import copy
from collections import Counter
from math import factorial

def comb(n,r):
  a = factorial(n) / factorial(r) // factorial(n - r)
  return int(a)

N=int(input())
A=list(map(int,input().split() ))
B=[-1]*N   #メモ化。iの時の方法の総数

f_cnt=Counter(A)
f_dic=dict(f_cnt)

for i,item in enumerate(A):
  if B[item-1]>-1:
    print(B[item-1])
  else:
    D=copy.deepcopy(f_dic)
    D[item] -= 1
    opt=0
    for item3 in D:
      if D[item3]>=2:
        opt += comb(D[item3],2)
    B[item-1]=opt
    print(opt)

Buggy submission (verdict: Runtime Error):
from scipy.misc import comb
from collections import Counter

N=int(input())
A=list(map(int,input().split() ))
B=[-1]*N   #メモ化。iの時の方法の総数

for i,item in enumerate(A):
  if B[item-1]>-1:
    #print(i,item,"は計算済み！")
    #print(i,B[item-1],"done")
    print(B[item-1])
  else:
    C=A[0:i]+A[i+1:] #仮で作るリスト
    cnt = Counter(C)
    D=dict(cnt)
    E=[]
    for item2 in D:
      if D[item2]>=2:
        E.append(D[item2])
    #print(i,E)
    opt=0
    for item3 in E:
      opt += comb(item3,2,exact=True)
    B[item-1]=opt
    #print(i,opt)
    print(opt)
    #print(i,E,opt)
    #print(C,cnt)
Problem p02743 (python)

Fixed submission:
from math import sqrt
from decimal import Decimal
 
a,b,c = map(int,input().split())
s=c-a-b

if s>=0:
  if Decimal(4*a*b)< Decimal(s**2):
    print("Yes")
  else:
    print("No")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
from math import sqrt
from decimal import Decimal
 
a,b,c = map(int,input().split())
s=c-a-b

if a*b< (S**2)/4:
  print("Yes")
else:
  print("No")
Problem p02756 (python)

Fixed submission:
S=input()
Q=int(input())
import sys
from collections import deque
d=deque()
for _ in S:
  d.append(_)
flag=False

for _ in range(Q):
  s = list(sys.stdin.readline())
  if s[0]=="1":
    if flag:
      flag=False
    else:
      flag=True
  else:
    if s[2]=="1":
      if flag:
        d.append(s[4])
      else:
        d.appendleft(s[4])
    else:
      if flag:
        d.appendleft(s[4])
      else:
        d.append(s[4])
      
if flag:
  d.reverse()
  
print("".join(d))

Buggy submission (verdict: Runtime Error):
S=input()
Q=int(input())

for i in range(Q):
  a=input().split()
  if a[0]=="1":
    S=S[::-1]
  else:
    if a[1]=="1":
      S="".join((a[2],S))
    else:
      S="".join([(S,a[2]))
      
print(S)