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: Accepted

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


class Process:
    def __init__(self, line):
        self.name = line[0]
        self.time = int(line[1])


LEN = 100000
n = 0
head = 0
tail = 0
Q = [0] * LEN


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

def dequeue():
    global head
    x = Q[head]
    head = (head + 1) % LEN
    return x


def main():
    n, q = map(int, input().split())
    ps = [Process(input().split()) for _ in range(n)]
    for p in ps:
        enqueue(p)

    global head, tail

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n, q = map(int, input().split())
queue = [input() for i in range(n)]
cnt = 0
while len(queue) != 0:
    name, time = queue.pop(0).split()
    if int(time) <= q:
        cnt+=int(time)
        print(name,str(cnt))
    else:
        cnt+=q
        time = str(int(time) - q)
        queue.append(name+" "+time)

Submission status: Accepted

Solution code:
#87
#ALDS1_3_B
# キューは最初のやつから参照される

from queue import Queue
n,q=map(int,input().split())
que=Queue()

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

total=0
while que.qsize()>0:
    name,time = que.get()
    total += min(q,time)
    if q < time:
        que.put((name,time-q))
    else:
        print(name,total)

Submission status: Accepted

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

while len(ps) > 0:
  if ps[0][1] > p:
    ps.append([ps[0][0], ps[0][1]-p])
    t += p
    ps.pop(0)
  else:
    t += ps[0][1]
    print('{0} {1}'.format(ps[0][0], t))
    ps.pop(0)

Submission status: Accepted

Solution code:
from collections import deque
import sys
n, q = map(int, input().split())
queue = deque([])
for _ in range(n):
    name, time = input().split()
    time = int(time)
    queue.append([name, time])
time = 0
while True:
    try:
        if queue[0][1] <= q:
            time += queue[0][1]
            print(queue[0][0], time)
            queue.popleft()
        else:
            time += q
            queue[0][1] -= q
            queue.rotate(-1)
    except:
        sys.exit()

Submission status: Accepted

Solution code:
n, q = map(int, input().split())
p = []
for i in range(n):
    p_tmp = input().split()
    p.append([p_tmp[0], int(p_tmp[1])])
# print(n, q)
# for i in range(n):
#     print(i, p[i])
time = 0
while len(p) != 0:
    process_time = q
    # print(time)
    # print(process_time)
    # print(p)
    if p[0][1] > q:
        p_tmp = p.pop(0)
        p.append([p_tmp[0], p_tmp[1]-q])
        time += process_time
        process_time = 0
    else:
        process_time -= p[0][1]
        time += p[0][1]
        print(p[0][0], time)
        p.pop(0)

Submission status: Accepted

Solution code:
from collections import deque
 
n, q = map(int,(input().split()))
queue = deque()
 
for i in range(n):
    name, time = input().split()
    queue.append( [name, int(time)]  )
     
t = 0
while queue:
    p = queue.popleft()
    t += min(q, p[1])
    if q < p[1]:
        queue.append([p[0], p[1] - q])
    else:
        print(f"{p[0]} {t}")

Submission status: Accepted

Solution code:
from collections import deque

A = input().split(' ')
n = int(A[0])
q = int(A[1])

a = deque()
for _ in range(n):
    t = (input().split(' '))
    t[1] = int(t[1])
    a.append(t)

b = deque()
s = 0
while len(a) != 0:
    t = a.popleft()
    if t[1] - q <= 0:
        b.append((t[0], t[1] + s))
        s += t[1]
    else:
        t[1] -= q
        s += q
        a.append(t)

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

Submission status: Accepted

Solution code:
from collections import deque

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

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

total = 0
while alist:
    curr = iter(alist)
    ob = next(curr)
    res = int(ob[1]) - q
    if res > 0:
        total += q
        ob[1] = res
        alist.append(ob)
        alist.popleft()
    else:
        total += q + res
        ob[1] = total
        endlist.append(ob)
        alist.popleft()

for x in endlist:
    print('{} {}'.format(x[0], x[1]))

Submission status: Accepted

Solution code:
#! /usr/local/bin/python3
# coding: utf-8

from collections import deque

def main():
    n, q = [int(x) for x in input().split()]

    proc = deque()

    for i in range(n):
        name, ptime = input().split()
        proc.appendleft((name, int(ptime)))

    time = 0
    while proc:
        name, ptime = proc.pop()
        time += min(q, ptime)
        ptime -= min(q, ptime)
        if ptime <= 0:
            print(name, time)
        else:
            proc.appendleft((name, ptime))

main()

Submission status: Accepted

Solution code:
n,q = map(int,input().split(" "))
#空のキューを用意
Q = []

# キューにプロセスと処理時間を追加
for i in range(n):
    process, time = input().split(" ")
    Q.append([process,int(time)])
    
total_time = 0
# キューが空になるまで繰り返す
while Q != []:
    # 先頭をdequeue
    p_t = Q.pop(0)
    # クオンタイム以下
    if p_t[1] <= q:
        total_time += p_t[1]
        print(p_t[0],total_time)
    # クオンタイムより大
    else: 
        total_time += q
        # 末尾にenqueue
        Q.append([p_t[0],p_t[1] - q])

Submission status: Accepted

Solution code:

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

list=[]
for i in range(n):
    x=input().split(" ")
    p=x[0]
    time=int(x[1])
    list.append([p,time])
 
time=0
while len(list)>0:
    if list[0][1]<=q:
        time+=list[0][1]
        print(list[0][0]+" "+str(time))
        list.pop(0)
    else:
        time+=q
        list[0][1]-=q
        list.append(list[0])
        list.pop(0)

Submission status: Accepted

Solution code:
from collections import deque

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


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

end_time = 0
while len(queue) > 0:
    p = queue.popleft()
    if p.time > q:
        p.time -= q
        end_time += q
        queue.append(p)
    else:
        end_time += p.time
        print('%s %d' % (p.name, end_time))

Submission status: Accepted

Solution code:
from collections import deque

def print_dict_multi_low(a_dict):
    for k, v in a_dict.items():
        print("{0} {1}".format(k, v))
        
def calc_round_robin(A, q):
    t = 0
    B = {}
    queue = deque([])
    for k, v in A.items():
        queue.append((k, v))
    
    while queue:
        k, v = queue.popleft()
        residual = int(v) - q
        if residual > 0:
            queue.append((k, residual))
            t += q
        else:
            t += (q + residual)
            B[k] = t
    print_dict_multi_low(B)

def read_n_lows_dict_input(n):
    a_dict = dict(input().split() for _ in range(n))
    return a_dict

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

calc_round_robin(A, q)

Submission status: Accepted

Solution code:
n, q = list(map(int, input().split()))
works = []
for i in range(n):
    works.append(list(input().split()))
 
count = 0
while len(works) != 0:
    work = works.pop(0)
    time = int(work[1])
    if time > q:
        count += q
        work[1] = time - q
        works.append(work)
    else:
        count += time
        print(work[0] , count)

Submission status: Accepted

Solution code:
from collections import deque
n, q = list(map(int, input().split()))
que = deque([])
for i in range(n):
  n, t = input().split()
  que.append((n, t))

e = 0
while len(que)>0:
  n, t = que.popleft()
  if int(t)<=q:
    e += int(t)
    print(n, e)
  else:
    e += q
    que.append((n, int(t)-q))

Submission status: Accepted

Solution code:
# Queue - Round-robin Scheduling
class Proc:
    def __init__(self, strs):
        self.name = strs[0]
        self.time = int(strs[1])
n,q = map(int, input().split(' '))
que = [Proc(input().split(' ')) for _ in range(n)]
proc_time = 0
while len(que) > 0:
    p = que.pop(0)
    if p.time <= q:
        proc_time += p.time
        print(p.name, proc_time)
    else:
        proc_time += q
        p.time -= q
        que.append(p)

Submission status: Runtime Error

Solution code:
import sys
n,q=map(int, input().split())
queue = list(map(lambda x: x.strip().split(),sys.stdin.readlines()))
i = 0
while len(queue) > 0:
    if queue[i%len(queue)][1]-=q < 0:
        print("{} {}".format(q[i%len(queue)][0], i*q + q + q[i%len(queue)][1]))
        q.pop(i%len(queue))
    i+=1

Submission status: Runtime Error

Solution code:
class a(object):
    def __init__(self, buf_size=10000):
        self.m = [None for _ in range(buf_size)]
        self.ind = 0
        self.cur = 0

    def enqueue(self, elem):
        self.m[self.ind] = elem
        self.ind += 1

    def dequeue(self):
        if self.is_empty(): raise EOFError('this queue is empty')
        result = self.m[self.cur]
        self.cur += 1
        return result

    def is_empty(self):
        return self.ind <=\
               self.cur

n, q = input().split()
qe = a()
cur_time = 0

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

while not qe.is_empty():
    name, time = qe.dequeue()
    if time > int(q):
        cur_time += int(q)
        time -= int(q)
        qe.enqueue((name, time))
    else:
        cur_time += int(time)
        print('{} {}'.format(name, cur_time))

Submission status: Runtime Error

Solution code:
class a(object):
    def __init__(self, buf_size=10000):
        self.m = [None for _ in range(buf_size)]
        self.ind = 0
        self.cur = 0

    def enqueue(self, elem):
        self.m[self.ind] = elem
        self.ind += 1

    def dequeue(self):
        if self.is_empty(): raise EOFError('this queue is empty')
        result = self.m[self.cur]
        self.cur += 1
        return result

    def is_empty(self):
        return self.ind <=\
               self.cur

n, q = input().split()
qe = a(n)
cur_time = 0

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

while not qe.is_empty():
    name, time = qe.dequeue()
    if time > int(q):
        cur_time += int(q)
        time -= int(q)
        qe.enqueue((name, time))
    else:
        cur_time += int(time)
        print('{} {}'.format(name, cur_time))

Submission status: Runtime Error

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

tmp =  [input().split() for i in range(n)]
a = [[name,int(time)] for name,time in tmp]

total_time = 0

count = 0
while(a):
    current = a.pop 
    if(current[1] > q):
        current[1] -= q
        a.append(current)
        total_time += q
    else:
        total_time += current[1]
        print(current[0],total_time,sep = " ")

Submission status: Runtime Error

Solution code:
class queue():
    def __init__(self):
        self.head = 0
        self.tail = 0
        self.MAX = 100000
        self.Q = [[0] for i in range(self.MAX-1)]

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

    def is_full(self):
        return self.head == (self.tail + 1) % self.MAX

    def enqueue(self, x):
        if self.is_full():
            raise ValueError("エラー（オーバーフロー）")
        self.Q[self.tail] = x
        if self.tail + 1 == self.MAX:
            self.tail = 0
        else:
            self.tail += 1

    def dequeue(self):
        if self.is_empty():
            raise ValueError("エラー（アンダーフロー）")
        x = self.Q[self.head]
        if self.head + 1 == self.MAX:
            self.head = 0
        else:
            self.head += 1
        return x

n, q = input().split(" ")
n = int(n)
q = int(q)
q_name = queue()
q_val = queue()
for i in range(n):
    name, t = input().split(" ")
    t = int(t)
    q_name.enqueue(name)
    q_val.enqueue(t)

results = []
end_time = 0
while True:
    process_val = q_val.dequeue()
    process_name = q_name.dequeue()
    if process_val <= q:
        end_time += process_val
        results.append([process_name, end_time])
    else:
        end_time += q
        rest_val = process_val - q
        q_name.enqueue(process_name)
        q_val.enqueue(rest_val)
    
    if q_val.head == q_val.tail:
        break

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

Submission status: Runtime Error

Solution code:
class queue():
    def __init__(self):
        self.head = 0
        self.tail = 0
        self.MAX = 100000
        self.Q = [[0] for i in range(self.MAX-1)]

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

    def is_full(self):
        return self.head == (self.tail + 1) % self.MAX

    def enqueue(self, x):
        if self.is_full():
            raise ValueError("エラー（オーバーフロー）")
        self.Q[self.tail] = x
        if self.tail + 1 == self.MAX:
            self.tail = 0
        else:
            self.tail += 1

    def dequeue(self):
        if self.is_empty():
            raise ValueError("エラー（アンダーフロー）")
        x = self.Q[self.head]
        if self.head + 1 == self.MAX:
            self.head = 0
        else:
            self.head += 1
        return x

n, q = input().split(" ")
n = int(n)
q = int(q)
q_name = queue()
q_val = queue()
for i in range(n):
    name, t = input().split(" ")
    t = long(t)
    q_name.enqueue(name)
    q_val.enqueue(t)

results = []
end_time = 0
while True:
    process_val = q_val.dequeue()
    process_name = q_name.dequeue()
    if process_val <= q:
        end_time += process_val
        results.append([process_name, end_time])
    else:
        end_time += q
        rest_val = process_val - q
        q_name.enqueue(process_name)
        q_val.enqueue(rest_val)
    
    if q_val.head == q_val.tail:
        break

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

Submission status: Runtime Error

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

t = 0
i = 0
while queue:
	p = queue[i % len(queue)]
	t += min(q, p[1])
	if p[1] > q:
		p[1] -= q
		i += 1
	else:
		print(p[0], t)
		queue.pop(i)

Submission status: Runtime Error

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

t = 0
i = 0
while queue:
	i %= len(queue)
	p = queue[i]
	t += min(q, p[1])
	if p[1] > q:
		p[1] -= q
		i += 1
	else:
		print(p[0], t)
		queue.pop(i)

Submission status: Runtime Error

Solution code:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>

using namespace std;

struct process {
    string name;
    int time;
};

class Queue {
    private:
        int head_;
        int tail_;

    public:
        process queue[100001];
        
        void initialize() {
            head_ = 0;
            tail_ = 0;    
        }

        bool isEmpty() {
            return head_ == tail_;
        }

        bool isFull() {
            return head_ == (tail_ + 1) % 100001;
        }

        void enqueue(struct process ps) {
            if (isFull()) {
                cout << "Warning, queue is full" << endl;
            }
            queue[tail_] = ps;
            if (tail_ + 1 == 100001) {
                tail_ = 0;
            }
            else {
                tail_++;
            }
        }

        process dequeue() {
            if (isEmpty()) {
                cout << "Warning, queue is empty" << endl;
            }
            process ps = queue[head_];
            if (head_ + 1 == 100001) {
                head_ = 0;
            }
            else {
                head_++;
            }
            return ps;
        }
};

void test(void) {
    process a = {"ABC", 123};
    Queue q;
    q.initialize();
    q.enqueue(a);
    q.enqueue({"BCD", 345});
    process y = q.dequeue();
    cout << y.name << endl;
    process z = q.dequeue();
    cout << z.name << endl;
}

int main(void) {
    int processNum, quantum;
    string processName;
    int processTime;
    int processTotalTime;

    cin >> processNum >> quantum;
    Queue processQ;

    processQ.initialize();

    // すべてのプロセスをキューに登録
    for (int i=0; i < processNum; i++) {
        cin >> processName >> processTime;
        processQ.enqueue( {processName, processTime} );
    }

    // シミュレーション
    while (processQ.isEmpty() == false) {
        process target = processQ.dequeue();
        
        if (target.time <= quantum) {
            processTotalTime += target.time;
            target.time = 0;
            cout << target.name << " "<< processTotalTime << endl;
        }
        else {
            processTotalTime += quantum;
            target.time -= quantum;
            processQ.enqueue(target);
        }

    }

    return 0;
}

Submission status: Runtime Error

Solution code:
from Queue import Queue

n, q = [ int( val ) for val in input( ).split( " " ) ]
names = Queue( )
times = Queue( )
for i in range( n ):
	name, time = input( ).split( " " )
	names.put( name )
	times.put( int( time ) )
 
qsum = 0
output = []
while not times.empty( ):
	name = names.get( )
	time = times.get( )
	if time <= q:
		qsum += time
		output.append( "{:s} {:d}".format( name, qsum ) )
	else:
		times.put( time - q )
		names.put( name )
		qsum += q

print( "\n".join( output ) )

Submission status: Runtime Error

Solution code:
kl=[]
n,p=map(int,raw_input().split())
for i in range(n):
	key,value=raw_input().split()
	dict.update({key:int(value)})
	kl.append(key)

cnt=0
time=0
while True:
	for k in kl:
		if dict[k]<=p:
			cnt+=dict[k]
			dict[k]=0
			print k,cnt
			del dict[k]
			kl.remove(k)
			time+=1
		else:
			dict[k]-=p
			cnt+=p
	if time==n: break

Submission status: Runtime Error

Solution code:
N_str, q_str = raw_input().spilit()
N = int(N_str)
q = int (q_str)
A =[]
B =[]
total =0

for i in N:
    t = raw_input().spilit()
    A.append(t[0],int(t[1]))

while A:
    name, time = A.pop(0)
    if time < q:
        total += time
        B.append(name, time)
       
    else:
        time -= q
        total += q
        A.append(name, time)

print " ".join()

Submission status: Runtime Error

Solution code:
N_str, q_str = raw_input().spilit()
N = int(N_str)
q = int (q_str)
A =[]
B =[]
total =0

for i in N:
    t = raw_input().spilit()
    A.append(t[0],int(t[1]))

while A:
    name, time = A.pop(0)
    if time < q:
        total += time
        B.append(name, time)
       
    else:
        time -= q
        total += q
        A.append(name, time)

print " ".join(B)

Submission status: Runtime Error

Solution code:
N_str, q_str = raw_input().spilit()
N = int(N_str)
q = int (q_str)
A =[]
B =[]
total =0

for i in N:
    t = raw_input().spilit()
    A.append(t[0],int(t[1]))

while A:
    name, time = A.pop(0)
    if time <= q:
        total += time
        B.append(name, time)
       
    else:
        time -= q
        total += q
        A.append(name, time)

print " ".join(B)

Submission status: Runtime Error

Solution code:
N_str, q_str = raw_input().spilit()
N = int(N_str)
q = int (q_str)
A =[]
B =[]
total =0

for i in N:
    t = raw_input().spilit()
    A.append(t[0],int(t[1]))

while A:
    name, time = A.pop(0)
    if time <= q:
        total += time
        B.append(name, time)
       
    else:
        time -= q
        total += q
        A.append([name, time])

print '\n'.join(B)

Submission status: Runtime Error

Solution code:
N_str, q_str = raw_input().spilit()
N = int(N_str)
q = int (q_str)
A =[]
B =[]
total =0

for i in N:
    t = raw_input().spilit()
    A.append(t[0],int(t[1]))

while A:
    name, time = A.pop(0)
    if time <= q:
        total += time
        B.append([name, time])
       
    else:
        time -= q
        total += q
        A.append([name, time])

print '\n'.join(B)

Submission status: Runtime Error

Solution code:
N_str, q_str = raw_input().spilit()
N = int(N_str)
q = int (q_str)
A =[]
B =[]
total =0

for i in N:
    t = raw_input().spilit()
    A.append(t[0],int(t[1]))

while A:
    name, time = A.pop(0)
    if time <= q:
        total += time
        B.append(name+" "+ str(total))
       
    else:
        time -= q
        total += q
        A.append([name, time])

print '\n'.join(B)

Submission status: Runtime Error

Solution code:
N_str, q_str = raw_input().spilit()
N = int(N_str)
q = int (q_str)
A =[]
B =[]
total =0

for i in N:
    t = raw_input().spilit()
    A.append([t[0],int(t[1])])

while A:
    name, time = A.pop(0)
    if time <= q:
        total += time
        B.append(name+" "+ str(total))
       
    else:
        time -= q
        total += q
        A.append([name, time])

print '\n'.join(B)

Submission status: Runtime Error

Solution code:
N_str, q_str = raw_input().split()
N = int(N_str)
q = int (q_str)
A =[]
B =[]
total =0

for i in N:
    t = raw_input().spilit()
    A.append([t[0],int(t[1])])

while A:
    name, time = A.pop(0)
    if time <= q:
        total += time
        B.append(name+" "+ str(total))
       
    else:
        time -= q
        total += q
        A.append([name, time])

print '\n'.join(B)

Submission status: Runtime Error

Solution code:
N_str, q_str = raw_input().split()
N = int(N_str)
q = int (q_str)
A =[]
B =[]
total =0

for i in N:
    t = raw_input().split()
    A.append([t[0],int(t[1])])

while A:
    name, time = A.pop(0)
    if time <= q:
        total += time
        B.append(name+" "+ str(total))
       
    else:
        time -= q
        total += q
        A.append([name, time])

print '\n'.join(B)

Submission status: Runtime Error

Solution code:
N_str, q_str = raw_input().split()
N = int(N_str)
q = in(q_str)
A =[]
B =[]
total =0

for i in N:
    t = raw_input().split()
    A.append([t[0],int(t[1])])

while A:
    name, time = A.pop(0)
    if time <= q:
        total += time
        B.append(name+" "+ str(total))
       
    else:
        time -= q
        total += q
        A.append([name, time])

print '\n'.join(B)

Submission status: Runtime Error

Solution code:
N_str, q_str = raw_input().split()
N = int(N_str)
q = int(q_str)
A =[]
B =[]
total =0

for i in N:
    t = raw_input().split()
    A.append([t[0],int(t[1])])

while A:
    name, time = A.pop(0)
    if time <= q:
        total += time
        B.append(name+" "+ str(total))
       
    else:
        time -= q
        total += q
        A.append([name, time])

print '\n'.join(B)

Submission status: Runtime Error

Solution code:
import sys

def isEmpty(S):
  if len(S) == 0:
    return True

def enqueue(x):
  x_list_list.append(x)

def dequeue(x_list_list):
  if isEmpty(x_list_list):
    print 'Error'
  del_list = x_list_list[0]
  x_list_list.pop(0)
  return(del_list)

y = sys.stdin.readline()
a, b = y.split(" ")
a = int(a)
b = int(b)

S = []
x_list_list = []

for i in range(a):
  text = raw_input()
  x_list = text.split()
  x_list[1] = int(x_list[1])
  x_list.append(0)
  x_list_list.append(x_list)

flag = a
while flag != 0:
  if int(x_list_list[0][1]) > b:
    x_list_list[0][1] -= int(b)
    for j in range(flag):
      x_list_list[j][2] += b
    del_list = dequeue(x_list_list)
    enqueue(del_list)
  elif int(x_list[0][1]) <= b:
    for j in range(flag):
      x_list_list[j][2] += x_list_list[0][1]
    x_list_list[0][1] = 0
    flag -= 1
    print x_list_list[0][0],x_list_list[0][2]
    dequeue(x_list_list)

Submission status: Runtime Error

Solution code:
import sys

def isEmpty(S):
  if len(S) == 0:
    return True

def isFull(S):
  if len(S) >= 100000
    return True

def enqueue(x):
  if isFull(x_list_list):
    print 'Error'
  x_list_list.append(x)

def dequeue(x_list_list):
  if isEmpty(x_list_list):
    print 'Error'
  del_list = x_list_list[0]
  x_list_list.pop(0)
  return(del_list)

y = sys.stdin.readline()
a, b = y.split(" ")
a = int(a)
b = int(b)

S = []
x_list_list = []

for i in range(a):
  text = raw_input()
  x_list = text.split()
  x_list[1] = int(x_list[1])
  x_list.append(0)
  x_list_list.append(x_list)

flag = a
while flag != 0:
  if int(x_list_list[0][1]) > b:
    x_list_list[0][1] -= int(b)
    for j in range(flag):
      x_list_list[j][2] += b
    del_list = dequeue(x_list_list)
    enqueue(del_list)
  elif int(x_list[0][1]) <= b:
    for j in range(flag):
      x_list_list[j][2] += x_list_list[0][1]
    x_list_list[0][1] = 0
    flag -= 1
    print x_list_list[0][0],x_list_list[0][2]
    dequeue(x_list_list)

Submission status: Runtime Error

Solution code:
import sys

def isEmpty(S):
  if len(S) == 0:
    return True

def isFull(S):
  if len(S) >= 100000:
    return True

def enqueue(x):
  if isFull(x_list_list):
    print 'Error'
  x_list_list.append(x)

def dequeue(x_list_list):
  if isEmpty(x_list_list):
    print 'Error'
  del_list = x_list_list[0]
  x_list_list.pop(0)
  return(del_list)

y = sys.stdin.readline()
a, b = y.split(" ")
a = int(a)
b = int(b)

S = []
x_list_list = []

for i in range(a):
  text = raw_input()
  x_list = text.split()
  x_list[1] = int(x_list[1])
  x_list.append(0)
  x_list_list.append(x_list)

flag = a
while flag != 0:
  if int(x_list_list[0][1]) > b:
    x_list_list[0][1] -= int(b)
    for j in range(flag):
      x_list_list[j][2] += b
    del_list = dequeue(x_list_list)
    enqueue(del_list)
  elif int(x_list[0][1]) <= b:
    for j in range(flag):
      x_list_list[j][2] += x_list_list[0][1]
    x_list_list[0][1] = 0
    flag -= 1
    print x_list_list[0][0],x_list_list[0][2]
    dequeue(x_list_list)

Submission status: Runtime Error

Solution code:
import sys

def isEmpty(S):
  if len(S) == -1:
    return True

def isFull(S):
  if len(S) >= 100000:
    return True

def enqueue(x):
  if isFull(x_list_list):
    print 'Error'
  x_list_list.append(x)

def dequeue(x_list_list):
  if isEmpty(x_list_list):
    print 'Error'
  del_list = x_list_list[0]
  x_list_list.pop(0)
  return(del_list)

y = sys.stdin.readline()
a, b = y.split(" ")
a = int(a)
b = int(b)

S = []
x_list_list = []

for i in range(a):
  text = raw_input()
  x_list = text.split()
  x_list[1] = int(x_list[1])
  x_list.append(0)
  x_list_list.append(x_list)

flag = a
while flag != 0:
  if int(x_list_list[0][1]) > b:
    x_list_list[0][1] -= int(b)
    for j in range(flag):
      x_list_list[j][2] += b
    del_list = dequeue(x_list_list)
    enqueue(del_list)
  elif int(x_list[0][1]) <= b:
    for j in range(flag):
      x_list_list[j][2] += x_list_list[0][1]
    x_list_list[0][1] = 0
    flag -= 1
    print x_list_list[0][0],x_list_list[0][2]
    dequeue(x_list_list)

Submission status: Runtime Error

Solution code:
import sys



def enqueue(x):
  x_list_list.append(x)

def dequeue(x_list_list):

  del_list = x_list_list[0]
  x_list_list.pop(0)
  return(del_list)

y = sys.stdin.readline()
a, b = y.split(" ")
a = int(a)
b = int(b)

S = []
x_list_list = []

for i in range(a):
  text = raw_input()
  x_list = text.split()
  x_list[1] = int(x_list[1])
  x_list.append(0)
  x_list_list.append(x_list)

flag = a
while flag != 0:
  if int(x_list_list[0][1]) > b:
    x_list_list[0][1] -= int(b)
    for j in range(flag):
      x_list_list[j][2] += b
    del_list = dequeue(x_list_list)
    enqueue(del_list)
  elif int(x_list[0][1]) <= b:
    for j in range(flag):
      x_list_list[j][2] += x_list_list[0][1]
    x_list_list[0][1] = 0
    flag -= 1
    print x_list_list[0][0],x_list_list[0][2]
    dequeue(x_list_list)

Submission status: Runtime Error

Solution code:
import sys

def isEmpty(S):
  if len(S) == 0:
    return True

def isFull(S):
  if len(S) >= 100000:
    return True

def enqueue(x):
  if isFull(x_list_list):
    print 'Error'
  x_list_list.append(x)

def dequeue(x_list_list):
  if isEmpty(x_list_list):
    print 'Error'
  del_list = x_list_list[0]
  x_list_list.pop(0)
  return(del_list)

y = sys.stdin.readline()
a, b = y.split(" ")
a = int(a)
b = int(b)

S = []
x_list_list = []

for i in range(a):
  text = raw_input()
  x_list = text.split()
  x_list[1] = int(x_list[1])
  x_list.append(0)
  x_list_list.append(x_list)

flag = a
while flag != 0:
  if int(x_list_list[0][1]) > b:
    x_list_list[0][1] -= int(b)
    for j in range(flag):
      x_list_list[j][2] += b
    del_list = dequeue(x_list_list)
    enqueue(del_list)
  elif int(x_list[0][1]) <= b:
    for j in range(flag):
      x_list_list[j][2] += x_list_list[0][1]
    x_list_list[0][1] = 0
    flag -= 1
    print x_list_list[0][0],x_list_list[0][2]
    dequeue(x_list_list)

Submission status: Runtime Error

Solution code:
N = int(raw_input())
A = []
B = []

def insert(B, x):
    B.insert(0, x)
    return B
def delete(B, x):
    i = 0
    for num in B:
        if num == x:
            B.pop(i)
            break
        i += 1
    return B
def deleteFirst(B):
    B.pop(0)
    return B
def deleteLast(B):
    B.pop()
    return B
operation = {'insert':insert, 'delete':delete, 'deleteFirst':deleteFirst, 'deleteLast':deleteLast}

for i in range(N):
    a = raw_input().split()
    if len(a) == 2:
        A.append([a[0], int(a[1])])
    else:
        A.append([a[0]])


for item in A:
    if len(item) == 2:
        command, num = item
        B = operation[command](B, num)
    else:
        command = item[0]
        B = operation[command](B)

print B