func_code_string: #include <bits/stdc++.h>   using namespace std;   struct tc {     int cnt, count;     long long p[5001];   } q[5001];   struct sc {     int id;     long long num;   } anss[200010], s[200010];   void merge(int l, int mid, int r) {     int i = l, j = mid + 1;     int cc = l;     while (i <= mid && j <= r) {       if (anss[i].num <= anss[j].num) {         s[cc].id = anss[i].id;         s[cc++].num = anss[i++].num;       } else {         s[cc].id = anss[j].id;         s[cc++].num = anss[j++].num;       }     }     while (i <= mid) {       s[cc].id = anss[i].id;       s[cc++].num = anss[i++].num;     }     while (j <= r) {       s[cc].id = anss[j].id;       s[cc++].num = anss[j++].num;     }     for (i = l; i < cc; i++) {       anss[i].id = s[i].id;       anss[i].num = s[i].num;     }     return;   }   void mergesort(int x, int y) {     if (x < y) {       int mid = (x + y) / 2;       mergesort(x, mid);       mergesort(mid + 1, y);       merge(x, mid, y);     }     return;   }   int main() {     int i, j;     long long n, a, x, y, m;     int ans = -1, k, sum, l = 0;     cin >> n;     for (i = 0; i < n; i++) {       scanf( %d %I64d %I64d %I64d %I64d , &k, &a, &x, &y, &m);       sum = 0;       l += k;       q[i].cnt = 1;       q[i].count = k;       q[i].p[1] = a;       for (j = 2; j <= k; j++) {         q[i].p[j] = (x * q[i].p[j - 1] + y) % m;         if (q[i].p[j] < q[i].p[j - 1]) sum++;       }       ans = max(ans, sum);     }     printf( %d n , ans);     int st = 0, end = 0;     if (l <= 2e5) {       while (end < l) {         for (i = 0; i < n; i++) {           for (j = q[i].cnt; j <= q[i].count; j++) {             if (j != q[i].cnt && q[i].p[j] < q[i].p[j - 1]) {               q[i].cnt = j;               break;             }             anss[end].id = i;             anss[end++].num = q[i].p[j];           }           if (j > q[i].count) q[i].cnt = j;         }         mergesort(st, end - 1);         st = end;       }       for (i = 0; i < l; i++) printf( %I64d %d n , anss[i].num, anss[i].id + 1);     }     return 0;   }   