malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6;   int lp[N + 1];   vector<int> pr;   int i, j, p1, p2, x0, x1, x2, ans;   int main() {     for (i = 2; i <= N; i++) {       if (lp[i] == 0) {         lp[i] = i;         pr.push_back(i);       }       for (j = 0; j < pr.size() && pr[j] <= lp[i] && i * pr[j] <= N; j++)         lp[i * pr[j]] = pr[j];     }     cin >> x2;     for (i = pr.size() - 1; i >= 0; i--)       if (x2 % pr[i] == 0) break;     if (x2 == pr[i]) {       cout << x2 << endl;       return 0;     }     p2 = pr[i];     ans = x2 - p2 + 1;     for (j = 0; j < pr.size() && pr[j] <= x2; j++) {       p1 = pr[j];       x1 = ((x2 - p2) / p1 + 1) * p1;       if (x1 > x2) continue;       if (x1 == p1)         x0 = p1;       else         x0 = x1 - p1 + 1;       if (x0 >= 3) ans = min(ans, x0);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long M = 2100000;   const long long N = 210000;   struct node {     long long inx;     long long a, b;     long long m;     long long lt, rt;   };   vector<node> odd_nodes[M];   vector<node> even_nodes[M];   bool cmp(node a, node b) {     if (a.lt == b.lt)       return a.rt > b.rt;     else       return a.lt < b.lt;   }   long long lt_ans[N], rt_ans[N];   set<long long> op;   int main() {     ios::sync_with_stdio(false);     long long tt;     cin >> tt;     while (tt--) {       op.clear();       long long m, n;       cin >> n;       long long a, b;       for (long long i = 0; i < n; i++) {         cin >> a >> b >> m;         long long mn = max(0ll, a - m);         long long tb = b - (m - (a - mn));         long long mx = max(0ll, b - m);         long long ta = a - (m - (b - mx));         long long v = a + b - m;         op.insert(v);         odd_nodes[v].push_back({i, a, b, m, mn - tb, ta - mx});       }       long long ans = 0;       for (auto &u : op) {         auto &p = odd_nodes[u];         if (p.empty()) continue;         sort(p.begin(), p.end(), cmp);         long long st = 0, ed = 1e9;         for (long long i = 0; i < p.size(); i++) {           if (p[i].lt > ed) {             for (long long j = st; j < i; j++) {               long long t = (p[j].a - p[j].b + p[j].m - ed) / 2;               lt_ans[p[j].inx] = t;               rt_ans[p[j].inx] = p[j].m - t;             }             ans++;             ed = p[i].rt;             st = i;           } else {             ed = min(ed, p[i].rt);           }         }         ans++;         for (long long j = st; j < p.size(); j++) {           long long t = (p[j].a - p[j].b + p[j].m - ed) / 2;           lt_ans[p[j].inx] = t;           rt_ans[p[j].inx] = p[j].m - t;         }         p.clear();       }       cout << ans << endl;       for (long long i = 0; i < n; i++)         cout << lt_ans[i] <<     << rt_ans[i] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, a[1000005], r[3], cnt;   bool up, down;   set<int> s;   int main() {     srand(75435);     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     if (n <= 2) {       cout << -1;       return 0;     }     for (int i = 0; i < n; i++) {       if (s.find(a[i]) == s.end()) {         if (cnt < 3) r[cnt++] = i;         s.insert(a[i]);       }     }     if (cnt == 3) {       if (r[0] > r[1]) swap(r[0], r[1]);       if (r[0] > r[2]) swap(r[0], r[2]);       if (r[1] > r[2]) swap(r[1], r[2]);       if ((a[r[1]] > a[r[0]] && a[r[1]] > a[r[2]]) ||           (a[r[1]] < a[r[0]] && a[r[1]] < a[r[2]])) {         cout << r[0] + 1 <<     << r[2] + 1;         return 0;       }       cout << r[0] + 1 <<     << r[1] + 1 << endl;       return 0;     }     for (int i = 0; i < n - 1; i++)       if (a[i] != a[i + 1]) {         swap(a[i], a[i + 1]);         up = true;         down = true;         for (int j = 0; j < n - 1; j++)           if (a[j] > a[j + 1])             up = false;           else if (a[j] < a[j + 1])             down = false;         if (!down && !up) {           cout << i + 1 <<     << i + 2;           return 0;         }         swap(a[i], a[i + 1]);       }     cout << -1;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b;     cin >> a >> b;     vector<string> N(a), M(b);     for (auto& i : N) cin >> i;     for (auto& i : M) cin >> i;     int q;     cin >> q;     while (q--) {       int n;       cin >> n;       cout << N[(n - 1) % a] << M[(n - 1) % b] <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     set<int> s;     for (int i = 0; i < n; i++) {       int t;       cin >> t;       s.insert(t);     }     int a, b;     cin >> a >> b;     int res = 0;     while (a > b) {       int mx = 1;       set<int> toerase;       for (set<int>::reverse_iterator it = s.rbegin(); it != s.rend(); ++it) {         int curr = a % *it;         if (a - curr >= b) {           if (curr > mx) mx = curr;         } else {           toerase.insert(*it);         }         if (mx >= *it) break;       }       for (set<int>::iterator it = toerase.begin(); it != toerase.end(); ++it) {         s.erase(*it);       }       a -= mx;       res++;     }     cout << res;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2020, mod = 1000000007;   int n, m, t = 0, a[N] = {}, vis[N] = {};   int *f[N] = {}, *g, *h, arr[N][N << 2] = {};   vector<int> e[N];   long long ans = 0;   int main() {     cin >> n >> m;     for (int i = 1, u, v; i <= m; ++i) {       cin >> u >> v;       e[u].push_back(v);       e[v].push_back(u);     }     for (auto x : e[1])       if (!vis[x]) {         int l = 1, now = x, last = 1, tmp;         vis[now] = true;         while (now != 1) {           tmp = last;           last = now;           now = e[now][e[now][0] == tmp];           vis[now] = true;           ++l;         }         a[++t] = l;       }     for (int i = 0; i <= t; ++i) f[i] = arr[i] + m;     f[0][0] = 1;     for (int i = 1; i <= t; ++i)       for (int v = -m; v <= m; ++v) {         if (v + a[i] <= m) f[i][v] = (f[i][v] + f[i - 1][v + a[i]]) % mod;         if (v - a[i] >= -m) f[i][v] = (f[i][v] + f[i - 1][v - a[i]]) % mod;         f[i][v] = (f[i][v] + f[i - 1][v]) % mod;       }     g = arr[t + 1] + m;     h = arr[t + 2] + m;     for (int i = 1; i <= t; ++i) {       copy(f[t] - m, f[t] + m + 1, g - m);       fill(h - m, h + m + 1, 0);       for (int v = -m; v <= m; ++v) {         g[v + a[i]] = (g[v + a[i]] + mod - g[v]) % mod;         g[v + a[i] + a[i]] = (g[v + a[i] + a[i]] + mod - g[v]) % mod;         h[v + a[i]] = g[v];         g[v] = 0;       }       for (int v = -a[i] + 2; v <= a[i] - 2; ++v)         ans = (ans + h[v] * 2 % mod) % mod;     }     memset(arr, 0, sizeof(arr));     f[0][0] = 1;     for (int i = 1; i <= t; ++i)       for (int v = -m; v <= m; ++v) {         if (v + a[i] <= m) f[i][v] = (f[i][v] + f[i - 1][v + a[i]]) % mod;         if (v - a[i] >= -m) f[i][v] = (f[i][v] + f[i - 1][v - a[i]]) % mod;       }     g = arr[t + 1] + m;     h = arr[t + 2] + m;     for (int i = 1; i <= t; ++i) {       copy(f[t] - m, f[t] + m + 1, g - m);       fill(h - m, h + m + 1, 0);       for (int v = -m; v <= m; ++v) {         g[v + a[i] + a[i]] = (g[v + a[i] + a[i]] + mod - g[v]) % mod;         h[v + a[i]] = g[v];         g[v] = 0;       }       ans = (ans + h[a[i] - 1] * 2ll + h[1 - a[i]] * 2ll) % mod;     }     ans = (ans + f[t][0]) % mod;     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 2e9;   const long long LINF = 1LL << 60;   const double inf = 1e15;   long long mod = 1e9 + 7;   char READ_DATA;   int SIGNAL_INPUT;   template <typename Type>   inline Type ru(Type &v) {     SIGNAL_INPUT = 1;     while ((READ_DATA = getchar()) <  0  || READ_DATA >  9 )       if (READ_DATA ==  - )         SIGNAL_INPUT = -1;       else if (READ_DATA == EOF)         return EOF;     v = READ_DATA -  0 ;     while ((READ_DATA = getchar()) >=  0  && READ_DATA <=  9 )       v = v * 10 + READ_DATA -  0 ;     v *= SIGNAL_INPUT;     return v;   }   inline long long modru(long long &v) {     long long p = 0;     SIGNAL_INPUT = 1;     while ((READ_DATA = getchar()) <  0  || READ_DATA >  9 )       if (READ_DATA ==  - )         SIGNAL_INPUT = -1;       else if (READ_DATA == EOF)         return EOF;     p = v = READ_DATA -  0 ;     while ((READ_DATA = getchar()) >=  0  && READ_DATA <=  9 ) {       v = (v * 10 + READ_DATA -  0 ) % mod;       p = (p * 10 + READ_DATA -  0 ) % (mod - 1);     }     v *= SIGNAL_INPUT;     return p;   }   template <typename A, typename B>   inline char ru(A &x, B &y) {     if (ru(x) == EOF) return EOF;     ru(y);     return 2;   }   template <typename A, typename B, typename C>   inline char ru(A &x, B &y, C &z) {     if (ru(x) == EOF) return EOF;     ru(y);     ru(z);     return 3;   }   template <typename A, typename B, typename C, typename D>   inline char ru(A &x, B &y, C &z, D &w) {     if (ru(x) == EOF) return EOF;     ru(y);     ru(z);     ru(w);     return 4;   }   struct Edge {     int u, v, next;     long long w, cap, flow;     Edge(int _u = 0, int _v = 0, int nxt = -1, long long _w = 1,          long long _cap = 0) {       u = _u;       v = _v;       w = _w;       cap = _cap;       flow = 0;       next = nxt;     }     int operator<(const Edge &b) const { return w < b.w; }   };   const int maxn = 2e6 + 3, N = 2e7, SZ = 21;   double eps = 1e-7, pi = acos(-1.0);   long long seed = 131, smod = (1LL << 32) - 267;   long long a, b, p, n;   long long sp(long long a, long long b, long long mod) {     long long ans = 1, x = a;     while (b) {       if (b & 1) (ans *= x) %= mod;       (x *= x) %= mod;       b >>= 1;     }     return ans;   }   long long c[maxn];   long long ans1, ans2;   int main() {     cin >> a >> b >> p >> n;     c[0] = 1;     for (register int j = 1; j < p; ++j) c[j] = c[j - 1] * a % p;     for (register int j = 1; j < p; ++j) {       long long y = c[j * (p - 2) % (p - 1)] * b % p;       long long t = (j - y + p) % p;       if (t * (p - 1) + j > n) continue;       long long u = ((n - j) / (p - 1) - t) / p;       ans2 += (u + 1);     }     cout << ans2;   }
#include <bits/stdc++.h>   using namespace std;   void change(char &x) {     if (x ==  B )       x =  W ;     else       x =  B ;   }   int main() {     string s;     int n;     cin >> n;     cin >> s;     int w = 0, b = 0;     for (int i = 0; i < n; i++) {       if (s[i] ==  B )         b++;       else         w++;     }     if (b % 2 != 0 && w % 2 != 0) {       cout << -1;       return 0;     }     string c = s;     vector<int> vec1, vec2;     for (int i = 0; i < n - 1; i++) {       if (s[i] ==  B ) {         vec1.push_back(i + 1);         if (s[i] ==  B ) change(s[i]);         change(s[i + 1]);       }     }     if (s[n - 1] ==  W ) {       cout << vec1.size() << endl;       for (int i = 0; i < vec1.size(); i++) cout << vec1[i] <<    ;       return 0;     }     for (int i = 0; i < n - 1; i++) {       if (c[i] ==  W ) {         vec2.push_back(i + 1);         change(c[i]);         change(c[i + 1]);       }     }     if (s[n - 1] ==  B ) {       cout << vec2.size() << endl;       for (int i = 0; i < vec2.size(); i++) cout << vec2[i] <<    ;       return 0;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T, class T2>   inline int chkmax(T &x, const T2 &y) {     return x < y ? x = y, 1 : 0;   }   template <class T, class T2>   inline int chkmin(T &x, const T2 &y) {     return x > y ? x = y, 1 : 0;   }   const int MAXN = (1 << 20);   int n, m;   int64_t g[MAXN], b[MAXN];   void read() {     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> b[i];     for (int i = 0; i < m; i++) cin >> g[i];   }   void solve() {     sort(b, b + n);     sort(g, g + m);     if (b[n - 1] > g[0]) {       cout << -1 <<   n ;       return;     }     int64_t answer = 0;     for (int i = 0; i < n; i++) answer += b[i] * 1ll * m;     for (int i = m - 1; i >= 0; i--) answer += g[i];     if (b[n - 1] == g[0])       answer -= m * 1ll * b[n - 1];     else {       answer -= (m - 1) * 1ll * b[n - 1];       answer -= b[n - 2];     }     cout << answer <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     read();     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i;     long long sum = 0, z = 0, s = 0, m = 0, mm = 0;     cin >> n;     vector<long long> a(n);     for (i = 0; i < n; i++) cin >> a[i];     for (i = 0; i < (n - 1); i++) {       if (i % 2 == 0)         sum = sum + abs(a[i + 1] - a[i]);       else         sum = max(z, sum - abs(a[i + 1] - a[i]));       m = max(m, sum);     }     for (i = 1; i < (n - 1); i++) {       if (i % 2 == 1)         s = s + abs(a[i + 1] - a[i]);       else         s = max(z, s - abs(a[i + 1] - a[i]));       m = max(s, m);     }     cout << m;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a[100];     cin >> n;     int i, loce, loco, even = 0, odd = 0;     for (i = 0; i < n; i++) {       cin >> a[i];       if (a[i] % 2 == 0) {         even++;         loce = i;       }       if (a[i] % 2 == 1) {         odd++;         loco = i;       }     }     if (odd > even) {       cout << loce + 1;     } else {       cout << loco + 1;     }   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int an[333333];   int bit[333333];   void upd(int x, int v) {     for (int i = x; i <= n; i += (i & -i)) {       bit[i] += v;     }   }   int get(int x) {     int an = 0;     for (int i = x; i > 0; i -= (i & -i)) an += bit[i];     return an;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) upd(i, 1);     while (m--) {       int from, to, win;       scanf( %d%d%d , &from, &to, &win);       int add = get(to);       int dec = get(from - 1);       while (add > dec) {         int ll = from, rr = to;         while (ll <= rr) {           int mid = (ll + rr) / 2;           if (get(mid) == dec)             ll = mid + 1;           else             rr = mid - 1;         }         an[ll] = win;         upd(ll, -1);         --add;       }       an[win] = 0;       upd(win, 1);     }     for (int i = 1; i <= n; ++i) printf( %d  , an[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e4 + 5;   const int mod = 1e9 + 7;   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n;     cin >> n;     int a[n + 5], mx = 0;     long long sum = 0;     for (int i = 0; i < n; i++) cin >> a[i], sum += a[i], mx = max(mx, a[i]);     sum -= mx;     cout << (mx - sum + 1) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     long long k;     cin >> n >> k;     int arr[n];     for (int i = 0; i < n; i++) cin >> arr[i];     sort(arr, arr + n);     int prev = arr[0], best = -1, num, left = 0;     for (int i = 0; i < n; i++) {       k -= (0LL + i - left) * (arr[i] - prev);       while (k < 0) {         k += arr[i] - arr[left++];       }       if (best < i - left + 1) {         best = i - left + 1;         num = arr[i];       }       prev = arr[i];     }     cout << best <<     << num << endl;     return 0;   }
#include <bits/stdc++.h>   int g[1010][1010];   int main() {     int n, k, ans, i, j;     while (~scanf( %d%d , &n, &k)) {       ans = 0;       memset(g, 0, sizeof(g));       for (i = 0; i < n; i++)         for (j = i + 1; j <= i + k; j++) g[i][j % n] = 1, ans++;       int flag = 1;       for (i = 0; i < n; i++)         for (j = 0; j < n; j++)           if (g[i][j] && g[j][i]) flag = 0;       if (flag) {         printf( %d n , ans);         for (i = 0; i < n; i++)           for (j = 0; j < n; j++)             if (g[i][j]) printf( %d %d n , i + 1, j + 1);       } else         puts( -1 );     }     return 0;   }
#include <bits/stdc++.h>   struct node {     int a, b, w;   } p[200005];   int fa[200005];   bool d[200005];   bool cmp(node x, node y) { return x.w > y.w; }   int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }   int main() {     int n, m, ans = 0;     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       scanf( %d%d%d , &p[i].a, &p[i].b, &p[i].w);     }     std::sort(p + 1, p + m + 1, cmp);     for (int i = 1; i <= n; i++) {       fa[i] = i;       d[i] = true;     }     for (int i = 1; i <= m; i++) {       int x = find(p[i].a);       int y = find(p[i].b);       if (x != y && (d[x] || d[y])) {         fa[y] = x;         ans += p[i].w;         d[x] = d[x] & d[y];       } else if (x == y && d[x]) {         d[x] = false;         ans += p[i].w;       }     }     printf( %d n , ans);     return 0;   }
#include<bits/stdc++.h>   #define ll long long int   using namespace std;      int t;      int main(){       ios_base::sync_with_stdio(false);       cin.tie(NULL);       int n;       cin >> n;       int sum=0;       int odd=-1;       vector<int> a(n);       for (int q=0;q<n;q++){           int x;           cin>>x;           a[q]=x;           sum+=x;           if (odd==-1 && x%2==1){               odd=q;           }       }       if (sum%2==1){           cout<<0<<  n ;       }else{           int s=sum/2;           bool dp[n+1][s+1];           for (int i=0;i<=n;i++){               dp[i][0]=true;           }           for (int j=1;j<=s;j++){               dp[0][j]=false;           }           for (int i=1;i<=n;i++){               for (int j=1;j<=s;j++){                   if (dp[i-1][j]==true){                       dp[i][j]=true;                   }else{                       if (a[i-1]>j){                           dp[i][j]=false;                       }else{                           dp[i][j]=dp[i-1][j-a[i-1]];                       }                   }               }           }           if (dp[n][s]==false){               cout<<0<<  n ;           }else{               if (odd!=-1){                   cout<<1<<  n ;                   cout<<odd+1<<  n ;               }else{                   int idx=-1;                   int mn=33;                   for (int i=0;i<n;i++){                       if (mn > __builtin_ctz(a[i])){                           mn=__builtin_ctz(a[i]);                           idx=i;                       }                   }                   cout<<1<<  n ;                   cout<<idx+1<<  n ;               }           }       }          }
#include <bits/stdc++.h>   using namespace std;   int pre[100010];   char f[100010];   int a[100010];   int ans[100010];   int main() {     int n, m, i, c, cnt = 0;     scanf( %d , &n);     scanf( %d , &m);     for (i = 0; i < n; ++i) {       scanf( %c , &f[i]);       scanf( %c , &f[i]);       scanf( %d , &a[i]);       --a[i];       if (f[i] ==  + ) {         pre[a[i]]++;         pre[a[i] + 1]--;       } else {         if (a[i]) {           pre[0]++;           pre[a[i]]--;         }         pre[a[i] + 1]++;       }     }     if (pre[0] == m) {       ans[0] = 1;       cnt++;     } else {       ans[0] = 0;     }     for (i = 1; i < n; ++i) {       pre[i] = pre[i - 1] + pre[i];       if (pre[i] == m) {         ans[i] = 1;         cnt++;       } else {         ans[i] = 0;       }     }     if (cnt > 1)       for (i = 0; i < n; ++i)         if (ans[i] == 1) ans[i] = -1;     for (i = 0; i < n; ++i) {       if (f[i] ==  + ) {         if (ans[a[i]] == 1)           printf( Truth n );         else if (ans[a[i]] == 0)           printf( Lie n );         else           printf( Not defined n );       } else {         if (ans[a[i]] == 0)           printf( Truth n );         else if (ans[a[i]] == 1)           printf( Lie n );         else           printf( Not defined n );       }     }   }
#include <bits/stdc++.h>   using namespace std;   int vis[500500];   int a[500500];   int b[500500];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     for (int j = 0; j < n; j++) cin >> b[j];     int ans = 0;     int j = 0;     for (int i = 0; i < n; i++) {       if (vis[a[i]]) continue;       while (j < n && b[j] != a[i]) {         vis[b[j]] = 1;         ans++;         j++;       }       if (j < n && a[i] == b[j]) j++;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, u, r;   long long ans = -1e18;   long long a[35], b[35], k[35], p[35];   void calc(long long aa[]) {     long long mx = 0;     for (int i = 1; i <= n; i++) mx += aa[i] * k[i];     ans = (ans > mx ? ans : mx);   }   void dfs(long long depth, long long aa[]) {     if (depth == u) {       calc(aa);       return;     }     long long t1[35], t2[35];     for (int i = 1; i <= n; i++) t1[i] = aa[i] ^ b[i];     if ((u - depth) % 2)       calc(t1);     else       calc(aa);     for (int i = 1; i <= n; i++) t2[i] = aa[p[i]] + r;     dfs(depth + 1, t2);     if (depth <= u - 2) {       for (int i = 1; i <= n; i++) t2[i] = t1[p[i]] + r;       dfs(depth + 2, t2);     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie();     cout.tie();     cin >> n >> u >> r;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n; i++) cin >> b[i];     for (int i = 1; i <= n; i++) cin >> k[i];     for (int i = 1; i <= n; i++) cin >> p[i];     dfs(0, a);     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, q;     cin >> n >> q;     vector<int> res(n + 1, 0);     vector<vector<int>> adjacenyList(n + 1);     for (int i = 1; i < n; i++) {       int u, v;       cin >> u >> v;       adjacenyList[u].emplace_back(v);       adjacenyList[v].emplace_back(u);     }     function<void(int, int)> DFS = [&](int u, int val) {       res[u] = val;       for (int v : adjacenyList[u]) {         if (res[v]) continue;         DFS(v, min(v, val));       }     };     int c = 0, l = 0;     int t, x;     cin >> t >> x;     x = (x + l) % n + 1;     c = x;     DFS(x, x);     while (--q) {       cin >> t >> x;       x = (x + l) % n + 1;       if (t & 1) {         c = min(c, res[x]);       } else {         l = min(c, res[x]);         cout << l <<   n ;       }     }   }