Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
sys.setrecursionlimit(10**7)
n = int(input())
g = [[] for _ in range(n)]

for _ in range(n-1):
    u,v,w = map(int,input().split())
    g[u-1].append((v-1,w))
    g[v-1].append((u-1,w))
    
ans = [0] * n

def dfs(v,p,c):
    ans[v] = c
    for i in g[v]:
        if i[0] != p:
            if i[1] % 2 ==0:
                dfs(i[0],v,c)
            else:
                dfs(i[0],v,1-c)

dfs(0,-1,0)

for i in ans:
    print(i)

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
n = int(input())
g = [[] for _ in range(n)]

for _ in range(n-1):
    u,v,w = map(int,input().split())
    g[u-1].append((v-1,w))
    g[v-1].append((u-1,w))
    
ans = [0] * n

def dfs(v,p,c):
    ans[v] = c
    for i in g[v]:
        if i[0] != p:
            if i[1] % 2 ==0:
                dfs(i[0],v,c)
            else:
                dfs(i[0],v,1-c)

dfs(0,-1,0)

for i in ans:
    print(i)

Buggy python submission (verdict: Runtime Error):
n = int(input())
g = [[] for _ in range(n)]

for _ in range(n-1):
    u,v,w = map(int,input().split())
    g[u-1].append((v-1,w))
    g[v-1].append((u-1,w))
    
ans = [0] * n

def dfs(v,p,c):
    ans[v] = c
    for i in g[v]:
        if i[0] != p:
            if i[1] % 2 ==0:
                dfs(i[0],v,c)
            else:
                dfs(i[0],v,1-c)

dfs(0,-1,0)

for i in ans:
    print(i)

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
n = int(input())
g = [[] for _ in range(n)]

for _ in range(n-1):
    u,v,w = map(int,input().split())
    g[u-1].append((v-1,w))
    g[v-1].append((u-1,w))
    
ans = [0] * n

def dfs(v,p,c):
    ans[v] = c
    for i in g[v]:
        if i[0] != p:
            if i[1] % 2 ==0:
                dfs(i[0],v,c)
            else:
                dfs(i[0],v,1-c)

dfs(0,-1,0)

for i in ans:
    print(i)
Buggy python submission (verdict: Runtime Error):
import math
N = int(input())
S = []
counterBX = 0
counterXA = 0
counterBXA = 0
counterAB = 0
for i in range(N):
    S.append(input())
    if S[i][0] == 'B' and S[i][-1] != 'A':
        counterBX +=1
    if S[i][0] != 'B' and S[i][-1] == 'A':
        counterXA +=1
    if S[i][0] == 'B' and S[i][-1] == 'A':
        counterBXA +=1
    if len(S[i]) > 1:
        for j in range(len(S[i]) - 1):
            if S[i][j] == 'A' and S[i][j+1] == 'B':
                counterAB +=1
minval = min(counterBX,counterXA)
sa = abs(counterBX - counterXA)

if counterBXA == 0:
    ans = counterAB + min(counterXA,counterBX)
elif counterBXA >=1 and counterXA == 0 and counterBX == 0:
    ans = counterAB + counterBXA - 1
elif counterBXA >=1 and counterXA >=1 and counterBX == 0:
    ans = counterAB + (counterBXA - 1) + 1 + min(counterXA - 1,counterBX)
elif counterBXA >=1 and counterXA == 0 and counterBX >=1:
    ans = counterAB + (counterBXA - 1) + 1 +min(counterXA,counterBX - 1)
else:
    ans = counter(BXA - 1) + 2 + min(counterXA - 1, counterBX - 1)
print(ans)

Fixed submission:
import math
N = int(input())
S = []
counterBX = 0
counterXA = 0
counterBXA = 0
counterAB = 0
for i in range(N):
    S.append(input())
    if S[i][0] == 'B' and S[i][-1] != 'A':
        counterBX +=1
    if S[i][0] != 'B' and S[i][-1] == 'A':
        counterXA +=1
    if S[i][0] == 'B' and S[i][-1] == 'A':
        counterBXA +=1
    if len(S[i]) > 1:
        for j in range(len(S[i]) - 1):
            if S[i][j] == 'A' and S[i][j+1] == 'B':
                counterAB +=1
minval = min(counterBX,counterXA)
sa = abs(counterBX - counterXA)

if counterBXA == 0:
    ans = counterAB + min(counterXA,counterBX)
elif counterBXA >=1 and counterXA == 0 and counterBX == 0:
    ans = counterAB + counterBXA - 1
elif counterBXA >=1 and counterXA >=1 and counterBX == 0:
    ans = counterAB + (counterBXA - 1) + 1 + min(counterXA - 1,counterBX)
elif counterBXA >=1 and counterXA == 0 and counterBX >=1:
    ans = counterAB + (counterBXA - 1) + 1 +min(counterXA,counterBX - 1)
else:
    ans = counterAB + (counterBXA - 1) + 2 + min(counterXA - 1, counterBX - 1)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
from functools import reduce
N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(N):
    tmp_arr = A[:i] + A[i+1:]
    ans_tmp = reduce(gcd,tmp_arr)
    if ans < ans_tmp:
        ans = ans_tmp
print(ans)

Fixed submission:
from fractions import gcd
from functools import reduce
N = int(input())
A = list(map(int, input().split()))
L = [A[0]]
R = [A[-1]]
for i in range(N-1):
    L.append(gcd(L[i],A[i+1]))
    R.append(gcd(R[(i)],A[-(i+2)]))
ans = []    
for i in range(N):
    if i == 0:
        ans.append(R[N - 2])
    elif i <= N - 2:
        ans.append(gcd(L[i - 1],R[N - i - 2]))
    else:
        ans.append(L[N - 2])

print(max(ans))

Buggy python submission (verdict: Runtime Error):
import math
from functools import reduce
N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(N):
    tmp_arr = A[:i] + A[i+1:]
    ans_tmp = reduce(math.gcd,tmp_arr)
    if ans < ans_tmp:
        ans = ans_tmp
print(ans)

Fixed submission:
from fractions import gcd
from functools import reduce
N = int(input())
A = list(map(int, input().split()))
L = [A[0]]
R = [A[-1]]
for i in range(N-1):
    L.append(gcd(L[i],A[i+1]))
    R.append(gcd(R[(i)],A[-(i+2)]))
ans = []    
for i in range(N):
    if i == 0:
        ans.append(R[N - 2])
    elif i <= N - 2:
        ans.append(gcd(L[i - 1],R[N - i - 2]))
    else:
        ans.append(L[N - 2])

print(max(ans))
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()
k = int(input())

moji = s[k]
ans = ''
for i in range(n):
    if s[i] == moji:
        ans = ans + moji
    else:
        ans = ans + '*'
print(ans)

Fixed submission:
n = int(input())
s = input()
k = int(input())

moji = s[k-1]
ans = ''
for i in range(n):
    if s[i] == moji:
        ans = ans + moji
    else:
        ans = ans + '*'
print(ans)
Buggy python submission (verdict: Runtime Error):
from math import ceil
a,b,c,d,e = map(int,input().split())

def f(S,v):
    if S:
        res = []
        for s in S:
            res += f(S - {s}, 10 * ceil(v / 10) + s)
        return res
    else:
        return [v]
ans = min(f({a,b,c,d,e},0))
print(ans)

Fixed submission:
from math import ceil
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

def f(S,v):
    if S:
        res = []
        for i in range(len(S)):
            res += f(S[:i] + S[i+1:], 10 * ceil(v / 10) + S[i])
        return res
    else:
        return [v]
ans = min(f([a,b,c,d,e],0))
print(ans)
Buggy python submission (verdict: Runtime Error):
s = input()

moji = ("A","C","G","T")
count = []
tmp = 0
for i in range(len(s)):
    if s[i] in moji:
        tmp +=1
    else:
        count.append(tmp)
        tmp = 0
print(max(count))

Fixed submission:
S = input()
ans = []
for n in range(len(S)):
    counter = 0
    for i in range(n,len(S)):
        if (S[i] == 'A' or S[i] == 'C' or S[i] == 'G' or S[i] =='T'):
            counter+=1
        else:
            break
    ans.append(counter)
print(max(ans))
Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split())
S = input()
l,r = [],[]
index = []
for i in range(Q):
    tmp1,tmp2 = map(int,input().split())
    l.append(tmp1)
    r.append(tmp2)
for i in range(len(S) - 1):
    if(S[i] == 'A' and S[i+1] == 'C'):
        index.append(i+1)
def f(l,r):
    ans = [i for i in index if l-1 < i <= r-1]
    return len(ans)

for i in range(Q):
    print(f(l[i],r[i]))

Fixed submission:
N,Q = map(int,input().split())
S = input()
l,r = [],[]
index = []
for i in range(Q):
    tmp1,tmp2 = map(int,input().split())
    l.append(tmp1)
    r.append(tmp2)
counter = 0
index.append(counter)
for i in range(1,len(S)):
    if(S[i-1] == 'A' and S[i] == 'C'):
        counter += 1
    index.append(counter)
def f(l,r):
    return index[r-1] - index[l-1]
for i in range(Q):
    print(f(l[i],r[i]))
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = []
B = []
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
C = zip(A,B)
C = sorted(C)
A, B = zip(*C)
index = 0
count = 0

for i in range(N):
      if(count<=M):
        index = i
        sum += A[i]*B[i]
        count += B[i]
sum +=A[index]*(M-count)
print(sum)

Fixed submission:
var = list(map(int, input().split()))
N = var[0]
M = var[1]
 
A = [0] * N
B = [0] * N
for i in range(N):
    A[i], B[i] = map(int, input().split())
C = zip(A,B)
C = sorted(C)
A, B = zip(*C)
 
index = 0
count = 0
for i in range(N):
      if(count<=M):
        index = i
      count += B[i]
count = 0
sum = 0
for i in range (index):
    sum+=A[i]*B[i]
    count+=B[i]
sum +=A[index]*(M-count)
print(sum)
Buggy python submission (verdict: Time Limit Exceeded):
A, B = map(int, input().split())
a = A
for i in range(B,A,-1):
    a = a^i
print(a)

Fixed submission:
A, B = map(int, input().split())
sa = B-A
if (A%2==0 and B%2 ==1):
    if(sa%4==1):
        ans = 1
    else:
        ans = 0
elif(A%2==0 and B%2==0):
    if(sa%4==2):
        ans = B+1
    else:
        ans = B
elif(A%2==1 and B%2 ==1):
    if(sa%4==2):
        ans = A-1
    else:
        ans = A
elif(A%2==1 and B%2 ==0):
    if(sa%4==1):
        ans = A^0^B
    else:
        ans = A^1^B
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import queue
a,b,c = map(int,input().split())
q = queue.LifoQueue()
for i in range(1,100):
  if(a%i == 0 and b%i == 0):
    q.put(i)
if c != 1:
  for i in range(c-1):
    q.get()
print(q.get())

Fixed submission:
a,b,c = map(int,input().split())
if (a*c <= b):
  print(c)
else:
  print(int(b/a))
Buggy python submission (verdict: Runtime Error):
from collections import deque
S = input()
S = list(S)
counter = 0
que = deque([])
stack = deque([])
for i in range(len(S)):
    que.append(S[i])
for i in range(1000000):
  if stack:
    1
  else:
    stack.append(que.popleft())
  if que:
    s1 = que.popleft()
  else:
    break
  s2 = stack.pop()
  if(s1 != s2):
    counter+=2
  else:
    stack.append(s1)
    stack.append(s2)
print(counter)

Fixed submission:
S =input()
S = list(S)
c_one = S.count('1')
c_zero = S.count('0')
print(min(c_one,c_zero)*2)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
S =input()
counter = 0
S = list(S)
q = deque([])
for i in range(len(S)):
    q.append(S[i])
for i in range(10000000):
    if q:
        s1 = q.pop()
    else:
        break
    if q:
        s2 = q.pop()
    else:
        break
    if(s1 != s2):
        counter+=2
    else:
        q.appendleft(s1)
        q.append(s2)
print(counter)

Fixed submission:
S =input()
S = list(S)
c_one = S.count('1')
c_zero = S.count('0')
print(min(c_one,c_zero)*2)

Buggy python submission (verdict: Runtime Error):
from collections import deque
S =input()
counter = 0
S = list(S)
q = deque([])
for i in range(len(S)):
    q.append(S[i])
for i in range(len(S)):
    if q:
        s1 = q.popleft()
        s2 = q.popleft()
        if(s1 != s2):
            counter+=2
        else:
            q.append(s1)
            q.appendleft(s2)
    else:
        break
print(counter)

Fixed submission:
S =input()
S = list(S)
c_one = S.count('1')
c_zero = S.count('0')
print(min(c_one,c_zero)*2)
Buggy python submission (verdict: Time Limit Exceeded):
from queue import PriorityQueue
N = int(input())
A = map(int, input().split())
q = PriorityQueue()
for a in A:
  q.put(a)
x = q.get()
while not q.empty():
  y=q.get()
  if y == 0:
    continue
  q.put(x % y)
  x = y
print(x)

Fixed submission:
from queue import PriorityQueue
N = int(input())
A = map(int, input().split())
q = PriorityQueue()
for a in A:
    q.put(-a)
x = -q.get()
while not q.empty():
    y = -q.get()
    if y == 0:
        break
    q.put(-(x % y))
    x = y
print(x)

Buggy python submission (verdict: Runtime Error):
from queue import PriorityQueue
N = int(input())
A = map(int, input().split())
q = PriorityQueue
for a in A:
  q.put(a)
x = q.get()
while not q.empty():
  y=q.get()
  if y == 0:
    break
  q.put(x % y)
  x = y
print(x)

Fixed submission:
from queue import PriorityQueue
N = int(input())
A = map(int, input().split())
q = PriorityQueue()
for a in A:
    q.put(-a)
x = -q.get()
while not q.empty():
    y = -q.get()
    if y == 0:
        break
    q.put(-(x % y))
    x = y
print(x)
Buggy python submission (verdict: Runtime Error):
s = input()
fl = 0
for i in range(len(s)):
    for j in range(len(s)):
        if i <= j:
            tmp = s[:i] + s[j:]
            if tmp == "keyence":
                flg = 1
if flg == 1:
    print("YES")
else:
    print("NO")

Fixed submission:
s = input()
flg = 0
for i in range(len(s)):
    for j in range(len(s)):
        if i <= j:
            tmp = s[:i] + s[j:]
            if tmp == "keyence":
                flg = 1
if flg == 1:
    print("YES")
else:
    print("NO")

Buggy python submission (verdict: Runtime Error):
s = input()
key = "keyence"
j = 0
counter = 0
judge = []
word = key[j]
for i in range(len(s)):
    if s[i] == key[j] and j != 7:
        j +=1
    else:
        judge.append(i)

for i in range(len(judge) - 1):
    if judge[i+1] - judge[i] > 1:
        counter +=1

if j == 7 and counter == 0:            
    print("YES")
else:
    print("NO")

Fixed submission:
s = input()
flg = 0
for i in range(len(s)):
    for j in range(len(s)):
        if i <= j:
            tmp = s[:i] + s[j:]
            if tmp == "keyence":
                flg = 1
if flg == 1:
    print("YES")
else:
    print("NO")
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
h = list(map(int,input().split()))

dp = [float("inf")]*(n)

dp[0] = 0

def chmin(a,b,index):
    if a > b:
        dp[index] = b

for i in range(n-1):
    for j in range(1,k+1):
        chmin(dp[i+j],dp[i] + abs(h[i] - h[i+j]),i+j)
        if i+j >= n-1:
            break
print(dp[n-1])

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

dp = [float("inf")]*(n)

dp[0] = 0

def chmin(a,b,index):
    if a > b:
        dp[index] = b

for i in range(n-1):
    for j in range(1,k+1):
        chmin(dp[i+j],dp[i] + abs(h[i] - h[i+j]),i+j)
        if i+j >= n-1:
            break
print(dp[n-1])
Buggy python submission (verdict: Runtime Error):
N,W = map(int,input().split())
w = []
v = []
for i in range(n):
    a,b = map(int,input().split())
    w.append(a)
    v.append(b)
dp = [0] * (W+1)

for i in range(N):
    tmp_w = w[i]
    tmp_v = v[i]
    for j in range(W):
        if dp[j] != 0:
            if j + tmp_w <= W:
                if dp[j + tmp_w] < tmp_v:
                    dp[j + tmp_w] = dp[j] + tmp_v
    if dp[tmp_w] < tmp_v:
        dp[tmp_w] = tmp_v
print(max(dp))

Fixed submission:
N,W = map(int,input().split())
w, v = zip(*(map(int, input().split()) for _ in range(N)))

dp = [0] * (W+1)

for i in range(N):
    for j in range(W,0,-1):
        if j - w[i] >= 0 and dp[j] < dp[j - w[i]] + v[i]:
            dp[j] = dp[j - w[i]] + v[i] #jは重さ、w[i]も重さ、dp[j]は重さjの時の価値、v[i]は重さw[i]の時の価値
    if dp[w[i]] == 0 or dp[w[i]] < v[i]:
        dp[w[i]] = v[i]
print(max(dp))

Buggy python submission (verdict: Runtime Error):
N,W = map(int,input().split())
w = []
v = []
for i in range(n):
    a,b = map(int,input().split())
    w.append(a)
    v.append(b)
dp = [0] * (W+1)

for i in range(N):
    tmp_w = w[i]
    tmp_v = v[i]
    for j in range(W):
        if dp[j] != 0:
            if j + tmp_w <= W:
                if dp[j + tmp_w] < tmp_v:
                    dp[j + tmp_w] = dp[j] + tmp_v
    if dp[tmp_w] < tmp_v:
        dp[tmp_w] = tmp_v
print(max(dp))

Fixed submission:
N,W = map(int,input().split())
w, v = zip(*(map(int, input().split()) for _ in range(N)))

dp = [0] * (W+1)

for i in range(N):
    for j in range(W,0,-1):
        if j - w[i] >= 0 and dp[j] < dp[j - w[i]] + v[i]:
            dp[j] = dp[j - w[i]] + v[i] #jは重さ、w[i]も重さ、dp[j]は重さjの時の価値、v[i]は重さw[i]の時の価値
    if dp[w[i]] == 0 or dp[w[i]] < v[i]:
        dp[w[i]] = v[i]
print(max(dp))
Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().split())
h = []
for _ in range(N):
    h.append(int(input()))
h = sorted(h)
tmp = 0
loop = N-K+1
for i in range(loop):
    tmp = h[K+i-1] - h[0+i]
    if(tmp < ans):
        ans = tmp
print(ans)

Fixed submission:
N,K = map(int,input().split())
h = []
for _ in range(N):
    h.append(int(input()))
h = sorted(h)
tmp = 0
ans = 10000000000
loop = N-K+1
for i in range(loop):
    tmp = h[K+i-1] - h[0+i]
    if(tmp < ans):
        ans = tmp
print(ans)

Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().split())
h = []
for _ in range(N):
    h.append(int(input()))
h = sorted(h)
tmp = 0
loop = N-K+1
for i in range(loop):
    tmp = h[K+i-1] - h[0+i]
    if(tmp < ans):
        ans = tmp
print(ans)

Fixed submission:
N,K = map(int,input().split())
h = []
for _ in range(N):
    h.append(int(input()))
h = sorted(h)
tmp = 0
ans = 10000000000
loop = N-K+1
for i in range(loop):
    tmp = h[K+i-1] - h[0+i]
    if(tmp < ans):
        ans = tmp
print(ans)

Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().split())
h = []
for _ in range(N):
    h.append(int(input()))
h = sorted(h)
tmp = 0
ans = 1000000000
loop = min(K+1,N-K+1)
for i in range(loop+1):
    tmp = h[K+i-1] - h[0+i]
    if(tmp < ans):
        ans = tmp
print(ans)

Fixed submission:
N,K = map(int,input().split())
h = []
for _ in range(N):
    h.append(int(input()))
h = sorted(h)
tmp = 0
ans = 10000000000
loop = N-K+1
for i in range(loop):
    tmp = h[K+i-1] - h[0+i]
    if(tmp < ans):
        ans = tmp
print(ans)

Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().split())
h = []
for _ in range(N):
    h.append(int(input()))
h = sorted(h)
tmp = 0
ans = 1000000000
if (N == K):
    ans = sum(h)
else:
    for i in range(K):
        tmp = h[K+i-1] - h[0+i]
        if(tmp < ans):
            ans = tmp
print(ans)

Fixed submission:
N,K = map(int,input().split())
h = []
for _ in range(N):
    h.append(int(input()))
h = sorted(h)
tmp = 0
ans = 10000000000
loop = N-K+1
for i in range(loop):
    tmp = h[K+i-1] - h[0+i]
    if(tmp < ans):
        ans = tmp
print(ans)

Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().split())
h = []
for _ in range(N):
    h.append(int(input()))
h = sorted(h)
tmp = 0
ans = 1000000000
for i in range(K):
    tmp = h[K+i-1] - h[0+i]
    if(tmp < ans):
        ans = tmp
print(ans)

Fixed submission:
N,K = map(int,input().split())
h = []
for _ in range(N):
    h.append(int(input()))
h = sorted(h)
tmp = 0
ans = 10000000000
loop = N-K+1
for i in range(loop):
    tmp = h[K+i-1] - h[0+i]
    if(tmp < ans):
        ans = tmp
print(ans)
Buggy python submission (verdict: Runtime Error):
N,X = map(int,input().split())
finished_dic ={} 
def f(N):
    if(N == 0):
        return 'P'
    else:
        if(N in finished_dic):
            return finished_dic[N]
        else:
            finished_dic[N] = ('B' + f(N-1) + 'P' + f(N-1) + 'B')
            return finished_dic[N]
burger = f(N)
print(burger[0:X].count('P'))

Fixed submission:
N,X = map(int,input().split())
bg_cnt = [1]
pan_cnt = [1]
for i in range(N):
    bg_cnt.append(bg_cnt[i] * 2 + 3)
    pan_cnt.append(pan_cnt[i] * 2 + 1)

def f(N,X):
    if N == 0:
        return 1
    elif X == 1:
        return 0
    elif X <= 1 + bg_cnt[N-1]:
        return f(N-1,X-1)
    elif X == 2 + bg_cnt[N-1]:
        return 1 + f(N-1,X-1)
    else:
        return pan_cnt[N-1] + 1 + f(N-1,X-2-bg_cnt[N-1])    
print(f(N,X))

Buggy python submission (verdict: Time Limit Exceeded):
N,X = map(int,input().split())
def f(N):
    if(N == 0):
        return 'P'
    else:
        return 'B' + f(N-1) + 'P' + f(N-1) + 'B'
burger = f(N)
burger = burger[0:X]
print(burger.count('P'))

Fixed submission:
N,X = map(int,input().split())
bg_cnt = [1]
pan_cnt = [1]
for i in range(N):
    bg_cnt.append(bg_cnt[i] * 2 + 3)
    pan_cnt.append(pan_cnt[i] * 2 + 1)

def f(N,X):
    if N == 0:
        return 1
    elif X == 1:
        return 0
    elif X <= 1 + bg_cnt[N-1]:
        return f(N-1,X-1)
    elif X == 2 + bg_cnt[N-1]:
        return 1 + f(N-1,X-1)
    else:
        return pan_cnt[N-1] + 1 + f(N-1,X-2-bg_cnt[N-1])    
print(f(N,X))
Buggy python submission (verdict: Runtime Error):
from itertools import product
N = input()
length = len(N)
T = [''.join(t) for t in product(('3','5','7'),repeat = 3)]

def f(N,s):
    if len(s) == length:
        if int(s) < int(N) and '3' in s and '5' in s and '7' in s:
            return 1
        else:
            return 0
    else:
        if '3' in s and '5' in s and '7' in s:
            a = 1
        else:
            a = 0
        a += sum(f(N,s+c) for c in('3','5','7'))
        return a
print(sum(f(N, t) for t in T))

Fixed submission:
from itertools import product
N = input()
length = len(N)
T = [''.join(t) for t in product(('3','5','7'),repeat = 3)]

def f(N,s):
    if len(s) == length:
        if int(s) <= int(N) and '3' in s and '5' in s and '7' in s:
            return 1
        else:
            return 0
    else:
        if '3' in s and '5' in s and '7' in s:
            a = 1
        else:
            a = 0
        a += sum(f(N,s+c) for c in('3','5','7'))
        return a
if int(N)<357:
    print(0)
else:
    print(sum(f(N, t) for t in T))
Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
p,y = [],[]
for i in range(m):
    v1,v2 = map(int,input().split())
    p.append(v1)
    y.append(v2)
    
py = zip(p,y,range(m))
py = sorted(py)
p,y,index = zip(*py)
 
ans = []
start = p[0]
count = 1
for i in range(m):
    if start == p[i]:
        ans.append(str(p[i]).zfill(6) + str(count).zfill(6))
        count += 1
    else:
        count = 1
        start = p[i]
        ans.append(str(p[i]).zfill(6) + str(count).zfill(6))
        count += 1
 
ans = zip(index,ans)
ans = sorted(ans1)
index,ans = zip(*ans)
for i in ans:
    print(i)

Fixed submission:
n,m = map(int,input().split())
p,y = [],[]
for i in range(m):
    v1,v2 = map(int,input().split())
    p.append(v1)
    y.append(v2)
    
py = zip(p,y,range(m))
py = sorted(py)
p,y,index = zip(*py)

ans = []
start = p[0]
count = 1
for i in range(m):
    if start == p[i]:
        ans.append(str(p[i]).zfill(6) + str(count).zfill(6))
        count += 1
    else:
        count = 1
        start = p[i]
        ans.append(str(p[i]).zfill(6) + str(count).zfill(6))
        count += 1

ans1 = zip(index,ans)
ans1 = sorted(ans1)
index,ans = zip(*ans1)
for i in ans:
    print(i)
Buggy python submission (verdict: Runtime Error):
s = input()
w = int(input())
ans = ''
for i in range(len(s)):
    ans+=s[i*w]
    if (i+1) * w > len(s):
        break
print(ans)

Fixed submission:
s = input()
w = int(input())
ans = ''
for i in range(len(s)):
    ans+=s[i*w]
    if (i+1) * w > len(s) - 1:
        break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
x,y = map(int,input().split())

for i in range(1, 10**9):
    if x * i % y != 0:
        print(x*i)
        break
    if x*i >= 10**18:
        print(-1)
        break

Fixed submission:
x,y = map(int,input().split())

for i in range(1, 10**9):
    if x * i % y != 0:
        print(x*i)
        break
    if x*i <= 10**18:
        print(-1)
        break
Buggy python submission (verdict: Runtime Error):
n = int(input())
t = []
x = []
y = []
ans = "Yes"
tmpx = 0
tmpy = 0
for i in range(n):
    v1,v2,v3 = map(int,input().split())
    t.append(v1)
    x.append(v2)
    y.append(v3)
for i in range(n):
    if abs(tmpx-x[i]) + abs(tmpy-y[i]) <= t[i]:
        tmpx = x[i]
        tmpy = y[i]
        continue
    else:
        flg = "No"
        break
print(flg)

Fixed submission:
n = int(input())
t = []
x = []
y = []
ans = "Yes"
tmpx = 0
tmpy = 0
tmpt = 0
for i in range(n):
    v1,v2,v3 = map(int,input().split())
    t.append(v1)
    x.append(v2)
    y.append(v3)
for i in range(n):
    if abs(tmpx-x[i]) + abs(tmpy-y[i]) <= t[i] - tmpt and (abs(tmpx-x[i]) + abs(tmpy-y[i])) % 2 == (t[i] - tmpt) % 2:
        tmpx = x[i]
        tmpy = y[i]
        tmpt = t[i]
        continue
    else:
        ans = "No"
        break
print(ans)