stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <iostream>

#include <algorithm>



using namespace std;



const int MAXN = 100000 + 5;



struct process {

  string name;

  int time;

};



process Q[MAXN];

int head, tail;

int n, q, total_time = 0;



void enqueue(process x) {

  Q[tail] = x;

  tail++;

  tail %= MAXN;

}



process dequeue() {

  process x = Q[head];

  head++;

  head %= MAXN;

  return x;

}



bool isEmpty() {

  return head == tail;

}



int main() {

  cin >> n >> q;

  for (int i = 0; i < n; i++) {

    cin >> Q[i].name >> Q[i].time;

  }

  head = 0, tail = n;

  while (!isEmpty()) {

    process crt = dequeue();

    int need = min(crt.time, q);

    crt.time -= need;

    total_time += need;

    if (crt.time == 0) {

      cout << crt.name << " " << total_time << endl;

    } else {

      enqueue(crt);

    }

  }

  return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.394949482923383x):
#include<iostream>

#include<cstdio>

#include<algorithm>

using namespace std;



const int maxx = 100000 + 10;

struct task {

    // 任务的名字和耗费的时间

    char name[100];

    int t;

};

task Queue[maxx];



// 指向队头和队尾的指针

int head, tail;





// 判断循环队列是否已满

bool isFull() {

    return head == (tail + 1) % maxx;

}



// 判断循环队列是否为空

bool isEmpty() {

    return head == tail;

}



// 将元素x添加到队列的末尾

void enqueue(task x) {

    Queue[tail] = x;

    // 循环队列

    tail = (tail + 1) % maxx;

}



// 返回队头元素并删除

task dequeue() {

    task x = Queue[head];

    // 循环队列

    head = (head + 1) % maxx;

    return x;

}

int main() {

    int n, q;

    scanf("%d %d", &n, &q);

    for (int i = 0; i < n; i++) {

        scanf("%s %d", Queue[i].name, &Queue[i].t);

    }

    // 当前已经有n个元素

    head = 0; tail = n;

    // 当前时间

    int nowtime = 0;

    while (!isEmpty()) {

        // 取出队头

        task u = dequeue();

        // 执行时间片 p 和 所需要时间u.t

        int c = min(q, u.t);

        // 任务执行了 c ms

        u.t -= c;

        // 当前时间加上c ms

        nowtime += c;

        // 任务还没做完，加入到队尾

        if (u.t > 0) {

            enqueue(u);

        }

        else { // 任务已经完成，打印出结果

            printf("%s %d\n", u.name, nowtime);

        }



    }

    return 0;

}
// Slower C++ solution:
#include <iostream>

#include <string>

#include <list>

#include <iterator>

using namespace std;



int main() {

    string name;

    int i,n,q,time,elapsedt = 0;

    list<pair<string,int> > que,ans;

    list<pair<string,int> >::iterator it;

    cin>>n>>q;

    for(i=0;i<n;i++) {

        cin>>name>>time;

        que.push_back(make_pair(name,time));

    }

    it = que.begin();

    while(!que.empty()){

        if((*it).second <= q) {

            elapsedt += (*it).second;

            ans.push_back(make_pair((*it).first,elapsedt));

            it = que.erase(it);

        } else {

            elapsedt += q;

            (*it).second -= q;

            it++;

        }

        if (it == que.end()) it=que.begin();

    }

    for(it=ans.begin();it!=ans.end();it++) {

        cout<<(*it).first<<" "<<(*it).second<<endl;

    }

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.207158868744661x):
#include <cstdio>

#include <cstring>

using namespace std;



#define QUE_SIZE 1000000

typedef struct {

    char name[10];

    int time;

} QUE;

QUE que[QUE_SIZE];



int main() {

    int i,j,n,q,time=0,head=0,tail;

    char name[10];

    scanf("%d %d", &n, &q);

    tail=n;

    for(i=0;i<n;i++){

        scanf("%s %d", name, &time);

        for (j=0;j<strlen(name);j++) que[i].name[j] = name[j];

        que[i].time = time;

    }

    time=0;

    while(head!=tail){

        if(que[head].time <= q || (QUE_SIZE+tail-head)%QUE_SIZE == 1) {

            time += que[head].time;

            printf("%s %d\n", que[head].name, time);

            head = (head+1)%QUE_SIZE;

        } else {

            time += q;

            for (j=0;j<strlen(name);j++) que[tail].name[j] = que[head].name[j];

            que[tail].time = que[head].time - q;

            head = (head+1)%QUE_SIZE;

            tail = (tail+1)%QUE_SIZE;

        }

    }

    return 0;

}
// Slower C++ solution:
#include <iostream>

#include <string>

#include <list>

#include <iterator>

using namespace std;



int main() {

    string name;

    int i,n,q,time,elapsedt = 0;

    list<pair<string,int> > que,ans;

    list<pair<string,int> >::iterator it;

    cin>>n>>q;

    for(i=0;i<n;i++) {

        cin>>name>>time;

        que.push_back(make_pair(name,time));

    }

    it = que.begin();

    while(!que.empty()){

        if((*it).second <= q) {

            elapsedt += (*it).second;

            ans.push_back(make_pair((*it).first,elapsedt));

            it = que.erase(it);

        } else {

            elapsedt += q;

            (*it).second -= q;

            it++;

        }

        if (it == que.end()) it=que.begin();

    }

    for(it=ans.begin();it!=ans.end();it++) {

        cout<<(*it).first<<" "<<(*it).second<<endl;

    }

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.21874354998549x):
#include <cstdio>

#include <cstring>

using namespace std;



#define QUE_SIZE 1000000

typedef struct {

    char name[10];

    int time;

} QUE;

QUE que[QUE_SIZE];



int main() {

    int i,j,n,q,time=0,head=0,tail;

    char name[10];

    scanf("%d %d", &n, &q);

    tail=n;

    for(i=0;i<n;i++) scanf("%s %d", que[i].name, &que[i].time);

    time=0;

    while(head!=tail){

        if(que[head].time <= q || (QUE_SIZE+tail-head)%QUE_SIZE == 1) {

            time += que[head].time;

            printf("%s %d\n", que[head].name, time);

            head = (head+1)%QUE_SIZE;

        } else {

            time += q;

            que[head].time -= q;

            que[tail] = que[head];

            head = (head+1)%QUE_SIZE;

            tail = (tail+1)%QUE_SIZE;

        }

    }

    return 0;

}
// Slower C++ solution:
#include <iostream>

#include <string>

#include <list>

#include <iterator>

using namespace std;



int main() {

    string name;

    int i,n,q,time,elapsedt = 0;

    list<pair<string,int> > que,ans;

    list<pair<string,int> >::iterator it;

    cin>>n>>q;

    for(i=0;i<n;i++) {

        cin>>name>>time;

        que.push_back(make_pair(name,time));

    }

    it = que.begin();

    while(!que.empty()){

        if((*it).second <= q) {

            elapsedt += (*it).second;

            ans.push_back(make_pair((*it).first,elapsedt));

            it = que.erase(it);

        } else {

            elapsedt += q;

            (*it).second -= q;

            it++;

        }

        if (it == que.end()) it=que.begin();

    }

    for(it=ans.begin();it!=ans.end();it++) {

        cout<<(*it).first<<" "<<(*it).second<<endl;

    }

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.217695485294112x):
#include <cstdio>

#include <cstring>

using namespace std;



#define QUE_SIZE 1000000

typedef struct {

    char name[10];

    int time;

} QUE;

QUE que[QUE_SIZE];



int main() {

    int i,n,q,time=0,head=0,tail;

    char name[10];

    scanf("%d %d", &n, &q);

    tail=n;

    for(i=0;i<n;i++) scanf("%s %d", que[i].name, &que[i].time);

    time=0;

    while(head!=tail){

        if(que[head].time <= q || (QUE_SIZE+tail-head)%QUE_SIZE == 1) {

            time += que[head].time;

            printf("%s %d\n", que[head].name, time);

            head = (head+1)==QUE_SIZE?0:(head+1);

        } else {

            time += q;

            que[head].time -= q;

            que[tail] = que[head];

            head = (head+1)==QUE_SIZE?0:(head+1);

            tail = (tail+1)==QUE_SIZE?0:(tail+1);

        }

    }

    return 0;

}
// Slower C++ solution:
#include <iostream>

#include <string>



#define LEN 100005

using namespace std;





typedef struct pp

{

	string name;

	int time;

} P;



P Q[LEN+1];

int head, tail;



void enqueue(P x)

{

	Q[tail] = x;

	tail = (tail+1)%LEN;

}



P dequeue()

{

	P x = Q[head];

	head = (head+1)%LEN;

	return x;

}



int main()

{

	int n, q;

	cin >> n >> q;

	for (int i = 0; i < n; i++)

		cin >> Q[i].name >> Q[i].time;

	head = 0, tail = n;

	int elaps = 0, c;

	P temp;

	while (head != tail)

	{

		temp = dequeue();

		c = min(temp.time, q);

		temp.time -= c;

		elaps += c;

		if (temp.time)

			enqueue(temp);

		else 

			cout << temp.name << " " << elaps << endl;

	}

	return 0;

}




// Faster C++ solution for the same problem (measured speedup: 5.240282275870327x):
#include<iostream>

#include<string>

#include<queue>



using namespace std;



int main()

{

	int n, q, time, k, elaps = 0;

	queue<pair<string, int>> Q;

	string name; 

	cin >> n >> q;

	for (int i = 0; i < n; i++)

	{

		cin >> name >> time;

		Q.push(make_pair(name, time));

	}

	pair <string, int> u;

	while (!Q.empty())

	{

		u = Q.front();

		Q.pop();

		k = min(u.second, q);

		elaps += k;

		u.second -= k;

		if (u.second)

			Q.push(u);

		else

			cout << u.first << " " << elaps << endl;

	}

}
// Slower C++ solution:
#include<iostream>

#include<string>

using namespace std;



class task {

public:

	void input(string n, int time) {

		name = n;

		endTime = time;

	}



	int  timeReduce(int q) {

		endTime -= q;

		return endTime;

	}



	string getName() {

		return name;

	}

	

//	void setName(char n[]) {

////		name = n;

//		strcpy(name.c_str, n);

//	}



	int getTime() {

		return endTime;

	}



	void setTime(int t) {

		endTime = t;

	}



//private:

	string name;

	int endTime;

};



class queue {

public:

	queue(int h, int t) {

		m_iHead = h;

		m_iTail = t;

	}



	bool isEmpty() {

		return m_iHead == m_iTail;

	}



	bool isFull() {

		return m_iHead == (m_iTail + 1) % m_iMAX;

	}



	void enqueue(task x) {

		if (isFull()) return;

		Q[m_iTail] = x;

		if (m_iTail + 1 == m_iMAX) {

			m_iTail = 0;

		}

		else {

			m_iTail++;

		}

	}



	 task dequeue() {

		 task t;

		 if (isEmpty()) return t;

		t = Q[m_iHead];

		if (m_iHead + 1 == m_iMAX) {

			m_iHead = 0;

		}

		else {

			m_iHead++;

		}

		return t;

	}



	 task * getQ() {

		 return Q;

	 }



private:

	task Q[100000];

	int m_iHead;

	int m_iTail;

	const int m_iMAX = 100000;

};



int main() {

	int proces; //??????????????°

	int quwontum;

	int elaps = 0;



	cin >> proces;

	cin >> quwontum;

	queue  *pQ = new queue(0, proces);

	for (int i = 0; i < proces; i++) {

		//string sTemp;

		//int iTemp;

		cin >> pQ->getQ()[i].name;

		cin >> pQ->getQ()[i].endTime;

		//pQ->getQ()[i]->name;

		//pQ->getQ()[i]->endTime;

	}



	while (!pQ->isEmpty()) {

		task t = pQ->dequeue();

		int eT = quwontum < t.endTime ? quwontum : t.endTime;

		t.endTime -= eT;

		elaps += eT;

		if (t.endTime > 0) {

			pQ->enqueue(t);

		}

		else {

			cout << t.name << " " << elaps << endl;

		}

	}



	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.988852071911409x):
#include<iostream>

#include<queue>

#include<string>

using namespace std;



//class node {

//public:

//	string name;

//	int time;

//};



int main() {

	queue<pair<string, int>> qu;

	int numNode;

	int qwon;



	cin >> numNode >> qwon;

	for (int i = 0; i < numNode; i++) {

		string name;

		int time;

		cin >> name >> time;

		qu.push(make_pair(name, time));

	}



	int elaps = 0;

	while (!qu.empty()) {

		pair<string, int> q = qu.front();

		qu.pop();

		int t = q.second < qwon ? q.second : qwon;

		q.second -= t;

		elaps += t;



		if (q.second > 0) {

			qu.push(q);

		}

		else {

			cout << q.first << " " << elaps << endl;

		}

	}

	return 0;

}
// Slower C++ solution:
#include <iostream>

#include <string>

#include <queue>

#include <algorithm>

using namespace std;



int main() {

  int n, q, t;

  string name;



  queue<pair<string, int> > Q;



  cin >> n >> q;



  for ( int i = 0; i < n; i++ ) {

    cin >> name >> t;

    Q.push(make_pair(name, t));

  }



  pair<string, int> u;

  int elaps = 0, a;



  while ( !Q.empty() ) {

    u = Q.front(); Q.pop();

    a = min(u.second, q);

    u.second -= a;

    elaps += a;

    if ( u.second > 0 ) {

      Q.push(u);

    } else {

      cout << u.first << " " << elaps << endl;

    }

  }



  return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.258585505819329x):
#include<stdio.h>



#define LIM 1000001

struct Process {

  char name[11];

  int time;

};

Process A[LIM];





class Queue {

  int head, tail;

  public:

  Queue() {

    head = 0;

    tail = 0;

  }

  void enqueue(Process p) {

    A[tail] = p;

    tail = (tail + 1) % LIM;

  }

  Process dequeue() {

    Process p = A[head];

    head = (head + 1) % LIM;

    return p;

  }

  bool empty() {

    return head == tail;

  }

};

int main() {

  int n, q, sum = 0;

  Process p;

  Queue queue;



  scanf("%d %d", &n, &q);



  for ( int i = 0; i < n; i++ ) {

    scanf("%s %d", p.name, &p.time);

    queue.enqueue(p);

  }



  while(!queue.empty()) {

    p = queue.dequeue();

    bool running_out = p.time <= q;

    if (running_out) {

      sum += p.time;

      printf("%s %d\n", p.name, sum);

    } else {

      p.time -= q;

      sum += q;

      queue.enqueue(p);

    }

  }



  return 0;

}
// Slower C++ solution:
#include <iostream>

#include <algorithm>



#define MAX 100005



using namespace std;



struct process{

    int time;

    string name;

};



class my_queue{

private:

    int head, tail;

    process queue[MAX];





public:

    my_queue()

    {

        head = 0;

        tail = 0;

    }



    bool isEmpty()

    {

        return head == tail;

    }



    bool isFull()

    {

        return head == (tail + 1) % MAX;

    }



    void enqueue(process n)

    {

        if(isFull())

        {

            cout << "Queue is full." << endl;

            return;

        }

        queue[tail++] = n;



        if(tail == MAX) tail = 0;



        return;

    }



    process dequeue()

    {

        if(isEmpty())

        {

            cout << "Queue is empty." << endl;

            exit(-1);

        }

        

        process ret = queue[head];



        if(head+1 == MAX) head = 0;

        else head++;



        return ret;

    }

};



int main(void)

{

    my_queue queue;

    process proc;

    int n, q;

    int time = 0;



    cin >> n >> q;

    for(int i = 0; i < n; i++)

    {

        cin >> proc.name >> proc.time;

        queue.enqueue(proc);

    }



    while(!queue.isEmpty())

    {

        proc = queue.dequeue();

        if(proc.time <= q)

        {

            time += proc.time;

            cout << proc.name << " " << time << endl;

        }

        else

        {

            proc.time = proc.time - q;

            queue.enqueue(proc);

            time += q;

        }

    }



    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.289538189843059x):
#include <iostream>

#include <string>

#include <queue>



using namespace std;



struct process {

    string name;

    int time;

};



int main(void) {

    int n, q;

    int time = 0;

    queue<process> p;



    cin >> n >> q;

    for (int i = 0; i < n; i++) {

        process temp;

        cin >> temp.name >> temp.time;

        p.push(temp);

    }

    while (not p.empty()) {

        process top = p.front();

        p.pop();

        if (top.time <= q) {

            time += top.time;

            cout << top.name << " " << time << endl;

        }

        else {

            time += q;

            top.time -= q;

            p.push(top);

        }

    }

    

    return 0;

}
// Slower C++ solution:
#include <iostream>

#include <queue>

#include <utility>

using namespace std;



typedef pair<string, int> ps;



int main()

{

	cin.tie(0);

	ios::sync_with_stdio(false);



	queue<ps> Q;

	int n, q, st = 0;

	cin >> n >> q;



	ps p;

	while (n--) {

		cin >> p.first >> p.second;

		Q.push(p);

	}



	while (!Q.empty()) {

		p = Q.front();

		Q.pop();

		if (p.second <= q) {

			st += p.second;

			cout << p.first << " " << st << endl;

		} else {

			st += q;

			p.second -= q;

			Q.push(p);

		}

	}

}


// Faster C++ solution for the same problem (measured speedup: 1.1061153382443611x):
#include <cstdio>

#include <queue>

#include <utility>

using namespace std;



typedef pair<char[11], int> ps;



int main()

{

	queue<ps> Q;

	int n, q, st = 0;

	scanf("%d %d", &n, &q);



	ps p;

	while (n--) {

		scanf("%s %d", p.first, &p.second);

		Q.push(p);

	}



	while (!Q.empty()) {

		ps t = Q.front();

		Q.pop();

		if (t.second <= q) {

			st += t.second;

			printf("%s %d\n", t.first, st);

		} else {

			st += q;

			t.second -= q;

			Q.push(t);

		}

	}

}
// Slower C++ solution:
#include<iostream>

#define SIZE 200000

using namespace std;

  

struct Queue{

  int table[SIZE];

  int tail,head;

  

  void init(){

    head=tail=0;

  }

  

  bool empty(){

    return head==tail;

  }

    

  void inqueue(int x){

    table[tail]=x;

    tail++;

    tail%=SIZE;

  }

  

  int dequeue(){

    if(empty())return 0;

    int res=table[head];

    head++;

    head%=SIZE;

    return res;

  }

};

  

int main(){

  Queue queue,queue2;

  int n,q,num;

  string table[SIZE];

  cin>>n>>q;

  queue.init();

  queue2.init();

  for(int i=0;i<n;i++){

    cin>>table[i]>>num;

    queue.inqueue(num);

    queue2.inqueue(i);

  }

    

  int now=0,A,B;

  while(!queue.empty()){

    A=queue.dequeue();

    B=queue2.dequeue();

    if(A<=q){

      now+=A;

      cout<<table[B]<<' '<<now<<endl;

    }else{

      now+=q;

      A-=q;

      queue.inqueue(A);

      queue2.inqueue(B);

    }

  }

    

  return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.3572109114717288x):
#include <iostream>

#include <string>

#include <sstream>

#define MAX 100000

using namespace std;



struct Queue{

    int head;

    int tail;

    int q[MAX];



    void initialize(){

        head = 0;

        tail = 0;

    }

    bool isEmpty(){

        return (head == tail);

    }

    bool isFull(){

        return (head == (tail+1)%MAX);

    }

    void enqueue(int x){

        if(isFull()){

            cout << "queue overflow\n";

            //exit(0);

        }

        q[tail] = x;

        if(tail == MAX-1){

            tail = 0;

        }

        else{

            tail += 1;

        }

    }

    int dequeue(){

        if(isEmpty()){

            cout << "queue underflow\n";

            //exit(0);

        }

        int x = q[head];

        if(head == MAX-1){

            head = 0;

        }

        else{

            head += 1;

        }

        return x;

    }

};



void calc(Queue q_name, string name[], Queue q_time, int quantum){

    int t_sum = 0;

    while(q_name.head != q_name.tail){

        if(q_time.q[q_time.head] <= quantum){

            t_sum += q_time.dequeue();

            int i_name = q_name.dequeue();

            cout << name[i_name] << " " << t_sum << '\n';

        }

        else{

            t_sum += quantum;

            q_name.enqueue(q_name.q[q_name.head]);

            q_time.enqueue(q_time.q[q_time.head]-quantum);



            if(q_name.head == MAX-1){

                q_name.head = 0;

                q_time.head = 0;

            }

            else{

                q_name.head += 1;

                q_time.head += 1;

            }

        }

    }

}



int main(){

    Queue q_name, q_time;

    int num, quantum;

    string name[MAX];

    int t;



    q_name.initialize();

    q_time.initialize();



    cin >> num >> quantum;

    for(int i=0; i<num; i++){

        string str;

        cin >> str;

        name[i] = str;

        cin >> t;

        q_name.enqueue(i);

        q_time.enqueue(t);

    }



    calc(q_name, name, q_time, quantum);



    return 0;

}
// Slower C++ solution:
#include <algorithm>

#include <functional>

#include <cmath>

#include <cstdio>

#include <cstdlib>

#include <cstring>

#include <string>

#include <sstream>

#include <iostream>

#include <iomanip>

#include <vector>

#include <list>

#include <stack>

#include <map>

#include <set>

#include <bitset>

#include <climits>



#define all(c) (c).begin(), (c).end()

#define rep(i,n) for(int i=0;i<(n);i++)

#define pb(e) push_back(e)

#define mp(a, b) make_pair(a, b)

#define fr first

#define sc second



const int INF=100000000;

int dx[4]={1,0,-1,0};

int dy[4]={0,1,0,-1};

using namespace std;

typedef pair<int ,int > P;

typedef long long ll;



template<class T, int N=100000>

class Queue {

private:

    T ary[N];

    int head,tail;

public:

    Queue() : head(0),tail(0) {}

    bool is_empty() {

        return head == tail;

    }

    void enqueue(T x) {

        ary[tail++] = x;

        tail %= N;

    }

    T dequeue() {

        T x = ary[head++];

        head %= N;

        return x;

    }

};



struct Job {

    string name;

    int time;

};

Job job[100005];

int main() {

    int n,q;

    cin>>n>>q;

    rep(i,n) cin>>job[i].name>>job[i].time;

    Queue<Job> que;

    rep(i,n) que.enqueue(job[i]);

    int total = 0;

    while(!que.is_empty()) {

        Job t = que.dequeue();

        total += min(t.time,q);

        t.time -= q;

        if(t.time > 0) {

            que.enqueue(t);

        }

        else {

            cout<<t.name<<" "<<total<<endl;

        }

    }

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.8736141764698244x):
#include <iostream>

#include <queue>

#include <string>



#define rep(i, n) for (int i = 0; i < (n); i++)



using namespace std;



struct Job {

    string name;

    int time;

};

Job job[100005];

int main() {

    int n, q;

    cin >> n >> q;

    rep(i, n) cin >> job[i].name >> job[i].time;

    queue<Job> que;

    rep(i, n) que.push(job[i]);

    int total = 0;

    while (!que.empty()) {

        Job t = que.front();

        que.pop();

        total += min(t.time, q);

        t.time -= q;

        if (t.time > 0) {

            que.push(t);

        } else {

            cout << t.name << " " << total << endl;

        }

    }

    return 0;

}
// Slower C++ solution:
#include <iostream>

#include <string>

#include <algorithm>



#define LEN 100000

using namespace std;



class Pro{

public:

	string name;

	int time;

};



class Que{

	Pro* p = new Pro[LEN];

public:

	~Que(){ delete[] p; }

	int head=0, tail=0, n;

	void enqueue(Pro x){

		p[tail] = x;

		tail = (tail + 1) % LEN;

	}



	Pro dequeue(){

		Pro x = p[head];

		head = (head + 1) % LEN;

		return x;

	}

};





int main()

{

	int n;//??????????????°

	cin >> n;

	int q;//?????????????????????

	cin >> q;

	

	Que Q;

	for (int i = 0; i < n; i++){

		Pro x;

		cin >> x.name;

		cin >> x.time;

		Q.enqueue(x);

	}



	//????????????

	int t=0;



	while (Q.head != Q.tail){

		Pro c;

		c = Q.dequeue();

		int b = min(c.time, q);

		c.time -= b;

		t += b;



		if (c.time > 0) {

			Q.enqueue(c);

		}

		else{

		cout << c.name << ' ' << t << '\n';

		}

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.325985645005993x):
#include <iostream>

#include <algorithm>

#define LEN 100005

using namespace std;



//?????????????????¨????§???????

typedef struct pp{

	char name[100];

	int t;

}P;



P Q[LEN];

int head, tail, n;



void enqueue(P x){

	Q[tail] = x;

	tail = (tail + 1) % LEN;

}



P dequeue(){

	P ret = Q[head];

	head = (head + 1) % LEN;

	return ret;

}



int main()

{

	//??????????????°

	int n;



	//???????????????

	int q;



	cin >> n;

	cin >> q;



	for (int i = 1; i <= n; i++){

		cin >> Q[i].name;

		cin >> Q[i].t;

	}



	head = 1;

	tail = n + 1;



	//????????????

	int elaps = 0;



	//sim

	while (tail != head){

		P u = dequeue();



		//??°????°?????????????????????¨

		int c = min(u.t, q);



		//?????????????¨????

		u.t -= c;



		//?????????????????????

		elaps += c;



		if (u.t > 0){

			enqueue(u);

		}

		else {

			cout << u.name << ' ' << elaps << '\n';

		}

	}



	return 0;

}