malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:1024000000,1024000000 )   template <typename T>   T Max(T a, T b) {     return a > b ? a : b;   }   template <typename T>   T Min(T a, T b) {     return a < b ? a : b;   }   template <typename T>   T Abs(T A) {     return A > 0 ? A : -1 * A;   }   template <typename T>   void Swap(T &a, T &b) {     T tmp = a;     a = b;     b = tmp;   }   const long long LINF = 0x3FFFFFFFFFFFFFFLL;   const int INF = 0X3FFFFFFF;   const int MAXN = 1e5 + 5;   long long sum[MAXN << 2][5];   int cnt[MAXN << 2];   char opt[MAXN][5];   int a[MAXN], c[MAXN];   inline void PushUp(int rt) {     for (int i = 0; i < 5; i++)       sum[rt][i] =           sum[rt << 1][i] + sum[rt << 1 | 1][((i - cnt[rt << 1]) % 5 + 5) % 5];   }   void Build(int l, int r, int rt) {     cnt[rt] = 0;     fill(sum[rt], sum[rt] + 5, 0);     if (l == r) return;     int m = (l + r) >> 1;     Build(l, m, rt << 1);     Build(m + 1, r, rt << 1 | 1);   }   void update(int pos, int val, int col, int l, int r, int rt) {     if (col)       cnt[rt]++;     else       cnt[rt]--;     if (l == r) {       sum[rt][0] = (long long)col * val;       return;     }     int m = (l + r) >> 1;     if (pos <= m)       update(pos, val, col, l, m, rt << 1);     else       update(pos, val, col, m + 1, r, rt << 1 | 1);     PushUp(rt);   }   int main() {     int n;     while (~scanf( %d , &n)) {       int id = 0;       for (int i = 1; i <= n; i++) {         scanf( %s , opt[i]);         if (opt[i][0] !=  s ) {           scanf( %d , c + i);           a[id++] = c[i];         }       }       sort(a, a + id);       int num = unique(a, a + id) - a;       if (num)         Build(1, num, 1);       else         sum[1][2] = 0;       for (int i = 1; i <= n; i++) {         int pos = lower_bound(a, a + num, c[i]) - a + 1;         if (opt[i][0] ==  a )           update(pos, c[i], 1, 1, num, 1);         else if (opt[i][0] ==  d ) {           if (cnt[1]) update(pos, c[i], 0, 1, num, 1);         } else {           if (cnt[1] == 0) sum[1][2] = 0;           printf( %I64d n , sum[1][2]);         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxN = 2e5 + 5;   const long long base = 9999991;   int n, m;   char s1[maxN], s2[maxN];   vector<int> res;   long long p[maxN], h1[30], h2[30];   int mark[30];   int check() {     for (int i = 0; i <= 25; ++i)       if (h1[i]) {         mark[i] = -1;         for (int j = 0; j <= 25; ++j)           if (h1[i] == h2[j]) mark[i] = j;         if (mark[i] == -1) return 0;       } else         mark[i] = -2;     for (int i = 0; i <= 25; ++i)       if (h1[i] && mark[mark[i]] != i && mark[mark[i]] != -2) return 0;     return 1;   }   int main() {     scanf( %d %d n%s n%s , &n, &m, s1 + 1, s2 + 1);     p[0] = 1;     for (int i = 1; i <= n; ++i) p[i] = p[i - 1] * 2 % base;     for (int i = 1; i <= m; ++i)       for (int j = 0; j <= 25; ++j) {         if (s1[i] -  a  == j)           h1[j] = (h1[j] * 2 + 1) % base;         else           h1[j] = h1[j] * 2 % base;         if (s2[i] -  a  == j)           h2[j] = (h2[j] * 2 + 1) % base;         else           h2[j] = h2[j] * 2 % base;       }     if (check()) res.push_back(1);     for (int i = m + 1; i <= n; ++i) {       for (int j = 0; j <= 25; ++j) {         if (s1[i - m] -  a  == j) h1[j] = (h1[j] - p[m - 1] + base) % base;         ;         if (s1[i] -  a  == j)           h1[j] = (h1[j] * 2 + 1) % base;         else           h1[j] = h1[j] * 2 % base;       }       if (check()) res.push_back(i - m + 1);     }     printf( %d n , (int)res.size());     for (int i = 0; i < (int)res.size(); ++i) printf( %d  , res[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int ans = INT_MAX;     char W[100001];     scanf( %100000s , W);     string s = W, t =  Bulbasaur ;     map<char, int> I, M;     for (char ch : t) ++I[ch];     for (char ch : s) ++M[ch];     for (auto p : I) {       ans = min(ans, M[p.first] / p.second);     }     printf( %d , ans);   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5;   const int lg = 22;   int spt[2 * N + 100][lg], par[N + 100][lg], H[N + 100], E[2 * N + 100],       L[2 * N + 100];   int dept[2 * N + 100], vis[N + 100], mx[N + 100][lg], P[N + 100],       rg[2 * N + 100], idx = 1;   vector<pair<int, int> > g[N + 100];   vector<pair<long, pair<int, int> > > edge1, edge2;   int find(int i) {     if (P[i] == i) return i;     return P[i] = find(P[i]);   }   bool sameset(int i, int j) { return (find(i) == find(j)); }   void dfs(int v, int dep, int p) {     dept[v] = dep;     H[v] = idx;     L[idx] = dep;     E[idx++] = v;     for (auto it : g[v]) {       if (it.first != p) {         mx[it.first][0] = it.second;         par[it.first][0] = v;         dfs(it.first, dep + 1, v);         E[idx] = v;         L[idx++] = dep;       }     }   }   int getmin(int i, int j) {     int l = min(i, j), r = max(i, j);     int lr = rg[r - l + 1];     if (L[spt[l][lr]] <= L[spt[r - (1 << lr) + 1][lr]])       return spt[l][lr];     else       return spt[r - (1 << lr) + 1][lr];   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       int u, v, w;       scanf( %d%d%d , &u, &v, &w);       edge1.push_back(make_pair(w, make_pair(u, v)));       edge2.push_back(make_pair(w, make_pair(u, v)));     }     sort(edge1.begin(), edge1.end());     for (int i = 1; i <= n; i++) P[i] = i;     for (int i = 0; (1 << i) <= 2 * N; i++) {       rg[1 << i] = i;     }     for (int i = 1; i <= 2 * N; i++) {       if (!rg[i]) rg[i] = rg[i - 1];     }     long long ans = 0;     for (auto it : edge1) {       int t1 = it.first;       int u = it.second.first, v = it.second.second;       if (!sameset(u, v)) {         ans += t1;         g[u].push_back(make_pair(v, t1));         g[v].push_back(make_pair(u, t1));         u = find(u);         v = find(v);         P[v] = u;       }     }     memset(dept, -1, sizeof dept);     dfs(1, 0, 0);     for (int j = 1; j < lg; j++) {       for (int i = 1; i <= n; i++) {         par[i][j] = par[par[i][j - 1]][j - 1];         mx[i][j] = max(mx[i][j - 1], mx[par[i][j - 1]][j - 1]);       }     }     for (int i = 1; i < 2 * n; i++) {       spt[i][0] = i;     }     for (int j = 1; j < lg; j++) {       for (int i = 1; i + (1 << j) - 1 < 2 * n; i++) {         if (L[spt[i][j - 1]] <= L[spt[i + (1 << (j - 1))][j - 1]])           spt[i][j] = spt[i][j - 1];         else           spt[i][j] = spt[i + (1 << (j - 1))][j - 1];       }     }     for (auto it : edge2) {       int u = it.second.first, v = it.second.second;       int lcs = E[getmin(H[u], H[v])];       int minus = 0;       int cur = u;       for (int i = lg - 1; i >= 0; i--) {         if (dept[par[cur][i]] >= dept[lcs]) {           minus = max(minus, mx[cur][i]);           cur = par[cur][i];         }       }       cur = v;       for (int i = lg - 1; i >= 0; i--) {         if (dept[par[cur][i]] >= dept[lcs]) {           minus = max(minus, mx[cur][i]);           cur = par[cur][i];         }       }       printf( %lld n , ans + it.first - minus);     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100000 + 10;   int n;   int data[maxn];   int f[25][maxn];   bool mark[(1 << 25)], tt;   int res = 0, p;   int tmp;   int tm, tp;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> data[i];     memset(mark, 0, sizeof(mark));     for (int k = 0; k <= 20; k++) {       p = -1;       for (int i = n; i >= 1; i--) {         if ((data[i] & (1 << k)) == 0) {           if (p == -1) {             p = i;           }           f[k][i] = p;         } else           p = -1;       }     }     for (int i = 1; i <= n; i++) {       tmp = data[i];       if (!mark[tmp]) {         mark[tmp] = 1;         res++;       }       p = i;       while (p <= n) {         tm = n + 1;         for (int k = 0; k <= 20; k++)           if ((tmp & (1 << k)) == 0 && f[k][i] < tm && f[k][i] > 0) {             tp = k;             tm = f[k][i];           }         if (tm >= n) break;         for (int k = 0; k <= 20; k++)           if (f[k][i] == tm) tmp += (1 << k);         if (!mark[tmp]) {           mark[tmp] = 1;           res++;         }         p = tm + 1;       }     }     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<string, int> person;   vector<pair<int, string> > points;   int cnt;   bool compare(pair<int, string> a, pair<int, string> b) {     if (a.first == b.first) return a.second < b.second;     return a.first > b.first;   }   void update(string name, int p = 0) {     if (!person[name]) {       person[name] = ++cnt;       points.push_back(make_pair(p, name));     } else       points[person[name] - 1].first += p;   }   int main() {     string me;     int n;     cin >> me >> n;     for (int i = 0; i < n; i++) {       string X, Y, type, temp;       cin >> X >> type;       int point;       if (type ==  posted ) {         cin >> temp >> Y >> temp;         point = 15;       } else if (type ==  commented ) {         cin >> temp >> Y >> temp;         point = 10;       } else {         cin >> Y >> temp;         point = 5;       }       Y = Y.substr(0, Y.length() - 2);       if (X == me)         update(Y, point);       else if (Y == me)         update(X, point);       else         update(X), update(Y);     }     sort(points.begin(), points.end(), compare);     for (int i = 0; i < cnt; i++) cout << points[i].second << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int maxn = 2e6 + 5;   char s[maxn], t[maxn];   int m;   struct Suffixam {     struct state {       int len, link;       map<char, int> next;     };     int id[maxn << 1], size[maxn << 1], cnt[maxn << 1];     state st[maxn << 1];     int last, sz;     int vis[maxn << 1];     void sam_init() {       memset(vis, -1, sizeof(vis));       sz = 0;       st[0].len = 0;       st[0].link = -1;       st[0].next.clear();       sz++;       last = 0;     }     void sam_extend(char c) {       int cur = sz++;       st[cur].len = st[last].len + 1;       st[cur].next.clear();       size[cur] = 1;       int p = last;       while (~p && !st[p].next.count(c)) {         st[p].next[c] = cur;         p = st[p].link;       }       if (p == -1) {         st[cur].link = 0;       } else {         int q = st[p].next[c];         if (st[p].len + 1 == st[q].len) {           st[cur].link = q;         } else {           int clone = sz++;           st[clone].len = st[p].len + 1;           st[clone].next = st[q].next;           st[clone].link = st[q].link;           while (~p && st[p].next[c] == q) {             st[p].next[c] = clone;             p = st[p].link;           }           st[q].link = st[cur].link = clone;         }       }       last = cur;     }     void get() {       for (int i = 1; i < sz; ++i) {         ++cnt[st[i].len];       }       for (int i = 1; i < sz; ++i) {         cnt[i] += cnt[i - 1];       }       for (int i = 1; i < sz; ++i) {         id[cnt[st[i].len]--] = i;       }       for (int i = sz; i >= 1; --i) {         size[st[id[i]].link] += size[id[i]];       }     }     void solve(const char *ss, int x) {       ll ans = 0;       int len = 0, now = 0;       for (int i = 0; ss[i]; ++i) {         if (st[now].next.count(ss[i]) != 0) {           now = st[now].next[ss[i]];           len++;           while (~now && st[st[now].link].len >= m) {             now = st[now].link;             len = st[now].len;           }           if (vis[now] != x && len >= m) {             ans += size[now];             vis[now] = x;           }         } else {           while (~now && !st[now].next.count(ss[i])) {             now = st[now].link;           }           if (now != -1) {             len = st[now].len + 1;             now = st[now].next[ss[i]];           } else {             len = 0;             now = 0;           }           while (~now && st[st[now].link].len >= m) {             now = st[now].link;             len = st[now].len;           }           if (vis[now] != x && len >= m) {             ans += size[now];             vis[now] = x;           }         }       }       printf( %lld n , ans);     }   } sam;   int main() {     scanf( %s , s + 1);     int n = strlen(s + 1);     sam.sam_init();     for (int i = 1; i <= n; ++i) {       sam.sam_extend(s[i]);     }     sam.get();     int q;     scanf( %d , &q);     while (q--) {       scanf( %s , t + 1);       m = strlen(t + 1);       for (int i = 1; i <= m; ++i) {         t[i + m] = t[i];       }       t[2 * m + 1] = 0;       sam.solve(t + 1, q);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mN = 30;   int a[mN];   int n;   void output(int x) {     string s;     string mid;     for (int i = 1; i <= n; i++) {       if (a[i] / x % 2) mid += char(i +  a  - 1);       for (int j = 1; j <= a[i] / x / 2; j++) s += char(i +  a  - 1);     }     s += mid;     for (int i = n; i >= 1; i--) {       for (int j = 1; j <= a[i] / x / 2; j++) s += char(i +  a  - 1);     }     for (int i = 1; i <= x; i++) {       cout << s;       reverse(s.begin(), s.end());     }   }   int gcd(int x, int y) {     if (x % y == 0) return y;     return gcd(y, x % y);   }   int main() {     cin >> n;     int odd = 0;     for (int i = 1; i <= n; i++) {       cin >> a[i];       if (a[i] % 2) odd++;     }     int maxl = a[1];     for (int i = 2; i <= n; i++) maxl = gcd(maxl, a[i]);     if (odd > 1) {       cout << 0 << endl;       output(1);     } else if (maxl > 1) {       if (odd <= 1) {         cout << maxl << endl;         output(maxl);       }     } else {       cout << maxl << endl;       output(maxl);     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxN = 130 * 1000 + 5;   const int mod = 1000 * 1000 * 1000 + 7;   short dp[21][32][maxN];   int mas[maxN];   int ss[6][maxN];   int a[20], b[20];   vector<int> v[6];   int c[20], d[20];   int n, m;   char ans[20][20];   int p;   void solve(int lev, int mask, int state) {     if (lev == 0) return;     int tmp = state;     for (int z = 0; z < n; z++) {       c[z] = tmp % p;       tmp /= p;     }     int smask = dp[lev][mask][state];     for (int j = 0; j < n; j++) {       d[j] = c[j];       if ((mask >> j & 1) != (smask >> j & 1)) {         if (mask >> j & 1) d[j]--;       }     }     int sstate = 0;     for (int j = n - 1; j >= 0; j--) sstate *= p, sstate += d[j];     solve(lev - 1, smask, sstate);     for (int i = 0; i < n; i++) ans[i][lev - 1] = ((mask >> i & 1) ?  *  :  . );   }   int tof[32][32], tofm[32][32];   int main() {     ios::sync_with_stdio(0);     cin.tie();     memset(dp, -1, sizeof dp);     cin >> n >> m;     for (int mask = 0; mask < (1 << n); mask++) {       int bef = 0, st = 0;       for (int i = 0; i < n; i++)         if (mask >> i & 1) {           if (bef == 0) st++;           bef = 1;         } else           bef = 0;       v[st].push_back(mask);     }     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < m; i++) cin >> b[i];     p = *max_element(a, a + n);     p++;     int stat = 0;     for (int i = n - 1; i >= 0; i--) stat *= p, stat += a[i];     for (int state = 0; state < stat + 1; state++) {       int tmp = state;       for (int z = 0; z < n; z++) {         ss[z][state] = tmp % p;         if (ss[z][state] == 0) mas[state] |= (1 << z);         tmp /= p;       }     }     for (int mask = 0; mask < (1 << n); mask++)       for (int smask = 0; smask < (1 << n); smask++) {         int pp = 0;         for (int j = 0; j < n; j++) {           d[j] = 0;           if ((mask >> j & 1) != (smask >> j & 1)) {             if (mask >> j & 1) d[j]--, tofm[mask][smask] |= (1 << j);           }         }         int sstate = 0;         for (int j = n - 1; j >= 0; j--) sstate *= p, sstate += d[j];         tof[mask][smask] = sstate;       }     for (int i = 1; i < m + 1; i++) {       int ind = b[i - 1];       for (int state = 0; state < stat + 1; state++) {         for (auto mask : v[ind]) {           for (auto smask : v[(i == 1 ? 0 : b[i - 2])]) {             if (tofm[mask][smask] & mas[state]) continue;             int sstate = state + tof[mask][smask];             if (dp[i - 1][smask][sstate] != -1 ||                 (i == 1 && sstate == 0 && smask == 0)) {               dp[i][mask][state] = smask;               break;             }           }         }       }     }     int answer = -1;     for (int i = 0; i < (1 << n); i++) {       if (dp[m][i][stat] > -1) {         answer = i;         break;       }     }     solve(m, answer, stat);     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) cout << ans[i][j];       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   long long min(long long x, long long y) {     if (x > y)       return y;     else       return x;   }   int main() {     long long n, m;     long long k;     scanf( %I64d %I64d %I64d , &n, &m, &k);     long long l = 1, r = n * m, mid, sum;     while (l <= r) {       mid = (l + r) >> 1;       sum = 0;       for (int i = 1; i <= n; i++) sum += min(m, (mid - 1) / i);       if (sum < k)         l = mid + 1;       else         r = mid - 1;     }     printf( %I64d , l - 1);     scanf(   );   }
#include <bits/stdc++.h>   using namespace std;   bool vis[8][8];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     char t;     int y, x;     cin >> t >> y;     --y;     x = t -  a ;     for (int i = 0; i < 8; i++) {       vis[i][y] = true;       vis[x][i] = true;     }     auto mark = [&](int x, int y) {       vis[x][y] = true;       for (int i = -2; i <= 2; i++) {         for (int j = -2; j <= 2; j++) {           if (i * i + j * j != 5) continue;           int dx = x + i, dy = y + j;           if (dx >= 0 && dx < 8 && dy >= 0 && dy < 8) vis[dx][dy] = true;         }       }     };     mark(x, y);     cin >> t >> y;     t;     --y;     mark(t -  a , y);     int cnt = 0;     for (int i = 0; i < 8; i++) {       for (int j = 0; j < 8; j++) cnt += vis[i][j];     }     cout << 64 - cnt;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int p[111], s[111], v[111];   int main() {     int n, m, k, i, Nr = 0, c;     cin >> n >> m >> k;     for (i = 1; i <= n; ++i) cin >> p[i];     for (i = 1; i <= n; ++i) {       cin >> s[i];       if (p[i] > v[s[i]]) v[s[i]] = p[i];     }     for (i = 1; i <= k; ++i) {       cin >> c;       if (p[c] < v[s[c]]) Nr++;     }     cout << Nr <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, m, u, cnt = 1, ch[4000005][4], dp[4000005][4], dpp[60][4][4];   long long rev[2][4], nw = 0, ans = 0;   char s[100005];   const long long inf = 2e18;   void dfs(int p) {     for (int i = 0; i < 4; i++) dp[p][i] = inf;     for (int i = 0; i < 4; i++) {       if (!ch[p][i])         dp[p][i] = 0;       else {         dfs(ch[p][i]);         for (int j = 0; j < 4; j++) dp[p][j] = min(dp[p][j], dp[ch[p][i]][j] + 1);       }     }   }   int main() {     scanf( %lld%s , &n, s + 1);     m = strlen(s + 1);     for (int i = 1; i <= m; i++) {       int lim = min(m, 1ll * i + 39);       u = 1;       for (int j = i; j <= lim; j++) {         int le = s[j] -  A ;         if (!ch[u][le]) ch[u][le] = ++cnt;         u = ch[u][le];       }     }     dfs(1);     for (int i = 0; i < 4; i++)       for (int j = 0; j < 4; j++) dpp[0][i][j] = dp[ch[1][i]][j] + 1;     for (int i = 1; i < 60; i++) {       for (int j = 0; j < 4; j++) {         for (int k = 0; k < 4; k++) {           dpp[i][j][k] = inf;           for (int u = 0; u < 4; u++)             dpp[i][j][k] = min(dpp[i][j][k], dpp[i - 1][j][u] + dpp[i - 1][u][k]);         }       }     }     ans = 0;     for (int i = 59; i >= 0; i--) {       for (int j = 0; j < 4; j++) rev[!nw][j] = inf;       for (int j = 0; j < 4; j++)         for (int k = 0; k < 4; k++)           rev[!nw][k] = min(rev[!nw][k], rev[nw][j] + dpp[i][j][k]);       long long sum = inf;       for (int j = 0; j < 4; j++) sum = min(sum, rev[!nw][j]);       if (sum < n) {         ans += (1ll << i);         for (int j = 0; j < 4; j++)           if (rev[!nw][j] >= n) rev[!nw][j] = inf;       } else         for (int j = 0; j < 4; j++) rev[!nw][j] = rev[nw][j];       nw = !nw;     }     printf( %lld n , ans + 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     vector<int> ans, a;     int n, temp;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &temp);       a.push_back(temp);     }     for (int i = 0; i < a.size(); i++) {       if (a[i] == 1) {         ans.push_back(1);       } else {         ans[ans.size() - 1]++;       }     }     printf( %d n%d , (int)ans.size(), ans[0]);     for (int i = 1; i < ans.size(); i++) {       printf(  %d , ans[i]);     }     printf(  n );   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s;     cin >> s;     string gen =  ACTG ;     int sum = 10000;     vector<bool> used_big(n, false);     vector<bool> used_gen(4, false);     for (int i = 0; i <= n - 4; i++) {       int tmp_sum = 0;       for (int j = 0; j < 4; j++) {         int dif = abs(s[i + j] - gen[j]);         if (26 - dif < dif) dif = 26 - dif;         tmp_sum += dif;       }       if (tmp_sum < sum) sum = tmp_sum;     }     cout << sum;   }
#include <bits/stdc++.h>   using namespace std;   void precalc(){};   const int N = 3010;   int n, m;   vector<vector<int>> g;   vector<vector<int>> dist;   pair<int, int> pre[N][3], post[N][3];   void bfs(int x) {     queue<int> q;     q.push(x);     while (q.size()) {       int head = q.front();       q.pop();       for (auto c : g[head]) {         if (dist[x][c] > n) {           dist[x][c] = dist[x][head] + 1;           q.push(c);         }       }     }   }   inline bool distinct(int a, int b, int c, int d) {     vector<int> z = {a, b, c, d};     sort(z.begin(), z.end());     return z[0] != z[1] && z[1] != z[2] && z[2] != z[3];   }   void solve(int ncase) {     cin >> n >> m;     g.assign(n + 1, vector<int>());     dist.assign(n + 1, vector<int>(n + 1, n + 1));     for (int i = 1; i <= n; i++) {       dist[i][i] = 0;     }     for (int i = 0; i < m; i++) {       int x, y;       cin >> x >> y;       g[x].push_back(y);     }     for (int i = 1; i <= n; i++) {       bfs(i);     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (dist[j][i] <= n) {           pair<int, int> tmppre = pair<int, int>(dist[j][i], j);           if (tmppre > pre[i][2]) {             pre[i][2] = tmppre;             if (pre[i][2] > pre[i][1]) {               swap(pre[i][2], pre[i][1]);               if (pre[i][1] > pre[i][0]) {                 swap(pre[i][1], pre[i][0]);               }             }           }         }         if (dist[i][j] <= n) {           pair<int, int> tmppost = pair<int, int>(dist[i][j], j);           if (tmppost > post[i][2]) {             post[i][2] = tmppost;             if (post[i][2] > post[i][1]) {               swap(post[i][2], post[i][1]);               if (post[i][1] > post[i][0]) {                 swap(post[i][1], post[i][0]);               }             }           }         }       }     }     int ans = -1;     vector<int> ret(4);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (i == j || dist[i][j] > n) continue;         for (int a = 0; a < 3; a++) {           if (pre[i][a].second == 0) continue;           for (int b = 0; b < 3; b++) {             if (post[j][b].second == 0) continue;             int tmp = pre[i][a].first + dist[i][j] + post[j][b].first;             if (tmp > ans &&                 distinct(pre[i][a].second, i, j, post[j][b].second)) {               ans = tmp;               ret = {pre[i][a].second, i, j, post[j][b].second};             }           }         }       }     }     cout << ret[0] <<     << ret[1] <<     << ret[2] <<     << ret[3] << endl;   }   int main() {     int T = 1;     int ncase = 0;     while (T--) {       solve(++ncase);     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, t, c = 1;     cin >> n >> t;     int mn = INT_MAX;     for (int i = 1; i <= n; i++) {       int s, d;       cin >> s >> d;       while (s < t) {         s += d;       }       if (s < mn) {         mn = s;         c = i;       }     }     cout << c << endl;     return 0;   }