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

def main():
    n,q = map(int, input().split())

    procs = [input().split() for x in range(n)]
    procs = deque([[proc[0], int(proc[1])] for proc in procs])

    finished_procs = []
    t = 0
    
    while len(procs) > 0:
        proc = procs.popleft()

        t += min(q, proc[1])

        if q - proc[1] >= 0:
            finished_procs.append([proc[0], t])
        else:
            proc[1] -= q
            procs.append(proc)

    for proc in finished_procs:
        print(proc[0] + ' ' + str(proc[1]))

if __name__ == "__main__":
    main()

Solution (Python):
from collections import deque
process_count, process_limit = map(int, input().split())

_target_list = []
for i in range(process_count):
    _input = input().split()
    _target_list.append([_input[0], int(_input[1])])
target_list = deque(_target_list)

def calc_process_time(target_list, process_limit):
    process_end_list = []
    process_time = 0
    while target_list:
        target_value = target_list.popleft()
        if target_value[1] > process_limit:
            target_value[1] -= process_limit
            target_list.append(target_value)
            process_time += process_limit
        else:
            process_time += target_value[1]
            process_end_list.append([target_value[0], process_time])
    return process_end_list

process_end_list = calc_process_time(target_list, process_limit)
for value in process_end_list:
    print(value[0], value[1])

Solution (Python):
from typing import TypeVar, Generic, List, Deque

T = TypeVar('T')

class Queue(Generic[T]):
	def __init__(self) -> None:
		self._container: Deque[T] = Deque()

	@property
	def empty(self) -> bool:
		return not self._container 

	def push(self, item: T):
		self._container.append(item)

	def pop(self) -> T:
		return self._container.popleft() 

	def __repr__(self) -> str:
		return repr(self._container)


if __name__ == "__main__":
	a = list(map(int, input().split()))
	n = a[0]
	q = a[1]
	queue = Queue()
	for _ in range(n):
		b = list(input().split())
		queue.push([b[0], int(b[1])])
	time = 0
	while not queue.empty:
		item = queue.pop()
		if item[1] - q <= 0:
			time += item[1]
			print(f"{item[0]} {time}")
		else:
			item[1] -= q
			queue.push(item)
			time += q

Solution (Python):
from collections import deque

class Data:
    def __init__(self, name, value):
        self.name = name
        self.value = value

Q = deque()

n, q = map(int, input().split())
for _ in range(n):
    name, value = input().split()
    tmp = Data(name, int(value))
    Q.append(tmp)

current_time = 0
done = 0

while True:
    datum = Q.popleft()
    if datum.value > q:
        current_time += q
        datum.value -= q
        Q.append(datum)
        
    else:
        current_time += datum.value
        print("%s %d"%(datum.name, current_time))
        done += 1
    if done == n:
        break

Solution (Python):
n, time_slice = map(int, input().split())

job = []
burst_time =[]
for i in range(n):
    a, b = input().split()
    b = int(b)
    job.append(a)
    burst_time.append(b)

dic = dict(zip(job, burst_time))
turn_around_time = 0

while True:
    if not job:
        break

    job_copy = job[:]

    for i in job_copy:
        if dic[i] > time_slice:
            turn_around_time += time_slice
            dic[i] = dic[i] - time_slice
            job.append(i)

        else:
            turn_around_time += dic[i]
            print(i, turn_around_time)

        del job[0]

Solution (Python):
from collections import deque

n,q = map(int,input().split())
que = deque([])

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

t =0
while len(que) >0:
    atop = que.popleft()
    spend = min(atop[1],q)
    atop[1] -= spend
    t += spend
    if atop[1] == 0:
        print(atop[0],t)
    else:
        que.append(atop)

Solution (Python):
from collections import deque
n, q = [int(x) for x in input().split() ]
name, time = deque([]), deque([])
for _ in range(n):
    tmp = [x for x in input().split()]
    name.append(tmp[0])
    time.append(int(tmp[1]))

if __name__ == '__main__':
    count = 0
    while name:
        if time[0] <= q:
            count += time.popleft()
            print(name.popleft(), count)
        else:
            count += q
            time.append(time.popleft() - q)
            name.append(name.popleft())

Solution (Python):
import sys

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

queue = list(map(lambda x: {"name": x[0], "time": int(x[1])}, [x.split() for x in sys.stdin]))
elapsed = 0
i = 0

while len(queue) > 0:
    
    p = queue[i]
    t = min(q, p["time"])
    p["time"] -= t
    elapsed += t

    
    if p["time"] > 0:
        
        i = (i + 1) % len(queue)
    else:
        print(p["name"], elapsed)
        del queue[i]
        i = i if len(queue) > i else 0

Solution (Python):
n, q = list(map(int, input().split()))


from collections import deque
que = deque([])
for _ in range(n):
    que.append((int(x) if x.isdigit() else x for x in input().split()))

tottime = 0
while que:
    name, lefttime = que.popleft()
    if lefttime <= q:
        tottime += lefttime
        print(name, tottime)
    else:
        lefttime -= q
        tottime += q
        que.append((name, lefttime))

Solution (Python):
n, q = [int(x) for x in input().split()]
pro = [[0, 0]]* n
for i in range(n):
    pro[i] = [str(x) for x in input().split()]

cnt = 0
while bool(pro):
    a = pro.pop(0)
    if int(a[1]) - q <= 0:
        cnt += int(a[1])
        print('{} {}'.format(a[0], cnt))
    else:
        cnt += q
        a[1] = str(int(a[1]) - q)
        pro.append(a)

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


def main():
    N, Q = map(int, input().split())

    total = 0
    queue = []

    for _ in range(N):
        inp = input().split()
        inp[1] = int(inp[1])
        queue.append(inp)

    

    while len(queue):
        process = queue.pop(0)
        if process[1] - Q > 0:
            total += Q
            process[1] -= Q
            queue.append(process)
        else:
            total += process[1]
            print("{0} {1}".format(process[0], total))


if __name__ == '__main__':
    main()

Solution (Python):
from collections import deque
n,q=map(int,input().split())
queue=deque([])
for _ in range(n):
  n,t=input().split()
  t=int(t)
  queue.append([n,t])
now=0
while queue:
  if queue[0][1]<=q:
    now+=queue[0][1]
    name=queue[0][0]
    queue.popleft()
    print(name,now)
  else:
    now+=q
    n,t=queue.popleft()
    t-=q
    queue.append([n,t])

Solution (Python):
"""
キューのデータ構造の定義
"""

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

    def enqueue(self, num):
        self.queue.append(num)

    def dequeue(self):
        return self.queue.pop(0)

    def exist(self):
        if len(self.queue) > 0:
            return True
        else:
            return False

class Process():
    def __init__(self, name, time):
        self.name = name
        self.time = time
    
    def execute(self, q):
        self.time -= q
        if self.time <= 0:
            return True, self.time+q
        else:
            return False, q

if __name__=="__main__":
    n, q = [int(i) for i in input().split()]
    queue = Queue()
    for i in range(n):
        name, time = [s for s in input().split()]
        queue.enqueue(Process(name, int(time)))

    total_execute_time = 0
    while queue.exist():
        p = queue.dequeue()
        is_finish, execute_time = p.execute(q)
        total_execute_time += execute_time
        if is_finish:
            print("{} {}".format(p.name, total_execute_time))
        else:
            queue.enqueue(p)

Solution (Python):
n, q = map(int,list(input().split()))
l = []
d = {}
t = 0
for _ in range(n):
    name, time = list(input().split())
    l.append(name)
    d[name] = int(time)
index = 0
while d:
    if d[l[0]] > q:
        d[l[0]] -= q
        t += q
        l.append(l.pop(0))
    else:
        t += d[l[0]]
        print(str(l[0]) + ' ' + str(t))
        del d[l[0]]
        del l[0]
        n -= 1

Solution (Python):
from collections import deque

n, q = map(int, input().split())
deq = deque()
for i in range(n):
  name, time = input().split()
  time = int(time)
  deq.append((name, time))


cul = 0
ans = []

while deq:
  name, time = deq.popleft()
  if time <= q:
    cul += time
    ans.append("%s %d" % (name, cul))
  else:
    cul += q
    time -= q
    deq.append((name, time))

print(*ans, sep="\n")

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

while len(queue) > 0:
    u = queue.pop(0)
    c = min(q, u[1])
    u[1] -= c
    elaps += c
    if u[1] > 0:
        queue.append(u)
    else:
        print(u[0], elaps)

Solution (Python):
from collections import deque





class Typedef:
    def __init__(self,name,time):
        self.name = name
        self.time = time

Q = deque([])


process_num,quantum = map(int, input().split())


for loop in range(process_num):
    input_str = list(map(str, input().split()))
    tmp_infomation = Typedef(input_str[0],int(input_str[1]))
    Q.append((tmp_infomation))


total_time =0 
finish_process = 0


while True:
    
    tmp_infomation = Q.popleft()
    
    if (tmp_infomation.time <=quantum):
        total_time += tmp_infomation.time
        finish_process +=1
        print("%s %d"%(tmp_infomation.name, total_time))
    
    else:
        total_time += quantum
        tmp_infomation.time -= quantum
        Q.append(tmp_infomation)
    
    if (finish_process == process_num):
        break

Solution (Python):
from collections import deque


class Process:

    def __init__(self, name, left):
        self.name = name
        self.left = left


def deal(quantam, pslist: [Process]):
    queue = deque(pslist)
    elaps = 0

    while queue:
        ps = queue.popleft()
        take = min(quantam, ps.left)
        ps.left -= take
        elaps += take
        if ps.left > 0:
            queue.append(ps)
        else:
            print(ps.name, elaps)


if __name__ == '__main__':
    n, q = [int(x) for x in input().split()]
    pslist = []
    for _ in range(int(n)):
        name, need = input().split()
        pslist.append(Process(name, int(need)))
    deal(q, pslist)

Solution (Python):


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

idx = 0
while True:
    lenQ = len(queue)
    if idx >= lenQ:
        break
    if queue[idx][1] <= q:
        totaltime += queue[idx][1]
        print(queue[idx][0] + ' {}'.format(totaltime))
        idx += 1
    else:
        totaltime += q
        name = queue[idx][0]
        time = queue[idx][1] - q
        queue.append([name, time])
        idx += 1

Solution (Python):
from collections import deque

n,q=map(int,input().split())
time=deque()
name=deque()
inst=[]*2
finish_time=0
time_inst=0
name_inst=0
string=""
for i in range(n):
    inst=input().split()
    name.append(inst[0])
    time.append(int(inst[1]))


while len(time)!=0:
    name_inst=name.popleft()
    time_inst=time.popleft()
    if time_inst<=q:
        finish_time+=time_inst
        string=name_inst+" "+str(finish_time)
        print(string)
    else:
        finish_time+=q
        time.append(time_inst-q)
        name.append(name_inst)

Solution (Python):
import copy
A = []  
B = []  


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

head = 0
tail = n
m = n + 1  


time = 0  
while head != tail:
    if A[head][1] <= q:
        B.append(copy.deepcopy(A[head]))
        B[-1][1] = B[-1][1] + time
        time += A[head][1]
    else:
        A[head][1] = A[head][1] - q
        A[tail] = A[head]
        tail = (tail + 1) % m
        time += q
    head = (head + 1) % m
    

    if head == tail:
        break

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

Solution (Python):
inputList=input().split()
n = int(inputList[0])
q = int(inputList[1])


p=[]

for i in range(n):
    inputList=input().split()
    name = inputList[0]
    t = int(inputList[1])
    p.append([name,t])
    
over=0

while 1:
    
    if len(p) <= 0:
        break
    
    tp = p[0]
    p.pop(0)
    tp[1]-=q
    over+=q
    if tp[1] > 0:
        p.append(tp)
    else :
        over += tp[1]
        print(tp[0]+' ' + str(over))

Solution (Python):

n,q=map(int,input().split())
que=[]

for i in range(n):
    name,time=input().split()
    time=int(time)
    que.append([name,time])
    
t=0
while len(que)>0:
    top=que.pop(0)
    score=min(top[1],q)
    top[1] -=score
    t +=score
    if top[1]==0:print(top[0],t)
    else:que.append(top)


"""from collections import deque

que=deque([])
n,q=map(int,input().split())

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

t=0
while len(que)>0:
    top=que.popleft()
    score=min(q,top[1])
    top[1] -=score
    t +=score
    if top[1]==0:print(top[0],t)
    else:que.append(top)"""

Solution (Python):
from collections import deque


def round_schedule(processes, q):
    queue = deque(processes)
    c_time = 0
    while len(queue) > 0:
        p_name, p_time = queue.popleft()
        res_time = p_time - q
        if res_time <= 0:
            c_time += p_time
            print(p_name, c_time)
        else:
            queue.append((p_name, res_time))
            c_time += q


if __name__ == "__main__":
    n, q = list(map(int, input().split()))
    processes = []
    for i in range(n):
        p_name, p_time = input().split()
        p_time = int(p_time)
        processes.append((p_name, p_time))
    
    round_schedule(processes, q)

Solution (Python):
class Node:
    def __init__(self, value, next, prev):
        self.value = value
        self.next = next
        self.prev = prev


class Que:
    def __init__(self):
        self.head = None
        self.last = None

    def add(self, value):
        new_node = Node(value, None, self.last)
        if not self.head:
            self.head = new_node
        else:
            self.last.next = new_node
        self.last = new_node

    def popleft(self):
        if not self.head:
            return -1
        v = self.head.value

        self.head = self.head.next
        return v

    def isempty(self):
        return not self.head


n, q = map(int, input().split())
a = []
for i in range(n):
    p, t = input().split()
    a.append([p, int(t)])

que = Que()

for e in a:
    que.add(e)

sum_t = 0
while not que.isempty():
    p, t = que.popleft()
    if t > q:
        que.add([p, t - q])
        sum_t += q
    else:
        sum_t += t
        print(p, sum_t)

Solution (Python):
from collections import deque

class Process:
    def __init__(self,name,time):
        self.name=name
        self.time=int(time)
    
    def __str__(self):
        return f'({self.name},{self.time})'

n,q=map(int,input().split())
ps=deque()
for i in range(n):
    name,time=input().split()
    ps.append(Process(name,time))

t=0
while len(ps)>0:
    p=ps.popleft()


    if p.time<=q:
        t+=p.time
        print(p.name,t)
    else:
        t+=q
        p.time-=q
        ps.append(p)

Solution (Python):
class Queue:
    def __init__(self):
        self.Q = [[] for _ in range(100000)]
        self.head = 0
        self.tail = 0
    def enqueue(self, x):
        self.Q[self.tail] = x
        if self.tail == 99999:
            self.tail = 0
        else:
            self.tail += 1
    def dequeue(self):
        if self.head == 99999:
            self.head = 0
        else:
            self.head += 1
        return self.Q[self.head-1]
    def len(self):
        return self.tail - self.head

nameQ = Queue()
timeQ = Queue()


N, q = map(int, input().split())
for i in range(N):
    namei, timei = input().split()
    timei = int(timei)
    timeQ.enqueue(timei)
    nameQ.enqueue(namei)
time = 0
while nameQ.len() != 0:
    namei = nameQ.dequeue()
    timei = timeQ.dequeue()
    if timei <= q:
        time += timei
        print(namei, time)
    else:
        time += q
        timei -= q
        nameQ.enqueue(namei)
        timeQ.enqueue(timei)

Solution (Python):
from queue import Queue

q = Queue()
Q=[]
time=0
N = list(map(int, input().split()))
qt=N[1]
for i  in range(N[0]):
  Q.append(list(map(str, input().split())))
for i in range(N[0]):
  q.put(Q[i])

while q.empty()==False:
  i=q.get()
  i[1]=str(int(i[1])-qt)
  if int(i[1])<=0:
    time=time+int(i[1])+qt
    print(i[0],time)
    pass
  else:
    time=time+qt
    q.put(i)

Solution (Python):
import sys
input=sys.stdin.readline
from collections import deque
n,q=map(int,input().split())
nt=[list(input().split()) for _ in range(n)]
t=0
l=deque(nt)
while l:
    tmp=l.popleft()
    tmp[1]=int(tmp[1])
    if tmp[1]>q:
        tmp[1]-=q
        l.append(tmp)
        t+=q
    else:
        t+=tmp[1]
        print(tmp[0],t)

Solution (Python):
from collections import deque
def RRS(N, P, q):
    end = []
    P_deq = deque(P)
    now = 0
    while(len(P_deq) != 0):
        P_n, P_t = P_deq.popleft()
        if P_t > q:
            P_t -= q
            now += q
            P_deq.append([P_n, P_t])
        else:
            now += P_t
            end.append([P_n, now])
    for p in end:
        print(*p)
    return 0

if __name__ == '__main__':
    N, q = map(int, input().split())
    A = [None]*N
    for i in range(N):
        p, t = map(str, input().split())
        A[i] = [p, int(t)]
    RRS(N, A, q)

Solution (Python):
N, q = map(int, input().split())
name = []
time = []

for n in range(N):
  n, t = input().split()
  name.append(n)
  time.append(int(t))
  
ansn = []
anst = []  
ntime = 0

while time:
  t = time.pop(0)
  n = name.pop(0)
  
  if t <= q:
    ansn.append(n)
    ntime += t
    anst.append(ntime)
  
  else:
    name.append(n)
    time.append(t - q)
    ntime += q

for i, j in zip(ansn, anst):
  print(i,j)

Solution (Python):
from collections import deque

class Task:
    def __init__(self,name,time):
        self.name = name
        self.time = time

def main():
    d = deque()
    num, q = [int(x) for x in input().split()]
    for i in range(num):
        pname,ptime = input().split()
        d.append( Task(pname, int(ptime)))
    passtime = 0
    while True:
        t = d.popleft()
        if t.time > q:
            t.time -= q
            passtime += q
            d.append(t)
        else:
            passtime += t.time
            print("{} {}".format(t.name,passtime))
            if len(d) == 0:
                exit(0)

if __name__ == '__main__':
    main()

Solution (Python):
class proc:
    def __init__(self, id, val):
        self.id=id
        self.val=int(val)

class queue:

    def __init__(self, n, datas):
        self.max=n*2
        self.head=0
        self.tail=0
        

        self.q=[None for _ in range(self.max)]
        for d in datas:
            p=proc(d[0],int(d[1]))
            self.enque(p)
            

        



    def enque(self,p):
        self.q[self.tail]=p
        self.tail=(self.tail+1)%self.max

    def deque(self):
        x=self.q[self.head]
        self.head=(self.head+1)%self.max
        return x

n, sec =map(int, input().split())
datas=[]
for i in range(n):
    datas.append(input().split())

q=queue(n,datas)
total=0
while(q.head !=q.tail):
    top=q.deque()
    usage=min(top.val, sec)
    total=total+usage
    top.val=top.val-usage
    if(top.val > 0):
        q.enque(top)
    else:
        print(top.id+" "+str(total))

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

deq = deque()

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

sum = 0

while deq:
    name, time = deq.popleft()
    if time <= q:
        sum += time
        print(name, sum)
    else:
        sum += q
        deq.append((name, time - q))

Solution (Python):
nq = list(map(int, input().split()))
n = nq[0]
q = nq[1]

name = []
time = []

for i in range(n):
    x = input().split()
    name.append(x[0])
    time.append(int(x[1]))

resultname = []
ms = 0
resulttime = []

while len(resultname) < n:
    result = time[0] - q
    popname = name.pop(0)
    poptime = time.pop(0)
    if result <= 0:
        resultname.append(popname)
        ms += poptime
        resulttime.append(ms)
    else:
        name.append(popname)
        time.append(result)
        ms += q

for i in range(n):
    print(resultname[i], resulttime[i])

Solution (Python):
def test():

	nq = list(map(int,input().split()))
	n = nq[0]
	q = nq[1]

	task_queue = []
	output_queue = []
	for i in range(n):
		inputs = input().split()
		task = []
		task.append(inputs[0])
		task.append(int(inputs[1]))
		task_queue.append(task)

	time = 0
	while task_queue:

		current = task_queue.pop(0)
		if current[1] > q:
			current[1] -= q
			task_queue.append(current)
			time += q
		elif current[1] == q:
			time += q
			current[1] = time
			output_queue.append(current)
		else:
			time += current[1]
			current[1] = time
			output_queue.append(current)

	for i in range(n):
		print(f"{output_queue[i][0]} {output_queue[i][1]}")

if __name__ == "__main__":
	test()

Solution (Python):
from collections import deque
nq = list(map(int, input().split()))
n = nq[0]
q = nq[1]
process = [input().split() for _ in range(n)]
ps = deque([[p[0], int(p[1])] for p in process])
time = 0
ans = []

while len(ps):
    p = ps.popleft()
    if p[1] > q:
        p[1] -= q
        ps.append(p)
        time += q
    else:
        time += p[1]
        ans.append((p[0], str(time)))
        
for a in ans:
     print(' '.join(a))

Solution (Python):
import queue
n,q = map(int,input().split())
qu = queue.Queue()
current = 0
for i in range(n):
    name,time = input().split()
    qu.put([name,int(time)])
    
while not qu.empty():
    process = qu.get()
    if process[1] <= q:
        print(process[0],str(current+process[1]))
        current += process[1]
    else:
        current += q
        process[1] -= q
        qu.put(process)

Solution (Python):
import queue

if __name__ == "__main__":
    task = queue.Queue()

    in_buf = input().split(" ")
    num_of_processes = int(in_buf[0])
    quantum = int(in_buf[1])

    for i in range(num_of_processes):
        in_buf = input().split(" ")
        process_name = in_buf[0]
        process_time = int(in_buf[1])
        task.put([process_name, process_time])

    completed_task = []  
    cumulative = 0  

    while True:
        if task.empty():
            break
        else:
            process = task.get()

            if process[1] - quantum <= 0:  
                completed_task.append([process[0], cumulative+process[1]])
                cumulative += process[1]
            else:  
                process[1] = process[1] - quantum
                task.put(process)
                cumulative += quantum

    for i in range(len(completed_task)):
        print("%s %d" % (completed_task[i][0], completed_task[i][1]))

Solution (Python):
from collections import deque
d = deque()
time = 0
n,q = map(int,input().split())
for i in range(n):
	d.append(input().split())
while len(d):
	d[0][1]=int(d[0][1])
	if d[0][1]>q:
		d[0][1] -= q
		time += q
		d.rotate(-1)
	else:
		time += d[0][1]
		print(f'{d.popleft()[0]} {time}')

Solution (Python):
processnum,process_time = list(int(element) for element in input().split())

processes = []
process2time = {}
elapsed_time = 0

for _ in range(int(processnum)):
  process, remaining_time = input().split()
  processes.append(process)
  process2time[process] = int(remaining_time)

while processes:
  new_processes = []
  for process in processes:
    if process2time[process] > process_time:
      elapsed_time += process_time
      process2time[process] -= process_time
      new_processes.append(process)
    else:
      elapsed_time += process2time[process]
      print(process + ' ' + str(elapsed_time))

  processes = new_processes

Solution (Python):
from collections import deque

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

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

t = 0
while queue:
    name, ti = queue.popleft()
    if ti <= q:
        print(name, t + ti)
        t += ti
    else:
        queue.append((name, ti - q))
        t += q

Solution (Python):
class Queue():
  def __init__(self):
      self.items = []

  def isEmpty(self):
      return self.items == []

  def enqueue(self, item):
      self.items.insert(0,item)

  def dequeue(self):
      return self.items.pop()

  def size(self):
      return len(self.items)
    
rs = Queue()

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

for i in range(n):
  inp = input().split()
  name = inp[0]
  time = int(inp[1])
  rs.enqueue([name, time])

all_time = 0

while rs.size() != 0: 
  task = rs.dequeue()
  temp = min(q, task[1])
  task[1] -= temp
  all_time += temp
  if task[1] == 0:
    print(task[0],all_time)
  else:
    rs.enqueue(task)

Solution (Python):
def getInput():
    (n, unit) = (int(i) for i in input().split(" "))
    q = []
    for i in range(n):
        tmp = [i for i in input().split(" ")]
        q.append([tmp[0], int(tmp[1])])
    return n, unit, q

def initQtable(Len_q):
    Q = [0 for i in range(Len_q+1)]
    return Q

def initPointer():
    head = tail = 0
    return head, tail

def isEmpty(head, tail):
    return head == tail

def isFull(head, tail, Len_q):
    return head == (tail+1)%Len_q

def enqueue(head, tail, Q, qname):
    Len_q = len(Q)
    if isFull(head, tail, Len_q):
        print("Error: Full Qtable")
        return
    tail = incrementPointer(tail, Len_q)
    Q[tail] = qname
    return tail
    
def dequeue(head, tail, Q):
    if isEmpty(head, tail):
        print("Error: Empty Qtable")
        return
    head = incrementPointer(head, Len_q+1)
    q = Q[head]
    return head, q

def incrementPointer(ptr, Len_q):
    ptr += 1
    if ptr >= Len_q:
        ptr = 0
    return ptr

n, unit, Jobs = getInput()
head, tail = initPointer()
Len_q = len(Jobs)
Q = initQtable(Len_q)
for i in range(Len_q):
    q = Jobs[i]
    tail = enqueue(head=head, tail=tail, Q=Q, qname=q)
total_time = 0
while not isEmpty(head, tail):
    head, [qname, time] = dequeue(head=head, tail=tail, Q=Q)
    progress = min(time, unit)
    total_time += progress
    time -= progress
    if time > 0:
        tail = enqueue(head=head, tail=tail, Q=Q, qname=[qname, time])
    else:
        print(qname, total_time, sep=" ")

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

def RRSchedule(Que,q):
    n = len(Que)
    t = 0
    while len(Que) != 0:
        if Que[0][1] > q:
            t += q
            Que[0][1] -= q
            Que.append(Que[0])
            del Que[0]
        else:
            t += Que[0][1]
            print(Que[0][0], end=" ")
            print(t)
            del Que[0]

RRSchedule(P,q)

Solution (Python):


from functools import wraps

def RoundRobinSchedule(process, n, q):
    elasped_time = 0
    head = 0
    tail = 0
    Q = [["a", i] for i in range(n+1)]


    def initialize():
        nonlocal head, tail, Q
        head = 0
        tail = 0


    def isEmpty():
        nonlocal head, tail, Q
        return head == tail


    def isFull():
        nonlocal head, tail, Q
        return head == (tail+1)%(n+1)


    def enqueue(x):
        nonlocal head, tail, Q
        if isFull():
            print("overflow")
            exit()
        Q[tail] = x
        if tail + 1 == n + 1:
            tail = 0
        else:
            tail += 1


    def dequeue():
        nonlocal head, tail, Q
        if isEmpty():
            print("underflow")
            exit()
        x = Q[head]
        if head + 1 == n + 1:
            head = 0
        else:
            head += 1
        return x


    for i in range(n):
        enqueue(process[i])
    while not isEmpty():
        target = dequeue()
        if target[1] <= q:
            elasped_time += target[1]
            print(target[0] + " " + str(elasped_time))
        else:
            elasped_time += q
            enqueue([target[0],target[1] - q])


n,q = [int(i) for i in input().split()]
process = []
for i in range(n):
    a,b = input().split()
    process.append([a,int(b)])
RoundRobinSchedule(process,n,q)

Solution (Python):
n,q=map(int,input().split())
ls=[]
for _ in range(n):
    ls.append(list(map(str,input().split())))
ans=[]
time=0
while len(ls)!=0:
    lsi=ls[0]
    lsi1=int(lsi[1])
    if lsi1>q:
        time+=q
        lsi[1]=lsi1-q
        ls.append(lsi)
        ls.pop(0)
    elif lsi1<=q:
        time+=lsi1
        lsi[1]=time
        ans.append(lsi)
        ls.pop(0)

def convert(list):
    res=" ".join(map(str, list))
    return res

for j in ans:
    print(convert(j))

Solution (Python):
Q = []
MAX = 100000
head = 0
tail = 0

class Process:
    def __init__(self):
        self.name = ''
        self.time = 0

def enqueue(x):
    global tail
    Q[tail] = x
    if tail + 1 == MAX:
        tail = 0
    else:
        tail += 1

def dequeue():
    global head
    x = Q[head]
    if head + 1 == MAX:
        head = 0
    else:
        head += 1
    return x

def main():
    input_line = input().split(" ")
    n = int(input_line[0])
    qtime = int(input_line[1])

    for _ in range(MAX):
        Q.append(None)

    for _ in range(n):
        v = input().split(' ')
        p = Process()
        p.name = v[0]
        p.time = int(v[1])
        enqueue(p)
    
    elaps = 0
    while head != tail:
        p = dequeue()
        t = min(qtime, p.time)
        p.time -= t
        elaps += t
        if p.time > 0:
            enqueue(p)
        else:
            print(p.name + " " + str(elaps))

if __name__ == "__main__":
    main()