Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from sys import stdin
def sqmatrix(n):
  return [[0] * n for i in range(n)]

def magicsq(m):
    n = len(m)
    j = n/2
    i = j + 1
    for num in range(1, n**2 + 1):
        m[i][j] = num
        i += 1
        j += 1
        i = i%n
        j = j % n
        if m[i][j] != 0:
            i += 1
            j -= 1
        if j < 0:
            j = n -1
        i = i % n
    return m

for line in stdin:
    n = int(line)
    if n == 0:
        break
    sm = sqmatrix(n)
    for row in magicsq(sm): print (' '.join(map(str,row)))

Fixed submission:
from sys import stdin
def sqmatrix(n):
  return [[0] * n for i in range(n)]

def magicsq(m):
    n = len(m)
    j = int(n/2)
    i = j + 1
    for num in range(1, n**2 + 1):
        m[i][j] = num
        i += 1
        j += 1
        i = i%n
        j = j % n
        if m[i][j] != 0:
            i += 1
            j -= 1
        if j < 0:
            j = n -1
        i = i % n
    return m

for line in stdin:
    n = int(line)
    if n == 0:
        break
    sm = sqmatrix(n)
    for row in magicsq(sm): print (''.join(map(lambda x: str(x).rjust(4, ' '),row)))
Buggy python submission (verdict: Runtime Error):
f = set(range(0,3000,4))
h = set(range(0,3000,100))
fh = set(range(0,3000,400))
lp = (f -h).union(fh)

while True:
  f,l = list(map(int, input().split()))
  if f == 0 and l == 0:
    break
  t = set(range(f,l+1))
  it = sorted(list(lp.intersection(t)))
  for y in t:
    print(y)
  if lent(it) == 0:
    print('NA')
  print (' ')

Fixed submission:
f = set(range(0,3000,4))
h = set(range(0,3000,100))
fh = set(range(0,3000,400))
lp = (f -h).union(fh)
 
a = False
while True:
  f,l = list(map(int, input().split()))
  if f == 0 and l == 0:
    break
  if a:
    print ('')
  t = set(range(f,l+1))
  it = sorted(list(lp.intersection(t)))
  for y in it:
    print(y)
  if len(it) == 0:
    print('NA')
  a = True
Buggy python submission (verdict: Runtime Error):
a,b = map(float,raw_input().split(' '))
print((a * b) / 3.305785)

Fixed submission:
a,b = map(float,input().split(' '))
print((a * b) / 3.305785)
Buggy python submission (verdict: Runtime Error):
from operator import itemgetter
n = int(input())
rs = [list(map(int(),input().split())) for i in range(n)]
rs = sorted(rs,key=itemgetter(0))
print(' '.join(map(str, sorted(rs, key=itemgetter(1),reverse=True)[0])))

Fixed submission:
from operator import itemgetter
n = int(input())
rs = [list(map(int,input().split())) for i in range(n)]
rs = sorted(rs,key=itemgetter(0))
print(' '.join(map(str, sorted(rs, key=itemgetter(1),reverse=True)[0])))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
from collections import defaultdict
G = defaultdict(list)
for i in range(n):
    i = [int(i) for i in input().split()]
    k = i[1]
    G[i[0]] = list(zip(i[2::2],i[3::2]))

def mind(Q, d):
    c = float('inf')
    ret = 0
    for i, j in enumerate(d):
        if c > j and i in Q:
            c = j
            ret = i
    return ret

def dijkstra(G):
    d = [0] + [float('inf')] * (n - 1)
    Q = set(range(n))
    while len(Q) != 0:
        u = mind(Q, d)
        Q = Q - set([u])
        for v, c in G[u]:
            if d[v] > d[u] + c:
                d[v] = d[u] + c
    return d

for i,j in enumerate(dijkstra(G)):
    print(i, j)

Fixed submission:
n = int(input())
import heapq
G = {}
for i in range(n):
    i = [int(i) for i in input().split()]
    k = i[1]
    G[i[0]] = list(zip(i[2::2],i[3::2]))

def dijkstra(G):
    d = [0] + [float('inf')] * (n - 1)
    Q = [(d[i], i) for i in range(n)]
    heapq.heapify(Q)
    while len(Q) != 0:
        _, u = heapq.heappop(Q)
        for v, c in G[u]:
            if d[v] > d[u] + c:
                d[v] = d[u] + c
                heapq.heappush(Q, (d[v], v))
    return d

for i,j in enumerate(dijkstra(G)):
    print(i, j)
Buggy python submission (verdict: Runtime Error):
x, y = map(int,input().split())
while True 
  if x >= y:
    x %= y
  else
    y %= x
  if x == y:
    print(x)
    break

Fixed submission:
x, y = map(int,input().split())
while True:
  if x >= y:
    x %= y
  else:
    y %= x
  if x == 0 or y == 0:
    print(x+y)
    break
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
n = int(input())
r=[int(input()) for i in range(n)]
rv = r[::-1][:-1]
m = None
for j,r_j in enumerate(rv):
    for r_i in r[:-(j+1)]:
        t = r_j - r_i
        if m == None or t > m:
            m = t
print(m)

Fixed submission:
n = int(input())
minv = int(input())
maxv = -2*10**9
for i in range(n-1):
    r = int(input())
    maxv = max(maxv,r-minv)
    minv = min(minv,r)
print(maxv)

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
n = int(input())
r=[int(input()) for i in range(n)]
rv = r[::-1][:-1]
m = None
for j,r_j in enumerate(rv):
    r_i = min(r[:-(j+1)])
    t = r_j - r_i
    if m == None or t > m:
        m = t
print(m)

Fixed submission:
n = int(input())
minv = int(input())
maxv = -2*10**9
for i in range(n-1):
    r = int(input())
    maxv = max(maxv,r-minv)
    minv = min(minv,r)
print(maxv)
Buggy python submission (verdict: Runtime Error):
stack = [i for i in input().split()]

op = ['+', '*', '-']
while True:
    a = stack.pop()
    if a in op:
        l = stack.pop()
        r = stack.pop()
        stack.append(eval(l + a + r))
    if len(stack) == 1:
        break
print (stack[0])

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


op = ['+', '*', '-']
stack = []

for j in i:
    if j in op:
        r = stack.pop()
        l = stack.pop()
        stack.append(str(eval(l + j + r)))
    else:
        stack.append(j)
print (stack[0])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = map(int, input().split())

def binarySearch(array, target):
    l = len(array)
    first_half = array[:l//2]
    second_half = array[l//2:]
    if first_half == []:
        if target in second_half:
            return True
        return False
    if first_half[-1] == target:
        return True
    elif first_half[-1] < target:
        return binarySearch(second_half, target)
    else:
        return binarySearch(first_half, target)

a = 0
for t in T: a += binarySearch(S, t)
print(a)

Fixed submission:
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = map(int, input().split())


def binarySearch(A, key):
    left = 0
    right = len(A)
    while left < right:
        mid = (left + right) // 2
        if A[mid] == key:
            return True
        elif key < A[mid]:
            right = mid
        else:
            left = mid + 1
    return False


a = 0
for t in T: a += binarySearch(S, t)
print(a)
Buggy python submission (verdict: Runtime Error):
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = map(int, input().split())

def binarySearch(array, target):
    l = len(array)
    first_half = array[:l//2]
    second_half = array[l//2:]
    if first_half == []:
        return False
    if first_half[-1] == target:
        return True
    elif first_half[-1] < target:
        return binarySearch(second_half, target)
    else:
        return binarySearch(first_half, target)

a = 0
for t in T: a += binarySearch(S, t)
print(a)

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

def f(P):
    i = 0
    for j in range(k):
        s = 0
        while s + w[i] <= P:
            s += w[i]
            i += 1
            if i == n: return n
    return i

left = 0
right = 100000 * 10000

while right - left > 1:
    mid = (left + right) // 2
    v = f(mid)
    if v>=n:right=mid
    else: left = mid
print (right)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
w = [int(input()) for i in range(n)]

def f(P):
    mx = k * P
    total = 0
    for i in range(n):
        tmp = total + w[i]
        if tmp > mx:
            return i
        else:
            total = tmp
    return n

def f(P):
    i = 0
    for j in range(k):
        s = 0
        while s + w[i] <= P:
            s += w[i]
            i += 1
            if i == n: return n
    return i

P = 0
l = range(sum(w))

while f(P) < n:
    P += 1
print(P)
    

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

def f(P):
    i = 0
    for j in range(k):
        s = 0
        while s + w[i] <= P:
            s += w[i]
            i += 1
            if i == n: return n
    return i

left = 0
right = 100000 * 10000

while right - left > 1:
    mid = (left + right) // 2
    v = f(mid)
    if v>=n:right=mid
    else: left = mid
print (right)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int, input().split()))
q = int(input())
M = map(int, input().split())

def solve(i, m):
    if m == 0:
        return True
    if i >= n:
        return False
    res = solve(i + 1, m) or solve(i + 1, m - A[i])
    return res
for m in M:
    if solve(0, m):
        print('yes')
    else:
        print('no')

Fixed submission:
n = int(input())
A = list(map(int, input().split()))
q = int(input())
M = map(int, input().split())

memo = {}
def solve(i, m):
    if m == 0:
        return True
    if i >= n:
        return False
    if memo.get((i, m), None) == None:
        memo[(i, m)] = solve(i + 1, m) or solve(i + 1, m - A[i])
    return memo[(i, m)]
for m in M:
    if solve(0, m):
        print('yes')
    else:
        print('no')
Buggy python submission (verdict: Runtime Error):
n = int(input())
class Node(object):
    def __init__(self, p, l, r):
        self.p = p
        self.l = l
        self.r = r

nodes = [Node(None, None, None) for i in range(n)]

for i in range(n):
    id, left, right = map(int, input().split())
    nodes[i].l = left
    nodes[i].r = right
    if left != -1:
        nodes[left].p = i
    if right != -1:
        nodes[right].p = i

def pre(node):
    print(node, end=" ")
    if nodes[node].l != -1:
        pre(nodes[node].l)
    if nodes[node].r != -1:
        pre(nodes[node].r)

def ino(node):
    if nodes[node].l != -1:
        ino(nodes[node].l)
    print(node, end=" ")
    if nodes[node].r != -1:
        ino(nodes[node].r)

def post(node):
    if nodes[node].l != -1:
        post(nodes[node].l)
    if nodes[node].r != -1:
        post(nodes[node].r)
    print(node, end=" ")

for ind, n in enumerate(nodes):
    if n.p != -1:
        root = ind
        break

print('Preorder')
pre(root)
print('\n')
print('InOrder')
ino(root)
print('\n')
print('Postorder')
post(root)

Fixed submission:
n = int(input())
class Node(object):
    def __init__(self, p, l, r):
        self.p = p
        self.l = l
        self.r = r

nodes = [Node(None, None, None) for i in range(n)]

for i in range(n):
    id, left, right = map(int, input().split())
    nodes[id].l = left
    nodes[id].r = right
    if left != -1:
        nodes[left].p = i
    if right != -1:
        nodes[right].p = i

def pre(node,path):
    path.append(node)
    if nodes[node].l != -1:
        pre(nodes[node].l,path)
    if nodes[node].r != -1:
        pre(nodes[node].r,path)

def ino(node,path):
    if nodes[node].l != -1:
        ino(nodes[node].l,path)
    path.append(node)
    if nodes[node].r != -1:
        ino(nodes[node].r,path)

def post(node,path):
    if nodes[node].l != -1:
        post(nodes[node].l,path)
    if nodes[node].r != -1:
        post(nodes[node].r,path)
    path.append(node)

for ind, n in enumerate(nodes):
    if n.p == None:
        root = ind
        break
print('Preorder')
l = []
pre(root, l)
print(' ' +  ' '.join(map(str, l)))
print('Inorder')
l = []
ino(root, l)
print(' ' +  ' '.join(map(str, l)))
print('Postorder')
l = []
post(root,l)
print(' ' + ' '.join(map(str, l)))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(input()) for i in range(n)]
dp = [0 for i in range(n)]
dp[0] = a[0]
length = 1
for i in range(1, n):
    if dp[length-1] < a[i]:
        dp[length] = a[i]
        length += 1        
    else:
        for j in range(length):
            if dp[j] >= a[i]:
                dp[j] = a[i]
                break
print(length)


Fixed submission:
from bisect import bisect_left
n = int(input())
a = [int(input()) for i in range(n)]
dp = [0 for i in range(n)]
dp[0] = a[0]
length = 1
for i in range(1, n):
    if dp[length-1] < a[i]:
        dp[length] = a[i]
        length += 1        
    else:
        dp[bisect_left(dp[:length],a[i])] = a[i]
print(length)
Buggy python submission (verdict: Runtime Error):
class Dice:
    def __init__(self,l1,l2,l3,l4,l5,l6):
        self.l1 = l1
        self.l2 = l2
        self.l3 = l3
        self.l4 = l4
        self.l5 = l5
        self.l6 = l6
        self.top = 1
        self.front = 2
        self.right = 3

    def get_up_front(self):
        return eval("("+"self." + 'l' + str(self.top)+","+"self." + 'l' + str(self.front)+")")

    def get_right(self):
        return eval("self." + 'l' + str(self.right))

    def rot(self):
        self.front,self.right = self.right,7-self.front

    def move(self, order):
        if order == 'S':
            pretop = self.top
            self.top = 7 - self.front
            self.front = pretop
        elif order == 'E':
            pretop = self.top
            self.top = 7 - self.right
            self.right = pretop
        elif order == 'N':
            pretop = self.top
            self.top = self.front
            self.front = 7 - pretop
        elif order == 'W':
            pretop = self.top
            self.top = self.right
            self.right = 7 - pretop

l = list(map(int,input().split()))
q = int(input())
d = Dice(l[0],l[1],l[2],l[3],l[4],l[5])

for i in range(q):
    up,front = list(map(int,input().split()))
    while (up,front) != d.get_up_front():
        for j in range(4):
            d.move('S')
            if up == d.get_up_front()[0]:
                break
        for k in range(4):
            d.rot()
            if front == d.get_up_front()[1]:
                break
    print (d.get_right())

Fixed submission:
class Dice:
    def __init__(self,l1,l2,l3,l4,l5,l6):
        self.l1 = l1
        self.l2 = l2
        self.l3 = l3
        self.l4 = l4
        self.l5 = l5
        self.l6 = l6
        self.top = 1
        self.front = 2
        self.right = 3

    def get_top(self):
        return eval("self." + 'l' + str(self.top))

    def move(self, order):
        if order == 'S':
            pretop = self.top
            self.top = 7 - self.front
            self.front = pretop
        elif order == 'E':
            pretop = self.top
            self.top = 7 - self.right
            self.right = pretop
        elif order == 'N':
            pretop = self.top
            self.top = self.front
            self.front = 7 - pretop
        elif order == 'W':
            pretop = self.top
            self.top = self.right
            self.right = 7 - pretop

l = list(map(int,input().split()))
orders = input()
d = Dice(l[0],l[1],l[2],l[3],l[4],l[5])
for order in orders:
    d.move(order)
print(d.get_top())
Buggy python submission (verdict: Runtime Error):
x = raw_input()
print x**3

Fixed submission:
x = raw_input()
print int(x)**3
Buggy python submission (verdict: Runtime Error):
a,b = raw_input().split(" ")
a = int(a)
b = int(b)
print str(a*b) + " " str(2*a + 2*b) 

Fixed submission:
a,b = raw_input().split(" ")
a = int(a)
b = int(b)
print str(a*b) + " " + str(2*a + 2*b)
Buggy python submission (verdict: Runtime Error):
a,b = map(raw_input().split(" "),int)
if a < b:
  print "a < b"
elsif print a > b:
  print "a > b"
else:
  print "a == b"

Fixed submission:
a,b = map(int,raw_input().split(" "))
if a < b:
  print "a < b"
elif a > b:
  print "a > b"
else:
  print "a == b"

Buggy python submission (verdict: Runtime Error):
a,b = map(int,raw_input().split(" "))
if a < b:
  print "a < b"
elsif print a > b:
  print "a > b"
else:
  print "a == b"

Fixed submission:
a,b = map(int,raw_input().split(" "))
if a < b:
  print "a < b"
elif a > b:
  print "a > b"
else:
  print "a == b"

Buggy python submission (verdict: Runtime Error):
a,b = map(int,raw_input().split(" "))

if a < b:
  print "a < b"
elif print a > b:
  print "a > b"
else:
  print "a == b"

Fixed submission:
a,b = map(int,raw_input().split(" "))
if a < b:
  print "a < b"
elif a > b:
  print "a > b"
else:
  print "a == b"

Buggy python submission (verdict: Runtime Error):
a,b = map(int,raw_input().split(" "))
if a < b:
  print "a < b"
elsif a > b:
  print "a > b"
else:
  print "a == b"

Fixed submission:
a,b = map(int,raw_input().split(" "))
if a < b:
  print "a < b"
elif a > b:
  print "a > b"
else:
  print "a == b"

Buggy python submission (verdict: Runtime Error):
a,b,c = map(int,raw_input().split(" "))
 
if a < b and b < c:
  print "Yes"
else:
  print "No"

Fixed submission:
a,b = map(int,raw_input().split(" "))
if a < b:
  print "a < b"
elif a > b:
  print "a > b"
else:
  print "a == b"
Buggy python submission (verdict: Runtime Error):
a,b,c = map(int,raw_input().split(" "))

if a < b and b < c:
  print "Yes"
else
  print "No"

Fixed submission:
a,b,c = map(int,raw_input().split(" "))
  
if a < b and b < c:
  print "Yes"
else:
  print "No"
Buggy python submission (verdict: Runtime Error):
W,H,x,y,r = map(int,raw_input())
if x + r <= w and y + r <= H:
  print "Yes"
else:
  print "No"

Fixed submission:
W,H,x,y,r = map(int,raw_input().split(" "))
if x + r <= W and y + r <= H and x - r >= 0 and y - r >= 0:
  print "Yes"
else:
  print "No"

Buggy python submission (verdict: Runtime Error):
W,H,x,y,r = map(int,raw_input())
if x + r <= W and y + r <= H:
  print "Yes"
else:
  print "No"

Fixed submission:
W,H,x,y,r = map(int,raw_input().split(" "))
if x + r <= W and y + r <= H and x - r >= 0 and y - r >= 0:
  print "Yes"
else:
  print "No"
Buggy python submission (verdict: Runtime Error):
a,b = map(int,raw_input().split(" "))
f = a / b
d,r = divmod(a,b)
print ("%s %s %s" %(d,r,f))

Fixed submission:
a,b = map(int,raw_input().split())
d = a/b
r = a % b
f = float(a) / b
print "%d %d %f"%(d,r,f)

Buggy python submission (verdict: Runtime Error):
a,b = map(int,raw_input().split(" "))
d = a / b
r = a % b
f = a * 1.0 / b
print "%s %s %s" %(d,r,f)

Fixed submission:
a,b = map(int,raw_input().split())
d = a/b
r = a % b
f = float(a) / b
print "%d %d %f"%(d,r,f)

Buggy python submission (verdict: Runtime Error):
a,b = map(int,raw_input().split(" "))
f = a / b
d,r = divmod(a,b)
print ("%s %s %s" %(d,r,f))

Fixed submission:
a,b = map(int,raw_input().split())
d = a/b
r = a % b
f = float(a) / b
print "%d %d %f"%(d,r,f)

Buggy python submission (verdict: Runtime Error):
a,b = map(int,raw_input().split(" "))
d,r = divmod(a,b)
f = a/b
print ("%s %s %s"%(d,r,f))

Fixed submission:
a,b = map(int,raw_input().split())
d = a/b
r = a % b
f = float(a) / b
print "%d %d %f"%(d,r,f)
Buggy python submission (verdict: Runtime Error):
from math import pi
r = int(raw_input())
print "%s %s"%(pi * pow(r,2), 2 * pi * r)

Fixed submission:
from math import pi
r = float(input())
print ("%s %s"%(pi * pow(r,2), 2 * pi * r))
Buggy python submission (verdict: Runtime Error):
import sys

for line in sys.stdin.readline():
  a,op,b = line.split()
  if op == '?':
    break
  print eval(line)
  

Fixed submission:
import sys
  
for line in sys.stdin:
  a,op,b=line.split()
  if op == '?':
    break
  print eval(line)

Buggy python submission (verdict: Runtime Error):
import sys
 
l = []
for line in sys.stdin.readline():
  l.append(line)

for i in l:
  a,op,b=i.split()
  if op == '?':
    break
  print eval(i)

Fixed submission:
import sys
  
for line in sys.stdin:
  a,op,b=line.split()
  if op == '?':
    break
  print eval(line)
Buggy python submission (verdict: Runtime Error):
import sys

l = [map(int,l.split()) for line in sys.stdin]
n = l[0]
l = l[1]

print "%s %s %s" %(min(l),max(l),sum(l))

Fixed submission:
import sys
 
l = [map(int,line.split()) for line in sys.stdin]
n = l[0]
l = l[1]
 
print "%s %s %s" %(min(l),max(l),sum(l))
Buggy python submission (verdict: Runtime Error):
words = input()
_words = ""
for case in words:
  if case != case.upper():
    case = case.upper()
  elif case != case.lower():
    case = case.lower()
  _words += case
print (_words)

Fixed submission:
words = input()
_words = ""
for case in words:
  if case != case.upper():
    case = case.upper()
  elif case != case.lower():
    case = case.lower()
  _words += case
print (_words)
Buggy python submission (verdict: Runtime Error):
for i in range(1,10):for i in range(1,10):print("%dx%d=%d"%(i,j,i*j))

Fixed submission:
for i in range(1,10):
		for j in range(1,10):
			print("%dx%d=%d"%(i,j,i*j))

Buggy python submission (verdict: Runtime Error):
for i in range(1,10):
		for i in range(1,10):
			print("%dx%d=%d"%(i,j,i*j))

Fixed submission:
for i in range(1,10):
		for j in range(1,10):
			print("%dx%d=%d"%(i,j,i*j))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import namedtuple

Task = namedtuple('Task', 'name time')

class Queue:
    def __init__(self, n):
        self.n = n
        self._l = [None for _ in range(self.n + 1)]
        self._top = 0

    def enqueue(self, x):
        if self.isFull():
            raise IndexError("queue is full")
        else:
            self._top += 1
            self._l[self._top] = x

    def dequeue(self):
        if self.isEmpty():
            raise IndexError("pop from empty queue")
        else:
            e = self._l[1]
            for i in range(1, self._top):
                self._l[i] = self._l[i+1]
            self._l[self._top] = None
            self._top -= 1
            return e

    def isEmpty(self):
        return self._top == 0

    def isFull(self):
        return self._top == self.n

if __name__ == '__main__':
    n, q = map(int, input().split())
    queue = Queue(n)
    for _ in range(n):
        name, time = input().split()
        time = int(time)
        queue.enqueue(Task(name=name, time=time))

    now = 0
    while not queue.isEmpty():
        task = queue.dequeue()
        t = task.time
        if t <= q:
            now += t
            print(task.name, now)
        else:
            now += q
            queue.enqueue(Task(task.name, t - q))



Fixed submission:
from collections import namedtuple

Task = namedtuple('Task', 'name time')

class Queue:
    def __init__(self, n):
        self.n = n
        self._l = [None for _ in range(self.n + 1)]
        self._head = 0
        self._tail = 0

    def enqueue(self, x):
        if self.isFull():
            raise IndexError("queue is full")
        self._l[self._tail] = x
        self._tail += 1
        if self._tail > self.n:
            self._tail = 0

    def dequeue(self):
        if self.isEmpty():
            raise IndexError("pop from empty queue")
        e = self._l[self._head]
        self._l[self._head] = None
        self._head += 1
        if self._head > self.n:
            self._head = 0
        return e

    def isEmpty(self):
        return self._head == self._tail

    def isFull(self):
        return self._head == (self._tail + 1) % (self.n + 1)

if __name__ == '__main__':
    n, q = map(int, input().split())
    queue = Queue(n)
    for _ in range(n):
        name, time = input().split()
        time = int(time)
        queue.enqueue(Task(name=name, time=time))

    now = 0
    while not queue.isEmpty():
        task = queue.dequeue()
        t = task.time
        if t <= q:
            now += t
            print(task.name, now)
        else:
            now += q
            queue.enqueue(Task(task.name, t - q))