malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int H, M, K;   int NonZeroDigit(int x) {     int res = 0;     while (x) {       if (x % 10) res++;       x /= 10;     }     return res;   }   int Get(int x, int p) {     for (int i = 1; i < p; ++i) x /= 10;     return x;   }   long long Solve(int h, int m) {     int d = NonZeroDigit(M - 1);     long long res = Get(h, K - d);     res += (long long)Get(m, K) + (long long)h * Get(M - 1, K);     return res;   }   int main() {     cin >> H >> M >> K;     int h1, m1, h2, m2;     cin >> h1 >> m1 >> h2 >> m2;     if (pair<int, int>(h1, m1) <= pair<int, int>(h2, m2))       cout << Solve(h2, m2) - Solve(h1, m1) << endl;     else       cout << Solve(H - 1, M - 1) - Solve(h1, m1) +                   (NonZeroDigit(H - 1) + NonZeroDigit(M - 1) >= K) + Solve(h2, m2)            << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a1, a2, a3, a4;   int head;   int b, c;   int nott(int x) {     if (x == 4) return 7;     return 4;   }   int main() {     cin >> a1 >> a2 >> a3 >> a4;     if (abs(a3 - a4) > 1) {       cout << -1 << endl;       return 0;     }     if (a3 > a4) head = 4;     if (a4 > a3) head = 7;     c = a3;     b = a4;     if (!head) {       if (b != a1)         head = 4;       else         head = 7;     }     if (head) {       if (head == 7)         c++;       else         b++;     }     if (b > a1 || c > a2) {       cout << -1 << endl;       return 0;     }     if (head == 7) {       cout << 7;       a2--;       a4--;       c--;     }     for (int i = 0; i < a1 - (b - 1); ++i) cout << 4;     for (int i = 0; i < b - 1 - (b == c + 1); ++i) cout << 74;     for (int i = 0; i < a2 - (b - 1) + (b == c + 1); ++i) cout << 7;     if (b == c + 1) cout << 4;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string st, t;   vector<string> a;   int p;   int main() {     ios_base ::sync_with_stdio(false);     cin >> st;     for (auto i : st) {       t += i;       if (i ==  > ) {         a.push_back(t);         t =   ;       }     }     for (auto i : a) {       if (i[1] ==  / ) {         --p;       }       for (int j = 0; j < p; ++j) {         cout <<     ;       }       cout << i << endl;       if (i[1] !=  / ) {         ++p;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int a[110][110], row[110], col[110], ansrow[110], anscol[110], n, m, tans, ans;   bool flag;   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) scanf( %d , &a[i][j]);     ans = 10000000;     for (int i = 0; i <= 500; i++) {       row[1] = i;       flag = 1;       for (int j = 1; j <= m; j++)         if (a[1][j] < i) {           flag = 0;           break;         } else           col[j] = a[1][j] - i;       if (!flag) break;       for (int j = 2; j <= n; j++) {         if (a[j][1] - col[1] < 0) {           flag = 0;           break;         }         row[j] = a[j][1] - col[1];         for (int k = 2; k <= m; k++)           if (a[j][k] - col[k] != row[j]) {             flag = 0;             break;           }         if (!flag) break;       }       if (!flag) continue;       tans = 0;       for (int j = 1; j <= n; j++) tans += row[j];       for (int j = 1; j <= m; j++) tans += col[j];       if (tans < ans) {         ans = tans;         for (int j = 1; j <= n; j++) ansrow[j] = row[j];         for (int j = 1; j <= m; j++) anscol[j] = col[j];       }     }     if (ans == 10000000) {       printf( -1 );       return 0;     }     printf( %d n , ans);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= ansrow[i]; j++) printf( row %d n , i);     for (int i = 1; i <= m; i++)       for (int j = 1; j <= anscol[i]; j++) printf( col %d n , i);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[1000050];   vector<int> vec[1000050];   int pos[1000050];   int main() {     int n, x;     scanf( %d%d , &n, &x);     for (int i = 0; i < n; i++) {       scanf( %d , a + i);       vec[a[i]].push_back(i);     }     pos[x + 1] = n;     int st = 1;     for (int i = x; i; i--) {       pos[i] = pos[i + 1];       if (vec[i].size()) {         if (vec[i].back() < pos[i]) {           pos[i] = vec[i][0];         } else {           st = i + 1;           break;         }       }     }     int cur = -1;     long long res = 0;     for (int i = 1; i <= x; i++) {       int p = lower_bound(pos + st, pos + x + 1, cur) - pos;       p = max(p, i + 1);       res += (x - p + 2);       if (p == i) res--;       if (vec[i].size()) {         if (cur < vec[i][0])           cur = vec[i].back();         else           break;       }     }     printf( %lld n , res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, k;     cin >> n >> k;     priority_queue<pair<int, int> > p;     set<int> s;     for (int i = 1; i <= n; i++) {       int in;       cin >> in;       p.push({in, i});       s.insert(i + k);     }     long long ans = 0;     vector<int> v(n);     while (p.size()) {       int c = p.top().first, d = p.top().second;       p.pop();       auto it = s.lower_bound(d);       ans += 1LL * (*it - d) * c;       v[d - 1] = *it;       s.erase(it);     }     cout << ans <<   n ;     for (auto i : v) cout << i <<    ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string arf[1005], ars[1005];   string ans[1005];   void solve() {     int n;     cin >> n;     map<string, vector<int> > f, s;     int done[n];     memset(done, 0, sizeof(done));     ;     for (int i = 0; i < (int)(n); i++) {       string s1, s2;       cin >> s1 >> s2;       arf[i] = s1.substr(0, 3);       ars[i] = s1.substr(0, 2) + s2.substr(0, 1);       f[arf[i]].push_back(i);       s[ars[i]].push_back(i);     }     map<string, int> final;     for (auto i = f.begin(); i != f.end(); i++) {       if (i->second.size() > 1) {         for (int k = 0; k < i->second.size(); k++) {           final[ars[i->second[k]]]++;           ans[i->second[k]] = ars[i->second[k]];           done[i->second[k]] = 1;         }       }     }     for (int i = 0; i < n; i++) {       if (done[i] == 0) {         if (final[ars[i]] == 0) {           final[ars[i]] = 1;           ans[i] = ars[i];         } else if (final[arf[i]] == 0) {           final[arf[i]] = 1;           ans[i] = arf[i];         } else {           cout <<  NO ;           return;         }       }     }     for (auto i = final.begin(); i != final.end(); i++) {       if (i->second > 1) {         cout <<  NO ;         return;       }     }     cout <<  YES n ;     for (int i = 0; i < (int)(n); i++) {       cout << ans[i] <<   n ;     }   }   int main() {     cin.tie(0);     cout.tie(0);     cin.sync_with_stdio(0);     cout.sync_with_stdio(0);     int TC = 1;     for (int ZZ = 1; ZZ <= TC; ZZ++) {       clock_t start = clock();       solve();       clock_t end = clock();       cerr <<  Time:   << (double)(end - start) / CLOCKS_PER_SEC <<   seconds             <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 20;   int h[maxn], n, q, cnt;   string s;   struct Node {     int ans, mx, mn, l, r, lazy;     Node(int a = 0) { ans = mn = mx = l = r = lazy = a; }     void update(Node a, Node b) {       ans = max({a.ans, b.ans, a.l + b.mx, b.r + a.mx});       mx = max({a.mx, b.mx});       mn = min({a.mn, b.mn});       l = max({a.l, b.l, a.mx - 2 * b.mn});       r = max({a.r, b.r, b.mx - 2 * a.mn});     }   } sg[4 * maxn];   void add(int qval, int id) {     sg[id].l -= qval;     sg[id].r -= qval;     sg[id].mn += qval;     sg[id].mx += qval;     sg[id].lazy += qval;   }   void shift(int id) {     add(sg[id].lazy, id * 2);     add(sg[id].lazy, id * 2 + 1);     sg[id].lazy = 0;   }   void update(int l, int r, int ql, int qr, int qval, int id) {     if (l >= ql && r <= qr)       add(qval, id);     else if (l > qr || r < ql)       return;     else {       int mid = (l + r) / 2;       shift(id);       update(l, mid, ql, qr, qval, id * 2);       update(mid + 1, r, ql, qr, qval, id * 2 + 1);       sg[id].update(sg[id * 2], sg[id * 2 + 1]);     }   }   void build(int l, int r, int id) {     if (l == r) {       sg[id].mn = sg[id].mx = h[r];       sg[id].l = sg[id].r = -h[r];     } else {       int mid = (l + r) / 2;       build(l, mid, id * 2);       build(mid + 1, r, id * 2 + 1);       sg[id].update(sg[id * 2], sg[id * 2 + 1]);     }   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n >> q >> s;     for (int i = 0; i < 2 * n - 2; i++) {       if (s[i] ==  ( )         cnt++;       else         cnt--;       h[i + 2] = cnt;     }     build(1, 2 * n - 1, 1);     int a, b, tmp;     cout << sg[1].ans << endl;     while (q--) {       cin >> a >> b;       if (a > b) swap(a, b);       tmp = 0;       if (s[a - 1] ==  (  && s[b - 1] ==  ) ) tmp = -2;       if (s[a - 1] ==  )  && s[b - 1] ==  ( ) tmp = 2;       update(1, 2 * n - 1, a + 1, b, tmp, 1);       cout << sg[1].ans << endl;       swap(s[a - 1], s[b - 1]);     }   }
#include <bits/stdc++.h>   using namespace std;   int safeop(int n, int mod) { return (n + mod) % mod; }   int main() {     int n;     cin >> n;     vector<int> v(n, 0);     vector<pair<int, int>> ans(n);     for (int i = 0; i < n; i++) {       cin >> v[i];     }     int vn = n;     int v1 = -1;     stack<int> bal1;     stack<int> bal2;     stack<int> bal3;     for (int i = 0; i < n; i++) {       if (v[i] == 3) {         if (vn - v1 == 1) {           cout << -1;           return 0;         }         vn--;         ans[i] = make_pair(vn, -1);         if (!bal3.empty()) {           int tmp = bal3.top();           bal3.pop();           ans[tmp].second = i;           bal3.push(i);         } else {           bal3.push(i);         }       } else if (v[i] == 2) {         if (vn - v1 == 1) {           cout << -1;           return 0;         }         v1++;         ans[i] = make_pair(v1, -1);         if (!bal3.empty()) {           int tmp = bal3.top();           bal3.pop();           ans[tmp].second = i;           bal2.push(i);         } else {           bal2.push(i);         }       } else if (v[i] == 1) {         if (!bal2.empty()) {           int tmp = bal2.top();           bal2.pop();           ans[tmp].second = i;           ans[i] = make_pair(ans[tmp].first, 0);         } else if (!bal3.empty()) {           if (vn - v1 == 1) {             cout << -1;             return 0;           }           vn--;           ans[i] = make_pair(vn, 0);           int tmp = bal3.top();           bal3.pop();           ans[tmp].second = i;         } else {           if (vn - v1 == 1) {             cout << -1;             return 0;           }           vn--;           ans[i] = make_pair(vn, 0);         }       } else {         continue;       }     }     for (int i = 0; i < n; i++) {       if (ans[i].second == -1) {         cout << -1 << endl;         return 0;       }     }     set<pair<int, int>> ansset;     for (int i = 0; i < n; i++) {       if (v[i] == 1) {         ansset.insert(make_pair(i + 1, ans[i].first + 1));       }       if (v[i] == 2) {         ansset.insert(make_pair(i + 1, ans[i].first + 1));         ansset.insert(make_pair(ans[i].second + 1, ans[i].first + 1));       }       if (v[i] == 3) {         ansset.insert(make_pair(i + 1, ans[i].first + 1));         ansset.insert(make_pair(ans[i].second + 1, ans[i].first + 1));         ansset.insert(make_pair(ans[i].second + 1, ans[ans[i].second].first + 1));       }     }     cout << ansset.size() << endl;     for (auto it = ansset.begin(); it != ansset.end(); ++it) {       cout << n + 1 - it->second <<     << it->first << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int t, n;   string s;   int main(void) {     cin >> t;     while (t--) {       map<pair<int, int>, int> m;       int start = 0, end = 2147483647, x = 0, y = 0;       cin >> n >> s;       s.insert(s.begin(),  0 );       m.insert({make_pair(0, 0), 0});       for (int i = 1; i < s.size(); i++) {         if (s[i] ==  L )           x -= 1;         else if (s[i] ==  R )           x += 1;         else if (s[i] ==  U )           y += 1;         else           y -= 1;         pair<int, int> p = make_pair(x, y);         if (m.find(p) == m.end()) {           m.insert({p, i});         } else {           if (i - m[p] < end - start) {             start = m[p] + 1;             end = i;           }           m[p] = i;         }       }       if (end == 2147483647)         cout <<  -1 n ;       else         cout << start <<     << end << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 20;   const int M = 1e5 + 55;   pair<int, int> dp[(1 << N) + 5];   int dis[N][N];   int My[(1 << N) + 5][N];   int taken[(1 << N) + 5][N];   char s[M];   int sum[N];   int lg[(1 << N) + 55];   int m, n;   pair<int, int> bt(int mask) {     if (mask == (1 << n) - 1) return {0, 0};     pair<int, int>& ret = dp[mask];     if (ret.first != -1) return ret;     ret = {10000000, 0};     int cur = 0;     pair<int, int> nxt;     for (int v = 0; v < n; v++) {       if ((mask & (1 << v)) == 0) {         nxt = bt(mask + (1 << v));         cur = nxt.second - My[mask][v];         cur += nxt.first + taken[mask][v];         if (cur < ret.first)           ret = {cur, nxt.second + taken[mask][v] - My[mask][v]};       }     }     return ret;   }   void prep(int mask, int i, int l, int pre) {     if (i == n - 1) {       taken[mask][l] = pre;       My[mask][l] = 0;       return;     }     if (My[mask][l] != -1) return;     for (int j = 0; j < n; j++) {       if ((mask & (1 << j)) == 0 && j != l) {         prep(mask + (1 << j), i + 1, l, pre + dis[l][j]);         My[mask][l] = My[mask + (1 << j)][l] + dis[l][j];       }     }     taken[mask][l] = pre;   }   int main() {     memset(dp, -1, sizeof dp);     memset(My, -1, sizeof My);     scanf( %d %d , &m, &n);     scanf( %s , s);     for (int i = 0; i < m - 1; i++) {       if (s[i] != s[i + 1]) {         dis[s[i] -  a ][s[i + 1] -  a ]++;         sum[s[i] -  a ]++;         sum[s[i + 1] -  a ]++;         dis[s[i + 1] -  a ][s[i] -  a ]++;       }     }     for (int i = 0; i < n; i++) lg[(1 << i)] = i;     int ms;     for (int l = 0; l < n; l++) {       for (int mask = (1 << n) - 1; mask >= 0; mask--) {         if (mask & (1 << l)) continue;         mask += (1 << l);         ms = mask | (mask + 1);         mask -= (1 << l);         ms -= (1 << l);         if (ms >= (1 << n)) {           taken[mask][l] = sum[l];           My[mask][l] = 0;           continue;         }         My[mask][l] = My[ms][l] + dis[lg[mask ^ ms]][l];         taken[mask][l] = taken[ms][l] - dis[l][lg[mask ^ ms]];       }     }     cout << bt(0).first << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a[100001];   int main() {     long long int n, i, count = 0;     long long sum = 0;     scanf( %I64d , &n);     for (i = 0; i < n; i++) scanf( %I64d , a + i);     sort(a, a + n);     for (i = 0; i < n; i++) {       if (sum <= a[i]) {         count++;         sum += a[i];       }     }     printf( %I64d n , count);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int x, y, idx;     cin >> x >> y >> idx;     if (idx == 0)       cout << x << endl;     else if (idx == 1)       cout << y << endl;     else {       idx -= 2;       int z;       while (true) {         z = x + y;         idx--;         if (idx < 0) break;         x = y;         y = z;       }       cout << z << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   using INT = unsigned long long;   const int N = 100000;   struct Ring {     INT a[5];     Ring() { memset(a, 0, sizeof a); }     Ring operator+(Ring r) {       Ring R = r;       for (int i = 0; i < 5; i++) R.a[i] += a[i];       return R;     }     void operator+=(Ring r) { (*this) = (*this) + r; }     Ring operator*(Ring r) {       Ring R;       for (int i = 0; i < 5; i++)         for (int j = 0; j < 5; j++)           i + j < 5 ? R.a[i + j] += a[i] * r.a[j]                     : R.a[i + j - 5] -= a[i] * r.a[j];       return R;     }     void operator*=(Ring r) { (*this) = (*this) * r; }     Ring operator<<(int k) {       Ring R;       for (int i = 0; i < 5; i++) {         int j = (i + k) % 10;         j < 5 ? R.a[j] = a[i] : R.a[j - 5] = -a[i];       }       return R;     }     INT real() { return a[0] + a[1]; }   } x[N], w[10], tmp[10];   INT power(INT a, INT n, INT ans = 1) {     for (; n; n >>= 1, a *= a)       if (n & 1) ans *= a;     return ans;   }   Ring power(Ring a, INT n) {     Ring ans;     ans.a[0] = 1;     for (; n; n >>= 1, a *= a)       if (n & 1) ans *= a;     return ans;   }   void DFT(Ring *P, int op) {     for (int i = 1; i < N; i *= 10) {       for (int p = i * 10, j = 0; j < N; j += p) {         for (int k = 0; k < i; k++) {           for (int x = 0; x < 10; x++) tmp[x] = P[j + k + x * i];           for (int x = 0; x < 10; x++) {             Ring &r = P[j + k + x * i];             r = Ring();             for (int y = 0; y < 10; y++) r += tmp[y] << x * y * op;           }         }       }     }   }   int n;   int main() {     scanf( %d , &n);     for (int i = 0, k; i < n; i++) {       scanf( %d , &k);       x[k].a[0]++;     }     DFT(x, 1);     for (int i = 0; i < N; i++) x[i] = power(x[i], n);     DFT(x, 9);     INT inv = power(5, (1ull << 63) - 5);     for (int i = 0; i < n; i++)       printf( %I64d n , (x[i].real() >> 5) * inv & ((1ull << 58) - 1));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, cnt = 0;     cin >> n;     char arr[n];     for (i = 0; i < n; i++) cin >> arr[i];     for (i = 0; i < n - 1; i++) {       if (arr[i] ==  U  && arr[i + 1] ==  R ) {         arr[i] =  D ;         arr[i + 1] =  D ;       } else if (arr[i] ==  R  && arr[i + 1] ==  U ) {         arr[i] =  D ;         arr[i + 1] =  D ;       }     }     for (i = 0; i < n; i++)       if (arr[i] ==  D ) ++cnt;     cout << n - cnt / 2;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base ::sync_with_stdio(false);     cin.tie(NULL);     long long int tests = 1;     while (tests--) {       long long int n;       int x;       cin >> n >> x;       if (n % 6 == 0)         cout << x;       else if (n % 6 == 1) {         if (x == 0)           cout << 1;         else if (x == 1)           cout << 0;         else           cout << 2;       } else if (n % 6 == 2) {         if (x == 0)           cout << 1;         else if (x == 1)           cout << 2;         else           cout << 0;       } else if (n % 6 == 3) {         if (x == 0)           cout << 2;         else if (x == 1)           cout << 1;         else           cout << 0;       } else if (n % 6 == 4) {         if (x == 0)           cout << 2;         else if (x == 1)           cout << 0;         else           cout << 1;       } else {         if (x == 0)           cout << 0;         else if (x == 1)           cout << 2;         else           cout << 1;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   ostream &operator<<(ostream &out, const pair<T, U> &p) {     out <<  (  << p.first <<  ,   << p.second <<  ) ;     return out;   }   template <template <typename, typename...> class ContainerType,             typename ValueType, typename... Args>   void print(const ContainerType<ValueType, Args...> &c) {     for (const auto &v : c) cout << v <<    ;     cout <<   n ;   }   void print() { cout <<   n ; }   template <typename T, typename... Args>   void print(T a, Args... args) {     cout << a <<    ;     print(args...);   }   long long llipower(long long x, long long y, long long p = LLONG_MAX) {     long long res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   int main() {     int t;     cin >> t;     while (t--) {       int x, y, z;       cin >> x >> y >> z;       if (x == y && x >= z) {         cout <<  YES               <<   n ;         print(x, 1, z);       } else if (y == z && y >= x) {         cout <<  YES               <<   n ;         print(1, x, y);       } else if (z == x && x >= y) {         cout <<  YES               <<   n ;         print(1, x, y);       } else {         cout <<  NO               <<   n ;       }     }   }
#include <bits/stdc++.h>   int isPerfectSquare(int number) {     int iVar;     float fVar;     fVar = sqrt((double)number);     iVar = fVar;     if (iVar == fVar)       return 1;     else       return 0;   }   int main() {     int no;     scanf( %d n , &no);     int a[no];     int max;     max = -1000000;     for (int i = 0; i < no; i++) {       scanf( %d , &a[i]);     }     for (int i = 0; i < no; i++) {       if (isPerfectSquare(a[i]))         continue;       else {         if (a[i] > max) max = a[i];       }     }     printf( %d , max);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 7;   vector<int> ad[N];   int h[N], n, m, dp[N][30];   int d[N], R = 320;   vector<int> red;   void dfs(int v, int p) {     h[v] = h[p] + 1;     dp[v][1] = p;     for (auto u : ad[v]) {       if (u != p) dfs(u, v);     }   }   int dis(int u, int v) {     int res = 0;     if (h[v] < h[u]) swap(v, u);     for (int i = 20; i >= 1; i--) {       if (h[v] - (1 << (i - 1)) >= h[u]) {         res += (1 << (i - 1));         v = dp[v][i];       }     }     if (u == v) return res;     for (int i = 20; i >= 1; i--) {       if (dp[v][i] != dp[u][i]) {         res += 2 * (1 << (i - 1));         v = dp[v][i];         u = dp[u][i];       }     }     return res + 2;   }   void bfs() {     deque<int> dq;     memset(d, 0, sizeof d);     for (auto u : red) dq.push_back(u), d[u] = 1;     while (dq.size()) {       int v = dq[0];       dq.pop_front();       for (auto u : ad[v]) {         if (!d[u]) d[u] = d[v] + 1, dq.push_back(u);       }     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     for (int i = 1; i < n; i++) {       int u, v;       cin >> u >> v;       ad[u].push_back(v);       ad[v].push_back(u);     }     for (int i = 1; i <= n; i++) dp[i][0] = i;     dfs(1, 0);     for (int j = 2; j <= 20; j++)       for (int i = 1; i <= n; i++) dp[i][j] = dp[dp[i][j - 1]][j - 1];     vector<int> pos;     red.push_back(1);     bfs();     while (m--) {       int t;       cin >> t;       if (t == 1) {         int tt;         cin >> tt;         pos.push_back(tt);         if (pos.size() > R) {           for (auto u : pos) {             red.push_back(u);           }           bfs();           pos.clear();         }       } else {         int v;         cin >> v;         int res = d[v] - 1;         for (auto u : pos) res = min(res, dis(v, u));         cout << res <<   n ;       }     }     return 0;   }