#include <iostream>
using namespace std;
int main() {
    int n;
    cout << "Enter total number of processes: ";
    cin >> n;
    int at[10], bt[10], temp[10];
    int wt[10] = {0}, tat[10];
    int quantum;
    int time = 0, count = 0, remaining = n;
    float total_wt = 0, total_tat = 0;
    for (int i = 0; i < n; i++) {
        cout << "Process " << i + 1 << " Arrival time: ";
        cin >> at[i];
        cout << "Process " << i + 1 << " Burst time: ";
        cin >> bt[i];
        temp[i] = bt[i];  
    }
    cout << "Enter Time Quantum: ";
    cin >> quantum;
    cout << "\nProcess No\tBurst Time\tTurnaround Time\tWaiting Time\n";
    while (remaining > 0) {
        bool done = true;
        for (int i = 0; i < n; i++) {
            if (temp[i] > 0 && at[i] <= time) {
                done = false;
                if (temp[i] <= quantum) {
                    time += temp[i];
                    temp[i] = 0;
                    tat[i] = time - at[i];
                    wt[i] = tat[i] - bt[i];
                    cout << "P" << i + 1 << "\t\t" << bt[i] << "\t\t" << tat[i] << "\t\t" << wt[i] << "\n";
                    total_wt += wt[i];
                    total_tat += tat[i];
                    remaining--;
                } else {
                    temp[i] -= quantum;
                    time += quantum;
                }
            }
        }
        if (done) {
            time++;
        }
    }
    cout << "Average Waiting Time: " << total_wt / n << endl;
    cout << "Average Turnaround Time: " << total_tat / n << endl;
    return 0;
}