malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   using namespace rel_ops;   const int inf = ~0u >> 2;   const long long INF = ~0ull >> 2;   const double err = 1e-11;   const double pi = acos(-1);   inline long long read() {     long long x;     if (scanf( %lld , &x) == -1) exit(0);     return x;   }   inline double readf() {     double x;     if (scanf( %lf , &x) == -1) exit(0);     return x;   }   template <typename _>   inline _ sqr(_ x) {     return x * x;   }   ostream &operator<<(ostream &o, const pair<int, int> &x) {     return o <<  (  << x.first <<  ,  << x.second <<  ) ;   }   mt19937 rnd(time(0));   const int N = 20010;   const int mod = (0 ? 1000000007 : 998244353);   long long T;   string s;   deque<char> a;   set<char> Set;   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> T;     while (T--) {       cin >> s;       Set.clear();       a.clear();       long long i = 0, f = 1;       for (auto c : s) {         if (Set.empty()) {           Set.insert(c);           a.push_back(c);           continue;         }         if (Set.count(c)) {           if (i != 0 && a[i - 1] == c) {             i--;             continue;           }           if (i != (long long)a.size() - 1 && a[i + 1] == c) {             i++;             continue;           }           f = false;         } else {           if (i == 0) {             a.push_front(c);             Set.insert(c);             continue;           }           if (i == (long long)a.size() - 1) {             a.push_back(c);             Set.insert(c);             i++;             continue;           }           f = false;         }       }       if (f) {         cout <<  YES  << endl;         for (long long i = ( a ), _ = ( z  + 1); i < _; i++)           if (!Set.count(i)) {             a.push_back(i);           }         for (auto i : a) cout << char(i);         cout << endl;       } else         cout <<  NO  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   int dx[] = {0, 0, 1, -1};   int dy[] = {1, -1, 0, 0};   int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};   int dy8[] = {1, -1, -1, 0, 1, -1, 0, 1};   int kx8[] = {1, 1, 2, 2, -1, -1, -2, -2};   int ky8[] = {2, -2, 1, -1, 2, -2, 1, -1};   const int M = 100005;   vector<int> Slope[M * 4], C[M * 4], idx[M * 4];   long long get(int n, long long id, long long x) {     return (Slope[n][id] * x + C[n][id]);   }   double cross(int n, int x, int y) {     return (double)(C[n][x] - C[n][y]) / (Slope[n][y] - Slope[n][x]);   }   void AddLine(int n, int id, long long p, long long q) {     if (Slope[n].size() > 0 && Slope[n].back() == p) {       if (C[n].back() < q) {         Slope[n].pop_back();         C[n].pop_back();         idx[n].pop_back();       } else         return;     }     Slope[n].push_back(p);     C[n].push_back(q);     idx[n].push_back(id);     int hsz = Slope[n].size();     while (hsz >= 3 && cross(n, hsz - 3, hsz - 2) > cross(n, hsz - 3, hsz - 1)) {       --hsz;       Slope[n][hsz - 1] = Slope[n][hsz];       C[n][hsz - 1] = C[n][hsz];       idx[n][hsz - 1] = idx[n][hsz];       Slope[n].pop_back();       C[n].pop_back();       idx[n].pop_back();     }   }   pair<long long, long long> query(int n, long long x) {     long long hsz = (int)Slope[n].size() - 1;     long long lw = 0, hi = hsz, mid, midd;     pair<long long, long long> ans = {-9e18, 0};     while (hi - lw > 3) {       mid = (lw + hi) / 2;       midd = min(hsz, mid + 1);       if (get(n, mid, x) >= get(n, midd, x)) {         hi = mid;       } else {         lw = midd;       }     }     for (long long i = lw; i <= hi; i++)       ans = max(ans, {get(n, i, x), idx[n][i]});     return ans;   }   void update(int l, int r, int k, int L, pair<long long, long long> p) {     if (l > L || r < L) return;     AddLine(k, L, p.first, p.second);     if (l == r) return;     int mid = (l + r) / 2;     update(l, mid, k * 2, L, p);     update(mid + 1, r, k * 2 + 1, L, p);   }   pair<long long, long long> query(int l, int r, int k, int L, int R,                                    long long val) {     if (l > R || r < L) return {-9e18, 0};     if (l >= L && r <= R) {       return query(k, val);     }     int mid = (l + r) / 2;     pair<long long, long long> ret = {-9e18, 0};     ret = max(ret, query(l, mid, k * 2, L, R, val));     ret = max(ret, query(mid + 1, r, k * 2 + 1, L, R, val));     return ret;   }   vector<pair<pair<long long, long long>, long long> > vec;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n >> m;     for (int i = 1; i <= n; i++) {       int x, y;       cin >> x >> y;       vec.push_back({{y, x}, i});     }     sort(vec.begin(), vec.end());     for (auto z : vec) {       int id = z.second;       update(1, n, 1, id, z.first);     }     for (int i = 1; i <= m; i++) {       int l, r, x;       cin >> l >> r >> x;       cout << query(1, n, 1, l, r, x).second <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long x, y;   long long a[300010];   vector<long long> fac, facn;   vector<int> facx, facy;   vector<pair<int, int> > facv;   vector<long long> check;   int n;   long long sum[300010];   long long gcd(long long x, long long y) {     if (y == 0) return x;     return gcd(y, x % y);   }   void factorize(long long val) {     for (long long i = 2; i <= val && i <= 1000000ll; i++)       if (val % i == 0) {         fac.push_back(i);         while (val % i == 0) val /= i;       }     if (val > 1) {       long long q = (long long)(sqrt(val));       if (q * q == val) {         fac.push_back(q);         return;       }       for (int i = 1; i <= n; i++) check.push_back(a[i]);       check.push_back(x);       check.push_back(y);       long long g = val;       for (int i = 0; i < check.size(); i++) {         g = gcd(val, check[i]);         if (g != 1 && g != val) {           if (g < val / g) {             fac.push_back(g);             fac.push_back(val / g);           } else {             fac.push_back(val / g);             fac.push_back(g);           }           return;         }       }       fac.push_back(val);     }   }   int main() {     scanf( %d%I64d%I64d , &n, &x, &y);     for (int i = 1; i <= n; i++) scanf( %I64d , &a[i]);     factorize(y);     if (y % x) {       printf( 0 );       return 0;     }     for (int i = 0; i < fac.size(); i++) facv.push_back(make_pair(0, 0));     long long x1 = x;     long long chunhua = y;     for (int i = 0; i < fac.size(); i++) {       int cnt = 0;       while (x1 % fac[i] == 0) {         x1 /= fac[i];         cnt++;       }       facv[i].first = cnt;     }     for (int i = 0; i < fac.size(); i++) {       int cnt = 0;       while (chunhua % fac[i] == 0) {         chunhua /= fac[i];         cnt++;       }       facv[i].second = cnt;     }     for (int i = 0; i < fac.size(); i++) {       if (facv[i].first != facv[i].second) {         facn.push_back(fac[i]);         facx.push_back(facv[i].first);         facy.push_back(facv[i].second);       }     }     for (int i = 1; i <= n; i++) {       if (a[i] % x) continue;       long long val = a[i];       int mask = 0;       for (int j = 0; j < facn.size(); j++) {         int cnt = 0;         while (val % facn[j] == 0) {           val /= facn[j];           cnt++;         }         mask += ((cnt > facx[j]) << j);       }       sum[mask]++;     }     for (int i = 0; i < facn.size(); i++)       for (int mask = 0; mask < (1 << facn.size()); mask++)         if (mask & (1 << i)) sum[mask] += sum[mask - (1 << i)];     long long ans = 0;     for (int i = 1; i <= n; i++) {       if (y % a[i]) continue;       long long val = a[i];       int mask = 0;       for (int j = 0; j < facn.size(); j++) {         int cnt = 0;         while (val % facn[j] == 0) {           val /= facn[j];           cnt++;         }         mask += ((cnt < facy[j]) << j);       }       ans += sum[(1 << facn.size()) - mask - 1];     }     printf( %I64d , ans);   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int tc;     cin >> tc;     while (tc--) {       long long a, b, c, r;       cin >> a >> b >> c >> r;       if (a > b) swap(a, b);       long long left = c - r, right = c + r;       long long dist = 0;       if (b < left) {         cout << b - a <<   n ;       } else if (a > right) {         cout << b - a <<   n ;       } else {         dist += max(0ll, left - a);         dist += max(0ll, b - right);         cout << dist <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long f[55];   int a[55];   int main() {     int n, i;     long long k;     f[1] = 1, f[2] = 2;     for (i = 3; i <= 50; i++) f[i] = f[i - 1] + f[i - 2];     while (scanf( %d%lld , &n, &k) == 2) {       for (i = 1; i <= n;) {         if (k <= f[n - i] || i == n) {           a[i] = i;           i++;         } else {           k = k - f[n - i];           a[i] = i + 1;           i++;           a[i] = i - 1;           i++;         }       }       for (i = 1; i <= n; i++) printf( %d%c , a[i], (i == n) ?   n  :    );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int M = 1e9;   int ask(int x, int y) {     cout <<  ?   << x <<     << y << endl;     cin >> x;     return x;   }   int main() {     int s = ask(1, 1), k;     int u, v, l = 1, r = M, mid;     while (r > l + 1) {       mid = l + r >> 1;       k = ask(1, mid);       if (k + mid - 1 != s)         r = mid;       else         l = mid;     }     u = ask(1, l) + 1;     v = l;     printf( ! %d %d %d %d , u, v, v - 1 + M - ask(M, 1), u - 1 + M - ask(1, M));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long l, r, k, x, y;   int main() {     scanf( %lld%lld%lld , &l, &r, &k), x = 1;     if (k == 1 || l == r || (r - l == 1 && l % 2 && (l ^ r) >= l))       return printf( %lld n1 n%lld n , l, l), 0;     for (int i = 0;; i++) {       if (x > l) {         y = i;         break;       }       x *= 2;     }     if (x + x / 2 <= r && k >= 3)       return printf( 0 n3 n%lld %lld %lld n , x - 1, x + x / 2, x + x / 2 - 1), 0;     if (r - l == 1)       return printf( %lld n2 n%lld %lld n , l ^ (l + 1), l, l + 1), 0;     if (l % 2) l++;     if (l + 3 <= r && k >= 4)       return printf( 0 n4 n%lld %lld %lld %lld n , l, l + 1, l + 2, l + 3), 0;     else       return printf( 1 n2 n%lld %lld n , l, l + 1), 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MaxN = 10004, NA = -1, MaxC = 0x3F3F3F3F;   int m, n, x;   int f(int n, int m, int x) {     n -= x + x;     m -= x + x;     if (n <= 0 || m <= 0) return 0;     return (n * m + 1) >> 1;   }   int main(void) {     while (scanf(  %d %d %d , &n, &m, &x) != EOF) {       printf( %d n , f(n, m, x - 1) - f(n, m, x));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int num = 0;   int cnt[1000] = {0};   int candidate[400005] = {0};   string s;   bool check(int added) {     if (added % 2) return false;     if (n % (added + num)) return false;     if ((n / (added + num)) % 2 == 0) return false;     return true;   }   int main() {     cin >> n >> s;     for (int i = 0; i < n; ++i) cnt[s[i]]++;     for (int i = 0; i < 200; ++i) {       if (cnt[i] % 2) {         cnt[i] -= 1;         candidate[num++] = i;       }     }     if (num == 0) {       string before =   ;       string after =   ;       for (int j = 40; j < 130; ++j) {         while (cnt[j] >= 2) {           cnt[j] -= 2;           before += j;           after += j;         }       }       cout << 1 << endl;       reverse(before.begin(), before.end());       cout << before + after << endl;       return 0;     }     int added = 0;     while (!check(added)) ++added;     for (int i = 40; i < 130; ++i) {       if (!added) break;       if (cnt[i] > added) {         for (int j = 0; j < added; ++j) candidate[num++] = i;         cnt[i] -= added;         added = 0;       } else {         for (int j = 0; j < cnt[i]; ++j) candidate[num++] = i;         added -= cnt[i];         cnt[i] = 0;       }     }     cout << num << endl;     for (int i = 0; i < num; ++i) {       string before =   ;       string after =   ;       after += char(candidate[i]);       int remain = (n / num) - 1;       for (int j = 40; j < 130; ++j) {         if (!remain) break;         if (cnt[j] >= remain) {           for (int k = 0; k < remain / 2; ++k) {             before += char(j);             after += char(j);           }           cnt[j] -= remain;           remain = 0;         } else {           for (int k = 0; k < cnt[j] / 2; ++k) {             before += char(j);             after += char(j);           }           remain -= cnt[j];           cnt[j] = 0;         }       }       reverse(before.begin(), before.end());       cout << before + after <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int r1, c1, r2, c2, a[505][505], N, M, dx[4] = {-1, 0, 1, 0},                                          dy[4] = {0, 1, 0, -1};   bool viz[505][505];   char c;   queue<pair<int, int> > Q;   bool bfs(int x, int y, int xx, int yy) {     Q.push(make_pair(x, y));     while (Q.size()) {       pair<int, int> nod = Q.front();       Q.pop();       for (int i = 0; i < 4; ++i) {         int nx = nod.first + dx[i], ny = nod.second + dy[i];         if (a[nx][ny] == 1 && nx == xx && ny == yy) {           return 1;         } else if (a[nx][ny] == 2) {           --a[nx][ny];           Q.push(make_pair(nx, ny));         }       }     }     return 0;   }   int main() {     cin.sync_with_stdio(false);     cin >> N >> M;     for (int i = 1; i <= N; ++i)       for (int j = 1; j <= M; ++j) {         cin >> c;         if (c ==  . )           a[i][j] = 2;         else           a[i][j] = 1;       }     cin >> r1 >> c1 >> r2 >> c2;     if (bfs(r1, c1, r2, c2))       cout <<  YES ;     else       cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   const long double eps = 1e-7;   const int inf = 1000000010;   const long long INF = 10000000000000010LL;   const int mod = 1000000007;   const int MAXN = 100010;   long long n, m, k, x, y, z, a, b, c, t1, t2, cnt, p;   long long X[MAXN];   long long Y[MAXN];   bool X2[MAXN];   bool Y2[MAXN];   long long powmod(long long a, long long b) {     if (!b) return 1;     if (b & 1) return a * powmod(a, b - 1) % p;     return powmod(a * a % p, b >> 1);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> k;     if ((m ^ n) & 1) return cout << 0 <<   n , 0;     ;     for (int i = 0; i < k; i++) {       cin >> a >> b >> c;       X[a]++;       Y[b]++;       if (c == -1) {         X2[a] ^= 1;         Y2[b] ^= 1;       }     }     for (int i = 1; i <= n; i++)       if (X[i] == m) {         if (!X2[i]) return cout << 0 <<   n , 0;         ;         t1++;       }     for (int i = 1; i <= m; i++)       if (Y[i] == n) {         if (!Y2[i]) return cout << 0 <<   n , 0;         ;         t2++;       }     cnt = (n - t1 - 1) * (m - t2 - 1) - (k - t1 * m - t2 * n + t1 * t2);     cin >> p;     cout << powmod(2, cnt) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int deg[10000 + 10];   int main() {     int n;     cin >> n;     for (int i = 1; i < n; i++) {       int a, b;       cin >> a >> b;       deg[a - 1]++, deg[b - 1]++;     }     int ans = 0;     for (int i = 0; i < n; i++) ans += deg[i] * (deg[i] - 1) / 2;     cout << ans;   }
#include <bits/stdc++.h>   void build(const std::vector<std::pair<int, int>>& values,              std::vector<int64_t>& seg, int node, int start, int end) {     if (start == end) {       seg[node] = values[start].second;     } else if (start < end) {       int mid = (start + end) / 2;       build(values, seg, 2 * node, start, mid);       build(values, seg, 2 * node + 1, mid + 1, end);       seg[node] = seg[2 * node] + seg[2 * node + 1];     }   }   int64_t query(const std::vector<int64_t>& seg, int node, int start, int end,                 int l, int r) {     if (r < start || end < l) {       return 0;     }     if (l <= start && end <= r) {       return seg[node];     }     int mid = (start + end) / 2;     int64_t p1 = query(seg, 2 * node, start, mid, l, r);     int64_t p2 = query(seg, 2 * node + 1, mid + 1, end, l, r);     return (p1 + p2);   }   int getUpperBound(const std::vector<std::pair<int, int>>& values, int v,                     int start, int end) {     int l = start;     int r = end;     while (l < r) {       int m = (l + r + 1) / 2;       if (v >= values[m].first) {         l = m;       } else {         r = m - 1;       }     }     if (values[r].first <= v) return r;     return -1;   }   int main() {     std::ios::sync_with_stdio(false);     int s, b;     std::cin >> s >> b;     std::vector<int> a(s, 0);     for (int i = 0; i < s; ++i) std::cin >> a[i];     std::vector<std::pair<int, int>> dg(b, {0, 0});     for (int i = 0; i < b; ++i) std::cin >> dg[i].first >> dg[i].second;     std::sort(dg.begin(), dg.end());     std::vector<int64_t> seg(4 * b, 0);     build(dg, seg, 1, 0, b - 1);     for (int i = 0; i < s; ++i) {       auto offset = getUpperBound(dg, a[i], 0, b - 1);       if (offset != -1) {         std::cout << query(seg, 1, 0, b - 1, 0, offset) <<    ;       } else {         std::cout << 0 <<    ;       }     }     return 0;   }
#include <bits/stdc++.h>   const long long int mod = 1000000007;   const long long int AM = 2e5 + 5;   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     long long int t;     cin >> t;     while (t--) {       long long int n;       cin >> n;       string s[n + 1];       for (__typeof(0) i = 0; i < n; ++i) cin >> s[i];       long long int cnt[200] = {0};       for (__typeof(0) i = 0; i < n; ++i) {         for (__typeof(0) j = 0; j < s[i].size(); ++j) {           cnt[s[i][j] -  a ]++;         }       }       long long int flag = 1;       for (__typeof(0) i = 0; i < 26; ++i) {         if (cnt[i] % n != 0) flag = 0;       }       if (flag)         cout <<  YES n ;       else         cout <<  NO n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1);   long long n, a[103][2601] = {}, ans = 0, mod = 1000000007, tmp = 0;   string second;   char c;   vector<pair<int, int> > vp;   bool first, f1;   bool cmpvp(pair<int, int> p1, pair<int, int> p2) {     if (p1.first < p2.first) return 1;     if (p1.first == p2.first)       if (p1.second < p2.second) return 1;     return 0;   }   int main() {     for (int i = 0; i < 26; ++i) a[1][i] = 1;     for (int i = 2; i <= 100; ++i) {       for (int j = 0; j <= 2600; ++j) {         for (int k = 0; k < 26; ++k)           a[i][j + k] = (a[i][j + k] + a[i - 1][j]) % mod;       }     }     cin >> n;     for (int i = 0; i < n; ++i) {       tmp = 0;       cin >> second;       for (int j = 0; second[j]; ++j) tmp += second[j] -  a ;       cout << a[second.size()][tmp] - 1 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;            int main()   {       int t;       cin>>t;       while(t--)       {           long long int n;           cin>>n;           long long int sum=0;           for(int i=0;i<n;i++)           {               long long int a;               cin>>a;               sum+=a;           }           sum%=n;           long long int k=n-sum;           cout<<sum*k<<endl;       }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, a[200005];   map<int, int> mp;   int temp, largest_num;   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       mp[a[i]] = max(mp[a[i]], mp[a[i] - 1] + 1);       if (temp < mp[a[i]]) {         largest_num = a[i];         temp = mp[a[i]];       }     }     cout << temp << endl;     int start = largest_num - temp + 1;     for (int i = 0; i < n; i++) {       if (a[i] == start) {         cout << i + 1 <<    ;         start++;       }     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string second;     cin >> second;     map<string, string> mp1;     for (int i = 0; i < 10; i++) {       string s1;       cin >> s1;       mp1[s1] = to_string(i);     }     string p =   ;     string ans =   ;     for (int i = 0; i < second.length(); i++) {       if (i % 10 == 0) {         p =   ;       }       p += second[i];       if (i % 10 == 9)         if (p.length() != 0) ans += mp1[p];     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string a, b;     cin >> a >> b;     int x = 0, y = 0, z = 0;     for (int i = 0; i < a.length(); i++) {       if (a[i] != b[i]) {         if (a[i] ==  4 )           x++;         else           y++;       }     }     cout << min(x, y) + abs(x - y);   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e5 + 1;   int a[MAXN], pre[MAXN], num[MAXN];   int main() {     int n, m;     cin >> n >> m;     int i;     int Biggest = -1, Smallest = 0x7ffffff;     for (i = 1; i <= n; i++) {       cin >> a[i];       Biggest = max(Biggest, a[i]);       Smallest = min(Smallest, a[i]);       num[a[i] - 1]++;     }     if (Biggest == Smallest) {       cout << 0 << endl;       return 0;     }     for (i = Biggest - 1; i >= Smallest; i--) {       pre[i] = pre[i + 1] + num[i];     }     int ans = 1;     int now = 0;     for (i = Biggest; i >= Smallest; i--) {       now += pre[i];       if (now > m) {         now = pre[i];         ans++;       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e5 + 5;   struct Node {     int value;     struct Node *next;   } *head = NULL, *tail;   struct Query {     int index, ans1, ans2;     long long round;   } queries[maxn];   bool cmp_by_round(const Query &lhs, const Query &rhs) {     return lhs.round < rhs.round;   }   bool cmp_by_index(const Query &lhs, const Query &rhs) {     return lhs.index < rhs.index;   }   int a[maxn], b[maxn];   int main() {     int n, q, maxv = 0;     scanf( %d%d , &n, &q);     struct Node *last = NULL;     for (int i = 0; i < n; i++) {       scanf( %d , a + i);       struct Node *node = (Node *)malloc(sizeof(Node));       node->value = a[i];       node->next = NULL;       if (head == NULL) head = node;       if (last) last->next = node;       last = tail = node;       if (a[i] > a[maxv]) maxv = i;     }     for (int i = 0; i < q; i++) {       scanf( %lld , &queries[i].round);       queries[i].index = i;     }     sort(queries, queries + q, cmp_by_round);     int index_query = 0;     for (int i = 0; i < maxv; i++) {       struct Node *node1 = (Node *)malloc(sizeof(Node));       struct Node *node2 = (Node *)malloc(sizeof(Node));       int v1 = head->value, v2 = head->next->value;       while (1LL * i == queries[index_query].round - 1) {         queries[index_query].ans1 = head->value;         queries[index_query].ans2 = head->next->value;         index_query++;       }       if (v1 < v2) swap(v1, v2);       node1->value = v1;       if (head->next->next)         node1->next = head->next->next;       else         node1->next = node2;       node2->value = v2;       node2->next = NULL;       tail->next = node2;       tail = node2;       free(head->next);       free(head);       head = node1;     }     struct Node *node = head;     for (int i = 0; i < n; i++) {       b[i] = node->value;       node = node->next;     }     while (index_query < q) {       long long temp_round = queries[index_query].round - maxv;       queries[index_query].ans1 = b[0];       queries[index_query].ans2 = b[int((temp_round - 1) % (n - 1) + 1)];       index_query++;     }     sort(queries, queries + q, cmp_by_index);     for (int i = 0; i < q; i++)       printf( %d %d n , queries[i].ans1, queries[i].ans2);     return 0;   }