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

Fixed submission:
#print#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
from collections import Counter
def resolve():
    N,=pin()
    s=set()
    prev=""
    for i in range(N):
        temp=input()
        if temp in s:
            print("No")
            return
        if i>0 and temp[0]!=prev[-1]:
            print("No")
            return
        s.add(temp)
        prev=temp
    print("Yes")
#%%submit!
resolve()

Buggy submission (verdict: Runtime Error):
N= int(input())
words=[]
words.append(input())
ans="Yes"
for i in range(1,N):
    next=input()
    for word in words:
        if (next==word or  words[i-1][-1]==next[0]):
            ans = "No"
            break
        else:
            words.append(next)
print(ans)
Problem p03319 (python)

Fixed submission:
#print#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
import math
def resolve():
    N,M=pin()
    print(math.ceil((N-1)/(M-1)))

#%%submit!
resolve()

Buggy submission (verdict: Runtime Error):
N,M=map(int,input())
print(N//2)

Buggy submission (verdict: Runtime Error):
print(int(open(0)[0][0])//2)
Problem p03456 (python)

Fixed submission:
#print#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code

#なお、任意の整数 M に対して M の −2 進数表現が一意に定まることが証明できます。
#2桁ごとに見るとよかった（もう実験したよ）
def resolve():
    a,b=pin(str)
    s=a+b
    for i in range(1000):
        if i**2==int(s):
            print("Yes")
            break
    else:print("No")

#%%submit!
resolve()

Buggy submission (verdict: Runtime Error):
#print#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code

#なお、任意の整数 M に対して M の −2 進数表現が一意に定まることが証明できます。
#2桁ごとに見るとよかった（もう実験したよ）
def resolve():
    a,b=pin(str)
    s=a+b
    for i in range(100):
        if i**2=int(s):
            print("Yes")
            break
    else:print("No")

#%%submit!
resolve()
Problem p03633 (python)

Fixed submission:
# coding: utf-8
# Your code here!
# coding: utf-8
from fractions import gcd 
from functools import reduce
import sys
sys.setrecursionlimit(200000000)
from inspect import currentframe


# my functions here!
#標準エラー出力
def printargs2err(*args):
    names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' : '+repr(arg) for arg in args),file=sys.stderr)
def debug(x):
    print(x,file=sys.stderr)
def printglobals():
    for (symbol, value) in globals().items():
        print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)
def printlocals():
    for (symbol, value) in locals().items():
        print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)
#入力（後でいじる）
def pin(type=int):
    return map(type,input().split())

#繰り返し自乗法だよ
#これはnのp乗をmで割ったあまりをだすよ
def modular_w_binary_method (n,m,p):
    ans=1 if n>0 else 0
    while(p>0):
        if p%2==1:
            ans=(ans*n)%m
        n=(n**2)%m
        p//=2
    return ans
#mod上でのaの逆元を出すよ
"""
    フェルマーの小定理より a**(p)%p==a isTrue
    これを利用すれば a**(p-2)%p==a**(-1) isTrue
    元と逆元とをかけてpで割れば1が余るよ！
"""
def modular_inverse(a,prime):
    return(modular_w_binary_method(a,prime,prime-2))
#逆元を使うと容易に頑張れるｃ
def conbination(n,a,mod=10**9+7):
    #cはイラない
    res=1 
    for s in range(a):
        res=(res*(n-s)*(modular_inverse(s+1,mod)))%mod

        
    return res
#操作から作れるものの組み合わせは何個かー＞同じものでも違う方法で構成できるかから考える方法もある
"""
"""

#solution:

#input
N,=pin()
T=[int(input()) for i in range(N)]
from fractions import gcd
def lcm2(x, y):
    return (x * y) // gcd(x, y)
def lcm(numbers):
        return reduce(lcm2,numbers,1)
print(lcm(T))

#print(h)
#print(m)
#print(["No","Yes"][cond])
#print([["NA","YYMM"],["MMYY","AMBIGUOUS"]][cMMYY][cYYMM])
"""
#printデバッグ消した？
#前の問題の結果見てないのに次の問題に行くの？
"""
"""
お前カッコ閉じるの忘れてるだろ
"""

Buggy submission (verdict: Runtime Error):
def resolve():
    nclo=range(int(input()))
    from math import gcd
    def lcm(a,b):
        return (a*b)//gcd(a,b)
    next=0
    temp=1
    for i in nclo:
        next=int(input())
        temp=lcm(temp,next)
    print(temp)
        
#%%submit!
resolve()
Problem p03852 (python)

Fixed submission:
cond=0
if input() in "auieo":
    cond=1
print(["consonant","vowel"][cond])

Buggy submission (verdict: Runtime Error):
if input() in "auieo":
    cond=1
print(["consonant","vowel"][cond])
Problem p03854 (python)

Fixed submission:
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
import random
def resolve():
    
    S=input()
    A="dream dreamer erase eraser".split()
    #print(A)
    que=[S]
    while(que!=[]):
        t=len(que)
        #print(t)
        vS=que.pop(random.randint(0,t-1))
        if vS=="":
            print("YES")
            return
        for w in A:
            r=len(w)
            if vS[:r]==w:
                que.append(vS[r:])
        #print(que,"k")    

    print("NO")
#%%submit!
resolve()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
import random
def resolve():
    
    S=input()
    A="dream dreamer erase eraser".split()
    #print(A)
    que=[S]
    while(que!=[]):
        t=len(que)
        print(t)
        vS=que.pop(random.randint(0,t-1))
        if vS=="":
            print("YES")
            return
        for w in A:
            r=len(w)
            if vS[:r]==w:
                que.append(vS[r:])
        print(que,"k")    

    print("NO")
#%%submit!
resolve()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
import random
def resolve():
    
    S=input()
    A="dream dreamer erase eraser".split()
    #print(A)
    que=[S]
    while(que!=[]):
        t=len(que)
        print(t)
        vS=que.pop(random.randint(0,t-1))
        if vS=="":
            print("YES")
            return
        for w in A:
            r=len(w)
            if vS[:r]==w:
                que.append(vS[r:])
        print(que,"k")    

    print("NO")
#%%submit!
resolve()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
def resolve():
    S=input()
    n=len(S)
    A="dream dreamer erase eraser".split()
    #print(A)
    global cond
    cond=[]
    def dfslike_dreameraser(varS):#string->bool,resursion
        #print(varS)
        if len(varS)==0:
            cond.append(1)
            return 
        for word in A:
            if varS[:len(word)]==word:
                dfslike_dreameraser(varS[len(word):])
        return 
        
    dfslike_dreameraser(S)
    #print(cond)
    print(["NO","YES"][cond!=[]])
#%%submit!
resolve()
Problem p04030 (python)

Fixed submission:
s=input()
ans=[]
for i in s:
    if i!="B":
        ans.append(i)
    else:
        if ans!=[]:
            ans.pop(-1)
p=""
for j in ans:
   p+=j 
print(p)

Buggy submission (verdict: Runtime Error):
import math
N=int(input())
p=math.sqrt(N*2-0.25)-0.5
q=int(p)+1
M=q*(q+1)//2
L=M-N#must0or+
for i in range(1,q+1):
    if i != L:
        print(i)
Problem p02630 (python)

Fixed submission:
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
INF = 1000000000000

import bisect

n = I()
a = LI()
q = I()

cnt = [0]*1000000
for i in a:
    cnt[i] += 1
sm = sum(a)

for i in range(q):
    b,c = LI()
    sm += (c-b)*cnt[b]
    if(c != b):
        cnt[c] += cnt[b]
        cnt[b] = 0
    print(sm)

Buggy submission (verdict: Runtime Error):
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
INF = 1000000000000

import bisect

n = I()
a = LI()
q = I()

cnt = [0]*100000
for i in a:
    cnt[i] += 1
sm = sum(a)

for i in range(q):
    b,c = LI()
    sm += (c-b)*cnt[b]
    if(c != b):
        cnt[c] += cnt[b]
        cnt[b] = 0
    print(sm)
Problem p02642 (python)

Fixed submission:
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
INF = 1000000000000

n = I()
a = LI()

a.sort()
m = a[n-1]
flg = [False]*(m+1)

count = 0
for x in range(n):
    v = a[x]
    if(not flg[v]):
        i = v
        while(i <= m):
            flg[i] = True
            i += v
        if(x == n-1 or v != a[x+1]):
            count += 1

print(count)

Buggy submission (verdict: Runtime Error):
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
INF = 1000000000000

n = I()
a = LI()

a.sort()
f = [False]*n

if(a[0] == a[1]):
    f[0] = True
for i in range(1,n):
    for j in range(0,i):
        if(a[i] % a[j] == 0):
            f[i] = True
            break

count = 0
for i in range(n):
    if(not f[i]):
        count += 1

print(count)

Buggy submission (verdict: Runtime Error):
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
INF = 1000000000000

n = I()
a = LI()

a.sort()
f = [False]*n

if(a[0] == a[1]):
    f[0] = True
for i in range(1,n):
    for j in range(0,i):
        if(a[i] % a[j] == 0):
            f[i] = True
            break

count = 0
for i in range(n):
    if(not f[i]):
        count += 1

print(count)
Problem p02702 (python)

Fixed submission:
s = input()[::-1]
n = len(s)

a = [0]*2019
a[0] = 1
count = 0
val = 1
current = 0
for c in s:
    current = (current + val * int(c)) % 2019
    count += a[current%2019]
    a[current%2019] += 1
    val = val * 10 % 2019

print(count)

Buggy submission (verdict: Runtime Error):
s = input()
n = len(s)

a = [0]*2019
count = 0
val = 10
for i in range(n):
    tmp = int(s[n-i-1,n]) % 2019
    count = count + a[tmp]
    a[tmp] = a[tmp] + 1
    if(tmp == 0):
        count = count + 1
    val = val * 10

print(count)
Problem p02732 (python)

Fixed submission:
n = int(input())
data = list(map(int, input().split(" ")))
count = [0]*(n+1)
for i in range(n):
    count[data[i]] = count[data[i]]+1

val = [0]*(n+1)
sumval = 0
for i in range(n+1):
    if(count[i] >= 2):
        val[i] = count[i]-1
        sumval = sumval + int(count[i]*(count[i]-1)/2)

for i in range(n):
    print(sumval - val[data[i]])

Buggy submission (verdict: Runtime Error):
n = int(input())
data = list(map(int, input().split(" ")))
count = [0]*n
for i in range(n):
    count[data[i]] = count[data[i]]+1

val = [0]*n
sumval = 0
for i in range(n):
    if(count[i] >= 2):
        val[i] = count[i]-1
        sumval = sumval + int(count[i]*(count[i]-1)/2)

for i in range(n):
    print(sumval - val[data[i]])
Problem p02780 (python)

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

rsum  = [0]*n
for i in range(n):
    rsum[i] = (p[i]+1) / 2
    if(i != 0):
        rsum[i] = rsum[i] + rsum[i-1]

result = 0
if(n == k):
    result = rsum[n-1]
else:
    for i in range(n-k):
        if(result < rsum[i+k] - rsum[i]):
            result = rsum[i+k] - rsum[i]
print(result)

Buggy submission (verdict: Runtime Error):
n,k = map(int, input().split())
p = list(map(int, input().split()))

rsum  = [0]*n
for i in range(n):
    rsum[i] = (p[i]+1) / 2
    if(i != 0):
        rsum[i] = rsum[i] + rsum[i-1]

if(n == k):
    max = rsum[n-1]
else:
    for i in range(n-k):
        if(max < rsum[i+k] - rsum[i]):
            max = rsum[i+k] - rsum[i]
print(max)

Buggy submission (verdict: Runtime Error):
n,k = map(int, input().split())
p = list(map(int, input().split()))

rsum  = [0]*n
for i in range(n):
    rsum[i] = (p[i]+1) / 2
    if(i != 0):
        rsum[i] = rsum[i] + rsum[i-1]

if(n == k):
    max = rsum[n]
else:
    for i in range(n-k):
        if(max < rsum[i+k] - rsum[i]):
            max = rsum[i+k] - rsum[i]
print(max)
Problem p02934 (python)

Fixed submission:
n = int(input())
res = list(map(int, input().split()))
ans = 0 
for x in res:
  ans += 1/x
print(1/ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
res = list(map(int, input().split()))
ans = 0 
for x in res:
  ans += 1/res
print(1/ans)
Problem p02614 (python)

Fixed submission:
h,w,K=map(int,input().split())
s=[list(input())for i in range(h)]
import numpy as np
s=np.array(s)
l=[]

for i in range(h):
    l.append(len(s[i][s[i]=="#"]))
for i in range(w):
    l.append(len(s[:,i][s[:,i]=="#"]))
ss=sum(l)//2
n=h+w
ans=0
for i in range(1<<n):
    tmp=ss
    for j in range(h):
        if i>>j&1:
            tmp-=l[j]
    for j in range(h,n):
        if i>>j&1:
            tmp-=l[j]
            for idx,k in enumerate(s[:,j-h]):
                if k=="#":
                    if i>>idx&1:
                        tmp+=1
    if tmp==K:
        ans+=1
print(ans)

Buggy submission (verdict: Runtime Error):
h,w,K=map(int,input().split())
s=[list(input())for i in range(h)]
import numpy as np
s=np.array(s)
l=[]

for i in range(h):
    l.append(len(s[i][s[i]=="#"]))
for i in range(w):
    l.append(len(s[:,i][s[:,i]=="#"]))
ss=sum(l)//2
n=h+w
ans=0
for i in range(1<<n):
    tmp=ss
    for j in range(h):
        if i>>j&1:
            tmp-=l[j]
    for j in range(h,n):
        if i>>j&1:
            tmp-=l[j]
            for idx,k in enumerate(s[:,j-h]):
                if k=="#":
                    if i>>idx&1:
                        tmp+=1
    if tmp==K:
        ans+=1
print(ans)
Problem p02957 (python)

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

if (a + b) % 2 != 0:
    print("IMPOSSIBLE")
else:
    print((a + b) // 2)

Buggy submission (verdict: Runtime Error):
998244353 99824435
Problem p02684 (python)

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

p=1
if k<=n:
  for i in range(k):
    p=a[p-1]
  print(p)
  exit()

t=[-1]*n
t[0]=0
for i in range(1,n):
  p=a[p-1]
  if t[p-1] !=-1:
    break
  t[p-1]=i

d=i-t[p-1]
k-=i
k%=d
for i in range(k):
  p=a[p-1]
print(p)

Buggy submission (verdict: Runtime Error):
#https://zoom.us/j/96904363338?pwd=dVhyazRpV29MeWVEMGJRNi9ycmxmZz09
N,M=map(int,input().split())
A=[int(x) for x in input().split()]


loop_all=[1]
num=0
for index,i in enumerate(A,start=0):
    if i not in loop_all:
        loop_all.append(A[num])
        num=A[num]-1

loop_1=[]
tmp1=A[A[len(loop_all)-1]-1]
tmp2=loop_all.index(tmp1)

num1=0
for i in loop_all:
    if num1==tmp2:
        break
    loop_1.append(i)
    num1+=1


loop_2=[]
for i in loop_all[tmp2:]:
    loop_2.append(i)

if M<=len(loop_1)-1:
    print(A[K])
else:
    print(loop_2[ (M-len(loop_1)-1)%len(loop_2)-2])
Problem p03545 (python)

Fixed submission:
A,B,C,D=map(int,list(input()))

if A+B+C+D==7:
    print('{}+{}+{}+{}=7'.format(A,B,C,D))
elif A-B+C+D==7:
    print('{}-{}+{}+{}=7'.format(A,B,C,D))
elif A+B-C+D==7:
    print('{}+{}-{}+{}=7'.format(A,B,C,D))
elif A+B+C-D==7:
    print('{}+{}+{}-{}=7'.format(A,B,C,D))
elif A-B-C+D==7:
    print('{}-{}-{}+{}=7'.format(A,B,C,D))
elif A+B-C-D==7:
    print('{}+{}-{}-{}=7'.format(A,B,C,D))
elif A-B+C-D==7:
    print('{}-{}+{}-{}=7'.format(A,B,C,D))
elif A-B-C-D==7:
    print('{}-{}-{}-{}=7'.format(A,B,C,D))

Buggy submission (verdict: Runtime Error):
A,B,C,D=map(int,list(input())

if A+B+C+D==7:
    print('{}+{}+{}+{}=7'.format(A,B,C,D))
elif A-B+C+D==7:
    print('{}-{}+{}+{}=7'.format(A,B,C,D))
elif A+B-C+D==7:
    print('{}+{}-{}+{}=7'.format(A,B,C,D))
elif A+B+C-D==7:
    print('{}+{}+{}-{}=7'.format(A,B,C,D))
elif A-B-C+D==7:
    print('{}-{}-{}+{}=7'.format(A,B,C,D))
elif A+B-C-D==7:
    print('{}+{}-{}-{}=7'.format(A,B,C,D))
elif A-B+C-D==7:
    print('{}-{}+{}-{}=7'.format(A,B,C,D))
elif A-B-C-D==7:
    print('{}-{}-{}-{}=7'.format(A,B,C,D))
Problem p03556 (python)

Fixed submission:
N=int(input())

i=1
while(N>=i*i):
    i+=1

print((i-1)*(i-1))

Buggy submission (verdict: Runtime Error):
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); i++)
typedef long long ll;
using namespace std;

int main(){
    int N; cin >> N;
    int i=1;
    while(N>=i*i){
        i++;
    }
    cout << (i-1)*(i-1);
}
Problem p03694 (python)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
max_A=max(A)
min_A=min(A)
print(max_A-min_A)

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

N=int(input())
#A=np.array([map(int,input().split())])
A = np.array([int(i) for i in input().split()])
max_A=np.max(A)
min_A=np.min(A)
print(max_A-min_A)
Problem p02714 (python)

Fixed submission:
N =int(input())
S = str(input())
A = 0
R = []
G = []
B = []
for i in range(len(S)):
  if S[i] == "R":
    R.append(i+1)
  elif S[i] == "G":
    G.append(i+1)
  else:
    B.append(i+1)

A = len(R)*len(G)*len(B)
for i in range(N):
  for j in range(i+1,N):
    k = j + (j-i)
    if k >= N:
      break
    if S[i] != S[j] and S[j] != S[k] and S[i] != S[k]:
      A -= 1
print(A)

Buggy submission (verdict: Runtime Error):
N,S =input().split()
N = int(N)
A = 0
R = []
G = []
B = []
for i in range(len(S)):
  if S[i] == "R":
    R.append(i+1)
  elif S[i] == "G":
    G.append(i+1)
  else:
    B.append(i+1)
for r in R:
  for g in G:
    for b in B:
      C = sorted([r,g,b])
      if C[1] - C[0] != C[2] - C[1]:
        A += 1
print(A)
Problem p02756 (python)

Fixed submission:
from collections import deque
S = input()
S = deque(S)
N = int(input())

rev = 0

for i in range(N):
  Q = input().split()
  if Q[0] == "1":
    rev += 1
    rev %= 2
  else:
    if (rev + int(Q[1])) % 2 == 1:
      S.appendleft(Q[2])
    else:
      S.append(Q[2])
S = "".join(S)
if rev == 1:
  S = S[::-1]
print(S)

Buggy submission (verdict: Runtime Error):
from collections import deque
S = input()
S = deque(S)
N = int(input())

rev = 0

for i in range(N):
  Q = input().split()
  if Q[0] == "1":
    rev += 1
    rev %= 2
  else:
    if (rev + int(Q[1])) % 2 == 1:
      S.appendleft(Q[2])
    else:
      S.append(Q[2])
if rev == 1:
  S = S[::-1]
print("".join(S))

Buggy submission (verdict: Runtime Error):
def toku()
  S = input()
  Q = int(input())
  s = [S[0]]
  A = []
  count = 0
  for i in range(Q):
    A += [input().split()]
  for i in range(Q):
    if int(A[i][0]) == 2:
      if count % 2 == 1:
        s = s[::-1]
      count = 0
      if int(A[i][1]) == 1:
        s = [A[i][2]] + s
      else:
        s = s + [A[i][2]]
    else:
      count += 1
      if i == Q-1:
        if count % 2 == 1:
          s = s[::-1]


  result = ''.join(s)
  print(result)

Buggy submission (verdict: Runtime Error):
def toku()
  S = input()
  Q = int(input())
  s = [S[0]]
  A = []
  count = 0
  for i in range(Q):
    A += [input().split()]
  for i in range(Q):
    if int(A[i][0]) == 2:
      if count % 2 == 1:
        s = s[::-1]
      count = 0
      if int(A[i][1]) == 1:
        s = [A[i][2]] + s
      else:
        s = s + [A[i][2]]
    else:
      count += 1
      if i == Q-1:
        if count % 2 == 1:
          s = s[::-1]


  result = ''.join(s)
  print(result)
toku()
Problem p02802 (python)

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

wa = [0]*N
ac = [0]*N

wac = 0
acc = 0

for i in range(M):
  p,s = input().split()
  p = int(p)
  if s == "AC":
    if ac[p-1] != 1:
      ac[p-1] = 1
      acc += 1
      wac += wa[p-1]
  else:
    if ac[p-1] == 0:
      wa[p-1] += 1
print(str(acc) +" "+ str(wac))

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
P,S = [map(int,input().split()) for i in range(M)]

a = [0]*N

ac = 0
wa = 0

for i in range(M):
  if a[P[i]-1] == 0:
    if S[i] == "AC":
      ac += 1
      a[P[i]-1] = 1
    else:
      wa += 1
print(ac + " " + wa)
Problem p02817 (python)

Fixed submission:
T , S = input().split()
print(S +T)

Buggy submission (verdict: Runtime Error):
print(input().split().replace(" ","")
Problem p02818 (python)

Fixed submission:
A,B,K = map(int,input().split())
 
if K >= A:
  B = B -(K-A)
  A = 0
  if B < 0:
    B = 0
else:
  A = A - K

print(str(A) + " " + str(B))

Buggy submission (verdict: Runtime Error):
A,B,K = map(int,input().split())

for i in range(K):
  if A > 0:
    A -= 1
  else:
    if B > 0
    B -= 1

print(str(A) + " " + STR(B))
Problem p03086 (python)

Fixed submission:
S = input()

A = 0
B = 0
for i in S:
  if i == "A" or i == "C" or i == "G" or i == "T":
    B += 1
  else:
    A = max(A,B)
    B = 0
A = max(A,B)
print(A)

Buggy submission (verdict: Runtime Error):
S = input()
N = len(S)
ans = 0
for i in range(N):
	for j in range(i, N):
      if all('ACGT'.count(c) == 1 for c in S[i : j + 1]):
        ans = max(ans, j - i + 1)
print(ans)
Problem p03161 (python)

Fixed submission:
N,K = map(int,input().split())
H = [int(x) for x in input().split()]
 
def main(N,K,H):
    dp = [0]*N
    for i in range(1,N):
        L = [dp[j]+abs(H[i]-H[j]) for j in range(max(0,i-K),i)]
        dp[i] = min(L)
    print(dp[-1])
main(N,K,H)

Buggy submission (verdict: Runtime Error):
N,K = map(int,input().split())
h = list(map(int,input().split()))
 
def main(N,K,H):
    dp = [0]*N
    for i in range(1,N):
        L = [dp[j]+abs(H[i]-H[j]) for j in range(max(0,i-K),i)]
        dp[i] = min(L)
    print(dp[-1])
main(N,K,H)

Buggy submission (verdict: Runtime Error):
N,K = map(int,input().split())
h = list(map(int,input().split()))

dp = [0]*N
dp[1] = abs(h[1]-h[0])
for i in range(2,N):
  L = [dp[j] +abs(H[i] - H[j]) for j in range(max(0,i-K),i)]
  dp[i] = min(L)
print(dp[N-1])
Problem p03210 (python)

Fixed submission:
X = int(input())
 
if X == 3 or X == 5 or X == 7:
  print("YES")
else:
  print("NO")

Buggy submission (verdict: Runtime Error):
X = int(input())

if X == 3 or X == 5 or x == 7:
  print("YES")
else:
  print("NO")
Problem p03273 (python)

Fixed submission:
H,W = map(int,input().split())
a = [input() for _ in range(H)]

row = [False]*H
col = [False]*W

for i in range(H):
  for j in range(W):
    if a[i][j] == "#":
      row[i] = True
      col[j] = True

for i in range(H):
  if row[i]:
    for j in range(W):
      if col[j]:
        print(a[i][j],end = '')
    print()

Buggy submission (verdict: Runtime Error):
H,W = map(int,input().split())
a = [input() for _ in range(H)]

row = [False]*H
col = [Flase]*W

for i in range(H):
  for j in range(w):
    if a[i][j] == "#":
      row[i] = True
      col[j] = True

for i in range(h):
  if row[i]:
    for j in range(w):
      if col[j]:
        print(a[i][j],end = '')
  print()