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:
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 = 0


def enqueue(x):
    global queue
    queue.append(x)


def dequeue():
    global head
    head += 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

Submission status: Runtime Error

Solution code:
s=0
A=input().split()
n=(int)(A[0])
t=(int)(A[1])
x=[0 for i in range(2*n)]
for i in range(n):
    B=input().split()
    k=2*i
    x[k]=(B[0])
    x[k+1]=(int)(B[1])
while len(x)>0:
    s=x[1]-t
    if s>0: 
        sum+=t
        x.append(x[0])
        x.append(s)
        del x[0]
        del x[0]
    if s<=0:
        sum+=x[1]
        print( x[0],sum)
        del x[0]
        del x[0]

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(f(*e.split())for e in s[1:])
 t,a=0,[]
 while d:
  k,v=d.popleft()
  if v>q:v-=q;t+=q;d+[[k,v]]
  else:t+=v;a+=[f'{k} {t}\n']
 print(a[:-1])
m()

Submission status: Runtime Error

Solution code:
#16D8101014F 久留米 竜之介 Python
from collections import deque

n,time=map(int,input().split())
timenow = 0
p=[]
q=[]
queue=[] #p1,p2....
Queue=[] #time
for i in range (n):
	line=input().split()
	q.append(int(line.pop()))
	p.append(line.pop())

print(len(p))
while len(p) is not 0:
	Ptmp=p.deque()
	if Ptmp<=100:
		timenow+=Ptmp
		queue.append(q.deque())
		Queue.append()
	else:
		timenow+=100
		Ptmp-=100
		q.append(ptmp)
		p.append(p.deque())#??
		
print(queue,Queue)

Submission status: Runtime Error

Solution code:
#16D8101014F 久留米 竜之介 Python

n,time=map(int,input().split())
timenow = 0
p=[]
q=[]
queue=[] #p1,p2....
Queue=[] #time
for i in range (n):
	line=input().split()
	q.append(int(line.pop()))
	p.append(line.pop())

head=0
tail=len(p)-1
while head is not tail:
	#print(p)
	#print(q)
	#print(head,tail)
	Ptmp=q[head]
	if Ptmp<=time:
		timenow+=Ptmp
		queue.append(p[head])
		Queue.append(timenow)
		head+=1
	else:
		timenow+=time
		Ptmp-=time
		q.append(Ptmp)
		p.append(p[head])
		head+=1
		tail+=1
Ptmp=q[head]
timenow+=Ptmp
queue.append(p[head])
Queue.append(timenow)

for i in range(n):
		print(queue[i],Queue[i])

Submission status: Runtime Error

Solution code:
n, p = map(int, input().split())
ps = []
for i in range(n):
    ps.append(input().split())
    ps[i][1] = int(ps[i][1])
t = 0
i = 0
j = 0
while len(ps) > 0:
    if ps[i][1] > p:
        ps[i][1] -= p
        t += p
        i = (i + 1) % n
    elif ps[i][1] != 0:
        t += ps[i][1]
        print("{0} {1}".format(ps[i][0], t))
        ps.pop(i)
        n -= 1

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 29 14:42:43 2018

@author: maezawa
"""

def print_array(g):
    ans = str(g[0])
    if len(g) > 1:
        for i in range(1,len(g)):
            ans += ' '+str(g[i]) 
    print(ans)

name=[]
time=[]
current_time = 0

n, q = list(map(int, input().split()))
for i in range(n):
    s = input().split()
    name.append(s[0])
    time.append(int(s[1]))
# =============================================================================
# print(n,q)
# print(name)
# print(time)
# =============================================================================
finished = []
fin_time = []
i=0
remain = n
while True:
    if time[i] <= q:
        current_time += time.pop(i)
        finished.append(name.pop(i))
        fin_time.append(current_time)      
        remain -= 1
        if remain == 0:
            break
%        i = (i+1)%remain
    else:
        time[i] -= q
        current_time += q
        i = (i+1)%remain

for i in range(n):
    print("{} {}".format(finished[i], fin_time[i]))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 29 14:42:43 2018

@author: maezawa
"""

def print_array(g):
    ans = str(g[0])
    if len(g) > 1:
        for i in range(1,len(g)):
            ans += ' '+str(g[i]) 
    print(ans)

name=[]
time=[]
current_time = 0

n, q = list(map(int, input().split()))
for i in range(n):
    s = input().split()
    name.append(s[0])
    time.append(int(s[1]))
# =============================================================================
# print(n,q)
# print(name)
# print(time)
# =============================================================================
finished = []
fin_time = []
i=0
remain = n
while True:
    if time[i] <= q:
        current_time += time.pop(i)
        finished.append(name.pop(i))
        fin_time.append(current_time)      
        remain -= 1
        if remain == 0:
            break
        #i = (i+1)%remain
    else:
        time[i] -= q
        current_time += q
        i = (i+1)%remain

for i in range(n):
    print("{} {}".format(finished[i], fin_time[i]))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 29 14:42:43 2018

@author: maezawa
"""

def print_array(g):
    ans = str(g[0])
    if len(g) > 1:
        for i in range(1,len(g)):
            ans += ' '+str(g[i]) 
    print(ans)

name=[]
time=[]
current_time = 0

n, q = list(map(int, input().split()))
for i in range(n):
    s = input().split()
    name.append(s[0])
    time.append(int(s[1]))
# =============================================================================
# print(n,q)
# print(name)
# print(time)
# =============================================================================
finished = []
fin_time = []
i=0
remain = n
while True:
    if time[i] <= q:
        current_time += time.pop(i)
        finished.append(name.pop(i))
        fin_time.append(current_time)      
        i = (i+1)%remain
        remain -= 1
        if remain == 0:
            break
    else:
        time[i] -= q
        current_time += q
        i = (i+1)%remain

for i in range(n):
    print("{} {}".format(finished[i], fin_time[i]))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 29 14:42:43 2018

@author: maezawa
"""

def print_array(g):
    ans = str(g[0])
    if len(g) > 1:
        for i in range(1,len(g)):
            ans += ' '+str(g[i]) 
    print(ans)

name=[]
time=[]
current_time = 0

n, q = list(map(int, input().split()))
for i in range(n):
    s = input().split()
    name.append(s[0])
    time.append(int(s[1]))
# =============================================================================
# print(n,q)
# print(name)
# print(time)
# =============================================================================
finished = []
fin_time = []
i=0
remain = n
while True:
    if time[i] <= q:
        current_time += time.pop(i)
        finished.append(name.pop(i))
        fin_time.append(current_time)      
        i = i%remain
        remain -= 1
        if remain == 0:
            break
    else:
        time[i] -= q
        current_time += q
        i = (i+1)%remain

for i in range(n):
    print("{} {}".format(finished[i], fin_time[i]))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 29 14:42:43 2018

@author: maezawa
"""

def print_array(g):
    ans = str(g[0])
    if len(g) > 1:
        for i in range(1,len(g)):
            ans += ' '+str(g[i]) 
    print(ans)

name=[]
time=[]
current_time = 0

n, q = list(map(int, input().split()))
for i in range(n):
    s = input().split()
    name.append(s[0])
    time.append(int(s[1]))
# =============================================================================
# print(n,q)
# print(name)
# print(time)
# =============================================================================
finished = []
fin_time = []
i=0
remain = n
while True:
    if time[i] <= q:
        current_time += time.pop(i)
        finished.append(name.pop(i))
        fin_time.append(current_time)      
        remain -= 1
        i = i%remain
        if remain == 0:
            break
    else:
        time[i] -= q
        current_time += q
        i = (i+1)%remain

for i in range(n):
    print("{} {}".format(finished[i], fin_time[i]))

Submission status: Runtime Error

Solution code:


class Process:
    def __init__(self,n,head,tail):
        self.n = n
        self.head = head
        self.tail = tail
        self.name = []
        self.time = []

def void enqueue(self,x):
    self.data = x
    tail = (tail+1) % n

def dequeue(self):
    self.x = self.[head]
    head = (head+1) % n
    return x

process = Process()

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

for i in range(n):
    name[i],time[i] = map(input(),split())
list(map(int,time))
elaps = 0
head = 1
tail = n+1
process = Process(n,head,tail)

while head != tail:
    process.name = dequeue()
    process.time = dequeue()
    c = min(q,process.time)
    process.time -= c
    elaps += c
    if process.time > 0:
        enqueue(process.time)
        enqueue(process.name)
    else:
        print(process.name,elaps)

Submission status: Runtime Error

Solution code:
a=input().split()
n=int(a[0])
q=int(a[1])
b=[0 for i in range(2*n)]
cnt=0
for i in range(n):
    B=input().split()
    b[2*i]=B[0]
    b[2*i+1]=int(B[1])
while len(b)>0:
    if b[1]-100>0:
        tmp1=b[0]
        tmp2=b[1]-100
        del b[0]
        del b[0]
        b.append(tmp1)
        b.append(tmp2)
        cnt=cnt+100
    else:
        cnt=cnt+b[1]
        print(b[0],cnt)
        del b[0]
        del b[0

Submission status: Runtime Error

Solution code:
class Queue():
    def __init__(self, size=10):
        self.queue = [None] * size
        self.head = self.tail = 0
        self.MAX = size
        self.num_items = 0

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

    def is_full(self):
        return self.num_items == self.MAX

    def enqueue(self, x):
        if self.is_full():
            raise IndexError

        self.queue[self.tail] = x
        self.num_items += 1
        if self.tail+1 == self.MAX:
            self.tail = 0
        else:
            self.tail += 1

    def dequeue(self):
        if self.is_empty():
            raise IndexError

        x = self.queue[self.head]
        self.num_items -= 1
        if self.head+1 == self.MAX:
            self.head = 0
        else:
            self.head += 1

        return x


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

    def print_time(self):
        return self.time

    def print_name(self):
        return self.name


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

    t = 0
    for i in range(n):
        name, time = input().split()
        p = Process(name, int(time))
        qq.enqueue(p)

    while not qq.is_empty():
        p = qq.dequeue()

        if p.time - q <= 0:
            t += p.time
            print("{} {}".format(p.name, t))
        else:
            p.time -= q
            t += q
            qq.enqueue(p)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from collections import deque 
import numpy as np
n,q=map(int,input().split())
s=0
queue=deque([])
for i in range(n):
    name,time=input().split()
    queue.append([name,int(time)])
while len(queue)>0:
    t=queue.popleft()
    if t[1]>q:
        s=s+q
        t[1]=t[1]-q
        queue.append(t)
    else:
        s=s+t[1]
        print(t[0],s)

Submission status: Runtime Error

Solution code:
import java.util.Scanner;

public class Main {

	static class Node<E> {
		public E value;
		public Node<E> next;		
		public Node(E value) {
			this.value = value;
			this.next = null;
		}
	}

	static class SimpleQueue<E> {
		
		private Node<E> head;
		private Node<E> tail;
		int size;
		
		public SimpleQueue() {
			size = 0;
			head = null;
			tail = null;
		}
		
		public int getSize() {
			return size;
		}
		
		public boolean isEmpty() {
			return size == 0;
		}
		
		public void enqueue(E element) {
			Node<E> node = new Node<E>(element);
			if (head == null && tail == null) {
				head = tail = node;
			} else {
				tail.next = node;
				tail = node;
			}
			size++;
		}
		
		public E dequeue() {			
			if (isEmpty()) {
				return null;
			}
			E element = head.value;
			head = head.next;
			if (head == null) {
				tail = null;
			}
			size--;
			return element;			
		}
		
		public String toString() {
			StringBuilder sb = new StringBuilder();
			sb.append("[");
			Node<E> current = head;
			while (current != null) {
				sb.append(current.value);
				current = current.next;
				if (current != null) {
					sb.append(", ");
				}
			}			
			sb.append("](");
			if (tail != null) {
				sb.append(tail.value);
			}
			sb.append(")");
			return sb.toString();
		}		
	}
	
	static class Process {		
		public String name;
		public int time;		
		public Process(String name, int time) {
			this.name = name;
			this.time = time;
		}		
	}
	
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int q = sc.nextInt();
		
		SimpleQueue<Process> queue = new SimpleQueue<Process>();
		for (int i = 0; i < n; i++) {
			String name = sc.next();
			int time = sc.nextInt();
			queue.enqueue(new Process(name, time));
		}
		sc.close();

		int total = 0;
		while (!queue.isEmpty()) {
			
			Process process = queue.dequeue();
			if (process.time > q) {
				process.time = process.time - q;
				total += q;
				queue.enqueue(process);
			} else {
				total += process.time;
				System.out.println(process.name + " " + total);
			}			
		}
	}
}

Submission status: Runtime Error

Solution code:
process_num, qms = map(int, input().split())
raw_procs = [input() for i in range(process_num)]


if __name__ == '__main__':
    procs = []
    for row in raw_procs:
        name, time = row.split()
        procs.push = {
            "name": name,
            "time": int(time),
        }

    total_time = 0
    current_proc = 0
    while len(procs) > 0:
        if procs[current_proc]["time"] > 100:
            procs[current_proc]["time"] = procs[current_proc]["time"] - qms
            total_time += qms
            if current_proc == len(procs)-1:
                current_proc = 0
            else:
                current_proc += 1
        else:
            total_time += procs[current_proc]["time"]
            print("{} {}".format(procs[current_proc]["name"], total_time))
            del procs[current_proc]
            if current_proc >= len(procs)-1:
                current_proc = 0

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-


def simu(pro, q):
    end_time = 0

    while bool(pro):
        if pro[1] > q:
            end_time += q
            pro.append(pro[0])
            pro.append(pro[1] - q)
            pro.pop(0)
            pro.pop(1)

        elif pro[1] <= q:
            end_time += pro[1]
            print('{0} {1}'.format(pro[1], end_time))
            pro.pop(0)
            pro.pop(1)


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

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

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-


def simu(pro, q):
    end_time = 0

    while bool(pro):
        if pro[1] > q:
            end_time += q
            pro.append(pro[0])
            pro.append(pro[1] - q)
            pro.pop(0) * 2
            
        elif pro[1] <= q:
            end_time += pro[1]
            print('{0} {1}'.format(pro[0], end_time))
            pro.pop(0) * 2


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

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

simu(pro, q)

Submission status: Runtime Error

Solution code:
#coding: utf-8

class Queue:
    class Cell:
        def __init__(self,data,link=None):
            self.data=data
            self.link=link
    
    def __init__(self):
        self.size=0
        self.front=None
        self.rear=None

    def enqueue(self,x):
        if self.size==0:
            self.front = self.rear = Queue.Cell(x)
        else:
            new_cell = Queue.Cell(x)
            self.rear.link=new_cell
            self.rear=new_cell
        self.size +=1

    def dequeue(self):
        if self.size==0:
            raise IndexError
        value=self.front.data
        self.front=self.front.link
        self.size -=1
        if self.size==0:
            self.rear=None
        return value

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

def generator(n1, n2, step=1):
    n = n1
    while n<n2:
        yield n
        n+= step

n, q = map(int, raw_input().split())
 
que = queue()
for i in generator(0,n):
    name, time = raw_input().split()
    que.enqueue([name, int(time)])

stime = 0
while not que.isEmpty:
    job = que.dequeue()
    tmp=min(q,job[1])
    stime += tmp
    job[1] -= tmp
    if job[1]==0:
        print job[0], stime
    else:
        que.que.enqueue(job)

Submission status: Runtime Error

Solution code:
#coding: utf-8
import sys

class Queue:
    class Cell:
        def __init__(self, x, y = None):
            self.data = x
            self.next = y

    def __init__(self):
        self.size = 0
        self.rear = None

    def enqueue(self, x):
        if self.size == 0:
            self.rear = Queue.Cell(x)
            self.rear.next = self.rear
        else:
            new_cell = Queue.Cell(x, self.rear.next)
            self.rear.next = new_cell
            self.rear = new_cell
        self.size += 1

    def dequeue(self):
        if self.size == 0: raise IndexError
        front = self.rear.next
        self.rear.next = front.next
        self.size -= 1
        if self.size == 0: self.rear = None
        return front.data

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

def generator(n1, n2, step=1):
    n = n1
    while n<n2:
        yield n
        n+= step

n, q = map(int, raw_input().split())
 
A = Queue()
for i in generator(0,n):
    name, time = raw_input().split()
    A.enqueue([name, int(time)])

stime = 0
while not A.isEmpty():
    job = A.dequeue()
    if q>=job[1]:
        stime += job[1]
        print job[0], stime
    else:
        stime += q
        job[1] -= tmp
        A.enqueue(job)

Submission status: Runtime Error

Solution code:
n,q = map(int, raw_input().split())
que = [map(str, raw_input().split()) for i in range(n)]
for i in range(n):que[i][1] = int(que[i][1])
mxt = sum([y for x,y in que])
t = 0
i = 0
while t < mxt:
	i %= n
	c = que[i][1]
	if c <= q:
		t += c
		que.pop(i)
		n -= 1
		print a[0],t				
	else:
		t += q
		que[i][1] = c - q
		i += 1

Submission status: Runtime Error

Solution code:
n,q = map(int, raw_input().split())
que = [map(str, raw_input().split()) for i in range(n)]
for i in range(n):que[i][1] = int(que[i][1])
mxt = sum([y for x,y in que])
t = 0
i = 0
while t < mxt:
	if que[i][1] <= q:
		t += que[i][1]
		que.pop(i)
		n -= 1
		print que[i][0],t				
	else:
		t += q
		que[i][1] = que[i][1] - q
		i = (i+1)%n

Submission status: Runtime Error

Solution code:
n,q = map(int, raw_input().split())
que = [map(str, raw_input().split()) for i in range(n)]
for i in range(n):que[i][1] = int(que[i][1])
mxt = sum([y for x,y in que])
t = 0
i = 0
while t < mxt:
    if i = n: i = 0
    if que[i][1] <= q:
        t += que[i][1]
        print que[i][0],t
        que.pop(i)
        n -= 1
    else:
        t += q
        que[i][1] -= q
        i += 1

Submission status: WA: Presentation Error

Solution code:
import Queue
n,q=map(int,raw_input().strip().split())
name=[]
time=[]
qu=Queue.Queue()
class task:
    def __init__(self,name,time):
        self.name=name
        self.time=time
        self.total=0
for i in xrange(n):
    inp=raw_input().strip().split()
    qu.put(task(inp[0],int(inp[1])))
curtime=0

while not qu.empty():
    tmp=qu.get()
    if tmp.time>q:
        tmp.time-=q
        curtime+=q
        qu.put(tmp)
    else:

        curtime+=tmp.time

        print tmp.name,' ',curtime
#    print curtime

Submission status: WA: Presentation Error

Solution code:

from __future__ import print_function
import Queue
n,q=map(int,raw_input().strip().split())
name=[]
time=[]
qu=Queue.Queue()
class task:
    def __init__(self,name,time):
        self.name=name
        self.time=time
        self.total=0
for i in xrange(n):
    inp=raw_input().strip().split()
    qu.put(task(inp[0],int(inp[1])))
curtime=0

while not qu.empty():
    tmp=qu.get()
    if tmp.time>q:
        tmp.time-=q
        curtime+=q
        qu.put(tmp)
    else:

        curtime+=tmp.time
        ed='' if qu.qsize()==0 else '\n'
        print(tmp.name,' ',curtime,end=ed)
#    print curtime

Submission status: WA: Presentation Error

Solution code:

from __future__ import print_function
import Queue
n,q=map(int,raw_input().strip().split())
name=[]
time=[]
qu=Queue.Queue()
class task:
    def __init__(self,name,time):
        self.name=name
        self.time=time
        self.total=0
for i in xrange(n):
    inp=raw_input().strip().split()
    qu.put(task(inp[0],int(inp[1])))
curtime=0

while not qu.empty():
    tmp=qu.get()
    if tmp.time>q:
        tmp.time-=q
        curtime+=q
        qu.put(tmp)
    else:

        curtime+=tmp.time
        ed='' if qu.qsize()==0 else '\n'
        print(tmp.name,curtime,end=ed)
#    print curtime

Submission status: WA: Presentation Error

Solution code:
from collections import deque

n , q = map(int,input().split())
p , t = deque() , deque()
for i in range(n):
    x , y = input().split()
    p.append(x)
    t.append(int(y))
time = 0
temp1 = ""
temp2 = 0

while p:
    temp1 , temp2 = p.popleft() , t.popleft()
    if temp2 <= q :
        time += temp2
        print(temp1," ",time)
        temp1 , tmep2 = "" , 0
    else:
        time += q
        temp2 -= q
        p.append(temp1)
        t.append(temp2)

Submission status: WA: Presentation Error

Solution code:
s=input()
d=s.split()
n=int(d[0])
q=int(d[1])
end_t=0
processes=[]
for i in range(n):
    processes.append([])
    s=input()
    d=s.split()
    processes[i].append(d[0])
    processes[i].append(int(d[1]))

cnt=0
i=0
while True:
    if processes[i][1]<=q:
       if processes[i][1]==0:
           i=(i+1)%n
           continue
       end_t+=processes[i][1]
       processes[i][1]=0
       print(processes[i][0]," ",end_t)
       i=(i+1)%n
       cnt+=1
       if cnt==n:
           break
   
    else:
       processes[i][1]-=q
       end_t+=q
       i=(i+1)%n

Submission status: WA: Presentation Error

Solution code:
a=input().split()
n=int(a[0])
q=int(a[1])
b=[0 for i in range(2*n)]
cnt=0
for i in range(n):
    B=input().split()
    b[2*i]=B[0]
    b[2*i+1]=int(B[1])
while len(b)>0:
    if b[1]-100>0:
        tmp1=b[0]
        tmp2=b[1]-100
        del b[0]
        del b[0]
        b.append(tmp1)
        b.append(tmp2)
        cnt=cnt+100
    else:
        cnt=cnt+b[1]
        print(b[0]," ",cnt)
        del b[0]
        del b[0]