Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
S = list(input())
N = len(S)

def f(x):
    print(x)
    exit()

if N < 5:
    f("NO")
elif S[0] == "d":
    w = 1
elif S[0] == "e":
    w = -1
else:
    f("NO")

i = 0
while True:
    if w > 0:
        if S[i]+S[i+1]+S[i+2]+S[i+3]+S[i+4] == "dream":
            i += 5
            if i == N:
                f("YES")
            elif S[i] == "d":
                pass
            elif S[i] == "e":
                if i+1 <= N-1:
                    if S[i+1] == "r":
                        if i+1 == N-1:
                            f("YES")
                        elif S[i+2] == "a":
                            w *= -1
                        elif S[i+2] == "e":
                            i += 2
                            w *= -1
                        elif S[i+2] == "d":
                            i += 2
                        else:
                            f("NO")
                    else:
                        f("NO")
                else:
                    f("NO")
            else:
                f("NO")
        else:
            f("NO")
    elif w < 0:
        if S[i]+S[i+1]+S[i+2]+S[i+3]+S[i+4] == "erase":
            i += 5
            if i == N:
            if S[i] == "r":
                i += 1
                if i == N:
            if S[i] == "d":
                w *= -1
            elif S[i] == "e":
                pass
            else:
                f("NO")
        else:
            f("NO")
    if i+4 > N-1:
        f("NO")


Fixed submission:
S = list(input())
N = len(S)

def f(x):
    print(x)
    exit()

if N < 5:
    f("NO")
elif S[0] == "d":
    w = 1
elif S[0] == "e":
    w = -1
else:
    f("NO")

i = 0
while True:
    if w > 0:
        if S[i]+S[i+1]+S[i+2]+S[i+3]+S[i+4] == "dream":
            i += 5
            if i == N:
                f("YES")
            elif S[i] == "d":
                pass
            elif S[i] == "e":
                if i+1 <= N-1:
                    if S[i+1] == "r":
                        if i+1 == N-1:
                            f("YES")
                        elif S[i+2] == "a":
                            w *= -1
                        elif S[i+2] == "e":
                            i += 2
                            w *= -1
                        elif S[i+2] == "d":
                            i += 2
                        else:
                            f("NO")
                    else:
                        f("NO")
                else:
                    f("NO")
            else:
                f("NO")
        else:
            f("NO")
    elif w < 0:
        if S[i]+S[i+1]+S[i+2]+S[i+3]+S[i+4] == "erase":
            i += 5
            if i == N:
                f("YES")
            if S[i] == "r":
                i += 1
                if i == N:
                    f("YES")
            if S[i] == "d":
                w *= -1
            elif S[i] == "e":
                pass
            else:
                f("NO")
        else:
            f("NO")
    if i+4 > N-1:
        f("NO")
Buggy python submission (verdict: Time Limit Exceeded):
N, T = map(int, input().split())
A = [int(i) for i in input().split()]

c = 0
MAX = 0
for i in range(N-1):
    a1 = min(A[:i+1])
    a2 = A[i+1]
    if MAX == a2 - a1:
        c += 1
    elif MAX < a2 - a1:
        MAX = a2 - a1
        c = 1
print(c)


Fixed submission:
N, T = map(int, input().split())
A = [int(i) for i in input().split()]

c = 0
MAX = 0
a1 = A[0]
for i in range(N-1):
    if A[i] <= a1:
        a1 = A[i]
    a2 = A[i+1]
    if MAX == a2 - a1:
        c += 1
    elif MAX < a2 - a1:
        MAX = a2 - a1
        c = 1
print(c)

Buggy python submission (verdict: Time Limit Exceeded):
N, T = map(int, input().split())
A = [int(i) for i in input().split()]

c = 0
MAX = 0
for i in range(N-1):
    for j in range(N-1-i):
        if MAX == A[i+1+j] - A[i]:
            c += 1
        elif MAX < A[i+1+j] - A[i]:
            MAX = A[i+1+j] - A[i]
            c = 1
print(c)


Fixed submission:
N, T = map(int, input().split())
A = [int(i) for i in input().split()]

c = 0
MAX = 0
a1 = A[0]
for i in range(N-1):
    if A[i] <= a1:
        a1 = A[i]
    a2 = A[i+1]
    if MAX == a2 - a1:
        c += 1
    elif MAX < a2 - a1:
        MAX = a2 - a1
        c = 1
print(c)
Buggy python submission (verdict: Runtime Error):
n, l = map(int, input().split())
s = [int(input()) for i in range(n)]

s.sort()
S = ""
for i in s:
    S += i
print(S)


Fixed submission:
n, l = map(int, input().split())
s = [input() for i in range(n)]

s.sort()
S = ""
for i in s:
    S += i
print(S)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
l = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
for _ in range(K):
    l.remove(int(input()))
n = [int(x) for x in str(N)]
c = len(n)

max = l[0]
min = l[-1]
if N > 1111 * max:
    b = 10000*min([i for i in l if i>0]) + 1111*min
else:
    a = [max] * c
    for j in range(c):
        if a[j] > n[j]:
            a[j] = min([i for i in l if i>=n[j]])
    b = ""
    for j in range(c):
        b += str(a[j])
    b = int(b)

print(b)


Fixed submission:
N, K = map(int, input().split())
D = list(input().split())

for i in range(N, 100000):
    for j in D:
        if j in str(i):
            break
    else:
        print(i)
        break
Buggy python submission (verdict: Runtime Error):
import math
N = int(input())
T, A = map(int, input().split())
Hs = [int(H) for H in input().split()]
min_diff = math.inf
ans = 0
for i, H in enumerate(Hs):
    T_at_H = T - H*0.006
    diff = abs(A - T_at_H)
    if diff < min_diff:
        min_diff = diff
        ans = i + 1
print(ans)

Fixed submission:
N = int(input())
T, A = map(int, input().split())
Hs = [int(H) for H in input().split()]
min_diff = 10e9
ans = 0
for i, H in enumerate(Hs):
    T_at_H = T - H*0.006
    diff = abs(A - T_at_H)
    if diff < min_diff:
        min_diff = diff
        ans = i + 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
str_to_int = {"W":0, "E":1}
input_ = input()
row = [str_to_int[input_[n]] for n in range(N)]

min_change_count = N+1
for n in range(N):
    west_side = row[:n]
    east_side = row[n:]
    count = len(west_side) - sum(west_side)
    count += sum(east_side)
    
    if count < min_change_count:
        min_change_count = count
        
print(min_change_count)

Fixed submission:
N = int(input())
str_to_int = {"W":0, "E":1}
input_ = input()
row = [str_to_int[input_[n]] for n in range(N)]

min_change_count = N+2

west_cum_sum = 0
east_cum_sum = 0
west_cum_sums = []
east_cum_sums = []
for n in range(N):
    if row[n] == 0:
        west_cum_sum += 1
    if row[N-n-1] == 1:
        east_cum_sum += 1
    west_cum_sums.append(west_cum_sum)
    east_cum_sums.append(east_cum_sum)
    
east_cum_sums = east_cum_sums[::-1]
    
min_count = min(east_cum_sums[1], west_cum_sums[N-2])
for n in range(1, N-1):
    count = west_cum_sums[n-1] + east_cum_sums[n+1]
    if count < min_count:
        min_count = count
        
print(min_count)
Buggy python submission (verdict: Runtime Error):
orders = input()
price = 700
if order in orders:
  if order == "x":
    price += 100
print(price)

Fixed submission:
orders = input()
price = 700
for order in orders:
  if order == "o":
    price += 100
print(price)
Buggy python submission (verdict: Time Limit Exceeded):
A, B, C, X, Y = map(int, input().split())

min_cost = 1e10
for a in range(X+1):
    for b in range(Y+1):
        left = max(X-a, Y-b)
        cost = a*A + b*B + left*C*2
        if cost < min_cost:
            min_cost = cost
print(min_cost)

Fixed submission:
A, B, C, X, Y = map(int, input().split())

min_cost = 1e10
for a in range(X+1):
    c = (X-a)*2
    left_b = max(0, Y - (X-a))
    cost = a*A+round(left_b)*B+c*C
    if cost < min_cost:
        min_cost = cost
    # 残り全部をABピザで賄う場合
    left_b = max(X-a, Y)
    cost = a*A + left_b*2*C
    if cost < min_cost:
        min_cost = cost
print(min_cost)
Buggy python submission (verdict: Runtime Error):
import numpy as np
array = np.zeros((3, 3), dtype="int8")
for i in range(3):
    inputs = map(int, input().split())
    for j in range(3):
        array[i, j] = inputs[j]
    
b_1 = array[0, 0]
b_2 = array[0, 1]
b_3 = array[0, 2]
a_2 = array[1, 0] - b_1
a_3 = array[2, 0] - b_1
if (array[1, 1] == (a_2 + b_2)) & (array[2, 2] == (a_3 + b_3)):
    flag = 1
else:
    flag = 0

if flag:
    print("Yes")
else:
    print("No")

Fixed submission:
l = [[] for _ in range(3)]
for i in range(0, 3):
    l[i] = [int(_) for _ in input().split()]
t = [0, 0, 0]
for i in range(0, 3):
    for j in range(0, 3):
        t[i] += l[j][i]
p = (t[0] - t[1]) / 3
q = (t[0] - t[2]) / 3
if l[0][0]-p == l[0][1] and l[0][0]-q == l[0][2] and l[1][0]-p == l[1][1] and l[1][0]-q == l[1][2] and l[2][0]-p == l[2][1] and l[2][0]-q == l[2][2]:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
import numpy as np

N = int(input())
grid = np.zeros((2, N),dtype="int")
for i in range(2):
    grid[i] = np.array([int(x) for x in input().split()])

candy_sums = np.zeros((2, N), dtype="int")
for i in range(2):
    for n in range(N):
        candy_sums[i,n] += grid[i,n]
        if (n-1) >= 0 & (i-1) >= 0:
            candy_sums[i,n] += max(candy_sums[i-1,n], candy_sums[i,n-1])
        elif (i-1) >= 0:
            candy_sums[i,n] += candy_sums[i-1, n]
        elif (n-1) >=0:
            candy_sums[i,n] += candy_sums[i, n-1]
            
print(candy_sums[1,N-1])

Fixed submission:
import numpy as np

N = int(input())
grid = np.zeros((2, N),dtype="int")
for i in range(2):
    grid[i] = np.array([int(x) for x in input().split()])

candy_sums = np.zeros((2, N), dtype="int")
for i in range(2):
    for n in range(N):
        candy_sums[i,n] += grid[i,n]
        if (n-1) >= 0 & (i-1) >= 0:
            candy_sums[i,n] += max(candy_sums[i-1,n], candy_sums[i,n-1])
        elif (i-1) >= 0:
            candy_sums[i,n] += candy_sums[i-1, n]
        elif (n-1) >=0:
            candy_sums[i,n] += candy_sums[i, n-1]
            
print(candy_sums[1,N-1])
Buggy python submission (verdict: Runtime Error):
N, A, B = map(int, input().split())
if (A-B) % 2 == 0:
    print("Alice)
else:
    print("Borys")

Fixed submission:
N, A, B = map(int, input().split())
if (A-B) % 2 == 0:
    print("Alice")
else:
    print("Borys")
Buggy python submission (verdict: Runtime Error):
date = input()
date[3] = "8"
print(date)

Fixed submission:
date = input()
new_date = "2018"+date[4:]
print(new_date)
Buggy python submission (verdict: Runtime Error):
a, b = map(int input())
avg = (a+b) /2
ans = (avg*10) // 10
if (avg*10)%10 == 0:
  print(ans)
else:
  print(ans+1)

Fixed submission:
a, b = map(int, input().split())
avg = (a+b) /2
ans = avg*10 // 10
if (avg*10)%10 == 0:
  print(int(ans))
else:
  print(int(ans+1))

Buggy python submission (verdict: Runtime Error):
a, b = map(int input())
avg = (a+b) /2
ans = avg // 10
if (avg*10)%10 == 0:
  print(ans)
else:
  print(ans+1)

Fixed submission:
a, b = map(int, input().split())
avg = (a+b) /2
ans = avg*10 // 10
if (avg*10)%10 == 0:
  print(int(ans))
else:
  print(int(ans+1))

Buggy python submission (verdict: Runtime Error):
a, b = map(int, input())
avg = (a+b) /2
if (avg*10)%10 == 0:
  print(avg)
else:
  print(avg+1)

Fixed submission:
a, b = map(int, input().split())
avg = (a+b) /2
ans = avg*10 // 10
if (avg*10)%10 == 0:
  print(int(ans))
else:
  print(int(ans+1))

Buggy python submission (verdict: Runtime Error):
a, b = map(int input())
avg = (a+b) /2
if (avg*10)%10 == 0:
  print(avg)
else:
  print(avg+1)

Fixed submission:
a, b = map(int, input().split())
avg = (a+b) /2
ans = avg*10 // 10
if (avg*10)%10 == 0:
  print(int(ans))
else:
  print(int(ans+1))

Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())
avg = (a+b) /2
if (avg*10)%10 == 0:
  print(avg)
else:
  print(avg+1)

Fixed submission:
a, b = map(int, input().split())
avg = (a+b) /2
ans = avg*10 // 10
if (avg*10)%10 == 0:
  print(int(ans))
else:
  print(int(ans+1))
Buggy python submission (verdict: Runtime Error):
s = input()
t = input()
sorted_s = sorted(s)
sorted_t = sorted(t, reverse=True)

len_s = len(sorted_s)
flag = 0
for i in range(len_s):
    s_i = sorted_s[i]
    t_i = sorted_t[i]
    if s_i < t_i:
        flag = 1
        break
if flag:
    print("Yes")
else:
    print("No")

Fixed submission:
s = input()
t = input()

sorted_s = sorted(s)
sorted_t = sorted(t, reverse=True)
len_s = len(sorted_s)
len_t = len(sorted_t)
iter_range = len_s if len_s < len_t else len_t

flag = 0
same_count = 0
for i in range(iter_range):
    s_i = sorted_s[i]
    t_i = sorted_t[i]
    if s_i < t_i:
        flag = 1
        break
    if s_i == t_i:
        same_count+= 1

if (same_count == len_s) & (len_s < len_t):
    print("Yes")
elif (same_count == len_s) & (len_s >= len_t):
    print("No")
elif flag:
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Runtime Error):
sorted_s = sorted(s)
sorted_t = sorted(t, reverse=True)

len_s = len(sorted_s)
flag = 0
for i in range(len_s):
    s_i = sorted_s[i]
    t_i = sorted_t[i]
    if s_i < t_i:
        flag = 1
        break
if flag:
    print("Yes")
else:
    print("No")

Fixed submission:
s = input()
t = input()

sorted_s = sorted(s)
sorted_t = sorted(t, reverse=True)
len_s = len(sorted_s)
len_t = len(sorted_t)
iter_range = len_s if len_s < len_t else len_t

flag = 0
same_count = 0
for i in range(iter_range):
    s_i = sorted_s[i]
    t_i = sorted_t[i]
    if s_i < t_i:
        flag = 1
        break
    if s_i == t_i:
        same_count+= 1

if (same_count == len_s) & (len_s < len_t):
    print("Yes")
elif (same_count == len_s) & (len_s >= len_t):
    print("No")
elif flag:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
X = int(input())
X_ = X
x_sum = 0
while True:
    if (X_ // 10) ==0 :
        break
    else:
        x_sum += X_ % 10
        X_ = X_ // 10
if X % x_sum == 0:
    print("Yes")
else:
    print("No")

Fixed submission:
X = int(input())
X_ = X
x_sum = 0
while True:
    x_sum += X_ % 10
    if (X_ // 10) ==0 :
        break
    else:
        X_ = X_ // 10
if X % x_sum == 0:
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Runtime Error):
X = int(input())
X_ = X
x_sum = 0
while True:
    if (X_ // 10) ==0 :
        break
    else:
        x_sum += X_ % 10
        X_ = X_ // 10
if X % x_sum == 0:
    print("Yes")
else:
    print("No")

Fixed submission:
X = int(input())
X_ = X
x_sum = 0
while True:
    x_sum += X_ % 10
    if (X_ // 10) ==0 :
        break
    else:
        X_ = X_ // 10
if X % x_sum == 0:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
Ls = map(int, input().split())

sorted_Ls = sorted(Ls, reverse=True)
length_sum = 0
for k in K:
    length_sum += sorted_Ls[k]
print(length_sum)

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

sorted_Ls = sorted(Ls, reverse=True)
length_sum = 0
for k in range(K):
    length_sum += sorted_Ls[k]
print(length_sum)
Buggy python submission (verdict: Runtime Error):
# スペース区切りの整数の入力
a, b, c = map(int, input().split())
num = a*100 + b*10 + c
if num % 4 == 0:
  print("YES")
else:
  print("NO)

Fixed submission:
# スペース区切りの整数の入力
a, b, c = map(int, input().split())
num = a*100 + b*10 + c
if num % 4 == 0:
  print("YES")
else:
  print("NO")

Buggy python submission (verdict: Runtime Error):
#a, b, c = map(int, input().split())
a, b, c = map(int, input().split())
num = a*100 + b*10 + c
if num % 4 == 0:
  print("YES)
else:
  print("NO")

Fixed submission:
# スペース区切りの整数の入力
a, b, c = map(int, input().split())
num = a*100 + b*10 + c
if num % 4 == 0:
  print("YES")
else:
  print("NO")

Buggy python submission (verdict: Runtime Error):
a, b, c = map(int, input().split())
num = a*100 + b*10 + c
if num % 4 == 0:
  print("YES)
else:
  @rint("NO")

Fixed submission:
# スペース区切りの整数の入力
a, b, c = map(int, input().split())
num = a*100 + b*10 + c
if num % 4 == 0:
  print("YES")
else:
  print("NO")

Buggy python submission (verdict: Runtime Error):
a, b, c = map(int input().split())
num = a*100 + b*10 + c
if num % 4 == 0:
  print("YES)
else:
  @rint("NO")

Fixed submission:
# スペース区切りの整数の入力
a, b, c = map(int, input().split())
num = a*100 + b*10 + c
if num % 4 == 0:
  print("YES")
else:
  print("NO")
Buggy python submission (verdict: Runtime Error):
_ = input()
As = [int(x) for x in input().split()]
even_pair_count = 0
odd_pair_count = 0
even_pair = []
odd_pair = []
for a in As:
    if a%2 == 0:
        even_pair.append(1)    
        if len(even_pair) == 2:
            even_pair = []
            even_pair_count += 1
    else:
        odd_pair.append(1)
        if len(odd_pair) == 2:
            odd_pair = []
            odd_pair_count += 1


pair_num = even_pair_count + odd_pair_count
rest_num = len(even_pair) + len(odd_pair)
# print(pair_num)
# print(rest_num)
elif rest_num == 2:
    print("NO")
if pair_num == 1:
    print("YES")
elif (pair_num+rest_num) % 2 == 0:
    print("YES")
else:
    print("NO")

Fixed submission:
_ = input()
As = [int(x) for x in input().split()]
if sum(As)%2 == 0:
    print("YES")
else:
    print("NO")
Buggy python submission (verdict: Time Limit Exceeded):
K, S = map(int, input().split())
count=0
for x in range(K+1):
    for y in range(K+1):
        for z in range(K+1):
          if x+y+z == S:
            count += 1
print(count)

Fixed submission:
K, S = map(int, input().split())
count=0
for x in range(K+1):
    for y in range(K+1):
        z = S - (x+y)
        if (z <= K) & (z >= 0):
            count += 1
print(count)

Buggy python submission (verdict: Runtime Error):
K, S = map(int, input().split())
count=0
for x in range(K+1):
    for y in range(K+1):
        for z in range(K+1):
        if x+y+z == S:
            count += 1
print(count)

Fixed submission:
K, S = map(int, input().split())
count=0
for x in range(K+1):
    for y in range(K+1):
        z = S - (x+y)
        if (z <= K) & (z >= 0):
            count += 1
print(count)

Buggy python submission (verdict: Runtime Error):
K, S = map(int, input().split())
count=0
for x in range(K+1):
    for y in range(K+1):
        for z in range(K+1)
        if x+y+z == S:
            count += 1
print(count)

Fixed submission:
K, S = map(int, input().split())
count=0
for x in range(K+1):
    for y in range(K+1):
        z = S - (x+y)
        if (z <= K) & (z >= 0):
            count += 1
print(count)
Buggy python submission (verdict: Runtime Error):
X,Y=map(int,input().split)
print(int(X+Y/2))


Fixed submission:
X,Y=map(int,input().split())
print(int(X+Y/2))

Buggy python submission (verdict: Runtime Error):
X,Y=map(int,input().split);
print(int(X+Y/2));


Fixed submission:
X,Y=map(int,input().split())
print(int(X+Y/2))

Buggy python submission (verdict: Runtime Error):
X,Y=map(int,input().split);
print(int(x+Y/2));

Fixed submission:
X,Y=map(int,input().split())
print(int(X+Y/2))

Buggy python submission (verdict: Runtime Error):
a = input()
b = input()
print(str(a+b/2))

Fixed submission:
a, b = map(int, input().split())
print(int(a+b/2))

Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())
print(str(a+b/2))

Fixed submission:
a, b = map(int, input().split())
print(int(a+b/2))

Buggy python submission (verdict: Runtime Error):
x,y = map(int,input().split())
print int(x + y/2)

Fixed submission:
x,y = map(int,input().split())
print (int(x + y/2))

Buggy python submission (verdict: Runtime Error):
x, y = map(int(), input().split(' '))
print(x + y // 2)


Fixed submission:
x, y = map(int, input().split(' '))
print(x + y // 2)

Buggy python submission (verdict: Runtime Error):
x, y = map(int(), input().split(' '))
print(x + y / 2)

Fixed submission:
x, y = map(int, input().split(' '))
print(x + y // 2)

Buggy python submission (verdict: Runtime Error):
n = int(input())
t, a = input().split(' ')
t = int(t)
a = int(a)
h = input().split(' ')

diff = 10000
point = 10000

for x in range(n):
    temp = t - int(h[x]) * 0.006
    tmp = abs(a - temp)

    if tmp < diff:
        diff = tmp
        point = x + 1

print(point)


Fixed submission:
x, y = input().split(' ')
x = int(x)
y = int(y)
print(int(y / 2 + x))

Buggy python submission (verdict: Runtime Error):
x, y = input().split(' ')
x = int(x)
y = int(y)

return y / 2 + x

Fixed submission:
x, y = input().split(' ')
x = int(x)
y = int(y)
print(int(y / 2 + x))
Buggy python submission (verdict: Runtime Error):
n = int(input())
t, a = input().split(' ')
t = int(t)
a = int(a)
h = input().split(' ')

diff = 100
point = 10000

for x in range(n):
    tmp = t - h[x] * 0.006 
    if tmp < diff:
        diff = tmp
        point = x + 1

print(point)

Fixed submission:
n = int(input())
t, a = input().split(' ')
t = int(t)
a = int(a)
h = input().split(' ')

diff = 10000
point = 10000

for x in range(n):
    temp = t - int(h[x]) * 0.006
    tmp = abs(a - temp)

    if tmp < diff:
        diff = tmp
        point = x + 1

print(point)
Buggy python submission (verdict: Runtime Error):
n = input()
print(''.join(map(lambda c: '9' if c == '1' else '1' if c == '9' else c, n))

Fixed submission:
n = input()
print(''.join(map(lambda c: '9' if c == '1' else '1' if c == '9' else c, n)))
Buggy python submission (verdict: Runtime Error):
N, K = list(map(int, input()))
a = -(-N//K) - (N//K)
print(a)

Fixed submission:
import math
N, K = list(map(int, input().split()))
x = N / K
print(math.ceil(x) - math.floor(x))

Buggy python submission (verdict: Runtime Error):
N, K = list(map(int, input()))
print(-(-N//K) - (N//K))

Fixed submission:
import math
N, K = list(map(int, input().split()))
x = N / K
print(math.ceil(x) - math.floor(x))
Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == '__main__':
    N, M = map(int, input().split())

    p_and_y = list()
    prefMap = {}
    for i in range(M):
        P, Y = map(int, input().split())

        p_and_y.append((P, Y))

        if P in prefMap:
            prefMap[P].append(Y)
        else:
            prefMap[P] = [Y]

    for shiList in prefMap.values():
        shiList.sort()

    for P, Y in p_and_y:
        left = str(P).zfill(6)

        right = prefMap[P].index(Y) + 1
        right = str(right).zfill(6)

        print(left + right)


Fixed submission:
if __name__ == '__main__':
    N, M = map(int, input().split())

    ans = [None] * M
    prefMap = {}
    for i in range(M):
        P, Y = map(int, input().split())

        if P in prefMap:
            prefMap[P].append((Y, i))
        else:
            prefMap[P] = [(Y, i)]

    for P, L in prefMap.items():
        L.sort()

        for j, (y, i) in enumerate(L):
            ans[i] = str(P).zfill(6) + str(j + 1).zfill(6)

    print("\n".join(ans))
Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == '__main__':
    s = input()
    x, y = map(int, input().split())

    s = s.split("T")
    s = [len(_) for _ in s]

    x_move = [ele for (i, ele) in enumerate(s) if i % 2 == 0]
    y_move = [ele for (i, ele) in enumerate(s) if i % 2 == 1]

    dpx = [[False for _ in range(sum(x_move) * 2 + 1)] for _ in range(len(x_move) + 1)]

    dpx[1][x_move[0]] = True
    for i, _x in enumerate(x_move):
        if i == 0:
            continue

        for j in range(-sum(x_move), sum(x_move) + 1):
            dpx[i + 1][j] = dpx[i][j - _x] or dpx[i][j + _x]

    dpy = [[False for _ in range(sum(y_move) * 2 + 1)] for _ in range(len(y_move) + 1)]

    dpy[0][0] = True
    for i, _y in enumerate(y_move):
        for j in range(-sum(y_move), sum(y_move) + 1):
            dpy[i + 1][j] = dpy[i][j - _y] or dpy[i][j + _y]

    try:
        dpx[len(x_move)][x] and dpy[len(y_move)][y]
    except:
        print("No")
        exit()

    if dpx[len(x_move)][x] and dpy[len(y_move)][y]:
        print("Yes")
    else:
        print("No")


Fixed submission:
def c(p, g, lis):
    for e in lis:
        if p <= g:
            p += e
        else:
            p -= e
    return p == g


if __name__ == '__main__':
    s = input()
    gx, gy = map(int, input().split())

    s = s.split("T")
    s = [len(_) for _ in s]

    x_move = s[::2]
    y_move = s[1::2]

    x = x_move.pop(0)
    y = 0

    x_move.sort(reverse=True)
    y_move.sort(reverse=True)

    if c(x, gx, x_move) and c(y, gy, y_move):
        print("Yes")
    else:
        print("No")