stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include <cstdio>

#include <cstring>

#include <iostream>

#include <algorithm>

#include <vector>

#include <queue>

#include <set>

#include <map>

#include <string>

#include <cmath>

#include <cstdlib>

using namespace std;



const int MAX = 100010;

struct Node {

    char s[10];

    int v;

};



Node Queue[MAX];

int len;

int head;

int last;



void init() {

    len = head = last = 0;

}



void push(Node node) {

    strcpy(Queue[last].s, node.s);

    Queue[last].v = node.v;

    len++;

    last = (last + 1) % MAX;

}



Node front() {

    return Queue[head];

}



void pop() {

    len--;

    head = (head + 1) % MAX;

}



int n;

int tm;



int main() {

    //freopen("in.txt", "r", stdin);

    //freopen("out.txt", "w", stdout);

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

    init();

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

        char s[10];

        Node node;

        scanf("%s %d", node.s, &node.v);

        push(node);

    }

    int tt = 0;

    while (len > 0) {

        Node node = front();

        pop();

        if (node.v <= tm) {

            tt += node.v;

            node.v = 0;

        } else {

            tt += tm;

            node.v -= tm;

        }

        if (node.v <= 0) {

            printf("%s %d\n", node.s, tt);

        } else {

            push(node);

        }

    }

    return 0;

}

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <cstdlib>

#define MAXN 100010

int n,q;

typedef struct p{

    char name[10];

    int time;

}P;

P que[MAXN];

int head,tail,tot;







void get_input() {

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

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

        scanf("%s %d",que[i].name,&que[i].time);

    }

    tail=n;

}



void solve() {

    P item;

    while(head!=tail) {

        item=que[head];

        head=(head+1)%(n+1);

        if(item.time>q) {

            item.time-=q;

            tot+=q;

            que[tail]=item;

            tail=(tail+1)%(n+1);

        } else {

            tot+=item.time;

            printf("%s %d\n",item.name,tot);

        }

    }

}



void display_output() {

    

}



int main() {

#ifdef debug

    freopen("in.txt","r",stdin);

#endif

    get_input();

    solve();

    display_output();

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <cstdio>

#include <queue>

using namespace std;



struct Node{

	char name[10];

	int time;

};



queue<Node >Q;



int t = 0;



int main(){

	int n,m;

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

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

		Node p;

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

		Q.push(p);

	}

	while(!Q.empty()){

		Node point = Q.front();Q.pop();

		if(point.time > m){

			point.time -= m;	

			t += m;

			Q.push(point);

			continue;

		}

		t += point.time;

		printf("%s %d\n",point.name,t);

	}

}

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <cstdlib>

#define MAXN 100010

int n,q;

typedef struct p{

    char name[10];

    int time;

}P;

P que[MAXN];

int head,tail,tot;







void get_input() {

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

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

        scanf("%s %d",que[i].name,&que[i].time);

    }

    tail=n;

}



void solve() {

    P item;

    while(head!=tail) {

        item=que[head];

        head=(head+1)%(n+1);

        if(item.time>q) {

            item.time-=q;

            tot+=q;

            que[tail]=item;

            tail=(tail+1)%(n+1);

        } else {

            tot+=item.time;

            printf("%s %d\n",item.name,tot);

        }

    }

}



void display_output() {

    

}



int main() {

#ifdef debug

    freopen("in.txt","r",stdin);

#endif

    get_input();

    solve();

    display_output();

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <cstdio>

#include <cstring>

#include <algorithm>

#include <queue>

#include <string>

using namespace std;



queue < pair<string,int> > que;



int main()

{

    int n,q,t;

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

    string name;

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

    {

        cin >> name >> t;

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

    }

    int sumt=0;

    pair <string,int> u;

    while(!que.empty())

    {

        u=que.front();

        que.pop();

        int temp=min(u.second,q);

        u.second-=temp;

        sumt+=temp;

        if(u.second>0)

            que.push(u);

        else

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

    }

    return 0;

}

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <cstdlib>

#define MAXN 100010

int n,q;

typedef struct p{

    char name[10];

    int time;

}P;

P que[MAXN];

int head,tail,tot;







void get_input() {

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

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

        scanf("%s %d",que[i].name,&que[i].time);

    }

    tail=n;

}



void solve() {

    P item;

    while(head!=tail) {

        item=que[head];

        head=(head+1)%(n+1);

        if(item.time>q) {

            item.time-=q;

            tot+=q;

            que[tail]=item;

            tail=(tail+1)%(n+1);

        } else {

            tot+=item.time;

            printf("%s %d\n",item.name,tot);

        }

    }

}



void display_output() {

    

}



int main() {

#ifdef debug

    freopen("in.txt","r",stdin);

#endif

    get_input();

    solve();

    display_output();

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

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 -= q;

        elaps += a;

        if (u.second > 0) {

            Q.push(u);

        } else {

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

        }

    }

    return 0;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<fstream>

#include<vector>

#include<algorithm>

using namespace std;

struct renwu{

  char m[100];

  int t;

}a[100000];

int main()

{

    int n;int p;

    int x=0;

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

    int k=0,l=0;

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

    {

        scanf("%s%d",a[i].m,&a[i].t);

    }

    int head=1;

    int tail=n+1;

    while(head!=tail)

    {

        k=min(p,a[head].t);

        x+=k;

        a[head].t-=k;

        if(a[head].t>0)

        {

           a[tail]=a[head];tail=(tail+1)%100005;

        }

        else

        {

          printf("%s %d\n",a[head].m,x);

        }

        head=(head+1)%100005;

    }

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}




// Optimized solution to the same problem (faster):
#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;

	}

}




// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}




// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}




// Fastest known solution for this problem:
// Original C++ solution (slower):
#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);

		}

	}

}


// Optimized solution to the same problem (faster):
#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);

		}

	}

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem: