malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int stmp;   const int MAXB = 100000;   const int INF = 1000000001;   int vis[MAXB + 1];   vector<int> arr;   int k, n, maxb, t, _t;   int z;   inline int lis() {     vector<int> L(z, INF);     for (int s = 0; s < (t); ++s) {       for (int i = 0; i < ((int)(arr).size()) && L.back() == INF; ++i)         *lower_bound((L).begin(), (L).end(), arr[i]) = arr[i];       int c = 0;       for (int i = 0; i < (((int)(arr).size())); ++i)         if (arr[i] == L[s])           ++c;         else           arr[i - c] = arr[i];       arr.erase(arr.end() - c, arr.end());     }     return find((L).begin(), (L).end(), INF) - L.begin();   }   int main(int argc, char *argv[]) {     stmp = scanf( %d %d %d %d , &k, &n, &maxb, &_t);     for (int c = (1); c <= (k); ++c) {       arr.resize(n);       int rb = 0;       for (int i = 0; i < (n); ++i) {         stmp = scanf( %d , &arr[i]);         if (vis[arr[i]] != c) ++rb;         vis[arr[i]] = c;       }       arr.resize(unique((arr).begin(), (arr).end()) - arr.begin());       z = rb;       t = min(_t, z);       printf( %d n , t < z ? lis() : z);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t;     cin >> t;     while (t--) {       long long w, h, k, arr[4], brr[1000000], ans;       cin >> w >> h;       for (int i = 0; i < 4; i++) {         cin >> k;         for (int j = 0; j < k; j++) {           cin >> brr[j];         }         arr[i] = (brr[k - 1] - brr[0]);       }       arr[0] = max(arr[0], arr[1]);       arr[2] = max(arr[2], arr[3]);       ans = max(arr[0] * h, arr[2] * w);       cout << ans << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 7;   const int inf = 0x3f3f3f3f;   const long long INF = 0x3f3f3f3f3f3f3f3f;   const int mod = 1e9 + 7;   const double eps = 1e-8;   const double PI = acos(-1);   int n, k, b, c, t[N];   pair<int, int> a[N];   long long ans = INF;   long long cnt = 0;   priority_queue<pair<long long, int> > que;   long long solve(pair<int, int> *a, long long b, long long c) {     while (!que.empty()) que.pop();     cnt = 0;     long long ans = INF, ret = 0;     for (int i = 1; i <= k; i++) {       ret += a[i].second * c;       ret += (a[i].first - a[i - 1].first) * cnt * b;       que.push(make_pair(c * a[i].second + (a[1].first - a[i].first) * b, i));       cnt++;     }     ans = min(ans, ret);     for (int i = k + 1; i <= n; i++) {       int p = que.top().second;       que.pop();       cnt--;       ret -= a[p].second * c;       ret -= (a[i - 1].first - a[p].first) * b;       ret += (a[i].first - a[i - 1].first) * cnt * b;       ret += a[i].second * c;       que.push(make_pair(c * a[i].second + (a[1].first - a[i].first) * b, i));       cnt++;       ans = min(ans, ret);     }     return ans;   }   int main() {     scanf( %d%d%d%d , &n, &k, &b, &c);     for (int i = 1; i <= n; i++) scanf( %d , &t[i]), t[i] += 1000000000;     sort(t + 1, t + 1 + n);     for (int i = 1; i <= n; i++) a[i].first = t[i], a[i].second = 0;     ans = min(ans, solve(a, c, 0));     for (int j = 0; j < 5; j++) {       for (int i = 1; i <= n; i++) {         a[i].second = ((j - (t[i] % 5)) + 5) % 5;         a[i].first = (t[i] + a[i].second) / 5;       }       ans = min(ans, solve(a, b, c));     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n], i;     double ans = 0.0f;     for (i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     if (n % 2 == 0) {       for (i = 0; i < n; i = i + 2) {         ans = ans + ((a[i + 1] * a[i + 1]) - (a[i] * a[i]));       }     } else {       ans = ans + a[0] * a[0];       for (i = 1; i < n; i = i + 2) {         ans = ans + ((a[i + 1] * a[i + 1]) - (a[i] * a[i]));       }     }     double pi = asin(1) * 2;     cout << fixed << setprecision(10) << ans * pi <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1 << 17;   int MAX[maxn << 1], lazy[maxn << 1], e[maxn];   void push_up(int now) { MAX[now] = max(MAX[now << 1], MAX[now << 1 | 1]); }   void push_down(int now) {     lazy[now << 1] += lazy[now];     lazy[now << 1 | 1] += lazy[now];     MAX[now << 1] += lazy[now];     MAX[now << 1 | 1] += lazy[now];     lazy[now] = 0;   }   void update(int now, int p, int L, int R, int l, int r) {     if (R < l) return;     if (R >= r) {       MAX[now] += p;       lazy[now] += p;       return;     }     if (lazy[now]) push_down(now);     int mid = (l + r) >> 1;     update(now << 1, p, L, R, l, mid);     update(now << 1 | 1, p, L, R, mid + 1, r);     push_up(now);   }   int query(int now, int l, int r) {     int mid = (l + r) >> 1;     if (l == r) return l;     if (lazy[now]) push_down(now);     if (MAX[now << 1 | 1] > 0)       return query(now << 1 | 1, mid + 1, r);     else       return query(now << 1, l, mid);   }   int main() {     int m, pos, op, x;     scanf( %d , &m);     for (int i = 0; i < m; i++) {       scanf( %d%d , &pos, &op);       if (op == 1) {         scanf( %d , &x);         e[pos] = x;         update(1, 1, 1, pos, 1, m);       } else {         update(1, -1, 1, pos, 1, m);       }       if (MAX[1] > 0) {         printf( %d n , e[query(1, 1, m)]);       } else         puts( -1 );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c = 0, n, t, i, j, flag = 0, sum, f;     string s, s1, s2;     cin >> t;     while (t--) {       cin >> n;       c = 0, sum = 0, flag = 0, f = 0;       int ara[n], ara1[n];       for (i = 0; i < n; i++) {         cin >> ara[i];       }       for (i = 0; i < n; i++) {         cin >> ara1[i];       }       for (i = 0; i < n; i++) {         if (ara[i] != ara1[i]) {           c = (ara1[i] - ara[i]);           flag = 1;         }         if (flag) break;       }       for (i = 0; i < n; i++) {         if (ara[i] == ara1[i])           sum++;         else if (ara[i] < ara1[i] && f == 0) {           if (ara[i] + c == ara1[i]) sum++;           if (ara[i + 1] == ara1[i + 1]) f = 1;         }       }       if (sum == n)         cout <<  YES               <<   n ;       else         cout <<  NO               <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int s, k;     cin >> k >> s;     while (s >= 1) {       for (int i = 1; i <= k; i++) {         if (s >= i) {           s = s - i;         } else {           cout << s << endl;           return 0;         }       }     }     cout << s << endl;   }
#include <bits/stdc++.h>   using namespace std;   inline int Read() {     char c = getchar();     int num = 0;     while ( 0  > c || c >  9 ) c = getchar();     while ( 0  <= c && c <=  9 ) num = num * 10 + c -  0 , c = getchar();     return (num);   }   inline void Add(int &a, int b) { a = max(a, b); }   int ans, n, m, f[2010][55][55], ln, s, p, a[2010], b[2010], ff[2010][55][55],       sf[2010];   int main() {     n = Read(), m = Read(), ln = Read();     s = Read();     for (int i = 1; i <= s; i++) a[Read()] = 1;     p = Read();     for (int i = 1; i <= p; i++) b[Read()] = 1;     for (int j = 0; j <= m; j++)       for (int k = 0; k <= ln; k++)         for (int l = 0; l <= ln; l++) f[j][k][l] = -1e9;     f[0][0][0] = 0;     for (int i = n; i; i--) sf[i] = sf[i + 1] + (a[i] || b[i]);     for (int lst = 0, i = 0; i < n; i++) {       int al = (n - i + ln) / ln;       al *= 2;       int low = max(0, m - al + 1);       for (int j = lst; j < low; j++)         for (int k = 0; k <= ln; k++)           for (int l = 0; l <= ln; l++) ans = max(ans, f[j][k][l] + sf[i + 1]);       for (int j = low; j <= m; j++)         for (int k = 0; k <= ln; k++)           for (int l = 0; l <= ln; l++) {             ff[j][k][l] = f[j][k][l], f[j][k][l] = -1e9;           }       for (int j = low; j <= m; j++) {         for (int k = 0; k < ln; k++)           for (int l = 0; l < ln; l++) {             int k_ = k, l_ = l;             if (k_) k_--;             if (l_) l_--;             if (!k && a[i + 1] && j < m)               Add(f[j + 1][ln - 1][l_], ff[j][k][l] + 1);             if (!l && b[i + 1] && j < m)               Add(f[j + 1][k_][ln - 1], ff[j][k][l] + 1);             Add(f[j][k_][l_], ff[j][k][l] + ((k && a[i + 1]) || (l && b[i + 1])));           }       }       lst = low;     }     for (int t = 0; t <= m; t++)       for (int i = 0; i <= ln; i++)         for (int j = 0; j <= ln; j++) ans = max(ans, f[t][i][j]);     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   int const nMax = 40000;   map<pair<int, int>, int> Q;   int main() {     int n;     int ans = 0;     scanf( %d , &n);     pair<int, int> a;     for (int i = 0; i < n; i++) {       scanf( %d%d , &a.first, &a.second);       if (Q.find(a) == Q.end()) {         Q[a] = 1;       } else {         Q[a] = Q[a] + 1;       }       if (Q[a] > ans) ans = Q[a];     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-9;   bool pd(complex<double> a, complex<double> b, complex<double> c,           complex<double> d) {     return imag((b - a) * conj(d - a)) * imag((b - a) * conj(c - a)) < -eps;   }   bool aa(complex<double> a, complex<double> b, complex<double> c) {     complex<double> d = c;     c = b + b - c;     if (imag((c - a) / (b - a)) < 0) swap(b, c);     double r = abs(b - c) / sin(arg((c - a) * conj(b - a))) / 2;     double th = acos(abs(b - a) / 2 / r);     complex<double> B = a + polar(r, arg(b - a) + th), A = a + a - B,                     C = b + b - B, D = d + d - C;     double dd[4];     dd[0] = abs(A - B), dd[1] = abs(A - D), dd[2] = abs(C - D),     dd[3] = abs(B - C);     sort(dd, dd + 4);     if ((fabs(dd[0] - dd[2]) < eps || fabs(dd[1] - dd[3]) < eps) &&         pd(A, C, B, D) && pd(B, D, A, C)) {       puts( YES );       printf( %.9lf %.9lf %.9lf %.9lf %.9lf %.9lf %.9lf %.9lf n , real(A),              imag(A), real(D), imag(D), real(C), imag(C), real(B), imag(B));       return 1;     }     return 0;   }   int main() {     int T;     scanf( %d , &T);     while (T--) {       int x1, y1, x2, y2, x3, y3;       scanf( %d%d%d%d%d%d , &x1, &y1, &x2, &y2, &x3, &y3);       complex<double> a = complex<double>(x1, y1), b = complex<double>(x2, y2),                       c = complex<double>(x3, y3);       if (aa(a, b, c)) continue;       if (aa(a, c, b)) continue;       if (aa(b, a, c)) continue;       if (aa(b, c, a)) continue;       if (aa(c, a, b)) continue;       if (aa(c, b, a)) continue;       puts( NO );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, r[500005];   int f[24][500005];   int Min[500005 * 8], key[500005];   void insert(int now, int l, int r, int pos, int val) {     if (pos > r || pos < l) return;     if (l == r) {       Min[now] = l;       key[l] = val;       return;     }     int mid = (l + r) >> 1;     insert(now << 1, l, mid, pos, val);     insert(now << 1 | 1, mid + 1, r, pos, val);     Min[now] = key[Min[now << 1]] < key[Min[now << 1 | 1]] ? Min[now << 1]                                                            : Min[now << 1 | 1];   }   int Query(int now, int l, int r, int ql, int qr) {     if (qr < ql) return 0;     if (r < ql || l > qr) return 0;     if (ql <= l && r <= qr) return Min[now];     int mid = (l + r) >> 1;     int pos1 = Query(now << 1, l, mid, ql, qr),         pos2 = Query(now << 1 | 1, mid + 1, r, ql, qr);     return key[pos1] < key[pos2] ? pos1 : pos2;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &r[i]), r[i + n] = r[i];     memset(Min, 0, sizeof Min);     memset(key, 0x3f, sizeof key);     for (int i = 1; i <= 2 * n; i++) {       int pos1 = Query(1, 1, 2 * n, max(max(1, i - r[i]), i - n + 1), i);       f[0][i] = pos1;       insert(1, 1, 2 * n, i, i - r[i]);     }     for (int j = 1; j < 24; j++)       for (int i = 1; i <= 2 * n; i++) f[j][i] = f[j - 1][f[j - 1][i]];     long long ans = 0;     for (int i = 2 * n; i > n; i--) {       int u = i;       for (int j = 24 - 1; j >= 0; j--) {         if (f[j][u] - r[f[j][u]] > i - n + 1) u = f[j][u], ans += (1 << j);       }       if (u - r[u] <= i - n + 1)         ans++;       else         ans += 2;     }     printf( %I64d , ans);   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int a[500050];   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     sort(a + 1, a + n + 1);     int m = n;     int res = 0;     for (int i = n / 2; i >= 1; i--) {       if (a[i] * 2 <= a[m]) {         m--;         res++;       }     }     cout << n - res;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   string s;   int dp[510][510];   bool has[510][510][30];   int dfs(int l, int r) {     if (l >= r) return 0;     int &ans = dp[l][r];     if (ans != 0) return ans;     if (!has[l + 1][r][s[l] -  a ]) return ans = dfs(l + 1, r);     ans = dfs(l + 1, r);     for (int i = l + 1; i <= r; i++)       if (s[i] == s[l]) ans = max(ans, dfs(l + 1, i) + 1 + dfs(i + 1, r));     return ans;   }   int main() {     cin >> n >> s;     for (int i = 0; i < (int)s.size(); i++)       for (int j = 0; j < (int)s.size(); j++)         for (int k = i; k <= j; k++) has[i][j][s[k] -  a ] = 1;     cout << (int)s.size() - dfs(0, s.size() - 1) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool pal(string s) {     string b = s;     reverse(b.begin(), b.end());     return b == s;   }   int main() {     string s;     cin >> s;     for (int i = 0; i <= s.size(); ++i) {       for (char a =  a ; a <=  z ; ++a) {         string b = s.substr(0, i) + a + s.substr(i);         if (pal(b)) {           cout << b << endl;           return 0;         }       }     }     cout <<  NA  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 1e3 + 10;   long double dp[MAXN][MAXN];   long long p[MAXN];   int main() {     ios_base ::sync_with_stdio(false);     cin.tie(0);     cout << fixed << setprecision(10);     long long n, m;     cin >> n >> m;     long double res = 0;     for (long long i = 1; i <= n; i++) {       cin >> p[i];     }     for (long long i = 1; i <= n; i++) {       for (long long j = i + 1; j <= n; j++) {         dp[i][j] = (p[j] < p[i]);       }     }     for (long long i = 0; i < m; i++) {       long long a, b;       cin >> a >> b;       if (a > b) {         swap(a, b);       }       for (long long j = b + 1; j <= n; j++) {         long double e = (dp[a][j] + dp[b][j]) / 2;         dp[a][j] = e;         dp[b][j] = e;       }       for (long long j = a - 1; j >= 1; j--) {         long double e = (dp[j][a] + dp[j][b]) / 2;         dp[j][a] = e;         dp[j][b] = e;       }       for (long long j = a + 1; j < b; j++) {         long double e = dp[a][j], f = dp[j][b];         dp[a][j] = (1 + e - f) / 2;         dp[j][b] = (1 + f - e) / 2;       }       dp[a][b] = (long double)(1) / 2;     }     for (long long i = 1; i <= n; i++) {       for (long long j = i + 1; j <= n; j++) {         res += dp[i][j];       }     }     cout << res;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1000000007;   const int inf = 1001001001;   const long long PRED = 2500000000;   int n, a[111111], used[111111], ans, k;   vector<int> v[111111], b[111111];   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       if (a[i] == i) ans = i;     }     for (int i = 1; i <= n; i++) {       if (used[i] == 0) {         int poz = i;         int f = 0;         while (poz != i || f == 0) {           f = 1;           used[poz] = 1;           v[k].push_back(a[poz]);           poz = a[poz];         }         b[v[k].size()].push_back(k);         k++;       }     }     if (b[1].size()) {       printf( YES n );       for (int i = 1; i <= n; i++) {         if (i != ans) printf( %d %d n , a[ans], a[i]);       }       return 0;     }     if (b[2].size()) {       for (int i = 0; i < k; i++) {         if (v[i].size() % 2 == 1) {           cout <<  NO ;           return 0;         }       }       int q = b[2][0];       printf( YES n%d %d n , v[q][0], v[q][1]);       for (int i = 0; i < k; i++) {         if (i != q) {           for (int j = 0; j < v[i].size(); j++) {             if (j % 2 == 0)               printf( %d %d n , v[q][0], v[i][j]);             else               printf( %d %d n , v[q][1], v[i][j]);           }         }       }       return 0;     }     cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, ans = 0;     vector<pair<long long, long long> > v;     cin >> n;     for (int i = 0; i < n; i++) {       long long a, b;       cin >> a >> b;       v.push_back(make_pair(a + b, a - b));     }     sort(v.begin(), v.end());     long long last = -1e10;     for (int i = 0; i < n; i++)       if (v[i].second >= last) {         ans++;         last = v[i].first;       }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 5;   int n, arr[N];   long long k;   int main() {     cin >> n >> k;     long long x = 1ll * n * (n + 1) / 2;     if (k < x) return cout << -1, 0;     long long rem = k - x;     set<int> all;     for (int i = 1; i <= n; ++i) all.insert(i);     long long ans = x;     for (int i = 1; i <= n; ++i) {       if (!rem) {         arr[i] = *all.begin();         all.erase(arr[i]);         continue;       }       if (*all.rbegin() - i <= rem) {         arr[i] = *all.rbegin();         ans += max(0, arr[i] - i);         rem -= max(0, arr[i] - i);         all.erase(arr[i]);       } else {         int x = *all.lower_bound(rem + i);         arr[i] = x;         ans += max(0, x - i);         rem -= max(0, x - i);         all.erase(x);       }     }     cout << ans << endl;     for (int i = 1; i <= n; ++i) printf( %d  , i);     puts(  );     for (int i = 1; i <= n; ++i) printf( %d  , arr[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 100005;   vector<long long> male[3];   vector<long long> fe[3];   string ms[3] = { lios ,  etr ,  initis };   string fs[3] = { liala ,  etra ,  inites };   string s;   long long n = 0;   long long m = 0, f = 0;   void check() {     long long flag = 0;     for (long long i = 0; i < 3; i++) {       if (s.size() >= ms[i].size() &&           s.substr(s.size() - ms[i].size()) == ms[i]) {         male[i].push_back(n);         m = 1;         flag = 1;       }     }     for (long long i = 0; i < 3; i++) {       if (s.size() >= fs[i].size() &&           s.substr(s.size() - fs[i].size()) == fs[i]) {         fe[i].push_back(n);         f = 1;         flag = 1;       }     }     if (!flag) {       cout <<  NO ;       exit(0);     }   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     while (cin >> s) {       check();       n++;     }     if (m && f) {       cout <<  NO ;       return 0;     }     long long req[n];     long long cur = 0, flag = 1;     for (long long i = 0; i < 3; i++) {       for (auto it : male[i]) {         if (it != cur) {           cout <<  NO ;           return 0;         } else           cur++;       }     }     for (long long i = 0; i < 3; i++) {       for (auto it : fe[i]) {         if (it != cur) {           cout <<  NO ;           return 0;         } else           cur++;       }     }     if (n == 1)       cout <<  YES ;     else if (f && fe[1].size() != 1)       cout <<  NO ;     else if (m && male[1].size() != 1)       cout <<  NO ;     else       cout <<  YES ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long q, n, c[30], r, a[100001];   string s;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> s;     for (int i = 0; i < n; i++) {       if (s[i] ==  ) ) {         c[1]--;         if (c[1] < 0) c[2] += 2;       } else         c[1]++;     }     if (c[1] != 0)       cout << -1;     else       cout << c[2];   }
#include <bits/stdc++.h>   using namespace std;   const int K = 50;   long long p[K], Rem[K], V, As, Aa, Ac, Topc;   int q[K], k;   long long IN() {     int c, f;     long long x;     while (!isdigit(c = getchar()) && c !=  - )       ;     c ==  -  ? (f = 1, x = 0) : (f = 0, x = c -  0 );     while (isdigit(c = getchar())) x = (x << 1) + (x << 3) + c -  0 ;     return !f ? x : -x;   }   void DFS_C(long long a, int x, long long c) {     if (c >= Topc) {       long long S = V + a * (V / c + c);       if (As == -1 || S < As) As = S, Aa = a, Ac = c;       return;     } else if (c * Rem[x] < Topc)       return;     if (x == k) return;     for (int i = 0; i < q[x] + 1; i++) DFS_C(a, x + 1, c), c *= p[x];   }   void DFS_A(int x, long long a) {     if (a > 1e6 || a * a * a > V) return;     if (x == k) {       if (As != -1 && V / a + a * 2 * sqrt(V / a) >= As) return;       V /= a, Topc = sqrt(V);       DFS_C(a, 0, 1), V *= a;       return;     }     int pre = q[x];     for (int i = 0; i < pre + 1; i++) DFS_A(x + 1, a), a *= p[x], q[x]--;     q[x] = pre;   }   int main() {     for (int T = IN(); T--;) {       V = 1;       As = -1;       k = IN();       for (int i = 0; i < k; i++) {         p[i] = IN(), q[i] = IN();         for (int j = 0; j < q[i]; j++) V *= p[i];       }       Rem[k] = 1;       for (int i = k - 1; ~i; i--) {         Rem[i] = Rem[i + 1];         for (int j = 0; j < q[i]; j++) Rem[i] *= p[i];       }       DFS_A(0, 1);       printf( %I64d %I64d %I64d %I64d n , 2 * As, Aa, V / Aa / Ac, Ac);     }   }
#include <bits/stdc++.h>   using namespace std;   string l, r;   long long f[16][16][1 << 16];   long long g[16][16], h[16][16][16];   void init() {     int m16 = (1 << 16) - 1;     for (int j = 0; j < 16; ++j) f[1][j][j] = 1;     for (int i = 1; i < 15; ++i) {       for (int j = 0; j < 16; ++j) {         for (int k = 0; k <= m16; ++k)           if (f[i][j][k]) {             for (int d = 0; d < 16; ++d) {               int s = i < 4 ? (d << (i * 4)) : 0;               f[i + 1][max(j, d)][k | s] += f[i][j][k];             }           }       }     }     for (int i = 1; i < 16; ++i) {       for (int j = 0; j < 16; ++j) {         for (int k = 0; k <= m16; ++k) {           g[i][j] += f[i][j][k];           for (int l = 0; l < 16; ++l)             if (k & (1 << l)) h[i][j][l] += f[i][j][k];         }       }     }   }   long long toInt(string x) {     long long rr = 0;     for (int i = 0; i < x.size(); ++i) {       rr = rr * 16 + (x[i] <=  9  ? x[i] -  0  : x[i] -  a  + 10);     }     return rr;   }   vector<int> tmp, digits;   long long bruteforce(long long x) {     long long rr = 0;     for (int i = 1; i <= x; ++i) {       tmp.clear();       int v = 0;       int j = i;       while (j) {         v = max(v, j % 16);         j /= 16;       }       if (i & (1 << v)) ++rr;     }     return rr;   }   long long count2(int len, long long cur, int bitmax) {     if (len <= 0) return (cur & (1 << bitmax)) ? 1 : 0;     long long rr = 0;     for (int j = 0; j < 16; ++j) {       int k = max(j, bitmax), block = k / 4 + 1;       if (len >= block) {         rr += h[len][j][k];       } else if (cur & (1 << k))         rr += g[len][j];     }     return rr;   }   long long count(long long x) {     if (x <= 0) return 0;     tmp.clear();     while (x) {       tmp.push_back(x % 16);       x /= 16;     }     int n = tmp.size();     long long rr = 0, cur = 0;     int bitmax = -1;     for (int i = n; i; --i) {       for (int d = 0; d < tmp.back() + (i <= 1); ++d) {         int v = max(bitmax, d);         long long cmask = cur | ((1LL * d) << (4 * (i - 1)));         rr += count2(i - 1, cmask, v);       }       bitmax = max(bitmax, tmp.back());       cur |= ((1LL * tmp.back()) << (4 * (i - 1)));       tmp.pop_back();     }     return rr;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie();     cout.tie();     init();     int q;     cin >> q;     while (q--) {       cin >> l >> r;       cout << count(toInt(r)) - count(toInt(l) - 1) << endl;     }     return 0;   }