malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e5 + 5;   const int inf = 0x3f3f3f3f;   const int mod = 1e9 + 7;   char s[maxn];   int ans[maxn];   void solve() {     int n, k;     scanf( %d%d , &n, &k);     scanf( %s , s + 1);     memset(ans, -1, sizeof(ans));     for (int i = 1; i <= n; i++) {       if (s[i] ==  ? ) continue;       if (ans[i % k + 1] == -1)         ans[i % k + 1] = s[i] -  0 ;       else {         if (s[i] -  0  != ans[i % k + 1]) {           printf( No n );           return;         }       }     }     int cnt1 = 0, cnt0 = 0;     for (int i = 1; i <= k; i++) {       if (ans[i] == 1) cnt1++;       if (ans[i] == 0) cnt0++;     }     if (cnt1 > k / 2 || cnt0 > k / 2 || k & 1) {       printf( No n );       return;     }     printf( Yes n );   }   int main() {     int T;     scanf( %d , &T);     while (T--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     int s[n];     int m[n];     string st;     cin >> st;     for (int i = 0; i < n; i++) s[i] = st[i] -  0 ;     cin >> st;     for (int i = 0; i < n; i++) m[i] = st[i] -  0 ;     sort(s, s + n);     sort(m, m + n);     int sher = 0;     int mor = 0;     int pos = 0;     for (int i = 0; i < n; i++) {       if (s[pos] < m[i]) {         sher++;         pos++;       }     }     pos = 0;     mor = n;     for (int i = 0; i < n; i++) {       if (m[i] >= s[pos]) mor--, pos++;     }     cout << mor <<   n  << sher;   }
#include <bits/stdc++.h>   using namespace std;   long long read() {     long long x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = 10 * x + ch -  0 ;       ch = getchar();     }     return x * f;   }   int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }   int power(int x, int y) {     int t = 1;     for (; y; y >>= 1, x = x * x % 1000000007)       if (y & 1) t = t * x % 1000000007;     return t;   }   long long n, m;   int main() {     n = read();     m = read();     if (min(n, m) == 1) {       long long ans = 6 * (max(n, m) / 6);       ans += max((long long)0, 2 * ((max(n, m) % 6) - 3));       cout << ans << endl;     } else if (min(n, m) == 2) {       if (max(n, m) == 3)         cout << 4 << endl;       else if (max(n, m) == 7)         cout << 12 << endl;       else if (max(n, m) == 2)         cout << 0 << endl;       else         cout << n * m << endl;     } else {       if ((n * m) % 2 == 0)         cout << n * m << endl;       else         cout << n * m - 1 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dx[10] = {1, -1, 0, 0};   int dy[10] = {0, 0, 1, -1};   const long long mod = 1e9 + 7;   long long cur;   long long tich = 1;   vector<int> G[300005];   int n, h, m;   int a[105][105];   int b[105][105];   int ans;   int main() {     cin >> n >> m;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) cin >> a[i][j];     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         cin >> b[i][j];         if (b[i][j] < a[i][j]) {           int tmp = b[i][j];           b[i][j] = a[i][j];           a[i][j] = tmp;         }       }     for (int i = 1; i < n; i++)       for (int j = 1; j <= m; j++) {         if (a[i][j] >= a[i + 1][j]) {           cout <<  Impossible ;           return 0;         }         if (b[i][j] >= b[i + 1][j]) {           cout <<  Impossible ;           return 0;         }       }     for (int i = 1; i <= n; i++)       for (int j = 1; j < m; j++) {         if (a[i][j] >= a[i][j + 1]) {           cout <<  Impossible ;           return 0;         }         if (b[i][j] >= b[i][j + 1]) {           cout <<  Impossible ;           return 0;         }       }     cout <<  Possible ;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3fffffff;   const int SINF = 0x7fffffff;   const long long LINF = 0x3fffffffffffffff;   const long long SLINF = 0x7fffffffffffffff;   const int MAXN = 300007;   const int MAX = 130;   int n;   int a[MAXN];   int ps[MAXN];   int pc[MAXN][2];   void init();   void input();   void work();   int main() {     init();     input();     work();   }   void init() { ios::sync_with_stdio(false); }   void input() {     scanf( %d , &n);     long long x;     for (int i = 1; i <= n; ++i) {       scanf( %I64d , &x);       a[i] = __builtin_popcountll(x);     }   }   void work() {     for (int i = 1; i <= n; ++i) ps[i] = ps[i - 1] + a[i];     int mx;     long long ans = 0;     for (int i = 1; i <= n; ++i) {       int j = i - 1;       mx = a[i];       for (; j && i - j <= MAX; --j) {         mx = (((mx) > (a[j])) ? (mx) : (a[j]));         if ((ps[i] & 1) == (ps[j - 1] & 1) && mx * 2 <= ps[i] - ps[j - 1]) ++ans;       }       ans += pc[j][ps[i] & 1];       pc[i][0] = pc[i - 1][0], pc[i][1] = pc[i - 1][1];       ++pc[i][ps[i - 1] & 1];     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 5e5 + 10;   struct edge {     int v, nxt;   } e[maxn << 1];   int head[maxn], ecnt = 0;   void add(int u, int v) { e[++ecnt] = (edge){v, head[u]}, head[u] = ecnt; }   vector<int> p[maxn];   int pos[maxn];   int tree[maxn];   void update(int x, int v) {     for (; x < maxn; x += x & -x) tree[x] += v;   }   long long query(int x) {     long long ret = 0;     for (; x; x -= x & -x) ret += tree[x];     return ret;   }   namespace ACAM {   int son[maxn][26], fail[maxn], cnt;   void insert(char *s, int id) {     int len = strlen(s + 1), u = 0;     p[id].push_back(u);     for (int i = 1; i <= len; i++) {       int c = s[i] -  a ;       if (!son[u][c]) son[u][c] = ++cnt;       u = son[u][c];       p[id].push_back(u);     }     pos[id] = u;   }   void build() {     queue<int> que;     for (int c = 0; c < 26; c++) {       int u = son[0][c];       if (u) que.push(u);     }     while (!que.empty()) {       int u = que.front();       que.pop();       for (int c = 0; c < 26; c++) {         int v = son[u][c];         if (!v)           son[u][c] = son[fail[u]][c];         else           fail[v] = son[fail[u]][c], que.push(v);       }     }     for (int i = 1; i <= cnt; i++) add(fail[i], i);   }   }  // namespace ACAM   int n, q, siz[maxn], dfn[maxn], idx = 0;   char s[maxn];   vector<pair<int, int> > op[maxn];   void dfs(int u) {     siz[u] = 1, dfn[u] = ++idx;     for (int i = head[u]; ~i; i = e[i].nxt) {       int v = e[i].v;       dfs(v);       siz[u] += siz[v];     }   }   long long ans[maxn];   int main() {     memset(head, -1, sizeof(head));     scanf( %d%d , &n, &q);     for (int i = 1; i <= n; i++) {       scanf( %s , s + 1);       ACAM::insert(s, i);     }     ACAM::build();     for (int i = 1; i <= q; i++) {       int k, l, r;       scanf( %d%d%d , &l, &r, &k);       op[l - 1].push_back(make_pair(i, -k));       op[r].push_back(make_pair(i, k));     }     dfs(0);     for (int i = 1; i <= n; i++) {       for (auto t : p[i]) update(dfn[t], 1);       for (auto qr : op[i]) {         int id = qr.first, u = qr.second;         if (u < 0)           u = -u, u = pos[u],           ans[id] -= query(dfn[u] + siz[u] - 1) - query(dfn[u] - 1);         else           u = pos[u], ans[id] += query(dfn[u] + siz[u] - 1) - query(dfn[u] - 1);       }     }     for (int i = 1; i <= q; i++) printf( %lld n , ans[i]);   }
#include <bits/stdc++.h>   using namespace std;   void update(int* Bit, int index) {     for (; index <= 100000; index += (index & (-index))) {       Bit[index] += 1;     }   }   int query(int* Bit, int index) {     int sum = 0;     for (; index > 0; index -= (index & -index)) sum += Bit[index];     return sum;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       int maxx;       for (int i = 31; i >= 0; i--) {         if (n & (1 << i)) {           maxx = i;           break;         }       }       long long ans = 1;       for (int i = 0; i < maxx; i++) {         ans = (ans + ans * (1 << i)) % m;       }       ans = (ans + m - 1) % m;       long long d = n - (1 << maxx) + 1;       ans = (((d + 1) * ans) % m + d) % m;       cout << ans << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a[1000];     int n, k;     scanf( %d , &n);     scanf( %d , &k);     for (int i = 0; i < 2 * n + 1; i++) {       scanf( %d , &a[i]);     }     for (int i = 1; i < 2 * n + 1; i += 2) {       if (a[i] - 1 > a[i + 1] && a[i] - 1 > a[i - 1]) {         a[i]--;         k--;       }       if (k == 0) {         break;       }     }     for (int i = 0; i < 2 * n + 1; i++) {       if (i) {         printf(   );       }       printf( %d , a[i]);     }     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int a[N];   int main() {     int i, j, k = 0, n;     cin >> n;     long long s = 0, t;     for (i = 1; i <= n; i++) {       cin >> a[i];       s += a[i];     }     if (s % 2 == 1) {       cout <<  0 n ;       return 0;     }     t = 0;     for (i = 1; i < n; i++) {       s -= a[i];       t += a[i];       if (s == t) k++;     }     cout << k << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 257, MOD = 1e9 + 7;   int pk[MAXN * MAXN], pk1[MAXN * MAXN], n, k, f[MAXN][MAXN], C[MAXN][MAXN];   int mul(int a, int b) { return 1LL * a * b % MOD; }   void add(int &a, const int &b) {     a += b;     if (a >= MOD) a -= MOD;   }   void sub(int &a, const int &b) {     a -= b;     if (a < 0) a += MOD;   }   int subs(int a, int b) {     a -= b;     if (a < 0) a += MOD;     return a;   }   int pw(int cs, int sm) {     if (sm == 0) return 1;     int hpw = pw(cs, sm >> 1);     hpw = 1LL * hpw * hpw % MOD;     if (sm & 1) hpw = 1LL * hpw * cs % MOD;     return hpw;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n >> k;     pk[0] = pk1[0] = 1;     for (int i = 1; i <= n * n; ++i) {       pk[i] = 1LL * pk[i - 1] * k % MOD;       pk1[i] = 1LL * pk1[i - 1] * (k - 1) % MOD;     }     C[0][0] = 1;     for (int i = 1; i <= n; ++i) {       C[i][0] = C[i][i] = 1;       for (int j = 1; j < i; ++j) C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % MOD;     }     int res = 0;     for (int i = 0; i <= n; ++i) {       int cur = mul(C[n][i], pw(subs(mul(pk[n - i], pk1[i]), pk1[n]), n));       if (i & 1)         sub(res, cur);       else         add(res, cur);     }     cout << res;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int N = 1e5 + 100, M = 1e14 + 10;   long long int n, k, l, r, mid, x, y, f[N], p[N], a[N];   vector<long long int> v;   void add(long long int v, long long int c) {     if (v == 0) return;     for (; v < N; v += v & -v) f[v] += c;   }   long long int get(long long int ind) {     long long int ret = 0;     for (; ind; ind -= ind & -ind) ret += f[ind];     return ret;   }   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n >> k;     p[0] = M;     v.push_back(p[0]);     for (int i = 1; i <= n; i++) {       cin >> a[i];       p[i] = p[i - 1] + a[i];       v.push_back(p[i]);     }     sort(v.begin(), v.end());     v.resize(unique(v.begin(), v.end()) - v.begin());     l = -M;     r = M;     while (r - l > 1) {       mid = l + r >> 1;       y = 0;       fill(f, f + N, 0);       for (int i = n; i >= 0; i--) {         x = upper_bound(v.begin(), v.end(), p[i] + mid - 1) - v.begin();         y += get(N - 1) - get(x + 1);         x = upper_bound(v.begin(), v.end(), p[i]) - v.begin();         add(x + 1, 1);       }       if (y >= k)         l = mid;       else         r = mid;     }     cout << l << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     string s;     getline(cin, s);     set<char> st;     for (int i = 0; i < s.length(); i++) {       if (s[i] ==  {  || s[i] ==  }  || s[i] ==  ,  || s[i] ==    ) {         continue;       } else {         st.insert(s[i]);       }     }     cout << st.size();   }
#include <bits/stdc++.h>   using namespace std;   int n, m, k;   int per;   int main() {     cin >> n >> m >> k;     per = 2;     int flag = 0;     int sum = 0;     int ff = 0;     int a = 1;     for (int i = 1; i <= n; ++i) {       if (!flag) {         for (int j = 1; j <= m; ++j) {           if (sum % 2 == 0 && a == k) {             if (ff++) cout << endl;             cout << n * m - 2 * (k - 1);             a++;           }           if (sum % 2 == 0 && a < k) {             if (ff++) cout << endl;             cout <<  2 ;             a++;           }           cout <<     << i <<     << j;           sum++;         }         flag = 1;         continue;       }       if (flag) {         for (int j = m; j >= 1; --j) {           if (sum % 2 == 0 && a == k) {             if (ff++) cout << endl;             cout << n * m - 2 * (k - 1);             a++;           }           if (sum % 2 == 0 && a < k) {             if (ff++) cout << endl;             cout <<  2 ;             a++;           }           cout <<     << i <<     << j;           sum++;         }         flag = 0;         continue;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const long long md = 1e9 + 7;   long long ans = 0;   long long st[1000000 + 5];   long long dp[1000000 + 5];   vector<long long> d[1000000 + 5];   long long n;   int32_t main() {     ios_base::sync_with_stdio(false);     cin >> n;     for (long long i = 0; i < n - 1; i++) {       long long l, r;       cin >> l >> r;       l--;       r--;       d[l].push_back(r);       d[r].push_back(l);     }     st[0] = 1;     for (long long i = 1; i <= n; i++) {       st[i] = st[i - 1] * 2;       st[i] %= md;     }     long long l = 0;     for (long long i = 0; i < n; i++) {       if (d[i].size() == 1) l++;     }     long long ans = l * st[n - l + 1] + (n - l) * st[n - l];     ans %= md;     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long x = 0, f = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (isdigit(ch)) {       x = (x << 1) + (x << 3) + ch -  0 ;       ch = getchar();     }     return x * f;   }   const long long maxn = 2e5 + 1e2;   struct Node {     long long a, b, w;   };   struct stt {     long long f[4 * maxn];     long long add[4 * maxn];     long long val[4 * maxn];     void up(long long root) { f[root] = min(f[root << 1], f[root << 1 | 1]); }     void pushdown(long long root, long long l, long long r) {       if (add[root]) {         add[root << 1] += add[root];         add[root << 1 | 1] += add[root];         f[root << 1] += add[root];         f[root << 1 | 1] += add[root];         add[root] = 0;       }     }     void build(long long root, long long l, long long r) {       if (l == r) {         f[root] = val[l];         return;       }       long long mid = l + r >> 1;       build(root << 1, l, mid);       build(root << 1 | 1, mid + 1, r);       up(root);     }     void update(long long root, long long l, long long r, long long x,                 long long y, long long p) {       if (x <= l && r <= y) {         f[root] += p;         add[root] += p;         return;       }       pushdown(root, l, r);       long long mid = l + r >> 1;       if (x <= mid) update(root << 1, l, mid, x, y, p);       if (y > mid) update(root << 1 | 1, mid + 1, r, x, y, p);       up(root);     }   };   stt a, b;   Node ymh[maxn];   long long n, m, cnt;   long long pp[maxn];   long long q;   vector<pair<long long, long long> > v[maxn];   void print(long long x) {     if (x >= 10) print(x / 10);     putchar(x % 10 +  0 );   }   signed main() {     n = read(), m = read();     q = read();     for (register long long i = 1; i < n; ++i)       a.val[i] = read(), pp[i] = a.val[i], b.val[i + 1] = read();     for (register long long i = 1; i <= m; ++i) {       ymh[i].a = read(), ymh[i].b = read(), ymh[i].w = read();       v[ymh[i].a].push_back(make_pair(ymh[i].b, ymh[i].w));     }     b.build(1, 1, n);     for (register long long i = 1; i <= n; ++i) {       for (register long long j = 0; j < v[i].size(); ++j) {         b.update(1, 1, n, 1, v[i][j].first, v[i][j].second);       }       a.val[i] += b.f[1];     }     a.build(1, 1, n);     cout << a.f[1] << endl;     for (long long i = 1; i <= q; i++) {       long long x = read(), y = read();       a.update(1, 1, n, x, x, y - pp[x]);       pp[x] = y;       print(a.f[1]);       puts(  );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, n;     cin >> n >> a >> b >> c;     int count = 0;     for (int i = 0; i <= b; i++) {       for (int j = 0; j <= c; j++) {         int num = n - i - 2 * j;         if (num >= 0 && 2 * num <= a) count++;       }     }     cout << count << endl;   }
#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int tc;     cin >> tc;     while (tc--) {       int n;       cin >> n;       string s, t;       cin >> s >> t;       vector<int> v, c;       for (int i = 1; i < n; i++) {         if (s[i] != s[i - 1]) v.push_back(i);       }       if (s[n - 1] != t[n - 1]) v.push_back(n);       for (int i = 1; i < n; i++) {         if (t[i] != t[i - 1]) c.push_back(i);       }       reverse(c.begin(), c.end());       cout << (int)v.size() + (int)c.size() <<    ;       for (int val : v) cout << val <<    ;       for (int val : c) cout << val <<    ;       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int LIM = 5e+5 + 10;   int sz[LIM];   int main() {     ios_base::sync_with_stdio(false);     int n;     cin >> n;     for (int i = 0; i < n; ++i) cin >> sz[i];     sort(sz, sz + n);     int pairs = 0;     int l = 0;     int lb = n / 2 + (n % 2);     int r = lb;     int rb = n;     while (l < lb && r < rb) {       if (sz[l] * 2 <= sz[r]) {         ++pairs;         ++l;         ++r;       } else {         ++r;       }     }     cout << n - pairs << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T1, typename T2>   istream &operator>>(istream &in, pair<T1, T2> &p) {     in >> p.first >> p.second;     return in;   }   template <typename T>   istream &operator>>(istream &in, vector<T> &v) {     for (auto &x : v) in >> x;     return in;   }   template <typename T1, typename T2>   ostream &operator<<(ostream &out, const std::pair<T1, T2> &p) {     out <<  [  << p.first <<  ,   << p.second <<  ]          <<   n ;     return out;   }   inline int gc() {     static const int BUF = 1e7;     static char buf[BUF], *bg = buf + BUF, *ed = bg;     if (bg == ed) fread(bg = buf, 1, BUF, stdin);     return *bg++;   }   inline int ri() {     int x = 0, f = 1, c = gc();     for (; c < 48 || c > 57; f = c ==  -  ? -1 : f, c = gc())       ;     for (; c > 47 && c < 58; x = x * 10 + c - 48, c = gc())       ;     return x * f;   }   const double EPS = 1e-10;   const double PI = acos(-1.0);   const long long mod = 1e9 + 7;   const int inf = 0x3f3f3f3f;   const long long infLL = 0x3f3f3f3f3f3f3f3fLL;   const long long ONE = 1;   const int maxN = 2e5 + 7;   int n, m, k, ans;   int a[maxN], sumA[2007];   pair<int, int> offers[maxN];   map<int, int> mii;   int dp[2007];   int getSum(int x, int y) {     if (x > y) return 0;     return sumA[y] - sumA[x - 1];   }   inline bool cmp1(const pair<int, int> &x, const pair<int, int> &y) {     return x.first < y.first;   }   inline bool cmp2(const pair<int, int> &x, const pair<int, int> &y) {     return x.first - x.second < y.first - y.second;   }   void CompletePack(int cost, int weight) {     for (int i = (cost); i <= (k); ++i) {       int x = dp[i - cost] + getSum(i - (cost - weight) + 1, i);       dp[i] = min(dp[i], x);     }   }   int main() {     std::ios::sync_with_stdio(false);     std::cin.tie(0);     ;     cin >> n >> m >> k;     for (int i = (1); i <= (n); ++i) cin >> a[i];     for (int i = (1); i <= (m); ++i) {       cin >> offers[i];       if (offers[i].first > k) {         --m;         --i;       } else if (mii.find(offers[i].first) != mii.end()) {         offers[mii[offers[i].first]].second =             max(offers[mii[offers[i].first]].second, offers[i].second);         --m;         --i;       } else {         mii[offers[i].first] = i;       }     }     sort(a + 1, a + n + 1);     n = k;     for (int i = (1); i <= (n); ++i) {       dp[i] = dp[i - 1] + a[i];       sumA[i] = dp[i];     }     sort(offers + 1, offers + m + 1, cmp1);     for (int i = (1); i <= (m); ++i) {       CompletePack(offers[i].first, offers[i].second);     }     sort(offers + 1, offers + m + 1, cmp2);     for (int i = (1); i <= (m); ++i) {       CompletePack(offers[i].first, offers[i].second);     }     cout << dp[k] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a1, a2, k1, k2;     int n;     cin >> a1 >> a2 >> k1 >> k2 >> n;     int n1 = n, n2 = n;     n1 -= (a1 * (k1 - 1));     n1 -= (a2 * (k2 - 1));     if (n1 <= 0)       cout << 0 <<    ;     else       cout << n1 <<    ;     if (k1 > k2) {       if (n2 < k2) {         cout << 0;         return 0;       } else {         n2 /= k2;         if (n2 >= a2) {           n -= (a2 * k2);           if (n >= k1) {             n /= k1;             if (n >= a1) {               cout << a1 + a2 <<    ;             } else {               cout << a2 + n <<    ;             }           } else {             cout << a2 <<    ;           }         } else {           cout << n2 <<    ;         }       }     } else {       if (n2 < k1) {         cout << 0;         return 0;       } else {         n2 /= k1;         if (n2 >= a1) {           n -= (a1 * k1);           if (n >= k2) {             n /= k2;             if (n >= a2) {               cout << a1 + a2 <<    ;             } else {               cout << a1 + n <<    ;             }           } else {             cout << a1 <<    ;           }         } else {           cout << n2 <<    ;         }       }     }     return 0;   }
#include<iostream>   #include<bits/stdc++.h>      using namespace std;      #define ll long long   #define pb push_back   #define mp make_pair   #define ff first   #define ss second   #define MOD 1000000007      // void func(){      // }      void solution(){     ll a,b; cin>>a>>b;     ll val = abs(a-b);     if(val==0){       cout<< 0 0 <<endl;       return;     }     ll count = min(val-(a%val),a%val);     cout<<val<<   <<count<<endl;   }      int main(){        ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);        #ifndef ONLINE_JUDGE     freopen( input.txt ,  r , stdin);     freopen( output.txt ,  w , stdout);     #endif        int t;     cin>>t;     // func();     while(t--){       solution();     }        return 0;   }