Problem:
There are n processes in a queue. Each process has name i and time i .  The round-robin scheduling handles the processes in order. A round-robin scheduler gives each process a quantum (a time slot) and interrupts the process if it is not completed by then. The process is resumed and moved to the end of the queue, then the scheduler handles the next process in the queue. For example, we have the following queue with the quantum of 100ms. A(150) - B(80) - C(200) - D(200) First, process A is handled for 100ms, then the process is moved to the end of the queue with the remaining time (50ms). B(80) - C(200) - D(200) - A(50) Next, process B is handled for 80ms. The process is completed with the time stamp of 180ms and removed from the queue. C(200) - D(200) - A(50) Your task is to write a program which simulates the round-robin scheduling .  Input  n  q  name 1 time 1  name 2 time 2 ...  name n time n  In the first line the number of processes n and the quantum q are given separated by a single space. In the following n lines, names and times for the n processes are given. name i and time i are separated by a single space. Output For each process, prints its name and the time the process finished in order. Constraints  1 ≤ n ≤ 100000  1 ≤ q ≤ 1000  1 ≤ time i ≤ 50000  1 ≤ length of name i ≤ 10  1 ≤ Sum of time i ≤ 1000000  Sample Input 1 5 100
p1 150
p2 80
p3 200
p4 350
p5 20 Sample Output 1 p2 180
p5 400
p1 450
p3 550
p4 800 Notes Template in C

Solution (Python):
from collections import deque
n, q_time = map(int, input().split())
d = deque()
for i in range(n):
    x, y = input().split()
    d.append((x, int(y)))

total = 0
while d:
    name, time = d.popleft()
    if time <= q_time:
        total += time
        print(name, total)
    else:
        total += q_time
        time -= q_time
        d.append((name, time))

Solution (Python):
import sys, os, math, bisect, itertools, collections, heapq, queue

from decimal import Decimal
from collections import defaultdict, deque
import copy

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, Q = il()
    que = queue.Queue()
    process_end = []

    for n in range(N):
        name, time = sl()
        que.put([name, int(time)])

    end_time = 0
    while not que.empty():
        name, time = que.get()
        if time > Q:
            end_time += Q
            que.put([name, time - Q])
        else:
            end_time += time
            process_end.append([name, end_time])

    for p in process_end:
        print(*p)


if __name__ == '__main__':
    main()

Solution (Python):
import queue

A = queue.Queue()
n, q = map(int, input().split())
for i in range(n):
    name, time = input().split()
    A.put([name, int(time)])
t = 0

while  not A.empty():
    L = A.get()
    if L[1] > q:
        L[1] -= q
        A.put(L)
        t += q
    else:
        t += L[1]
        print(L[0], t)

Solution (Python):
from collections import deque
d = deque()
n, quantum = map(int,input().split())
for i in range(n):
    n, t = input().split()
    d.append([n, int(t)])

total_flame = 0
while d:
    processing = d.popleft()
    if processing[1] <= quantum:
        print(processing[0], total_flame + processing[1])
        total_flame += processing[1]
    else:
        d.append([processing[0],processing[1]-quantum])
        total_flame += quantum

Solution (Python):
n, q = map(int, input().split())
elapse = 0
processes = []
result = []

for _ in range(n):
    name, time = input().split()
    time = int(time)
    processes.append([name, time])

while processes:
    process = processes.pop(0)
    if process[1] <= q:
        elapse += process[1]
        result.append([process[0], elapse])
    else:
        elapse += q
        processes.append([process[0], process[1]-q])

for process in result:
    print("{} {}".format(process[0], str(process[1])))

Solution (Python):


from collections import deque

def main():
    tasks={}
    task_number,quantum = map(int,input().split())
    tasks=list(input().split() for _ in range(task_number))
    q = deque()
    calculate_time=0
    for i in range(task_number):
        q.append(tasks[i])
    while len(q) > 0:
        value = q.popleft()
        if quantum < int(value[1]):
            tmp=int(value[1])-quantum
            value[1]=tmp
            q.append(value)
            calculate_time+=quantum
        else:
            calculate_time+=int(value[1])
            print(value[0],calculate_time)

if __name__=="__main__":
    main()

Solution (Python):
import queue

d = input().split(" ")

num = int(d[0])          
threshold = int(d[1])

input_data = []
for i in range(num):
    input_data.append(input())

total_time = 0


q = queue.Queue()
for data in input_data:
    q.put(data)

while not q.empty():
    p = q.get().split(" ")
    p_name = p[0]
    p_time = int(p[1])

    
    if p_time > threshold:   
        q.put(p_name + " " + str(p_time - threshold))
        total_time += threshold
    
    else:
        total_time += p_time
        print(p_name + " " + str(total_time))

Solution (Python):
from collections import deque

n, limit = map(int, input().split())

queue = deque()
for index in range(n):
    name, size = input().split()
    queue.append([name, int(size)])

time = 0
while len(queue) > 0:
    item = queue.popleft()
    if item[1] > limit:
        item[1] -= limit
        queue.append(item)
        time += limit
    else:
        time += item[1]
        print(" ".join([item[0], str(time)]))

Solution (Python):
from collections import deque

n, q = map(int, input().split())
queue = deque()
for _ in range(n):
    name, t = input().split()
    t = int(t)
    queue.append((name, t))

time = 0
while len(queue) != 0:
    name, t = queue.popleft()
    if t > q:
        queue.append((name, t - q))
        time += q
    elif t <= q:
        time += t
        print(name, time)

Solution (Python):
from collections import deque
import sys

input= sys.stdin.readline

n,q = [int(i) for i in input().strip().split()]

jobs = deque()
for i in range(n):
    name,time = input().strip().split()
    jobs.append((name,int(time)))

current_time = 0

while jobs:
    name,time = jobs.popleft()
    if time > q:
        jobs.append((name,time - q))
        current_time += q
    else:
        current_time += time
        print(name, current_time)

Solution (Python):
n, q = map(int, input().split())
process = []
for i in range(n) :
    name, time = input().split()
    process.append([name, int(time)])

time = 0
while True :
    if len(process) == 0 :
        break
    if process[0][1] > q :
        process[0][1] -= q
        time += q
        process.append(process[0])
        process.pop(0)
    else :
        time += process[0][1]
        print(process[0][0], time)
        del process[0]

Solution (Python):
from collections import deque

def main():
    process_num, max_q_time = map(int, input().split())
    r_schedule_lst = deque([])
    for i in range(0, process_num):
        r_schedule_lst.append(list(input().split()))
    
    current_process = []
    elapsed_time = 0
    res = []
    while r_schedule_lst:
        cur_process = list(r_schedule_lst.popleft())
        cur_process_name = cur_process[0]
        cur_process_time = int(cur_process[1])
        
        remaining_time = cur_process_time - max_q_time
        if remaining_time > 0:
            elapsed_time += max_q_time
            r_schedule_lst.append([cur_process_name, remaining_time])
        else:
            elapsed_time += cur_process_time
            res.append([cur_process_name, elapsed_time])
        
    for n, t in res:
        print(n, t)
            
if __name__ == '__main__':
    main()

Solution (Python):
from copy import deepcopy


def round_robin(l, q):
    work = deepcopy(l)
    res = []
    time = 0
    while len(work):
        if work[0][1] > q:
            work[0][1] -= q
            work.append(work.pop(0))
            l.append(l.pop(0))
            time += q
        else:
            time += work[0][1]
            work.pop(0)
            res.append(l.pop(0))
            res[-1][1] = time
    return res


if __name__ == '__main__':
    n, q = list(map(int, input().split()))
    d = [list(map(lambda x: int(x) if x.isnumeric() else x, input().split())) for _ in range(n)]
    res = round_robin(d, q)
    for i in res:
        print(i[0],i[1])

Solution (Python):
import sys

class Queue():
    def __init__(self):
        self.Q = []

    def isEmpty(self):
        return len(self.Q) == 0

    def enqueue(self,x):
        self.Q.append(x)

    def dequeue(self):
        if self.isEmpty():
            sys.exit("Empty")
        else:
            return self.Q.pop(0)

N,q = map(int,input().split(" "))

process_list = []
for n in range(N):
    p,time = input().split(" ")
    process_list.append([p,int(time)])

Q = Queue()
for p in process_list:
    Q.enqueue(p)

elapsed_time = 0
while not Q.isEmpty():
    process = Q.dequeue()
    if process[1] > q:
        elapsed_time += q
        Q.enqueue([process[0],process[1]-q])
    else:
        elapsed_time += process[1]
        print(process[0]+" "+str(elapsed_time))

Solution (Python):
n,q=input().split()
n=int(n)
q=int(q)
p_list=[]
timer=0
head=0
tail=n
for i in range(0,n):
    tmp=input()
    p_list.append([tmp.split()[0],int(tmp.split()[1])])
p_list.append("NULL")

def deque():
    global head
    tmp=p_list[head]
    head=(head+1)%(n+1)
    return tmp

def enque(x):
    global tail
    p_list[tail]=x
    tail=(tail+1)%(n+1)

while(head!=tail):
    elem=deque()
    timer+=min(elem[1],q)
    elem[1]-=min(elem[1],q)
    if elem[1]>0:
        enque(elem)
    else:
        print(str(elem[0])+" "+str(timer))

Solution (Python):
import collections
head = 0
tail = 0


def queue_put(q, a):
    global tail
    q[tail] = a
    tail = (tail + 1) % len(q)


def queue_get(q):
    global head
    result = q[head]
    head = (head + 1) % len(q)
    return result


Q = collections.namedtuple("Q", "nm tm")
n, period = map(int, input().split())

q = ["" for _ in range(n + 1)]
for i in range(n):
    nm, tmp = input().split()
    tm = int(tmp)

    queue_put(q, Q(nm, tm))

tm = 0
while head != tail:
    a = queue_get(q)

    d = min(period, a.tm)
    tm += d
    a = a._replace(tm=a.tm - d)

    if a.tm == 0:
        print(a.nm, tm)
    else:
        queue_put(q, a)

Solution (Python):
from collections import deque


n, q = map(int, input().split())
process = deque()
now = 0

for _ in range(n):
    name, time = input().split()
    process.append([name, int(time)])

while process:
    task = process.popleft()
    now += min(q, task[1])
    if q < task[1]:
        process.append([task[0], task[1] - q])
    else:
        print(task[0], now)

Solution (Python):
from collections import deque
n, q = input().rstrip().split(" ")
n = int(n)
q = int(q)

processes = deque()
now_time = 0

for i in range(n):
    name, time = input().rstrip().split(" ")
    time = int(time)
    processes.append([name, time])

while len(processes) >= 1:
    current_processes = processes.popleft()
    if current_processes[1] > q:
        current_processes[1] -= q
        now_time += q
        processes.append(current_processes)
    else:
        now_time += current_processes[1]
        print(current_processes[0] + " " + str(now_time))

Solution (Python):
from collections import deque

n, q = map(int, input().split())
name_time = [input().split() for _ in range(n)]

d = deque()
d.extend(name_time)

total_time = 0

while d:
    name, time = d.popleft()
    time = int(time)
    if time <= q:
        total_time += time
        print(name, total_time)
    else:
        total_time += q
        d.append([name, str(time-q)])

Solution (Python):
from collections import deque

n, q = map(int, input().split())
d = deque([input().split() for _ in range(n)])
a = []
tt = 0

while d:
    t = int(d[0][1])
    if t > q:
        tt += q
        d.append([d[0][0], str(t-q)])
        d.popleft()
    else:
        tt += t
        p = d.popleft()
        a.append([p[0], tt])

for n, t in a:
    print(n, t)

Solution (Python):
class Queue:
    def __init__(self, n):
        self.n = n + 1
        self.array = [0]*self.n
        self.head = 0
        self.tail = 0

    def enqueue(self, x):
        if not self.isfull():
            self.array[self.tail] = x
            self.tail += 1
            self.tail = self.tail % self.n
        else:
            raise ValueError

    def dequeue(self):
        if not self.isempty():
            val = self.array[self.head]
            self.head += 1
            self.head = self.head % self.n
            return val
        else:
            return False

    def isempty(self):
        return self.head == self.tail

    def isfull(self):
        return (self.tail+1) % self.n == self.head


def main():
    n, q = map(int, input().split())
    queue = Queue(n)
    time = 0

    for _ in range(n):
        query = input().split()
        queue.enqueue(query)

    task = True
    while not queue.isempty():
        task = queue.dequeue()
        if int(task[1]) > q:
            time += q
            tmp_time = int(task[1]) - q
            task = [task[0], tmp_time]
            queue.enqueue(task)
        else:
            time += int(task[1])
            print(task[0], time)


if __name__ == "__main__":
    main()

Solution (Python):
n, q = map(int,input().split())
Q = [0]*(n+1)
head = 0
tail = 0

def enqueue(x):
    global tail
    global Q

    Q[tail] = x
    tail += 1
    if tail == n+1:
        tail = 0

def dequeue():
    global Q
    global head

    X = Q[head]

    head += 1
    if head == n+1:
        head = 0

    return X

def main():
    global n
    global q
    global Q
    global tail
    global head

    time = 0
    cnt = 0

    que = [list(input().split()) for _ in range(n)]
    for i in range(n):
        enqueue(que[i])

    while True:
        temp = dequeue()
        if int(temp[1]) <= q:
            time += int(temp[1])
            print(temp[0] + ' ' + str(time))
            cnt += 1
        else:
            time += q
            temp[1] = str( int(temp[1]) - q )
            enqueue( temp )

        if cnt == n:
            break

main()

Solution (Python):
import sys
from collections import deque

input = sys.stdin.readline


def main():
    n, q = map(int, input().split())
    nt = [None] * n
    for i in range(n):
        line = input().split()
        nt[i] = [line[0], int(line[1])]

    queue = deque(nt)
    time = 0
    ans = []
    while queue:
        p = queue.popleft()
        if p[1] <= q:
            time += p[1]
            ans.append((p[0], time))
        else:
            p[1] -= q
            time += q
            queue.append(p)

    for a in ans:
        print(*a)


if __name__ == "__main__":
    main()

Solution (Python):
from collections import deque

def round_robin_scheduling(p,t):
    q=deque()
    for i in p:
        q.append(i)
    result=[]
    past_time=0
    while q:
        now=q.popleft()
        name,time=now
        rest_time=time-t
        if rest_time>0:
            q.append((name,rest_time))
            past_time+=t
        else:
            past_time+=time
            result.append((name,past_time))
    return result
n,t=map(int,input().split())
process=[]
for i in range(n):
    name,time=input().split()
    time=int(time)
    process.append((name,time))

for name,time in round_robin_scheduling(process,t):
    print(name+" "+str(time))

Solution (Python):
import time
import sys
import io
import re
import math
from Queue import Queue
import collections

start = time.clock();
i = 0
(n, q) = map(int, raw_input().split())

datalist = [raw_input().split() for _ in range(n)]
datalist = collections.deque(datalist)


while len(datalist):
    data = datalist.popleft()
    
    data[1] = int(data[1])
    
    if data[1] <= q:
        i += data[1]
        print data[0], i
    else:
        i += q
        data[1] -= q
        datalist.append(data)

Solution (Python):
from collections import deque

n,q=map(int,input().split())
Queue=deque()
for _ in range(n):
  Queue.append(input())

ans=0
while len(Queue)>0:
  x=Queue.popleft()
  
  
  name,time=x.split()
  t=int(time)
  if t>q:
    ans+=q
    Queue.append(name+' '+str(t-q))
  else:
    ans+=t
    print(name,ans)

Solution (Python):

from sys import stdin

class Queue:
    def __init__(self, process_list,quontime):
        self.process_list = process_list
        self.quontime = quontime
        self.elapsed_time = 0

    def process_done(self, process):
        process.update_leavetime_mili_seconds(process.leavetime_mili_seconds)
        print("{} {}".format(process.name,self.elapsed_time))

    def execute(self):
        while len(self.process_list) > 0:
            target_process = self.process_list.pop(0)
            if target_process.leavetime_mili_seconds <= self.quontime:
                self.elapsed_time += target_process.leavetime_mili_seconds
                self.process_done(target_process)
            else:
                self.elapsed_time += self.quontime
                target_process.update_leavetime_mili_seconds(self.quontime)
                self.process_list.append(target_process)

class Process:
    def __init__(self, arg_name,leavetime_mili_seconds):
        self.name = arg_name
        self.leavetime_mili_seconds = leavetime_mili_seconds
        

    def update_leavetime_mili_seconds(self, shori_time):
        self.leavetime_mili_seconds -= shori_time


n, q = map(int,stdin.readline().rstrip().split())
process_list = []
for i in range(n):
    input_t = stdin.readline().rstrip().split()
    process_list.append(Process(input_t[0], int(input_t[1])))
queue = Queue(process_list, q)
queue.execute()

Solution (Python):
n, q = map(int, input().split())
queue = []
for i in range(n):
  name, time = map(str, input().split())
  queue.append([name, int(time)])
    
length = 0
while queue:
  num = queue[0]
  if num[1] <= q:
    length += num[1]
    queue.pop(0)
    print(num[0], length)
  else:
    length += q
    queue.pop(0)
    queue.append([num[0], int(num[1]-q)])

Solution (Python):
N,Q = map(int, input().split())
import collections
dqn = collections.deque()
dqt = collections.deque()

def f(s):
    lst = s.split()
    return lst[0], int(lst[1])

for _ in range(N):
    ele = f(input())
    dqn.append(ele[0])
    dqt.append(ele[1])

Time = 0
while len(dqt) > 0:
    dqtime = dqt.popleft()
    dqname = dqn.popleft()
    if dqtime > Q:
        Time += Q
        dqt.append(dqtime - Q)
        dqn.append(dqname)
    else:
        Time += dqtime
        print(dqname,Time)

Solution (Python):
def resolve():
    from collections import deque
    n, q = [int(i) for i in input().split()]
    P = [input().split() for _ in range(n)]
    que = deque(P)
    totalTime = 0
    while len(que) > 0:
        name, time = que.popleft()
        time = int(time)
        if time <= q:
            totalTime += time
            print(name, totalTime)
        else:
            totalTime += q
            que.append([name, str(time - q)])


resolve()

Solution (Python):
from collections import deque

n, q = map(int, input().split())
pro = [list(map(str, input().split())) for i in range(n)]

for i in range(n):
    pro[i][1] = int(pro[i][1])

que = deque(pro)
done = False
time = 0

order = []

while not done:
    if len(que) == 0:
        done = True
        break
    now = que.popleft()
    t = now[1]
    name = now[0]
    if 0 < t <= q:
        time += t
        order.append(name + ' ' + str(time))
    if t > q:
        time += q
        t -= q
        que.append([name] + [t])

for i in order:
    print(i)

Solution (Python):
import collections
import queue
Q = collections.deque()
ans = 0
base = 0

line = input()

a = line.split()

n,q = map(int,a)

def work(listed):
    global ans
    global base
    v = int(listed[1])
    if v <= q:
        ans += v
        print(listed[0],ans)
        base += 1
    else:
        
        
        ans += q
        v -= q
        listed[1] = str(v)
        Q.append(listed)

for i in range (n):
    listed = list(input().strip().split())
    
    work(listed)


while base < n:
    listed = Q.popleft()
    work(listed)

Solution (Python):
import collections

n,q= map(int,input().split())
time= collections.deque()
name= collections.deque()
for _ in range(n):
    x,y= input().split()
    name.append(x)
    time.append(int(y))

cur=0
while True:
    if len(time)==0:
        break
    temp= time.popleft()
    if temp<= q:
        cur= temp+cur
        print(name.popleft(),cur)
        
    else:
        name.append(name.popleft())
        time.append(temp-q)
        cur+=q

Solution (Python):
n, q = map(int, input().split())
a = [list(map(str, input().split())) for _ in range(n)]
ans = []
time = 0
while a:
    j = a.pop(0)
    if int(j[1]) > q:
        j[1] = str(int(j[1]) - q)
        a.append(j)
        time += q
    else:
        time += int(j[1])
        ans.append([j[0], str(time)])
for i in range(n):
    print(' '.join(ans[i]))

Solution (Python):
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

from collections import deque,defaultdict,Counter
def main():
    N,Q = map(int,input().split()) 
    q = deque([])
    for _ in range(N):
        name,time = input().split()
        q.append((name,int(time)))
    
    ans = []
    t = 0
    while q:
        name,time = q.popleft()
        if time <= Q:
            t += time
            ans.append((name,t))
        else:
            t += Q
            time -= Q
            q.append((name,time))
    print('\n'.join(' '.join(map(str,a)) for a in ans))
if __name__ == '__main__':
    main()

Solution (Python):
from collections import deque

def main():
    n, p = map(int, input().split())
    q = deque([])
    score = 0
    cnt = 0
    for i in range(n):
        nt = list(map(str, input().split()))
        nt[1] = int(nt[1])
        q.append(nt)
    while q:
        tmp = q.popleft()
        if tmp[1] > p:
            score += p
            tmp[1] -= p
            cnt += 1
            q.append(tmp)       
        else:
            score += tmp[1]
            cnt += 1
            print(tmp[0], score)

if __name__ == '__main__':
    main()

Solution (Python):
from collections import deque
n,q = map(int,input().split())
ans = 0
NT = [list(input().split()) for i in range(n)]

queue = deque(NT)

while len(queue) > 0:
    a = queue.popleft()
    if int(a[1]) <= q:
        ans += int(a[1])
        print(a[0],ans)
    else:
        ans += q
        a[1] = str(int(a[1])-q)
        queue.append(a)

Solution (Python):
from collections import deque

n, q = map(int, input().split())
queue = deque()
for _ in range(n):
    n, t = input().split()
    queue.append([n, int(t)])
time = 0
finish = []
while len(queue) > 0:
    l = queue.popleft()
    cost = min(q, l[1])
    l[1] -= cost
    time += cost
    if l[1] == 0:
        finish.append((l[0], time))
    else:
        queue.append(l)
for f in finish:
    print(*f)

Solution (Python):
from collections import deque

queue = deque()
total_time = 0
n, q = map(int,input().split(' '))
for _ in range(n):
    name, time = input().split(' ')
    queue.append((name,int(time)))


while True:
    try:
        name, time = queue.popleft()
        if time - q <= 0:
            total_time += time
            print(name,total_time,sep=' ')
        elif time - q > 0:
            total_time += q
            queue.append((name,time-q))
    except IndexError:
        break

Solution (Python):
from sys import stdin
input = stdin.readline

n, q = map(int, input().split())
prosess = [input().split() for _ in range(n)]


class Queue():
    def __init__(self):
        self.head = 0
        self.tail = 0
        self.q = [0] * 10 ** 6
        self.max = 10 ** 6

    def isfull(self):
        return self.head == (self.tail + 1) % self.max

    def isempty(self):
        return self.head == self.tail

    def enqueue(self, x):
        if self.isfull():
            return "Full"
        else:
            self.q[self.tail] = x
            self.tail += 1

        if self.tail == self.max:
            self.tail = 0

    def dequeue(self):
        if self.isempty():
            return "Empty"
        else:
            self.x = self.q[self.head]
            self.head += 1

        if self.head == self.max:
            self.head = 0

        return self.x


queue = Queue()

for p in prosess:
    queue.enqueue([p[0], int(p[1])])

now_time = 0

while not queue.isempty():
    name, time = queue.dequeue()

    if time <= q:
        now_time += time
        print(name, now_time)
    else:
        time -= q
        now_time += q
        queue.enqueue([name, time])

Solution (Python):
def scheduling(A,n,q):
    ans = []
    time = 0
    while A != []:
        x = A.pop(0)
        if q < x[1]:
            x[1] -= q
            time += q
            A.append(x)
        elif x[1] <= q:
            time += x[1]
            x[1] = time
            ans.append(x)

    return ans



if __name__ == '__main__':
    n,q = [int(i) for i in input().split()]
    A = []
    for i in range(n):
        a = input().split()
        a[1] = int(a[1])
        A.append(a)
    ans = scheduling(A,n,q)
    for i in range(n):
        print(ans[i][0],ans[i][1])

Solution (Python):
import sys
from collections import deque
def input():
    return sys.stdin.readline()[:-1]
n,q = map(int, input().split())
A = deque()
for _ in range(n):
    a,b = input().split()
    A.append([a,int(b)])

t = 0
while True:
    a,b = A.popleft()
    if b > q:
        b = b - q
        t += q
        A.append([a,b])
    else:
        t += b
        print(f'{a} {t}')
    if len(A)==0:
        break

Solution (Python):
class queue():

    data = []
    cnt = 0

    def __init__(self):
        self.cnt = 0

    def add(self, a):
        self.data.append(a)

    def get(self):
        target = self.data[self.cnt]
        self.cnt += 1
        return target


buf = queue()

n, q = map(int, input().split())
for _ in range(n):
    name, time = input().split()
    time = int(time)

    buf.add([name, time])

finished = []
now = 0
while True:
    name, time = buf.get()
    if time - q > 0:
        buf.add([name, time-q])
        now += q
    else:
        finished.append([name, now+time])
        now += time

    if len(buf.data) == buf.cnt:
        break

for i in finished:
    print(i[0], i[1])

Solution (Python):
import sys
from io import StringIO
import unittest
from collections import deque
import math



def resolve():
    n, q = map(int, input().split())
    que = deque([])
    for i in range(n):
        name, time = input().split()
        name = str(name)
        time = int(time)
        que.append({'name': name, 'time': time})
    
    cur_time = 0
    while que:
        cur = que.popleft()
        if cur['time'] > q:
            cur['time'] -= q
            cur_time += q
            que.append(cur)
        else:
            cur_time += cur['time']
            print("{} {}".format(cur['name'], cur_time))

resolve()

Solution (Python):
n,q = map(int,input().split())
total = 0
que_list=[]
finish_list=[]


for i in range(n):
    que_list.append(input().split())


while que_list:
    m = que_list.pop(0)
    if int(m[1]) > q:
        total += q
        m[1] = int(m[1]) - q
        que_list.append(m)
    else:
        total+=int(m[1])
        m[1] = total
        finish_list.append(m)
        
for i in range(len(finish_list)):
    print(finish_list[i][0],finish_list[i][1])

Solution (Python):
n, q = map(int, input().split())
que, result = [], []
t = 0

for i in range(n):
    que_name, que_time = input().split()
    que.append([que_name, int(que_time)])

while len(que) != 0:
    a = que[0][1] - q
    if a > 0:
        t = t + q
        que.append([que[0][0], a])
        del(que[0])
    elif a == 0:
        t = t + q
        result.append([que[0][0], t])
        del(que[0])
    else:
        t = t + que[0][1]
        result.append([que[0][0], t])
        del(que[0])

for r in result:
    print("{} {}".format(r[0], r[1]))

Solution (Python):

from collections import deque as queue
N, Q = map(int, input().split())
q = queue()
for i in range(N):
    n, t = input().split()
    q.append((n, int(t)))
total = 0
while len(q) != 0:
    n, t = q.popleft()
    if t <= Q:
        total += t
        print(n, total)
    else:
        total += Q
        q.append((n, t-Q))

Solution (Python):
from collections import deque


def main():
    n, q = map(int, input().split())
    processes = deque()
    elapsed_time = 0

    for _ in range(n):
        name, time = input().split()
        processes.append([name, int(time)])

    while True:
        if len(processes) == 0:
            break

        process = processes.popleft()
        if process[1] <= q:
            elapsed_time += process[1]
            print(process[0], elapsed_time)
        else:
            elapsed_time += q
            process[1] -= q
            processes.append(process)


if __name__ == "__main__":
    main()

Solution (Python):
from collections import deque

n, q = map(int, input().split())

queue = deque()
for i in range(n):
    N, T = input().split()
    queue.append([N, int(T)])

t = 0
while queue:
    x = queue.popleft()
    if x[1] <= q:
        t += x[1]
        print(x[0], t)
        
    else:
        queue.append([x[0], x[1]-q])
        t += q

Solution (Python):
from collections import deque

totaltime = 0

n, q = (int(x) for x in input().split())


Q = deque()

for i in range(n):
    name, time = (x for x in input().split())
    Q.append([name,int(time)])
    
while len(Q) != 0:
    process = Q.popleft()
    time = process[1] - q
    if time > 0:
        process[1] = time
        totaltime += q
        Q.append(process)
        
    else:
        totaltime += process[1]
        print(process[0] + ' ' + str(totaltime))

Solution (Python):
class Proc:
    def __init__(self, name, time):
        self.name = name
        self.time = time

n, q = list(map(int, input().split()))
queue = []
for i in range(n):
    name, time = list(input().split())
    time = int(time)
    p = Proc(name, time)
    queue.append(p)

now = 0
while queue:
    p = queue.pop(0)
    if p.time <= q:
        now += p.time
        print(p.name, now)
    else:
        p.time -= q
        queue.append(p)
        now += q

Solution (Python):
from collections import deque
from sys import stdin
input = stdin.readline

n,q = map(int, input().split())
olist = deque()
for i in range(n):
    p,t = map(str, input().split())
    olist.append([p, int(t)])
count = 0
while olist:
    order = olist.popleft()
    remaintime = order[1] - q
    if remaintime > 0:
        count += q
        olist.append([order[0], remaintime])
    else:
        count += order[1]
        print(order[0], count)