Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
ab = []
for _ in range(n):
    ab.append(list(map(int,input().split())))

#%%

# print(n, m, ab)
# n, m, ab = 4, 30, [[6, 18], [2, 5], [3, 10], [7, 9]]


#%%
ab.sort()

#%%
ans = 0
num = 0
while num < m:
    a0 = ab[0][0]
    b0 = ab[0][1]
    if b0 >= m - num:
        ans += a0 * (m - num)
        break
    else:
        ans += a0 * b0
        num += b0
        ab.remove([a0, b0])
#%%
print(ans)
#%%


Fixed submission:
n, m = map(int, input().split())
ab = []
prod = [0]
prod_cum = [0]

num_cum = [0]
for i in range(n):
    a, b = map(int, input().split())
    ab.append([a,b])


#%%
ab.sort()

for i in range(n):
    a, b = ab[i][0],ab[i][1]
    # prod.append(a*b)
    prod_cum.append(a*b + prod_cum[-1])
    num_cum.append(b + num_cum[-1])
ab = [[0,0]] + ab
# print(ab)
# print(prod)
# print(prod_cum)
# print(num_cum)
# print(n, m, ab)
# n, m, ab = 4, 30, [[6, 18], [2, 5], [3, 10], [7, 9]]


#%%
ans = 0
prod = 0
for i in range(0, n+1):
    if num_cum[i] >= m:
        print(prod_cum[i] - ab[i][0] * (num_cum[i]-m))
        break



#%%
# ans = 0
# num = 0
# while num < m:
#     a0 = ab[0][0]
#     b0 = ab[0][1]
#     if b0 >= m - num:
#         ans += a0 * (m - num)
#         break
#     else:
#         ans += a0 * b0
#         num += b0
#         ab.remove([a0, b0])
#%%
# print(ans)
#%%
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(i) for i in input().split()]


#%%
# n, a = 4, [2, 10, 8, 40]


#%%


#%%

#%%
while len(a) >= 2:
    a.sort()

    for i in range(len(a) -1, 0, -1):
        a[i] = a[i] % a[0]
        if a[i] == 0:
            a.remove(a[i])
    


#%%
print(a[0])

#%%



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


def euclid_lcf(a, b):
    if b < a:
        a, b = b, a

    if b % a == 0:
        return a
    else:
        r = b % a
        return euclid_lcf(a, r)


com_factor = euclid_lcf(a[0], a[1])

if len(a) == 2:
    print(com_factor)
else:
    for i in range(2, len(a)):
        com_factor = euclid_lcf(com_factor, a[i])

    print(com_factor)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(i) for i in input().split()]


#%%
# n, a = 4, [2, 10, 8, 40]


#%%

a.sort()

#%%

#%%
while len(a) >= 2:
    if a[0] > a[1]:
        a[0], a[1] = a[1], a[0]

    for i in range(len(a) -1, 0, -1):
        a[i] = a[i] % a[0]
        if a[i] == 0:
            a.remove(a[i])
    


#%%
print(a[0])

#%%


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


def euclid_lcf(a, b):
    if b < a:
        a, b = b, a

    if b % a == 0:
        return a
    else:
        r = b % a
        return euclid_lcf(a, r)


com_factor = euclid_lcf(a[0], a[1])

if len(a) == 2:
    print(com_factor)
else:
    for i in range(2, len(a)):
        com_factor = euclid_lcf(com_factor, a[i])

    print(com_factor)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
x = list(map(int, input().split()))

# print(n, m, x)

# #%%
# n, m =2, 5
# x = [10, 12, 1, 2, 14]


#%%
x.sort()

#%%




#%%

diff_list = []
for i in range(m-1):
    diff = x[i+1] - x[i]
    diff_list.append(diff)


#%%
diff_list.sort()


#%%
if n-1>0:
    print(sum(diff_list[:-(n-1))])
else:
    print(0)    

#%%


#%%


Fixed submission:
n, m = map(int, input().split())
x = list(map(int, input().split()))

# print(n, m, x)

# #%%
# n, m =2, 5
# x = [10, 12, 1, 2, 14]


#%%
x.sort()

#%%




#%%

diff_list = []
for i in range(m-1):
    diff = x[i+1] - x[i]
    diff_list.append(diff)


#%%
diff_list.sort()


#%%
if n-1>0:
    print(sum(diff_list[:-(n-1)]))
else:
    print(sum(diff_list))    

#%%


#%%

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

# print(n, m, x)

# #%%
# n, m =2, 5
# x = [10, 12, 1, 2, 14]


#%%
x.sort()

#%%




#%%

diff_list = []
for i in range(m-1):
    diff = x[i+1] - x[i]
    diff_list.append(diff)


#%%
diff_list.sort()


#%%
print(x[-1] - x[0] - sum(diff_list[-(n-1):])

#%%


#%%


Fixed submission:
n, m = map(int, input().split())
x = list(map(int, input().split()))

# print(n, m, x)

# #%%
# n, m =2, 5
# x = [10, 12, 1, 2, 14]


#%%
x.sort()

#%%




#%%

diff_list = []
for i in range(m-1):
    diff = x[i+1] - x[i]
    diff_list.append(diff)


#%%
diff_list.sort()


#%%
if n-1>0:
    print(sum(diff_list[:-(n-1)]))
else:
    print(sum(diff_list))    

#%%


#%%

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

# print(n, m, x)

# #%%
# n, m =2, 5
# x = [10, 12, 1, 2, 14]


#%%
x.sort()

#%%




#%%

diff_list = []
for i in range(m-1):
    diff = x[i+1] - x[i]
    diff_list.append(diff)


#%%
diff_list.sort()


#%%
print(x[-1] - x[0] - sum(diff_list[-(n-1):])

#%%


#%%


Fixed submission:
n, m = map(int, input().split())
x = list(map(int, input().split()))

# print(n, m, x)

# #%%
# n, m =2, 5
# x = [10, 12, 1, 2, 14]


#%%
x.sort()

#%%




#%%

diff_list = []
for i in range(m-1):
    diff = x[i+1] - x[i]
    diff_list.append(diff)


#%%
diff_list.sort()


#%%
if n-1>0:
    print(sum(diff_list[:-(n-1)]))
else:
    print(sum(diff_list))    

#%%


#%%
Buggy python submission (verdict: Time Limit Exceeded):
# atcoder https://atcoder.jp/contests/dp/tasks/dp_d
def main():
    N, W = map(int, input().split())
    w, v = [], []
    for _ in range(N):
        wi, vi = map(int, input().split())
        w.append(wi)
        v.append(vi)


    dp = [[0 for j in range(W+1)] for i in range(N+1)]

    for i in range(1, N+1):
        for j in range(1, W+1):
            if j >= w[i-1]:
                dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i-1]]+v[i-1])
            else:
                dp[i][j] = dp[i-1][j]

    print(dp[N][W])

main()

Fixed submission:
# https://atcoder.jp/contests/dp/tasks/dp_d

def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

N, W = MAP()
w, v = [], []
for _ in range(N):
    wi, vi = MAP()
    w.append(wi)
    v.append(vi)

DP = [[0] * (N+1) for _ in range(W+1)]

for i in range(1, W+1):
    for j in range(1, N+1):
        if i < w[j-1]:
            DP[i][j] = max(
                DP[i][j-1],
                DP[i-1][j])
        else:
            DP[i][j] = max(
                DP[i][j-1],
                DP[i-w[j-1]][j-1] + v[j-1],
                DP[i-1][j])

print(DP[-1][-1])

Buggy python submission (verdict: Time Limit Exceeded):
# atcoder https://atcoder.jp/contests/dp/tasks/dp_d

N, W = map(int, input().split())
w, v = [], []
for _ in range(N):
    wi, vi = map(int, input().split())
    w.append(wi)
    v.append(vi)


dp = [[0 for j in range(W+1)] for i in range(N+1)]

for i in range(1, N+1):
    for j in range(1, W+1):
        if j >= w[i-1]:
            dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i-1]]+v[i-1])
        else:
            dp[i][j] = dp[i-1][j]

print(dp[N][W])

Fixed submission:
# https://atcoder.jp/contests/dp/tasks/dp_d

def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

N, W = MAP()
w, v = [], []
for _ in range(N):
    wi, vi = MAP()
    w.append(wi)
    v.append(vi)

DP = [[0] * (N+1) for _ in range(W+1)]

for i in range(1, W+1):
    for j in range(1, N+1):
        if i < w[j-1]:
            DP[i][j] = max(
                DP[i][j-1],
                DP[i-1][j])
        else:
            DP[i][j] = max(
                DP[i][j-1],
                DP[i-w[j-1]][j-1] + v[j-1],
                DP[i-1][j])

print(DP[-1][-1])
Buggy python submission (verdict: Time Limit Exceeded):
word = input()


#%%
# word = "BBBWWW"


#%%
ans = 0
for i in range(len(word)):
    if word[i] == "B":

        ans += len(word[i+1:].replace("B",""))
    
print(ans)
#%%


#%%


Fixed submission:
word = input()


#%%
# word = "BWBWBW"


#%%
word.count("W")
#%%
ans = 0
to_plus = word.count("W")
for i in range(len(word)):
    if word[i] == "B":
        ans += to_plus
    else:
        to_plus -= 1

    
print(ans)
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())

if a <= 8 and b <= 8:
  print("Yay!")
else:
  print(":(")

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

if a <= 8 and b <= 8:
  print("Yay!")
else:
  print(":(")
Buggy python submission (verdict: Time Limit Exceeded):
# https://atcoder.jp/contests/abc065/tasks/abc065_b

def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

N = INT()
a = []
for _ in range(N):
    a.append(INT() - 1)

light_idx = 0

ans = 0
while True:
    light_idx = a[light_idx]
    ans += 1

    if light_idx == 1:
        break

    if light_idx == 0:
        ans = -1
        break

print(ans)


Fixed submission:
# https://atcoder.jp/contests/abc065/tasks/abc065_b

def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

N = INT()
a = []
for _ in range(N):
    a.append(INT() - 1)

light_idx = 0

ans = 0
while True:
    light_idx = a[light_idx]
    ans += 1

    if light_idx == 1:
        break

    if ans > N:
        ans = -1
        break

print(ans)
Buggy python submission (verdict: Runtime Error):
import itertools
N,M,K = map(int,input().split())
A = [0]+list(map(int,input().split()))
B = [0]+list(map(int,input().split()))
SA = list(itertools.accumulate(A))
SB = list(itertools.accumulate(B))
ans = 0
j = len(B)-1
for i in range(len(SA)):
    while(pt>=0):
        if SA[i] + SB[j] <= K:
            ans = max(ans,i+j)
            break
        j-=1
print (ans)





Fixed submission:
import itertools
N,M,K = map(int,input().split())
A = [0]+list(map(int,input().split()))
B = [0]+list(map(int,input().split()))
SA = list(itertools.accumulate(A))
SB = list(itertools.accumulate(B))

ans = 0
pt = len(B)-1
for i,sa in enumerate(SA):
    while(pt>=0):
        if sa + SB[pt] <= K:
            ans = max(ans,i+pt)
            break
        pt-=1
print (ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
dxdy = ((-1,0), (1,0), (0,-1), (0,1)) # タプルやリストで持っておくと便利

H, W, K = map(int,input().split())
x1, y1, x2, y2 = map(int,input().split())
mp = [input() for _ in range(H)]
INF = 10**10
dist = [[INF]*W for _ in range(H)]
dist[x1-1][y1-1] = 0
q = deque()
q.append((x1-1,y1-1)) # スタート地点をenqueue
while(q):
    x, y = q.popleft()
    if x==x2-1 and y==y2-1:
        print (dist[x2-1][y2-1])
        exit()
    else:
        for dx, dy in  dxdy:
            for i in range(1,K+1):
                nx = x + dx*i
                ny = y + dy*i
                if not (0<=nx<H and 0<=ny<W) or mp[nx][ny]=='@':
                    break
                if dist[nx][ny] == INF:
                    q.append((nx,ny))
                dist[nx][ny] = min(dist[nx][ny], dist[x][y] + 1)
print(-1)

Fixed submission:
from collections import deque
dxdy = ((-1,0), (1,0), (0,-1), (0,1)) # タプルやリストで持っておくと便利

H, W, K = map(int,input().split())
x1, y1, x2, y2 = map(int,input().split())
mp = [input() for _ in range(H)]
INF = 10**10
dist = [[INF]*W for _ in range(H)]
dist[x1-1][y1-1] = 0
q = deque()
q.append((x1-1,y1-1)) # スタート地点をenqueue
while(q):
    x, y = q.popleft()
    if x==x2-1 and y==y2-1:
        print (dist[x2-1][y2-1])
        exit()
    else:
        for dx, dy in  dxdy:
            for i in range(1,K+1):
                nx = x + dx*i
                ny = y + dy*i
                if not (0<=nx<H and 0<=ny<W) or mp[nx][ny]=='@':
                    break
                #print(nx,ny,x,y)
                #print (dist[nx][ny] , dist[x][y])
                if dist[nx][ny] <= dist[x][y]:
                    break 
                #print(nx,ny,x,y)
                if dist[nx][ny] == INF:
                    q.append((nx,ny))
                dist[nx][ny] = dist[x][y] + 1
print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
N, K = map(int,input().split())
A = list(map(int,input().split()))
K = min(41,K)
#A = [0] * N

for k in range(K):
    imos = [0] * (N+1)
    for n in range(N):
        a = n - A[n]
        b = n + A[n]
        a = max(0,a)
        b = min(N-1,b)
        imos[a] += 1
        imos[b+1] -= 1
    csum = list(itertools.accumulate(imos))
    A = csum[:-1]
A = [str(a) for a in A]
print (' '.join(A))


Fixed submission:
import itertools
N, K = map(int,input().split())
A = list(map(int,input().split()))
K = min(41,K)
#A = [0] * N

for k in range(K):
    imos = [0] * (N+1)
    for n in range(N):
        a = n - A[n]
        b = n + A[n]
        a = max(0,a)
        b = min(N-1,b)
        imos[a] += 1
        imos[b+1] -= 1
    csum = list(itertools.accumulate(imos))
    A = csum[:-1]
A = [str(a) for a in A]
print (' '.join(A))
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
P = [2**i for i in range(len(A))]

# A = A[::-1]
# P = P[::-1]

# ans = 0
# node = 0
# for i in range(len(A)-1):
#     node = node + A[i]
#     node = min(node,2 * (P[i+1] - A[i+1]))
#     ans += node
#     if node <= 0:
#         print (-1)
#         exit()
#     print (node)
    
# ans += 1
# print (ans)

if A[0] > 0:
    print(-1)
    exit()
if A[-1] >= 2**N:
    print (-1)
    exit()

ans = [0]
node = [0]
def rec(i):
    if i==0:
        ans[0]+=1
        return 1
    node[0] = node[0] + A[i]
    node[0] = min(node[0], 2*rec(i-1))
    ans[0] += node[0]
    #print (node[0],node[0]-A[i])
    if i!=N and node[0] - A[i] <= 0:
        print(-1)
        exit()
    return node[0] - A[i]
rec(N)
print (ans[0])

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
P = [2**i for i in range(len(A))]
import sys
sys.setrecursionlimit(10**9)
# A = A[::-1]
# P = P[::-1]

# ans = 0
# node = 0
# for i in range(len(A)-1):
#     node = node + A[i]
#     node = min(node,2 * (P[i+1] - A[i+1]))
#     ans += node
#     if node <= 0:
#         print (-1)
#         exit()
#     print (node)
    
# ans += 1
# print (ans)

if N==0 and A[0]==1:
    print(1)
    exit()
if A[0] > 0:
    print(-1)
    exit()
# if A[-1] > 2**N:
#     print (-1)
#     exit()

# for a,p in zip(A[::-1],P[::-1]):
#     if a > p:
#         print (-1)
#         exit()

ans = [0]
node = [0]
def rec(i):
    if i==0:
        ans[0]+=1
        return 1
    node[0] = node[0] + A[i]
    node[0] = min(node[0], 2*rec(i-1))
    ans[0] += node[0]
    #print (node[0],node[0]-A[i])

    if (i!=N and node[0] - A[i] <= 0) or (node[0] - A[i] < 0):
        print(-1)
        exit()
    return node[0] - A[i]
rec(N)
print (ans[0])
Buggy python submission (verdict: Runtime Error):
import math
MOD = 1e+9+7
N = int(input())

d_p = dict()
d_m = dict()
ans = 1
zz = 0

for n in range(N):
    a,b = map(int,input().split())

    if a==0 and b==0:
        zz += 1
        continue
    if a==0:
        n_sign = 0
        b = 0
    elif b==0:
        n_sign = 1
        a = 0

    else:    
        n_sign = ((a<0) + (b<0))%2
        a = abs(a)
        b = abs(b)
        gcd = math.gcd(a,b)
        a//=gcd
        b//=gcd

    if n_sign==1:
        s =str(b)+'/'+str(a)
        d_m[s] = d_m.get(s,0) + 1
    elif n_sign==0:
        s =str(a)+'/'+str(b)
        d_p[s] = d_p.get(s,0) + 1      

for k,v in d_m.items():
    if k in d_p:
        ans *= (2**v + 2**d_p[k] - 1)
        d_p.pop(k)
    else:
        ans *= 2**v
    ans %= MOD

for k,v in d_p.items():
    ans *= 2**v
    ans %= MOD
    
ans -= 1
ans += zz
ans %= MOD
print (ans)


Fixed submission:
import math
MOD = 1000000007
N = int(input())
d_p = dict()
d_m = dict()
zz = 0
for n in range(N):
    a,b = map(int,input().split())

    if a==0 and b==0:
        zz += 1
        continue
    if a==0:
        n_sign = 1
        a=0
        b=0
    elif b==0:
        n_sign = 0
        a=0
        b=0  


    else:    
        n_sign = ((a<0) + (b<0))%2
        a = abs(a)
        b = abs(b)
        gcd = math.gcd(a,b)
        a//=gcd
        b//=gcd
        #print(n_sign,a,b)

    

    if n_sign==1:
        s =str(b)+'/'+str(a)
        d_m[s] = d_m.get(s,0) + 1
    elif n_sign==0:
        s =str(a)+'/'+str(b)
        d_p[s] = d_p.get(s,0) + 1      
    
#print (d_m,d_p)

ans = 1
for k,v in d_m.items():
    if k in d_p:
        ans *= (2**v + 2**d_p[k] - 1)
        
        d_p.pop(k)
    else:
        ans *= 2**v
    ans %= MOD

for k,v in d_p.items():
    ans *= 2**v
    ans %= MOD
ans -= 1
ans += zz
ans %= MOD
print (ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import queue

q = queue.Queue()
sys.setrecursionlimit(10**7)
INF = 10**10
MOD = 10**9 + 7
S = []
N, A, B, C = map(int,input().split())
ABC = 'ABC'
q = queue.Queue()
cnt = [A,B,C]
h = ''
q.put((cnt,0,h))
for n in range(N):
    s = input()
    s = s.replace('A','0').replace('B','1').replace('C','2')
    s = list(s)
    S.append(s)


i = 0
#print (S)
while(not q.empty()):
    cnt,d,h = q.get()
    
    #print (cnt,d,h)
    if (d > i):
        i+=1
        if (i==len(S)):
            print ('Yes')
            for k in h:
                print (k)
            exit()
    l,r = S[i]
    l  = int(l)
    r  = int(r)
    if (cnt[l] > 0):
        cnt_ = cnt[:]
        cnt_[l]-=1
        cnt_[r]+=1
        q.put((cnt_,d+1,h+ABC[r]))
        # cnt[l]+=1
        # cnt[r]-=1
    if (cnt[r] > 0):
        cnt_ = cnt[:]
        cnt_[r]-=1
        cnt_[l]+=1
        q.put((cnt_,d+1,h+ABC[l]))
        # cnt[r]+=1
        # cnt[l]-=1
print ('No') 

Fixed submission:
import sys
import queue

q = queue.Queue()
sys.setrecursionlimit(10**7)
INF = 10**10
MOD = 10**9 + 7
S = []
history = []
N, A, B ,C = map(int,input().split())
d = {}
d['A'] = A
d['B'] = B
d['C'] = C

for n in range(N):
    s = input()
    S.append(s)

def select(L,R,x):
    diff = 1
    if L!=x:
        diff *= -1
    d[L] += diff
    d[R] -= diff
    history.append(x)

for n in range(N):
    L, R = S[n]
    if d[L] >= 2:
        select(L,R,R)
    elif d[L] == 0:
        if d[R] == 0:
            print ('No')
            exit()
        else:
            select(L,R,L)
    elif d[L] == 1:
        if d[R] >= 2:
            select(L,R,L)
        elif d[R] == 0:
            select(L,R,R)
        elif d[R] == 1:
            if n!=N-1:
                if L in S[n+1]:
                    select(L,R,L)
                else:
                    select(L,R,R)
            else:
                select(L,R,L) # どちらでもOK
print ('Yes')
for h in history:
    print (h)
Buggy python submission (verdict: Time Limit Exceeded):
from math import gcd
K = int(input())
ans = 0
for i in range(K):
    for j in range(K):
        for k in range(K):
            ans += gcd(gcd(i+1,j+1),k+1)
print (ans)

Fixed submission:
import math
from functools import lru_cache

ls_gcd  = [[None for _ in range(201)] for _ in range(201)]
for i in range(201):
    for j in range(201):
        ls_gcd[i][j] = math.gcd(i,j)

# def gcd(a,b,c):
#     # ab = math.gcd(a,b)
#     # abc = math.gcd(ab,c)
#     ab = ls_gcd[a][b]
#     abc = ls_gcd[ab][c]
#     return abc

K = int(input())
ans = 0
for i in range(K):
    for j in range(K):
        ab = ls_gcd[i+1][j+1]
        t = ls_gcd[ab]
        for k in range(K):
            ans += t[k+1]
print (ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math
K = int(input())
ans = 0
for i in range(K):
    for j in range(K):
        for k in range(K):
            ans += math.gcd(math.gcd(i+1,j+1),k+1)
print (ans)

Fixed submission:
import math
from functools import lru_cache

ls_gcd  = [[None for _ in range(201)] for _ in range(201)]
for i in range(201):
    for j in range(201):
        ls_gcd[i][j] = math.gcd(i,j)

# def gcd(a,b,c):
#     # ab = math.gcd(a,b)
#     # abc = math.gcd(ab,c)
#     ab = ls_gcd[a][b]
#     abc = ls_gcd[ab][c]
#     return abc

K = int(input())
ans = 0
for i in range(K):
    for j in range(K):
        ab = ls_gcd[i+1][j+1]
        t = ls_gcd[ab]
        for k in range(K):
            ans += t[k+1]
print (ans)
Buggy python submission (verdict: Runtime Error):
code = '9876543210000000000'
def judge(n):
    n = str(n)
    for i in range(len(n)-1):
        ni = int(n[i])
        if abs((ni) - int(n[i+1])) > 1:
            if ni==9:

                return int(n[:i]+code[:len(n)-i])
            else:
                idx = 8 - ni
                return int(n[:i]+code[idx:idx+len(n)-i])
    return -1


i = 1
cnt = 0
k = int(input())
while(1):
    j = judge(i)
    if j==-1:
        cnt += 1

        i+=1
    else:
        i = j
    if cnt == k:
        print(i-1)
        exit()

Fixed submission:
x,y,z = map(int,input().split())
print (z,x,y)
Buggy python submission (verdict: Time Limit Exceeded):
d = input()
Q = int(input())
for q in range(Q):
    ls = input().split()
    if ls[0] == '1':
        d = d[::-1]
    else:
        if (ls[1]== '1'):
            
            d = ''.join([ls[2],d])
        else:
            
            d = ''.join([d,ls[2]])
print (d)


Fixed submission:
from collections import deque
d = deque()
s = input()
d.append(s)
rev = 0

Q = int(input())

for q in range(Q):
    ls = input().split()
    #print (ls)
    if ls[0] == '1':
        rev = (rev + 1) % 2
    else:
        if (int(ls[1]) + rev) % 2 == 0:
            d.append(ls[2])
        else:
            d.appendleft(ls[2])

ans = ''.join(list(d))
if rev == 1:
    ans = ans[::-1]
print (ans)

Buggy python submission (verdict: Time Limit Exceeded):


d = input()



Q = int(input())

for q in range(Q):
    ls = input().split()

    if ls[0] == '1':
        
        d = d[::-1]

    else:
        if (ls[1]== '1'):
            d = ls[2] + d
        else:
            d = d + ls[2]



print (d)


Fixed submission:
from collections import deque
d = deque()
s = input()
d.append(s)
rev = 0

Q = int(input())

for q in range(Q):
    ls = input().split()
    #print (ls)
    if ls[0] == '1':
        rev = (rev + 1) % 2
    else:
        if (int(ls[1]) + rev) % 2 == 0:
            d.append(ls[2])
        else:
            d.appendleft(ls[2])

ans = ''.join(list(d))
if rev == 1:
    ans = ans[::-1]
print (ans)