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

Fixed submission:
M=10**9+7
n,k,*a=map(int,open(y:=0).read().split())
a.sort()
x=s=1
r=k
while r>1:
 if(t:=a[y]*a[y+1])>a[-x]*a[~x]:s=s*t%M;y+=2;r-=2
 else:s=s*a[-x]%M;x+=1;r-=1
if r:s*=a[-x]
if a[-1]<0<k%2:
 s=1
 for i in a[-k:]:s=s*i%M
print(s%M)

Buggy submission (verdict: Runtime Error):
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# import numpy as np
sys.setrecursionlimit(int(pow(10,6)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("out.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def L(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]

# @lru_cache(None)

t=1
# t=int(input())
for _ in range(t):
    n,k=L()
    A=L()
    A.sort()
    x=bl(A,0)
    y=br(A,0)
    neg=A[:x]
    pos=A[y:][::-1]
    if len(pos)==0:
        neg=neg[::-1]
        neg=[1]+neg
        for i in range(1,len(neg)):
            neg[i]*=neg[i-1]
        print(neg[k]%mod)
        exit()
    
    neg=[1]+neg
    for i in range(1,len(neg)):
        neg[i]*=neg[i-1]

    pos=[1]+pos
    for i in range(1,len(pos)):
        pos[i]*=pos[i-1]
    mx=neg[min(k,len(neg)-1)]
    for i in range(0,len(neg),2):
        if (k-i)>=0 and (k-i)<len(pos):
            curr=neg[i]*pos[(k-i)]
            mx=max(curr,mx)

    # print(mx)
    print(mx%mod)
Problem p02660 (python)

Fixed submission:
N = int(input())
 
ans = 0
f = 2
while True:
  if N%f==0:
    c = 0
    while N%f==0:
      N /= f
      c += 1
    n = 1
    while n*(n+1)//2<=c:
      n += 1
    ans += n-1
  if f*f>N:
    break
  f += 1
if N>1:
  ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# sys.setrecursionlimit(int(pow(10, 2)))
#sys.stdin = open("input.txt", "r")
#sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]





# @lru_cache(None)
is_prime=[1 for i in range(10**6+1)]
is_prime[0]=0
is_prime[1]=0
for i in range(2,10**6+1):
    if(is_prime[i]):
        for j in range(2*i,10**6+1,i):
            is_prime[j]=0
n=l()[0]
div=[]
if(n==1):
    print(0)
    exit()
for i  in range(2,int(n**0.5)+1):
    if(n%i==0 and is_prime[i]):
        div.append(i)
        if(is_prime[n//i] and n//i!=i):
            div.append(n//i)
ans=0
for p in range(1,n//div[0]):
    x=n
    for ele in div:
        if(n%(ele**p)==0):
            # print(n,ele**p)
            ans+=1
            n//=(ele**p)
        else:
            break
    if(x==n):
        break
# print(ans)
for i in range(ele**p,n+1):
    if(x%i==0):
        x//=i
        ans+=1
    if(x==1):
        break
print(ans)
Problem p03161 (python)

Fixed submission:
import sys
def input():
    return sys.stdin.readline().strip()
 
def main():
    nk=list(map(int,input().split()))
    h=list(map(int,input().split()))
    n=nk[0]
    k=nk[1]
    dp=[10**9]*n
    dp[0]=0
    dp[1]=abs(h[1]-h[0])
    for i in range(2,n):
        dp[i]=min(dp[j]+abs(h[i]-h[j]) for j in range(max(0,i-k),i))
        # for j in range(max(0,i-k),i):
        #     dp[i]=min(dp[j]+abs(h[i]-h[j]),dp[i])
 
    print (dp[-1])
 
if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys
def input():
    return sys.stdin.readline().strip()
 
def main():
    nk=list(map(int,input().split()))
    h=list(map(int,input().split()))
    n=nk[0]
    k=nk[1]
    dp=[10**9]*n
    dp[0]=0
    dp[1]=abs(h[1]-h[0])
    for i in range(2,n):
        dp[i]=min(dp[j]+abs(h[i]-h[j]) for j in range(max(0,i-k),i))
    print (dp[-1])
 if __name__ == "__main__":
    main()
Problem p03487 (python)

Fixed submission:
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
# import math
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# sys.setrecursionlimit(int(pow(10, 2)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]





# @lru_cache(None)
n=l()[0]
A=l()
d={}
for i in range(n):
    if A[i] not in d:
        d[A[i]]=0
    d[A[i]]+=1
ans=0
for k in d:
    if(d[k]<k):
        ans+=d[k]
    else:
        ans+=(d[k]-k)
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
# import math
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# sys.setrecursionlimit(int(pow(10, 2)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]





# @lru_cache(None)
n=l()[0]
A=l()
d={}
for i in range(n):
    if A[i] not in d:
        d[A[i]]=0
    d[A[i]]+=1
anss=0
for k in d:
    if(d[k]<k):
        ans+=k
    else:
        ans+=(d[k]-k)
print(ans)
Problem p03673 (python)

Fixed submission:
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
# import math
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# sys.setrecursionlimit(int(pow(10, 2)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]





# @lru_cache(None)


n = int(input())
A = input().split()
if n%2==0:
    print(' '.join(A[1::2][::-1]),end=' ')
    print(' '.join(A[::2]))
else:
    print(' '.join(A[::2][::-1]),end=' ')
    print(' '.join(A[1::2]))

Buggy submission (verdict: Runtime Error):
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
# import math
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# sys.setrecursionlimit(int(pow(10, 2)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]





# @lru_cache(None)


n=l()[0]
A=l()
ans=[]
for i in range(n):
    if(i%2==0):
        ans+=[A[i]]
    else:
        ans=[A[i]]+ans
if(i%2==0):
    print(*ans[::-1])
else:
    print(*ans)
Problem p03779 (python)

Fixed submission:
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
# import math
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# sys.setrecursionlimit(int(pow(10, 2)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]





# @lru_cache(None)

X=l()[0]
i=1
while(X-i>0):
    X-=i
    i+=1

print(i)

Buggy submission (verdict: Runtime Error):
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
# import math
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# sys.setrecursionlimit(int(pow(10, 2)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]





@lru_cache(None)
def rec(x,t,curr):
    # print(x,t,curr)
    if(x==curr):
        return t
    if(t>x):
        return x
    return min(rec(x,t+1,curr+t+1),rec(x,t+1,curr),rec(x,t+1,curr-t-1))




X=l()[0]
print(min(rec(X,1,1),rec(X,1,0),rec(X,1,-1)))
Problem p02603 (python)

Fixed submission:
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):
    def uniq(arr):
        ret = [arr[0]]
        for a in arr[1:]:
            if ret[-1] == a:
                continue
            ret.append(a)
        return ret

    def compress(arr):
        if len(arr) <= 2:
            return arr
        ret = [arr[0]]        
        for a0, a1, a2 in zip(arr, arr[1:], arr[2:]):
            if a0 < a1 < a2 or a0 > a1 > a2:
                continue
            ret.append(a1)
        ret.append(arr[-1])
        return ret

    B = uniq(A)
    C = compress(B)
    if len(C) == 1:
        return 1000
    ans, m, s = 1000, 1000, 0
    for c0, c1 in zip(C, C[1:]):
        if c0 < c1:
            t = m // c0
            s += t
            m -= t * c0
        else:
            m += c0 * s
            s = 0
        ans = max(ans, m)
    else:
        m += c1 * s
        ans = max(ans, m)
    return ans

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    print(solve(N, A))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):
    def uniq(arr):
        ret = [arr[0]]
        for a in arr[1:]:
            if ret[-1] == a:
                continue
            ret.append(a)
        return ret

    def compress(arr):
        if len(arr) <= 2:
            return arr
        ret = [arr[0]]        
        for a0, a1, a2 in zip(arr, arr[1:], arr[2:]):
            if a0 < a1 < a2 or a0 > a1 > a2:
                continue
            ret.append(a1)
        ret.append(arr[-1])
        return ret

    B = uniq(A)
    C = compress(B)
    ans, m, s = 1000, 1000, 0
    for c0, c1 in zip(C, C[1:]):
        if c0 < c1:
            t = m // c0
            s += t
            m -= t * c0
        else:
            m += c0 * s
            s = 0
        ans = max(ans, m)
    else:
        m += c1 * s
        ans = max(ans, m)
    return ans

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    print(solve(N, A))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()
Problem p02631 (python)

Fixed submission:
#!/usr/bin/env python3
import sys


def solve(N: int, a: "List[int]"):
    from functools import reduce
    assert N % 2 == 0
    b = reduce(lambda a, b: a ^ b, a)
    return [aa ^ b for aa in a]

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    print(*solve(N, a))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys


def solve(N: int, a: "List[int]"):
    from functools import reduce
    assert N % 2 == 0
    b = reduce(lambda a, b: a ^ b, a)
    return [aa ^ b for aa in a]

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    print(*solve(N, a))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()
#!/usr/bin/env python3
import sys


def solve(N: int, a: "List[int]"):
    from functools import reduce
    assert N % 2 == 0
    b = reduce(lambda a, b: a ^ b, a)
    return [aa ^ b for aa in a]

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    print(*solve(N, a))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()
Problem p02690 (python)

Fixed submission:
#!/usr/bin/env python3
import sys

def show():
    for i in range(100):
        print(i, i**5)

def solve(X: int):
    A = [(i ** 5, i) for i in range(1000)]
    for a, b in A:
        for aa, bb in A:
            if a  - aa == X:
                return b, bb
            if a + aa == X:
                return b, -bb
    raise


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    print(*solve(X))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()
    #show()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys

def show():
    for i in range(100):
        print(i, i**5)

def solve(X: int):
    A = [(i ** 5, i) for i in range(100)]
    for a, b in A:
        for aa, bb in A:
            if a  - aa == X:
                return b, -bb
            if a + aa == X:
                return b, bb
    raise


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    print(*solve(X))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()
    #show()
Problem p02727 (python)

Fixed submission:
#!/usr/bin/env python3
import sys


def solve(X: int, Y: int, A: int, B: int, C: int, p: "List[int]", q: "List[int]", r: "List[int]"):
    p = sorted(p, reverse=True)
    q = sorted(q, reverse=True)
    d = sorted(p[:X] + q[:Y] + r)
    print(sum(sorted(d, reverse=True)[:X+Y]))

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    p = [int(next(tokens)) for _ in range(A)]  # type: "List[int]"
    q = [int(next(tokens)) for _ in range(B)]  # type: "List[int]"
    r = [int(next(tokens)) for _ in range(C)]  # type: "List[int]"
    solve(X, Y, A, B, C, p, q, r)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys


def solve(X: int, Y: int, A: int, B: int, C: int, p: "List[int]", q: "List[int]", r: "List[int]"):
    p = sorted(p, reverse=True)
    q = sorted(q, reverse=True)
    d = sorted(p[:X] + q[:Y])
    i = 0
    for rr in r:
        if d[i] <= rr:
            d[i] = rr
            i += 1
    print(sum(d))


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    p = [int(next(tokens)) for _ in range(A)]  # type: "List[int]"
    q = [int(next(tokens)) for _ in range(B)]  # type: "List[int]"
    r = [int(next(tokens)) for _ in range(C)]  # type: "List[int]"
    solve(X, Y, A, B, C, p, q, r)

if __name__ == '__main__':
    main()
Problem p02755 (python)

Fixed submission:
#!/usr/bin/env python3
import sys


def solve(A: int, B: int):
    for i, a, b in map(lambda x: (x, int(x*0.08), int(x*0.1)), range(A*100)):
        if a == A and b == B:
            return i
    return -1


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    print(solve(A, B))

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys


def solve(A: int, B: int):
    for i, a, b in map(lambda x: (x, int(x*0.08), int(x*0.1)), range(A*100)):
        if a == A and b == B:
            return i
    return -1


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    print(solve(A, B))

if __name__ == '__main__':
    main()
Problem p02756 (python)

Fixed submission:
#!/usr/bin/env python3

def main():
    from itertools import chain
    S = input()
    Q = int(input())
    Queries = [input().split() for _ in range(Q)]
    H_T = H, T = [], []
    flag = 0
    for query in Queries:
        if len(query) == 1:
            flag ^= 1
            continue
        _, f, c = query
        H_T[(int(f) + flag - 1) % 2].append(c)
    t = ''.join(chain(reversed(H), S, T))
    if flag:
        t = reversed(t)
    print(''.join(t))


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3

def main():
    from itertools import chain
    S = input()
    Q = int(input())
    Queries = [input().split() for _ in range(Q)]
    H_T = H, T = [], []
    flag = 0
    for query in Queries:
        if len(query) == 1:
            flag ^= 1
            continue
        _, f, c = query
        H_T[(int(f) + flag) % 2].append(c)
    if flag:
        print(''.join(chain(reversed(H), S, T)))
    else:
        print(''.join(chain(reversed(T), S, H)))

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
from collections import deque
d = deque(input())
flag = 0
for T_F_C in (input().split() for _ in range(int(input()))):
    if T_F_C[0] == '1':
        flag ^= 1
        continue
    _, f, c = T_F_C
    if (flag+int(f)) % 2:
	d.appendleft(c)
    else:
        d.append(c)
if flag:
    d = reversed(d)
print("".join(d))

Buggy submission (verdict: Runtime Error):
from collections import deque
d = deque(input())
flag = 0
for T_F_C in (input().split() for _ in range(int(input()))):
    print("".join(d) if flag else "".join(reversed(d)))
    if T_F_C[0] == '1':
        flag ^= 1
        continue
    _, f, c = T_F_C
    if (flag+int(f)) % 2:
        d.append(c)
    else:
        d.appendleft(c)
if flag:
    print("".join(d))
else:
    print("".join(reversed(d)))