Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
"""
s = LS()[1]
print("A"+s[0]+"C")
"""
#B
a,b,x = LI()
print(x//b-x//(a-1))
#C
"""
n,x = LI()
a = LI()
ans = 0
for i in range(n-1):
    if a[i]+a[i+1] > x:
        ans += a[i+1]+a[i]-x
        if x > a[i]:
            a[i+1] = x-a[i]
        else:
            a[i+1] = 0
            a[i] = x
print(ans)
"""

#D
"""
s = S()
l = len(s)
k = (s[0] == s[-1])
if (l%2)^k:
    print("First")
else:
    print("Second")
"""
#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


Fixed submission:
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
"""
s = LS()[1]
print("A"+s[0]+"C")
"""
#B
a,b,x = LI()
print(b//x-(a-1)//x)
#C
"""
n,x = LI()
a = LI()
ans = 0
for i in range(n-1):
    if a[i]+a[i+1] > x:
        ans += a[i+1]+a[i]-x
        if x > a[i]:
            a[i+1] = x-a[i]
        else:
            a[i+1] = 0
            a[i] = x
print(ans)
"""

#D
"""
s = S()
l = len(s)
k = (s[0] == s[-1])
if (l%2)^k:
    print("First")
else:
    print("Second")
"""
#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T
Buggy python submission (verdict: Time Limit Exceeded):
n,a = map(int, input().split())
x = list(map(int, input().split()))
for i in range(n):
    x[i] -= a
lis = []
for i in range(2**n):
    d = list(map(int, list(bin(i))[2:]))
    while len(d) < n:
        d.insert(0,0)
    lis.append(d)
ans = -1
for i in lis:
    su = 0
    for j in range(n):
        su += i[j]*x[j]
    if su == 0:
        ans += 1
print(ans)

Fixed submission:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,a = LI()
    x = LI()
    m = 2501
    d = [[0]*m for i in range(n+1)]
    d[0][0] = 1
    for xi in x:
        for i in range(n)[::-1]:
            ni = i+1
            for j in range(m):
                if not d[i][j]:
                    continue
                k = j+xi
                if k >= m:
                    break
                d[ni][k] += d[i][j]
    ans = 0
    for i in range(1,n+1):
        k = a*i
        if k < m:
            ans += d[i][k]
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()
Buggy python submission (verdict: Time Limit Exceeded):
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():

    return

#B
def B():

    return

#C
def C():
    n,c = LI()
    a = LI()
    b = LI()
    s = [[0]*(c+1) for i in range(n)]
    for k in range(c+1):
        for i in range(n):
            ai,bi = a[i],b[i]
            for x in range(ai,bi+1):
                s[i][k] += pow(x,k,mod)
                if s[i][k] >= mod:
                    s[i][k] %= mod
    dp = [[0]*(c+1) for i in range(n)]
    for k in range(c+1):
        dp[0][k] = s[0][k]

    for i in range(1,n):
        for k in range(c+1):
            for j in range(k+1):
                dp[i][k] += dp[i-1][j]*s[i][k-j]
                if dp[i][k] >= mod:
                    dp[i][k] %= mod
    print(dp[-1][c])
    return

#D
def D():

    return

#E
def E():

    return

#F
def F():

    return

#Solve
if __name__ == "__main__":
    C()


Fixed submission:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():

    return

#B
def B():

    return

#C
def C():
    n,c = LI()
    a = LI()
    b = LI()
    s = [[0]*(c+1) for i in range(n)]
    for i in range(n):
        ai,bi = a[i],b[i]
        for x in range(ai,bi+1):
            e = 1
            for k in range(c+1):
                s[i][k] += e
                if s[i][k] >= mod:
                    s[i][k] %= mod
                e *= x
                if e >= mod:
                    e %= mod
    dp = [[0]*(c+1) for i in range(n)]
    for k in range(c+1):
        dp[0][k] = s[0][k]

    for i in range(1,n):
        for k in range(c+1):
            for j in range(k+1):
                dp[i][k] += dp[i-1][j]*s[i][k-j]
                if dp[i][k] >= mod:
                    dp[i][k] %= mod
    print(dp[-1][c])
    return

#D
def D():

    return

#E
def E():

    return

#F
def F():

    return

#Solve
if __name__ == "__main__":
    C()
Buggy python submission (verdict: Runtime Error):
S = int(input())
mod = 10**9+7

ans = 0

x = [0]*(S+1)
x[3] = 1
x[4] = 1
x[5] = 1
for i in range(6, S+1):
    x[i] += 1
    for j in range(3, i-2):
        x[i] += x[j]
        x[i] %= mod

print(x[S])

Fixed submission:
S = int(input())
mod = 10**9+7

ans = 0

x = [0]*(2020)
x[3] = 1
x[4] = 1
x[5] = 1
for i in range(6, S+1):
    x[i] += 1
    for j in range(3, i-2):
        x[i] += x[j]
        x[i] %= mod

print(x[S])
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

H, W = map(int, input().split())
c1, c2 = map(int, input().split())
d1, d2 = map(int, input().split())
c1 += 1
c2 += 1
d1 += 1
d2 += 1
S = ["#"*(W+4)]*2 + ["##"+input()+"##" for _ in range(H)] + ["#"*(W+4)]*2

ans = [[10000000]*(W+4) for _ in range(H+4)]
ans[c1][c2] = 0
q = deque([[c1, c2]])

x = [[-1, 0], [0, -1], [0, 1], [1, 0]]

while q:
    h, w = q.popleft()
    
    for a, b in x:
        nh = h+a
        nw = w+b
        if S[nh][nw] == ".":
            if ans[nh][nw] > ans[h][w]:
                ans[nh][nw] = ans[h][w]
                q.appendleft([nh, nw])
    
    for a in range(-2, 3):
        for b in range(-2, 3):
            nh = h+a
            nw = w+b
            if S[nh][nw] == ".":
                if ans[nh][nw] > ans[h][w]+1:
                    ans[nh][nw] = ans[h][w]+1
                    q.append([nh, nw])

if ans[d1][d2] == 10000000:
    print(-1)
else:
    print(ans[d1][d2])

Fixed submission:
from collections import deque

H, W = map(int, input().split())
c1, c2 = map(int, input().split())
d1, d2 = map(int, input().split())
c1 += 1
c2 += 1
d1 += 1
d2 += 1
S = ["#"*(W+4)]*2 + ["##"+input()+"##" for _ in range(H)] + ["#"*(W+4)]*2

ans = [[10000000]*(W+4) for _ in range(H+4)]
ans[c1][c2] = 0
q = deque([[c1, c2]])

x = [[-1, 0], [0, -1], [0, 1], [1, 0]]

while q:
    h, w = q.popleft()
    
    for a, b in x:
        nh = h+a
        nw = w+b
        if S[nh][nw] == ".":
            if ans[nh][nw] > ans[h][w]:
                ans[nh][nw] = ans[h][w]
                q.appendleft([nh, nw])
    
    for a in range(-2, 3):
        for b in range(-2, 3):
            nh = h+a
            nw = w+b
            if S[nh][nw] == ".":
                if ans[nh][nw] > ans[h][w]+1:
                    ans[nh][nw] = ans[h][w]+1
                    q.append([nh, nw])

if ans[d1][d2] == 10000000:
    print(-1)
else:
    print(ans[d1][d2])
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
P = list(map(lambda x: int(x)-1, input().split()))
C = list(map(int, input().split()))

visited = [False]*N
lp = [[0] for _ in range(N)]

lidx = 0
for s in range(N):
    if visited[s]:
        continue

    nex = s
    while not visited[nex]:
        visited[nex] = True
        now = P[nex]
        nex = now
        lp[lidx].append(lp[lidx][-1] + C[now])

    lidx += 1

ans = -(10**10)

for k in range(lidx):
    loop = lp[k]
    km = loop[-1]
    
    lenloop = len(loop)-1

    pt = 0

    kk = K

    x = max(kk//lenloop-1, 0)
    if km > 0:
        pt += x*km
    kk -= x*lenloop

    # print(x, kk, km)

    for i in range(lenloop*2):
        loop.append(loop[i+1]+km)
    
    for i in range(lenloop):
        for j in range(i+1, i+kk+1):
            # print(i, j, loop[j]-loop[i])
            ans = max(loop[j]-loop[i]+pt, ans)

# print(lp)

print(ans)

Fixed submission:
N, K = map(int, input().split())
P = list(map(lambda x: int(x)-1, input().split()))
C = list(map(int, input().split()))

visited = [False]*N
lp = [[0] for _ in range(N)]

lidx = 0
for s in range(N):
    if visited[s]:
        continue

    nex = s
    while not visited[nex]:
        visited[nex] = True
        now = P[nex]
        nex = now
        lp[lidx].append(lp[lidx][-1] + C[now])

    lidx += 1

ans = -(10**10)

for k in range(lidx):
    loop = lp[k]
    km = loop[-1]
    
    lenloop = len(loop)-1

    pt = 0

    kk = K

    x = max(kk//lenloop-1, 0)
    if km > 0:
        pt += x*km
    kk -= x*lenloop

    # print(x, kk, km)

    for i in range(lenloop*2):
        loop.append(loop[i+1]+km)
    
    for i in range(lenloop):
        for j in range(i+1, i+kk+1):
            # print(i, j, loop[j]-loop[i])
            ans = max(loop[j]-loop[i]+pt, ans)

# print(lp)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = list(map(int, input().split()))

x = 1
for i in range(K):
    x *= A[i]

hyo = [0]*N
hyo[K-1] = x

for i in range(K, N):
    hyo[i] = hyo[i-1]//A[i-K]*A[i]
    if hyo[i] > hyo[i-1]:
        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] > A[i-K]:
        print("Yes")
    else:
        print("No")

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = list(map(int, input().split()))

x = 1
for i in range(K):
    x *= A[i]

hyo = [0]*N
hyo[K-1] = x

for i in range(K, N):
    hyo[i] = hyo[i-1]*A[i]//A[i-K]
    if hyo[i] > hyo[i-1]:
        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] > A[i-K]:
        print("Yes")
    else:
        print("No")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

A.append(0)

B = []
f = True
for i in range(N):
    if f:
        if A[i] < A[i+1]:
            B.append(A[i])
            f = False
    else:
        if A[i] > A[i+1]:
            B.append(A[i])
            f = True


if len(B) == 0:
    print(1000)
else:
    res = 1000
    xx = len(B)//2+1
    B = [0]+B+[10**10]
    for i in range(2**xx):
        en = 1000
        ka = 0
        for j in range(xx):
            if (i>>j)&1:
                en += ka*B[j*2]
                ka = 0
                ka = en//B[j*2+1]
                en = en%B[j*2+1]
        else:
            res = max(en, res)

    print(res)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
A.append(0)

kabu = 0
en = 1000

for i in range(N):
    a, b = divmod(en, A[i])
    kabu += a
    en = b
    if A[i+1] < A[i]:
        en += kabu*A[i]
        kabu = 0

print(en)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

A.append(0)

B = []
f = True
for i in range(N):
    if f:
        if A[i] < A[i+1]:
            B.append(A[i])
            f = False
    else:
        if A[i] > A[i+1]:
            B.append(A[i])
            f = True


if len(B) == 0:
    print(1000)
else:
    res = 1000
    for i in range(2**len(B)):
        en = 1000
        ka = 0
        for j in range(len(B)):
            if (i>>j)&1:
                if j % 2 == 0:
                    if en // B[j] == 0:
                        break
                    ka = en//B[j]
                    en %= B[j]
                else:
                    if ka == 0:
                        break
                    en += ka*B[j]
                    ka = 0
        else:
            res = max(en, res)

    print(res)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
A.append(0)

kabu = 0
en = 1000

for i in range(N):
    a, b = divmod(en, A[i])
    kabu += a
    en = b
    if A[i+1] < A[i]:
        en += kabu*A[i]
        kabu = 0

print(en)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = list(map(int, input().split()))
c = [0]*N

for _ in range(min(K, 100)):
    b = [0]*(N+1)
    for i, a in enumerate(A):
        b[max(i-a, 0)] += 1
        b[min(i+a+1, N)] -= 1
    
    x = 0
    for i in range(N):
        x += b[i]
        A[i] = x

print(" ".join(str(a) for a in A))

Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))
c = [0]*N

for _ in range(min(K, 100)):
    b = [0]*(N+1)
    for i, a in enumerate(A):
        b[max(i-a, 0)] += 1
        b[min(i+a+1, N)] -= 1
    
    x = 0
    for i in range(N):
        x += b[i]
        A[i] = x

print(" ".join(str(a) for a in A))

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = list(map(int, input().split()))

for _ in range(min(K, 100)):
    b = [0]*N
    for i, a in enumerate(A):
        for j in range(max(i-a, 0), min(a+i+1, N)):
            b[j] += 1
    A = b

print(" ".join(str(a) for a in A))


Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))
c = [0]*N

for _ in range(min(K, 100)):
    b = [0]*(N+1)
    for i, a in enumerate(A):
        b[max(i-a, 0)] += 1
        b[min(i+a+1, N)] -= 1
    
    x = 0
    for i in range(N):
        x += b[i]
        A[i] = x

print(" ".join(str(a) for a in A))

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = list(map(int, input().split()))

for _ in range(K):
    b = [0]*N
    for i, a in enumerate(A):
        for j in range(max(i-a, 0), min(a+i+1, N)):
            b[j] += 1
    A = b

print(" ".join(str(a) for a in A))

Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))
c = [0]*N

for _ in range(min(K, 100)):
    b = [0]*(N+1)
    for i, a in enumerate(A):
        b[max(i-a, 0)] += 1
        b[min(i+a+1, N)] -= 1
    
    x = 0
    for i in range(N):
        x += b[i]
        A[i] = x

print(" ".join(str(a) for a in A))
Buggy python submission (verdict: Runtime Error):
S, T = input().split()
if S == T[:len(S)-1]:
  print("Yes")
else:
  print("No")

Fixed submission:
S = input()
T = input()
if S == T[:len(S)]:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, ("0 "+input()).split()))


c = [0]*(N+1)
i = 1
cnt = 0
f = True

while cnt < K:
    if f and c[A[i]]:
        loop = cnt-c[A[i]]
        cnt += (K-cnt-1)//loop*loop
        f = False

    cnt += 1
    i = A[i]
    c[i] = cnt

print(i)

Fixed submission:
N, K = map(int, input().split())
A = list(map(int, ("0 "+input()).split()))


c = [0]*(N+1)
i = 1
cnt = 0
f = True

while cnt < K:
    if f and (c[A[i]] or A[i]==1):
        loop = cnt-c[A[i]]+1
        cnt += (K-cnt-1)//loop*loop
        f = False

    cnt += 1
    i = A[i]
    c[i] = cnt

print(i)

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, ("0 "+input()).split()))


c = [0]*(N+1)
i = 1
cnt = 0
f = True

while cnt < K:
    if f and c[A[i]]:
        print(cnt, i, c)
        loop = cnt-c[A[i]]
        cnt += (K-cnt-1)//loop*loop
        if cnt == K:
            break
        f = False

    cnt += 1
    i = A[i]
    c[i] = cnt

print(i)

Fixed submission:
N, K = map(int, input().split())
A = list(map(int, ("0 "+input()).split()))


c = [0]*(N+1)
i = 1
cnt = 0
f = True

while cnt < K:
    if f and (c[A[i]] or A[i]==1):
        loop = cnt-c[A[i]]+1
        cnt += (K-cnt-1)//loop*loop
        f = False

    cnt += 1
    i = A[i]
    c[i] = cnt

print(i)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
f = [False]*N
f2 = [False]*N
l = 0
r = 1
for i in range(M):
    flag = True
    while flag:
        if f[l] or f[r]:
            l += 1
            r += 1
            l %= N
            r %= N
            continue
        if f2[min(abs(r-l), N-abs(r-l))]:
            r += 1
            r %= N
            continue
        if N%2 == 0:
            if abs(r-l) == N//2:
                r += 1
                r %= N
        flag = False
    f[l] = True
    f[r] = True
    f2[min(abs(r-l), N-abs(r-l))] = True
    print(l+1, r+1)

Fixed submission:
N, M = map(int, input().split())
f = [False]*N
l = 0
r = N+1
for i in range(M):
    l += 1
    r -= 1
    while True:
        if N % 2 == 0:
            if r-l == N//2:
                r -= 1
                continue
        if f[min(r-l, N-(r-l))]:
            r -= 1
            continue
        break
            
    f[min(r-l, N-(r-l))] = True
    print(l, r)
Buggy python submission (verdict: Time Limit Exceeded):
H, W, K = map(int, input().split())
S = [list(input()) for _ in range(H)]

res = 10**9

for i in range(2**(H-1)):
    yoko = []
    for j in range(H-1):
        if (i>>j) & 1:
            yoko.append(j+1)
    yoko.append(H)
    
    sen = len(yoko)-1

    rS = [[0]*W for _ in range(sen+1)]

    flag = False

    for w in range(W):
        b = 0
        for j in range(sen+1):
            t = b
            b = yoko[j]
            for h in range(t, b):
                if S[h][w] == "1":
                    rS[j][w] += 1
            if rS[j][w] > K:
                flag = True
                break
        if flag:
            break
    
    if flag:
        continue
    
    x = [r[0] for r in rS]
    for w in range(1, W):
        for h in range(len(yoko)):
            x[h] += rS[h][w]
            if x[h] > K:
                x = [r[w] for r in rS]
                sen += 1
                break
    
    res = min(sen, res)
    if res == 0:
        break

print(res)

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

res = 10**9

for i in range(2**(H-1)):
    yoko = []
    for j in range(H-1):
        if (i>>j) & 1:
            yoko.append(j+1)
    yoko.append(H)
    
    sen = len(yoko)-1

    rS = [[0]*W for _ in range(sen+1)]

    flag = False

    for w in range(W):
        b = 0
        for j in range(sen+1):
            t = b
            b = yoko[j]
            for h in range(t, b):
                if S[h][w] == "1":
                    rS[j][w] += 1
            if rS[j][w] > K:
                flag = True
                break
        if flag:
            break
    
    if flag:
        continue
    
    x = [r[0] for r in rS]
    for w in range(1, W):
        for h in range(len(yoko)):
            x[h] += rS[h][w]
            if x[h] > K:
                x = [r[w] for r in rS]
                sen += 1
                break
    
    res = min(sen, res)
    if res == 0:
        break

print(res)
Buggy python submission (verdict: Time Limit Exceeded):
from decimal import Decimal, getcontext

a, b, c = map(int, input().split())

getcontext().prec = 5000

if Decimal(a)**Decimal(0.5) + Decimal(b)**Decimal(0.5) < Decimal(c)**Decimal(0.5):
    print("Yes")
else:
    print("No")


Fixed submission:
a, b, c = map(int, input().split())
d = c-a-b
if d > 0 and d**2 > 4*a*b:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
res = input()
r = False
for _ in range(int(input())):
    q = input().split()
    if q[0] == "1":
        r = not r
    else:
        if q[1] == "1":
            if r:
                res += q[2]
            else:
                res = q[2] + res
        else:
            if r:
                res = q[2] + res
            else:
                res += q[2]

if r:
    print(res[::-1])
else:
    print(res)

Fixed submission:
S = input()
r = False
L = []
R = []
for _ in range(int(input())):
    q = input().split()
    if q[0] == "1":
        r = not r
    else:
        if q[1] == "1":
            if r:
                R.append(q[2])
            else:
                L.append(q[2])
        else:
            if r:
                L.append(q[2])
            else:
                R.append(q[2])


if r:
    R.reverse()
    print("".join(R + list(S[::-1]) + L))
else:
    L.reverse()
    print("".join(L + [S] + R))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
d = {}
for _ in range(N):
    s = input()
    if s not in d:
        d[s] = 0
    d[s] += 1

n = d[max(d)]

res = [kv[0] for kv in d.items() if kv[1] == max(d.values())]

res.sort()

for s in res:
    print(s)

Fixed submission:
N = int(input())
d = {}
for _ in range(N):
    s = input()
    if s not in d:
        d[s] = 0
    d[s] += 1

n = max(d.values())

res = [kv[0] for kv in d.items() if kv[1] == n]

res.sort()

for s in res:
    print(s)
Buggy python submission (verdict: Time Limit Exceeded):
H, N = map(int, input().split())
A = []
B = []
for _ in range(N):
    a, b = list(map(int, input().split()))
    A.append(a)
    B.append(b)

dpl = H+max(A)
x = 10**10
dp = [x]*dpl
dp[0] = 0

for a, b in zip(A, B):
    for i in range(a, dpl):
        dp[i] = min(dp[i-a]+b, dp[i])
    for i in range(dpl-2, -1, -1):
        dp[i] = min(dp[i+1], dp[i])

print(dp[H])

Fixed submission:
H, N = map(int, input().split())
A = []
B = []
for _ in range(N):
    a, b = list(map(int, input().split()))
    A.append(a)
    B.append(b)

dpl = H+max(A)
x = 10**10
dp = [x]*dpl
dp[0] = 0

for a, b in zip(A, B):
    for i in range(a, dpl):
        dp[i] = min(dp[i-a]+b, dp[i])
    for i in range(dpl-2, -1, -1):
        dp[i] = min(dp[i+1], dp[i])

print(dp[H])