Problem:


There are n processes in a queue. Each process has namei and timei.  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

name1 time1

name2 time2

...

namen timen

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. namei and timei 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 ≤ timei ≤ 50000

1 ≤ length of namei ≤ 10

1 ≤ Sum of timei ≤ 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



Sample input:
5 100
p1 150
p2 80
p3 200
p4 350
p5 20


Sample output:
p2 180
p5 400
p1 450
p3 550
p4 800

Submission status: Runtime Error

Solution code:
class Trio:
    __pre=None
    __val=None
    __nex=None
    def __init__(self,val,p=None,n=None):
        self.__pre=p
        self.__val=val
        self.__nex=n
    
    def get_pre(self):return self.__pre
    
    def get_nex(self):return self.__nex
    
    def set_pre(self,n):self.__pre=n
        
    def set_nex(self,n):self.__nex=n
    
    def set_val(self,n):self.__val=n
    
    def get_val(self):return self.__val
    
class Queue:
    top = back = None
    def __init__(self):
        pass
    
    def enqueue(self,n):
        if(self.top==None):
            self.top = self.back = Trio(n)
        else:
            self.back.set_nex(Trio(n,p=self.back))
            self.back=self.back.get_nex()
    
    def dequeue(self):
        if(self.top==self.back):
            a,self.top,self.back=self.top.get_val(),None,None
            return a
        elif(self.top==None):
            return None
        else:
            self.top=self.top.get_nex()
            oldtop=self.top.get_pre()
            self.top.set_pre(None)
            return oldtop.get_val()

s = input()
n,limit=map(int,s.split())
que=Queue()
for i in range(n):
    lis=input().split()
    que.enqueue((lis[0],int(lis[1])))

time=0
while(True):
    elm=que.dequeue()
    if(elm==None):
        break
    elif(elm[1]>limit):
        que.enqueue((elm[0],elm[1]-limit))
        time+=100
    else:
        time+=elm[1]
        print(elm[0],time)

Submission status: Runtime Error

Solution code:
#coding:utf-8
#1_3_B
from collections import deque

def processing(queue, quantum, total_time):
    """ queue must be deque object """
    if not queue:
        return

    ps_name, ps_time = queue.popleft()
    if ps_time <= quantum:
        total_time += ps_time
        print(ps_name, total_time)
    else:
        total_time += quantum
        ps_time -= quantum
        queue.append([ps_name, ps_time])

    processing(queue, quantum, total_time)


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

processing(q, quantum, 0)

Submission status: Runtime Error

Solution code:
n, q = map(int, input().split())
q_list = collections.deque()
for i in range(n):
    name, time = input().split()
    q_list.append([name, int(time)])

time = 0
while q_list:
    if q_list[0][1] == 0:
        q_list.popleft()
    elif q_list[0][1] == 100:
        time += 100
        print (q_list[0][0], time)
        q_list[0][1] = 0
        q_list.rotate(-1)
    elif q_list[0][1] < 100:
        time += q_list[0][1]
        q_list[0][1] = 0
        print (q_list[0][0], time)
        q_list.rotate(-1)
    else:
        q_list[0][1] -= 100
        time += 100
        q_list.rotate(-1)

Submission status: Runtime Error

Solution code:
from collections import deque

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

  def getName(self):
    return self.name

  def getTime(self):
    return self.time

  def setTime(self, time):
    self.time = time

queue = deque()
n, q = map(int, raw_input().split())
for _ in xrange(n):
  name, time = raw_input().split()
  queue.append(Process(name, int(time)))
t = 0
while nameq:
  p = queue.popleft()
  if p.getTime() > q:
    p.setTime(p.getTime()-q)
    queue.append(p)
    t += q
  else:
    t += time
    print "%s %d" % (p.getName(), p.getTime())

Submission status: Runtime Error

Solution code:
# encoding: utf-8

import sys
from collections import deque


class Solution:
    @staticmethod
    def message_queue():
        # write your code here
        # tasks = deque(map(lambda x: x.split(), sys.stdin.readlines()))
        task_num, task_time = map(int, input().split())

        _input = sys.stdin.readlines()


        # task_deque = deque([{'name': i.split()[0], 'time': int(i.split()[1])} for i in _input])
        task_deque = deque(map(lambda x: dict(name=x.split()[0], time=x.split()[-1]), _input))
        total_time = 0

        while task_deque:
            item = task_deque.popleft()
            if item['time'] <= task_time:
                total_time += item['time']
                print(item['name'], total_time)
            else:
                item['time'] -= task_time
                total_time += task_time
                task_deque.append(item)


if __name__ == '__main__':
    solution = Solution()
    solution.message_queue()

Submission status: Runtime Error

Solution code:
import time as ti


class MyQueue(object):
    """
    My Queue class

    Attributes:
        queue: queue
        head
        tail
    """

    def __init__(self):
        """Constructor
        """
        self.length = 50005
        self.queue = [0] * self.length
        self.head = 0
        self.tail = 0

    # def enqueue(self, name, time):
    def enqueue(self, process):
        """enqueue method

        Args:
            name: enqueued process name
            time: enqueued process time

        Returns:
            None
        """
        self.queue[self.tail] = process
        self.tail = (self.tail + 1) % self.length

    def dequeue(self):
        """dequeue method

        Returns:
            None
        """
        self.queue[self.head] = 0
        self.head = (self.head + 1) % self.length

    def is_empty(self):
        """check queue is empty or not

        Returns:
            Bool
        """
        if self.head == self.tail:
            return True
        else:
            return False

    def is_full(self):
        """chech whether queue is full or not"""
        if self.tail - self.head >= len(self.queue):
            return True
        else:
            return False


class Process(object):
    """process class
    """

    def __init__(self, name="", time=0):
        """constructor
        Args:
            name: name
            time: time
        """
        self.name = name
        self.time = time

    def forward_time(self, time):
        """time forward method

        Args:
            time: forward time interval

        Returns:
            remain time

        """
        self.time -= time
        return self.time


def time_forward(my_queue, interval, current_time,):
    """

    Args:
        my_queue: queue
        interval: time step interval
        current_time: current time
    """

    # value = my_queue.queue[my_queue.head].forward_time(interval)
    value = my_queue.queue[my_queue.head] - interval
    if value <= 0:
        current_time += (interval + value)
        print my_queue.queue[my_queue.head].name, current_time
        my_queue.dequeue()

    elif value > 0:
        current_time += interval
        my_queue.enqueue(my_queue.queue[my_queue.head])
        my_queue.dequeue()

    return current_time


my_queue = MyQueue()
n, q = [int(x) for x in raw_input().split()]

counter = 0
while counter < n:
    name, time = raw_input().split()
    my_queue.enqueue(Process(name, int(time)))
    counter += 1

current_time = 0
while not my_queue.is_empty():
    current_time = time_forward(my_queue, q, current_time)

Submission status: Runtime Error

Solution code:
import collections
q = collections.deque(maxlen=100000)

n = int(input())
for i in range(n):
    com = input().split()
    if com[0]=='insert':
        q.appendleft(int(com[1]))
    elif com[0]=='delete':
        try:
            q.remove(int(com[0]))
        except ValueError:
            pass
    elif com[0]=='deleteFirst':
        q.popleft()
    elif com[0]=='deleteLast':
        q.pop()
print(' '.join(q))

Submission status: Runtime Error

Solution code:
n, q = map(int, input().split())
p = [input().split() for _ in range(n)]
t = i = 0
while n:
    i = i % n
    if int(p[i][1]) <= q:
        t += int(p[i][1])
        print(p[i][0], t)
        del p[i]
        n -= 1
    else:
        p[i][1] -= int(p[i][1]) - q
        t += q
        i += 1

Submission status: Runtime Error

Solution code:
class queue:
    head = tail = None
    size = 0
    def enqueue(self, x):
        if self.is_empty():
            self.head = self.tail = (x, None)
        else:
            self.tail[1] = (x, None)
            self.tail = self.tail[1]
        self.size += 1

    def dequeue(self):
        if not self.is_empty():
            self.head = self.head[1]
            self.size -=1

    def is_empty(self):
        return self.size == 0

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

s = queue()
t = list()
process = 0
for i in range(n):
    name, time = map(str, input().split())
    s.enqueue([name, int(time)])

while s.is_empty():
    diff = s[0][1] - q
    if diff <= 0:
        process += s[0][1]
        t.append([s[0][0], process])
        s.dequeue()
    else:
        process += q
        s.enqueue([s[0][0], diff])
        s.dequeue()
for i in t:
    print(i[0], i[1])

Submission status: Runtime Error

Solution code:
# encording: utf-8

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


def main(n, q):
    head = 0
    tail = -1
    lst = []
    all_time = 0

    for name, time in input().split():
        lst.append([name, int(time)])

    while head != tail:
        name, time = lst[head][0], lst[head][1]

        if time <= q:
            all_time += time
            print("{0} {1}".format(name, all_time))
            if tail == len(lst) - 1:
                tail = 0
            else:
                tail += 1
        else:
            all_time += time
            if head == len(lst) - 1:
                head = 0
            else:
                head +=1


print(main(n, q)

Submission status: Runtime Error

Solution code:
a = list(map(int, input().split()))
queuekey = []
queuetime = []

for i in range(0, a[0]):
    tmp = list(input().split())
    queuekey.append(tmp[0])
    queuetime.append(int(tmp[1]))

spentTime = 0
while len(queue) > 0:
    if queuetime[0] < a[1]:
        spentTime += queuetime[0]
        print(queuekey[0], end="")
        print(' ', end="")
        print(spentTime)
        queuekey.pop(0)
        queuetime.pop(0)
    else:
        spentTime += a[1]
        queuetime[0] -= a[1]
        queuetime.append(queletime[0])
        queuekey.append(quelekey[0])
        queuetime.pop(0)
        queuekey.pop(0)

Submission status: Runtime Error

Solution code:
a = list(map(int, input().split()))
queuekey = []
queuetime = []

for i in range(0, a[0]):
    tmp = list(input().split())
    queuekey.append(tmp[0])
    queuetime.append(int(tmp[1]))

spentTime = 0
while len(queuetime) > 0:
    if queuetime[0] < a[1]:
        spentTime += queuetime[0]
        print(queuekey[0], end="")
        print(' ', end="")
        print(spentTime)
        queuekey.pop(0)
        queuetime.pop(0)
    else:
        spentTime += a[1]
        queuetime[0] -= a[1]
        queuetime.append(queletime[0])
        queuekey.append(quelekey[0])
        queuetime.pop(0)
        queuekey.pop(0)

Submission status: Runtime Error

Solution code:
n,q = map(int, input().split())
Q = [0 for i in range(n+1)]
head = 0
tail = 0
def enqueue(x):
    global tail
    Q[tail] = ???
    tail = (tail + 1) % (n + 1)

def dequeue():
    global head
    x,t = Q[head]
    head = (head + 1) % (n + 1)
    return [x,t]
for i in range(n):
    P = input().split()
    enqueue([P[0], int(P[1])])

elaps = 0
while head != tail:
    u,t = dequeue()
    c = min(q, t)
    t -= c
    elaps += c
    if t > 0:
        enqueue([u,t])
    else:
        print(u + " " + str(elaps))

Submission status: Runtime Error

Solution code:
def enqueue(x):
    global tail
    Q[tail] = ???
    tail = (tail + 1) % (n + 1)

def dequeue():
    global head
    x,t = Q[head]
    head = (head + 1) % (n + 1)
    return [x,t]
n,q = map(int, input().split())
Q = [0 for i in range(n+1)]
head = 0
tail = 0
for i in range(n):
    P = input().split()
    enqueue([P[0], int(P[1])])

elaps = 0
while head != tail:
    u,t = dequeue()
    c = min(q, t)
    t -= c
    elaps += c
    if t > 0:
        enqueue([u,t])
    else:
        print(u + " " + str(elaps))

Submission status: Runtime Error

Solution code:
n,q = map(int, input().split())
Q = [0 for i in range(n+1)]
head = 0
tail = 0
def enqueue(x):
    global tail
    Q[tail] = ???
    tail = (tail + 1) % (n + 1)
def dequeue():
    global head
    x,t = Q[head]
    head = (head + 1) % (n + 1)
    return [x,t]
for i in range(n):
    P = input().split()
    enqueue([P[0], int(P[1])])
elaps = 0
while head != tail:
    u,t = dequeue()
    c = min(q, t)
    t -= c
    elaps += c
    if t > 0:
        enqueue([u,t])
    else:
        print(u + " " + str(elaps))

Submission status: Runtime Error

Solution code:
n,q = map(int, input().split())
MAX = n + 2
Q = [0 for i in range(MAX)]
head = 0
tail = 0

def enqueue(x):
    global tail
    Q[tail] = ???
    tail = (tail + 1) % MAX

def dequeue():
    global head
    x,t = Q[head]
    head = (head + 1) %MAX
    return [x,t]
for i in range(n):
    P = input().split()
    enqueue([P[0], int(P[1])])

elaps = 0
while head != tail:
    u,t = dequeue()
    c = min(q, t)
    t -= c
    elaps += c
    if t > 0:
        enqueue([u,t])
    else:
        print(u + " " + str(elaps))

Submission status: Runtime Error

Solution code:
n,q = map(int, input().split())
MAX = n + 2
Q = [0 for i in range(MAX)]
head = 0
tail = 0

def enqueue(x):
    global tail
    Q[tail] = ???
    tail = (tail + 1) % MAX

def dequeue():
    global head
    x,t = Q[head]
    head = (head + 1) %MAX
    return [x,t]
for i in range(n):
    P = list(input().split())
    enqueue([P[0], int(P[1])])

elaps = 0
while head != tail:
    u,t = dequeue()
    c = min(q, t)
    t -= c
    elaps += c
    if t > 0:
        enqueue([u,t])
    else:
        print(u + " " + str(elaps))

Submission status: Runtime Error

Solution code:
import Queue
import sys

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

def main():
    array = map(lambda x: int(x), sys.stdin.readline().strip().split(" "))
    p_num = array[0]
    q_time = array[1]
    p_queue = Queue.Queue()
    for i in range(0, p_num):
        array = sys.readline().strip().split()
        p_queue.put(Proc(array[0], int(array[1])))
    t = 0
    while not p_queue.empty():
        p = p_queue.get()
        if p.time > q_time:
            p.time = p.time - q_time
            p_queue.put(p)
            t += q_time
        else:
            t += p.time
            print p.name + " " + str(t)
    
if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import Queue
import sys

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

def main():
    array = map(lambda x: int(x), sys.stdin.readline().strip().split(" "))
    p_num = array[0]
    q_time = array[1]
    p_queue = Queue.Queue()
    for i in range(0, p_num):
        array = sys.readline().strip().split(" ")
        p_queue.put(Proc(array[0], int(array[1])))
    t = 0
    while not p_queue.empty():
        p = p_queue.get()
        if p.time > q_time:
            p.time = p.time - q_time
            p_queue.put(p)
            t += q_time
        else:
            t += p.time
            print p.name + " " + str(t)
    
if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
N, Q = map(int, input().strip().split())

A = []
D = {}
for l in range(N):
    n, t = input().strip().split()
    D[n] = int(t)
    A.append(n)

print(A)
T = 0
d = 0
while True:
    n = A.pop(0)
    if D[n] > Q:
        D[n] -= Q
        T += Q
        A.append(n)
    else:
        T += D[n]
        print(str(n) + ' ' + atr(T))
        d += 1
        if d == N:
            break

Submission status: Runtime Error

Solution code:
ef ALDS1_3B():
    n, q = map(int, input().split())
    PQ = [[l[0], int(l[1])] for l in  [input().split() for i in range(n)]  ]
    times = 0
    while PQ:
        p = PQ.pop(0)
        if p[1] <= q:
            times += p[1]
            print('%s %d' %(p[0], times))
        else:
            times += q
            PQ.append([p[0], p[1]-q])


if __name__ == '__main__':
    ALDS1_3B()

Submission status: Runtime Error

Solution code:
n, q = map(int , input().split())
queue = []
for _ in range(n):
    line = input().split()
    queue.append([line[0], int(line[1])])

class my_queue:
    def __init__(self, queue):
        self.queue = queue
    def enqueue(self, item):
        self.queue = self.queue + [item]
        self.queue.append(item)
    def dequeue(self):
        if len(self.queue) != 0:
            item = self.queue[0]
            self.queue = self.queue[1:]
        else :
            item = None
        return item


time = 0
finish_task = []

while(True):
    item = queue.pop()
    if item == None:
        break
    elif item[1] <= q:
        time += item[1]
        finish_task.append([item[0], time])
    else :
        time += q
        queue.append([item[0], item[1] - q])

for item in finish_task:
    print(item[0], item[1])

Submission status: Runtime Error

Solution code:
from collections import deque

def main():
    process_count, process_time, processes = get_input()
    result =  run_roundrobin(processes = processes, time = process_time)
    for r in result:
        print(r.name, r.time)


def run_roundrobin(processes, time, total_time = 0, result=[]):
    if not processes:
        return result

    p = processes.popleft()
    if p.time <= time:
        total_time += p.time
        p.time = total_time
        result.append(p)
    else:
        total_time += time
        p.time -= time
        processes.append(p)

    return run_roundrobin(processes, time, total_time, result)



def get_input():
    count, time = list(map(lambda x: int(x), input().split(' ')))

    processes = deque([])
    for _ in range(count):
        im = input().split(' ')
        p = Process(im[0], int(im[1]))
        processes.append(p)

    return count, time, processes


class Process():

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


main()

Submission status: Runtime Error

Solution code:
from collections import deque
import sys
sys.setrecursionlimit(10000)

def main():
    process_count, process_time, processes = get_input()
    result =  run_roundrobin(processes = processes, time = process_time)
    for r in result:
        print(r.name, r.time)


def run_roundrobin(processes, time, total_time = 0, result=[]):
    if not processes:
        return result

    p = processes.popleft()
    if p.time <= time:
        total_time += p.time
        p.time = total_time
        result.append(p)
    else:
        total_time += time
        p.time -= time
        processes.append(p)

    return run_roundrobin(processes, time, total_time, result)



def get_input():
    count, time = list(map(lambda x: int(x), input().split(' ')))

    processes = deque([])
    for _ in range(count):
        im = input().split(' ')
        p = Process(im[0], int(im[1]))
        processes.append(p)

    return count, time, processes


class Process():

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


main()

Submission status: Runtime Error

Solution code:
from collections import deque
import sys
sys.setrecursionlimit(1000000)

def main():
    process_count, process_time, processes = get_input()
    result =  run_roundrobin(processes = processes, time = process_time)
    for r in result:
        print(r.name, r.time)


def run_roundrobin(processes, time, total_time = 0, result=[]):
    if not processes:
        return result

    p = processes.popleft()
    if p.time <= time:
        total_time += p.time
        p.time = total_time
        result.append(p)
    else:
        total_time += time
        p.time -= time
        processes.append(p)

    return run_roundrobin(processes, time, total_time, result)



def get_input():
    count, time = list(map(lambda x: int(x), input().split(' ')))

    processes = deque([])
    for _ in range(count):
        im = input().split(' ')
        p = Process(im[0], int(im[1]))
        processes.append(p)

    return count, time, processes


class Process():

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


main()

Submission status: Runtime Error

Solution code:
from collections import deque
import sys
sys.setrecursionlimit(10000000000)

def main():
    process_count, process_time, processes = get_input()
    result =  run_roundrobin(processes = processes, time = process_time)
    for r in result:
        print(r.name, r.time)


def run_roundrobin(processes, time, total_time = 0, result=[]):
    if not processes:
        return result

    p = processes.popleft()
    if p.time <= time:
        total_time += p.time
        p.time = total_time
        result.append(p)
    else:
        total_time += time
        p.time -= time
        processes.append(p)

    return run_roundrobin(processes, time, total_time, result)



def get_input():
    count, time = list(map(lambda x: int(x), input().split(' ')))

    processes = deque([])
    for _ in range(count):
        im = input().split(' ')
        p = Process(im[0], int(im[1]))
        processes.append(p)

    return count, time, processes


class Process():

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


main()

Submission status: Runtime Error

Solution code:
from collections import deque
import sys
sys.setrecursionlimit(100000000)

def main():
    process_count, process_time, processes = get_input()
    result =  run_roundrobin(processes = processes, time = process_time)
    for r in result:
        print(r.name, r.time)


def run_roundrobin(processes, time, total_time = 0, result=[]):
    if not processes:
        return result

    p = processes.popleft()
    if p.time <= time:
        total_time += p.time
        p.time = total_time
        result.append(p)
    else:
        total_time += time
        p.time -= time
        processes.append(p)

    return run_roundrobin(processes, time, total_time, result)



def get_input():
    count, time = list(map(lambda x: int(x), input().split(' ')))

    processes = deque([])
    for _ in range(count):
        im = input().split(' ')
        p = Process(im[0], int(im[1]))
        processes.append(p)

    return count, time, processes


class Process():

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


main()

Submission status: Runtime Error

Solution code:
from collections import deque
import sys
sys.setrecursionlimit(1000000000)

def main():
    process_count, process_time, processes = get_input()
    result =  run_roundrobin(processes = processes, time = process_time)
    for r in result:
        print(r.name, r.time)


def run_roundrobin(processes, time, total_time = 0, result=[]):
    if not processes:
        return result

    p = processes.popleft()
    if p.time <= time:
        total_time += p.time
        p.time = total_time
        result.append(p)
    else:
        total_time += time
        p.time -= time
        processes.append(p)

    return run_roundrobin(processes, time, total_time, result)



def get_input():
    count, time = list(map(lambda x: int(x), input().split(' ')))

    processes = deque([])
    for _ in range(count):
        im = input().split(' ')
        p = Process(im[0], int(im[1]))
        processes.append(p)

    return count, time, processes


class Process():

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


main()

Submission status: Runtime Error

Solution code:
import sys
from collections import deque
n,q=map(int,input().split())
d=deque(map(lambda x,y:[x,int(y)],sys.stdin))
t=0
while d:
 k,v=d.popleft()
 v=int(v)
 if v>q:
  v-=q
  t+=q
  d.append([k,v])
 else:
  t+=v
  print(k,t)

Submission status: Runtime Error

Solution code:
import sys
from collections import deque
def m():
 s=sys.stdin.readlines()
 q=int(s[0].split()[1])
 f=lambda x,y:(x,int(y))
 d=deque(map(*e.split())for e in s[1:])
 t,a=0,[]
 while d:
  k,v=d.popleft()
  if v>q:v-=q;t+=q;d.append([k,v])
  else:t+=v;a+=[f'{k} {t}']
 print('\n'.join(a))
if'__main__'==__name__:m()

Submission status: Runtime Error

Solution code:
import sys
import numpy as np
import copy

fline = input().rstrip().split(' ')
N, Q = int(fline[0]), int(fline[1])

list = []
for i in range(N):
    tlist = []
    line = input().split(' ')
    tlist = [line[0], line[1]]
    #print(tlist)
    list.append(tlist)

#print(list)
current = 0
while len(list) != 0:
    if int(list[0][1]) <= Q:
        current += int(list[0][1])
        print(list[0][0] + " " + str(current))
        del list[0]
    else:
        list[0][1] = str((int)(list[0][1])-Q)
        list.append(list[0])
        del list[0]
        current += Q

Submission status: Runtime Error

Solution code:
import sys
import numpy as np
import copy

fline = input().rstrip().split(' ')
N, Q = int(fline[0]), int(fline[1])

list = []
for i in range(N):
    tlist = []
    line = input().split(' ')
    tlist = [line[0], line[1]]
    #print(tlist)
    list.append(tlist)

#print(list)
current = 0
while len(list) != 0:
    if int(list[0][1]) <= Q:
        current += int(list[0][1])
        print(list[0][0] + " " + str(current))
        del list[0]
    else:
        list[0][1] = str((int)(list[0][1])-Q)
        list.append(list[0])
        del list[0]
        current += Q
    #print(list)

Submission status: Runtime Error

Solution code:
INPUT = list(map(int, input().split()))
head, tail, n, quantum = 0, len(processes), INPUT[0], INPUT[1]
processes = [input().split() for _ in range(n)]


def enqueue(x):
    global processes, tail
    processes.append(0)
    processes[tail] = x
    tail += 1


def dequeue():
    global head
    head += 1


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

time, count = 0, 0
while count < n:
    y = processes[head][1] - quantum
    if y < 0:
        print(str(processes[head][0]) + " " + str(time + processes[head][1]))
        dequeue()
        time += y
        count += 1
    else:
        processes[head][1] -= quantum
        enqueue(processes[head])
        dequeue()

    time += quantum

Submission status: Runtime Error

Solution code:
INPUT = list(map(int, input().split()))
processes = [input().split() for _ in range(n)]
head, tail, n, quantum = 0, len(processes), INPUT[0], INPUT[1]


def enqueue(x):
    global processes, tail
    processes.append(0)
    processes[tail] = x
    tail += 1


def dequeue():
    global head
    head += 1


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

time, count = 0, 0
while count < n:
    y = processes[head][1] - quantum
    if y < 0:
        print(str(processes[head][0]) + " " + str(time + processes[head][1]))
        dequeue()
        time += y
        count += 1
    else:
        processes[head][1] -= quantum
        enqueue(processes[head])
        dequeue()

    time += quantum

Submission status: Runtime Error

Solution code:
INPUT = list(map(int, input().split()))
processes = [input().split() for _ in range(INPUT[0])]
head, tail, n, quantum = 0, len(processes), INPUT[0], INPUT[1]


def enqueue(x):
    global processes, tail
    processes.append(0)
    processes[tail] = x
    tail += 1


def dequeue():
    global head
    head += 1


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

time, count = 0, 0
while count < n:
    y = processes[head][1] - quantum
    if y < 0:
        print(str(processes[head][0]) + " " + str(time + processes[head][1]))
        dequeue()
        time += y
        count += 1
    else:
        processes[head][1] -= quantum
        enqueue(processes[head])
        dequeue()

    time += quantum

Submission status: Runtime Error

Solution code:
INPUT = list(map(int, input().split()))
processes = [input() for _ in range(INPUT[0])]
for i in range(INPUT[0]):
    processes[i].split()
head, tail, n, quantum = 0, len(processes), INPUT[0], INPUT[1]


def enqueue(x):
    global processes, tail
    processes.append(0)
    processes[tail] = x
    tail += 1


def dequeue():
    global head
    head += 1


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

time, count = 0, 0
while count < n:
    y = processes[head][1] - quantum
    if y < 0:
        print(str(processes[head][0]) + " " + str(time + processes[head][1]))
        dequeue()
        time += y
        count += 1
    else:
        processes[head][1] -= quantum
        enqueue(processes[head])
        dequeue()

    time += quantum

Submission status: Runtime Error

Solution code:
n, quantum = [int(i) for i in input().split()]
processes = []
for i in range(n):
    processes.append(input())
for i in range(n):
    processes[i].split()
head, tail = 0, len(processes)


def enqueue(x):
    global processes, tail
    processes.append(0)
    processes[tail] = x
    tail += 1


def dequeue():
    global head
    head += 1


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

time, count = 0, 0
while count < n:
    y = processes[head][1] - quantum
    if y < 0:
        print(str(processes[head][0]) + " " + str(time + processes[head][1]))
        dequeue()
        time += y
        count += 1
    else:
        processes[head][1] -= quantum
        enqueue(processes[head])
        dequeue()

    time += quantum

Submission status: Runtime Error

Solution code:
def parse(l):
    name, time = l.split()
    return name, int(time)


n, quantum = map(int, input().split())
queue = list(parse(input()) for _ in range(n))
head, tail = 0, len(queue)


def enqueue(x):
    global queue, tail
    queue.append(0)
    queue[tail] = x
    tail += 1


def dequeue():
    global head
    head += 1


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

total_time, count = 0, 0
while count < n:
    y = queue[head][1] - quantum
    if y < 0:
        print(str(queue[head][0]) + " " + str(total_time + queue[head][1]))
        dequeue()
        total_time += y
        count += 1
    else:
        queue[head][1] -= quantum
        enqueue(queue[head])
        dequeue()

    total_time += quantum