malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   int child[N], w[N];   long long dp[N][35][3], ans[N][2];   void pre(int n) {     for (int i = 0; i < n; i++) {       dp[i][0][0] = w[i];       dp[i][0][2] = w[i];       dp[i][0][1] = child[i];     }     for (int j = 1; j < 35; j++) {       for (int i = 0; i < n; i++) {         dp[i][j][1] = dp[dp[i][j - 1][1]][j - 1][1];         dp[i][j][0] = dp[i][j - 1][0] + dp[dp[i][j - 1][1]][j - 1][0];         dp[i][j][2] = min(dp[i][j - 1][2], dp[dp[i][j - 1][1]][j - 1][2]);       }     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     long long k;     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> child[i];     for (int i = 0; i < n; i++) cin >> w[i];     pre(n);     int pt;     for (int i = 0; i < n; i++) {       pt = i;       ans[i][1] = 1000000007ULL;       for (long long j = 0; (1LL << j) <= k; j++) {         if ((1LL << j) & k) {           ans[i][0] += dp[pt][j][0];           ans[i][1] = min(ans[i][1], dp[pt][j][2]);           pt = dp[pt][j][1];         }       }     }     for (int i = 0; i < n; i++) cout << ans[i][0] <<     << ans[i][1] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int is_prime[5000010 + 10], primes[5000010 + 10], firstp[5000010 + 10],       prime_cnt;   void get_primes() {     memset(is_prime, -1, sizeof(is_prime));     for (int i = 2; i <= 5000010; i++) {       if (is_prime[i]) {         primes[prime_cnt++] = i;         firstp[i] = i;       }       for (int j = 0; j < prime_cnt && primes[j] * i <= 5000010; j++) {         firstp[i * primes[j]] = primes[j];         is_prime[i * primes[j]] = 0;         if (i % primes[j] == 0) break;       }     }   }   long long bin[5000010], f[5000010], t, l, r;   int main() {     get_primes();     scanf( %I64d %I64d %I64d , &t, &l, &r);     long long ans = 0, pre = 1;     for (int i = 2; i < (5000001); i++)       f[i] = (f[i / firstp[i]] + (1LL * i * (firstp[i] - 1)) / 2 % 1000000007) %              1000000007;     for (int i = l; i < (r + 1); i++) {       ans = (ans + pre * f[i] % 1000000007) % 1000000007;       pre = pre * t % 1000000007;     }     printf( %I64d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     cin.tie(nullptr);     cout.tie(NULL);     ios_base::sync_with_stdio(false);     int t;     cin >> t;     while (t--) {       string s;       cin >> s;       int ans = 0;       int one;       bool turn = true;       while (s.size() != 0) {         one = 0;         vector<pair<int, int>> len;         bool go = false;         int start;         for (int i = 0; i < s.size(); i++) {           if (s[i] ==  1 ) {             if (!go) {               start = i;               go = true;             }             if (i == s.size() - 1) {               len.push_back({start, i});             }             one++;           } else {             if (go) {               len.push_back({start, i - 1});               go = false;             }           }         }         if (!one) {           cout <<  0 n ;           break;         }         int length = len[0].second - len[0].first;         pair<int, int> se = {len[0].first, len[0].second};         for (int i = 1; i < len.size(); i++) {           if (length < len[i].second - len[i].first) {             length = len[i].second - len[i].first;             se = {len[i].first, len[i].second};           }         }         if (turn) ans += length + 1;         s.erase(se.first, length + 1);         if (one - (length + 1) == 0) {           cout << ans <<   n ;           break;         }         if (turn)           turn = false;         else           turn = true;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long a, b;     cin >> a >> b;     if (a > b || (b - a) % 2) {       cout << -1;       return 0;     }     if (a == b) {       if (a == 0)         cout << 0;       else         cout << 1 <<   n  << a;     } else if (((a + (b - a) / 2) ^ ((b - a) / 2)) == a) {       cout << 2 <<   n  << a + (b - a) / 2 <<     << (b - a) / 2;     } else       cout << 3 << endl << a <<     << (b - a) / 2 <<     << (b - a) / 2;   }
#include <bits/stdc++.h>   using namespace std;   int arr[100000];   int main() {     int n, i, mi = 1e9 + 1, ans, last;     cin >> n, ans = n;     for (i = 0; i < n; i++) cin >> arr[i], mi = min(mi, arr[i]);     for (last = 0; arr[last] != mi; last++)       ;     for (i = last + 1; i < n; i++)       if (arr[i] == mi) ans = min(i - last, ans), last = i;     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int stak1[200010], tot1, stak0[200010], tot0;   int pre[200010], nex[200010];   char s[200010];   int a[200010];   int n, ans;   int stak_ans[200010], tot_ans;   int main() {     int i, j, k;     scanf( %s , s);     n = strlen(s);     for (i = 0; i < n; i++) a[i + 1] = s[i] ==  1  ? 1 : 0;     for (i = 1; i <= n; i++)       if (a[i]) {         if (!tot0) {           printf( -1 n );           return 0;         }         nex[stak0[tot0]] = i;         pre[i] = stak0[tot0];         tot0--;         stak1[++tot1] = i;       } else {         if (tot1) {           nex[stak1[tot1]] = i;           pre[i] = stak1[tot1];           tot1--;         }         stak0[++tot0] = i;       }     if (tot1) {       printf( -1 n );       return 0;     }     for (i = 1; i <= n; i++)       if (!pre[i]) ans++;     printf( %d n , ans);     for (i = 1; i <= n; i++)       if (!pre[i]) {         j = i, tot_ans = 0;         while (j) {           stak_ans[++tot_ans] = j;           j = nex[j];         }         printf( %d  , tot_ans);         for (j = 1; j <= tot_ans; j++) printf( %d  , stak_ans[j]);         printf(  n );       }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool isprime(long long n) {     if (n == 2) return true;     if (n < 2 || n % 2 == 0) return false;     for (long long i = 3; i * i <= n; i += 2) {       if (n % i == 0) return false;     }     return true;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     ;     int n;     cin >> n;     if (isprime(n))       cout << 1 << endl;     else if (n % 2 == 0)       cout << 2 << endl;     else if (isprime(n - 2))       cout << 2 << endl;     else       cout << 3 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, x, i;   int reachable[1000000];   int need_to_convert[1000000];   int main(int argc, char **argv) {     scanf( %d , &n);     for (i = 0; i < n; ++i) {       scanf( %d , &x);       int trans_op_num = 0;       while (x) {         ++reachable[x];         need_to_convert[x] += trans_op_num;         ++trans_op_num;         x >>= 1;       }     }     for (i = 1e5; i > 1 && reachable[i] != n; --i)       ;     x = need_to_convert[i];     while (true) {       int y = reachable[i + i];       if (n > y + y) break;       i = i + i;       x = x - y + n - y;     }     printf( %d n , x);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int x = 0, y = 0, z = 0;     for (int i = 0; i < n; i++) {       int a, b, c;       cin >> a >> b >> c;       x += a;       y += b;       c += z;     }     if (!x && !y && !z)       cout <<  YES ;     else       cout <<  NO ;   }
#include <bits/stdc++.h>   using namespace std;   const long long int INF = 1e18;   const int inf = 1e9;   const int MOD = 1e9 + 7;   const int nax = 1000000 + 10;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n, s;     cin >> n >> s;     int a, b, c, d;     cin >> a >> b;     if (a * 60 + b >= s + 1) {       cout << 0 <<     << 0;       return 0;     }     for (int i = 1; i < n; i++) {       cin >> c >> d;       if (a == c) {         int m = d - b;         if (m >= 2 * s + 2) {           int k = b + s + 1;           int j = k / 60;           int f = k % 60;           cout << a + j <<     << f;           return 0;         }       } else {         int m = c - a - 1;         m *= 60;         m += 60 - b;         m += d;         if (m >= 2 * s + 2) {           int k = b + s + 1;           int j = k / 60;           int f = k % 60;           cout << a + j <<     << f;           return 0;         }       }       a = c, b = d;     }     int k = b + s + 1;     int j = k / 60;     int f = k % 60;     cout << a + j <<     << f;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int ff[15][40000][15];   int maskk[15];   bool ok[15][40000][15];   int need[15], n;   vector<int> forbit[15];   long long int f(int x, int mask, int pre) {     if (ok[x][mask][pre]++) return ff[x][mask][pre];     long long int &ans = ff[x][mask][pre];     if (mask == 0) return ans = 1;     for (int submask = mask; submask > 0; submask--) {       submask &= mask;       bool ch = false;       if (submask == 0) break;       if (__builtin_popcount(submask & maskk[x]) > 1) continue;       for (int i = 0; i < forbit[x].size(); i++) {         if ((forbit[x][i] & submask) == forbit[x][i]) {           ch = true;           break;         }       }       if (ch) continue;       for (int i = pre + 1; i < n; i++) {         if (submask & (1 << i) && ((maskk[i] & (submask | (1 << x))) == maskk[i]))           if (__builtin_popcount((submask ^ (1 << i)) & maskk[x]) == 0 &&               (need[i] & submask) == need[i]) {             ans = (ans +                    1LL * f(i, submask ^ (1 << i), 0) * f(x, mask ^ submask, i));           }       }     }     return ans;   }   void read() {     int i, q, m, x, y;     scanf( %d %d %d , &n, &m, &q);     for (i = 1; i <= m; i++) {       scanf( %d %d , &x, &y);       x--;       y--;       maskk[x] |= (1 << y);       maskk[y] |= (1 << x);     }     for (i = 1; i <= q; i++) {       scanf( %d %d %d , &x, &y, &m);       x--;       y--;       m--;       forbit[m].push_back((1 << x) | (1 << y));       need[m] |= (1 << x) | (1 << y);     }     printf( %lld n , f(0, (1 << n) - 2, 0));   }   int main() { read(); }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   int a[2020];   void solve() {     int n, x, y;     cin >> n >> x >> y;     for (int i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     reverse(a, a + n);     int c = 0;     cout << a[x - 1] - a[x];   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int T = 1;     while (T--) solve();   }
#include <bits/stdc++.h>   const int N = 100001, M = 998244353, mod = 1000000007;   const long long MX = INT64_MAX, MN = INT64_MIN, oo = 1e18;   using namespace std;   vector<string> tokenizer(string str, char ch) {     std::istringstream var((str));     vector<string> v;     string t;     while (getline((var), t, (ch))) {       v.emplace_back(t);     }     return v;   }   template <typename T1, typename T2>   istream& operator>>(istream& in, pair<T1, T2>& a) {     in >> a.first >> a.second;     return in;   }   template <typename T1, typename T2>   ostream& operator<<(ostream& out, pair<T1, T2> a) {     out << a.first <<     << a.second;     return out;   }   void err(istream_iterator<string> it) {}   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {     cerr << *it <<   =   << a <<   n ;     err(++it, args...);   }   template <typename... T>   void read(T&... args) {     ((cin >> args), ...);   }   template <typename... T>   void put(T&&... args) {     ((cout << args <<    ), ...);   }   void file_i_o() {     freopen( ./tests/test01.txt ,  r , stdin);     freopen( ./tests/output01.txt ,  w , stdout);   }   void solve(int T) {     int n, m, k;     read(n, m, k);     vector<vector<int>> grid(n, vector<int>(m));     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) cin >> grid[i][j];     while (k--) {       int c;       read(c);       c--;       int r = 0;       while (r < n) {         if (grid[r][c] == 2)           r++;         else {           int nc = c;           if (grid[r][c] == 1)             nc++;           else             nc--;           grid[r][c] = 2;           c = nc;         }       }       put(c + 1);     }   }   int main(int argc, char const* argv[]) {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t = 1;     for (int i = 1; i < t + 1; i++) {       solve(t);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   void cmax(T &a, T b) {     a = (a > b ? a : b);   }   template <class T>   void cmin(T &a, T b) {     a = (a > b ? b : a);   }   const long long maxn = 270000, base = 31, kcz = 1e9 + 7;   long long inv;   long long ksm(long long ds, long long zs = kcz - 2, long long mod = kcz) {     long long res = 1;     for (; zs; zs >>= 1, ds = ds * ds % mod)       if (zs & 1) res = res * ds % kcz;     return res;   }   struct node {     long long len, l, r, val;   } tr[maxn << 1];   long long p[maxn];   node merge(node a, node b) {     node res;     if (!a.len) return b;     if (!b.len) return a;     if (a.r && b.l) {       a.val = (a.val + kcz - 1 - 1) * inv % kcz;       b.val = (b.val + (kcz - p[b.len - 1]) * 2) % kcz;       --b.len;       --a.len;       if (!a.len) {         b.l = 0;         return b;       }       if (!b.len) {         a.r = 0;         return a;       }     }     res.l = a.l;     res.r = b.r;     res.len = a.len + b.len;     res.val = (a.val * p[b.len] + b.val) % kcz;     return res;   }   char s[maxn];   void build(long long l, long long r, long long now) {     if (l == r) {       tr[now].l = tr[now].r = s[l] -  0 ;       tr[now].val = (s[l] -  0  + 1) * p[0];       tr[now].len = 1;       return;     }     build(l, ((l + r) >> 1), (now << 1));     build(((l + r) >> 1) + 1, r, (now << 1 | 1));     tr[now] = merge(tr[(now << 1)], tr[(now << 1 | 1)]);   }   node get(long long l, long long r, long long now, long long x, long long y) {     if (x <= l && r <= y) return tr[now];     if (y <= ((l + r) >> 1)) return get(l, ((l + r) >> 1), (now << 1), x, y);     if (x > ((l + r) >> 1))       return get(((l + r) >> 1) + 1, r, (now << 1 | 1), x, y);     return merge(get(l, ((l + r) >> 1), (now << 1), x, y),                  get(((l + r) >> 1) + 1, r, (now << 1 | 1), x, y));   }   long long n, m;   int main() {     scanf( %lld , &n);     inv = ksm(base);     p[0] = 1;     for (long long i = (1); i <= (n); ++i) p[i] = (p[i - 1] * base) % kcz;     scanf( %s , s + 1);     build(1, n, 1);     scanf( %lld , &m);     for (long long i = (1); i <= (m); ++i) {       if (i == 28) {         ++i;         --i;       }       long long x, y, L;       scanf( %lld%lld%lld , &x, &y, &L);       node na = get(1, n, 1, x, x + L - 1), nb = get(1, n, 1, y, y + L - 1);       if (na.val == nb.val)         puts( YES );       else         puts( NO );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MAX = 1000000000;   const int N = 100005;   struct Edge {     int to, next, w, vis;   };   struct Edge e[N << 1];   int head[N], E, f[N];   struct P {     long long val;     int idx;     P(long long val, int idx) : val(val), idx(idx) {}     bool operator<(const P &h) const { return val > h.val; }   };   priority_queue<P> Q;   long long dfs(int u) {     f[u] = 1;     long long ret = 0;     for (int i = head[u]; i != -1; i = e[i].next) {       if (e[i].vis) continue;       e[i].vis = e[i ^ 1].vis = 1;       ret += e[i].w;       if (!f[e[i].to]) ret += dfs(e[i].to);     }     return ret;   }   void addedge(int u, int to, int w) {     e[E].to = to;     e[E].w = w;     e[E].vis = 0;     e[E].next = head[u];     head[u] = E++;   }   int main() {     memset(head, -1, sizeof head);     E = 0;     int n, m, p, q;     scanf( %d%d%d%d , &n, &m, &p, &q);     int uu, vv;     for (int i = 0; i < m; i++) {       int u, v, w;       scanf( %d%d%d , &u, &v, &w);       addedge(u, v, w);       addedge(v, u, w);       uu = u, vv = v;     }     int tot = 0;     for (int i = 1; i <= n; i++) {       if (!f[i]) {         long long val = dfs(i);         Q.push(P(val, i));         tot++;       }     }     if (p + q < tot || tot < q) {       puts( NO );       return 0;     }     if (m == 0) {       if (p > 0 && q == n) {         puts( NO );         return 0;       }     }     puts( YES );     tot -= q;     int sum = 0;     while (sum < tot) {       P c1 = Q.top();       Q.pop();       P c2 = Q.top();       Q.pop();       printf( %d %d n , c1.idx, c2.idx);       uu = c1.idx, vv = c2.idx;       long long add = min(MAX, c1.val + c2.val + 1);       c1.val += add + c2.val;       Q.push(c1);       sum++;     }     for (int i = 0; i < p - tot; i++) {       printf( %d %d n , uu, vv);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e5 + 1;   vector<long long> arr(2e5 + 2, 0);   vector<long long> dp(2e5 + 2, 0);   vector<long long> left1(2e5 + 2, 0);   void solve() {     int n, k;     string s;     cin >> n >> k >> s;     for (int i = 0; i < n; i++) {       arr[i] = (s[i] -  0 ) * k;     }     long long last = n;     for (int i = n; i >= 0; i--) {       left1[i] = last;       if (i - 1 >= 0 && arr[i - 1] != 0) last = i - 1;     }     dp[0] = 1;     for (int i = 1; i < n; i++) {       long long firstcost =           (i - 1 - arr[i] >= 0) ? (dp[i - 1 - arr[i]] + i + 1) : (i + 1);       firstcost = min(firstcost, dp[i - 1] + i + 1);       long long rr = left1[i + 1];       if (rr < n && rr - i <= k) {         firstcost = min(firstcost,                         (rr - k - 1 >= 0) ? (dp[rr - k - 1] + rr + 1) : (rr + 1));       }       long long l = max(i - k - 1, -1);       long long r = left1[l + 1];       if (r < i) {         firstcost =             min(firstcost, ((r - k - 1 >= 0) ? dp[r - k - 1] + r + 1 : (r + 1)));       }       dp[i] = firstcost;     }     cout << dp[n - 1];   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[105];   bool judge(int x)   {       for(int i=1;i<=100;i++)       {           if(i*i==x)               return true;       }       return false;   }   int main()   {       int t;       cin>>t;       while(t--)       {           int n;           cin>>n;           for(int i=1; i<=n; i++)           {               cin>>a[i];           }           int loop=0;           for(int i=1; i<=n; i++)           {               if(judge(a[i]))               {                   continue;               }               else               {                   cout<< YES <<endl;                   loop=1;                   break;               }           }           if(loop==0)               cout<< NO <<endl;       }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s, provera;     int p = -1, d = -1, brojac = 0;     bool flag = false;     cin >> s >> provera;     for (int i = 0; i < provera.length(); ++i) {       if (provera[i] == s[brojac]) {         brojac++;       }       if (brojac == s.length()) {         p = i;         brojac--;         break;       }     }     for (int i = provera.length() - 1; i >= 0; --i) {       if (provera[i] == s[brojac]) brojac--;       if (brojac < 0) {         d = i;         break;       }     }     if ((d - p) > 0)       cout << d - p << endl;     else       cout << 0 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int lace[110][110];   int main() {     int x, y, i, j;     while (cin >> n >> m) {       memset(lace, 0, sizeof(lace));       for (i = 1; i <= m; i++) {         cin >> x >> y;         lace[x][y] = lace[y][x] = 1;       }       int xx, ans = 0;       while (1) {         int g[110], num = 0;         for (i = 1; i <= n; i++) {           xx = 0;           for (j = 1; j <= n; j++)             if (lace[i][j]) xx++;           if (xx == 1) g[++num] = i;         }         for (j = 1; j <= num; j++) {           for (i = 1; i <= n; i++) lace[g[j]][i] = lace[i][g[j]] = 0;         }         if (!num) break;         ans++;       }       cout << ans << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   long long power(long long x, long long y) {     long long res = 1;     x = x % 1000000007;     while (y > 0) {       if (y & 1) res = (res * x) % 1000000007;       y = y >> 1;       x = (x * x) % 1000000007;     }     return res % 1000000007;   }   long long inv(long long n) { return power(n, 1000000007 - 2) % 1000000007; }   long long isprime(long long n) {     if (n < 2) return 0;     long long i;     for (i = 2; i * i <= n; i++)       if (n % i == 0) return 0;     return 1;   }   void solve() {     long long ans = 1e18;     string s;     long long n;     cin >> n >> s;     for (char ch =  a ; ch <=  z ; ch++) {       long long i = 0, j = n - 1;       long long moves = 0;       long long ok = 1;       while (i < j) {         if (s[i] == s[j]) {           i++, j--;         } else if (s[i] == ch) {           i++;           moves++;         } else if (s[j] == ch) {           j--;           moves++;         } else {           ok = 0;           break;         }       }       if (ok) {         ans = min(ans, moves);       }     }     if (ans > n) ans = -1;     cout << ans <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t = 1;     long long tc = 0;     cin >> t;     while (t--) {       tc++;       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int N = 3e6 + 44;   const int X[] = {1, 0, -1, 0, 1, -1, 1, -1};   const int Y[] = {0, 1, 0, -1, 1, 1, -1, -1};   const int mod = 998244353;   const int INF = 1e9;   ll ans[N], add[N];   vector<int> g[N];   vector<pair<int, int> > query[N];   void dfs(int v = 0, int p = -1, int h = 0, ll sum = 0) {     for (auto pairr : query[v]) {       int d = pairr.first, x = pairr.second;       add[h] += x;       if (h + d + 1 < N) add[h + d + 1] -= x;     }     sum += add[h];     ans[v] = sum;     for (int to : g[v])       if (to != p) {         dfs(to, v, h + 1, sum);       }     for (auto pairr : query[v]) {       int d = pairr.first, x = pairr.second;       add[h] -= x;       if (h + d + 1 < N) add[h + d + 1] += x;     }   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL);     ;     int n;     cin >> n;     for (int i = 1; i < n; ++i) {       int u, v;       cin >> u >> v;       u--, v--;       g[u].push_back(v);       g[v].push_back(u);     }     int m;     cin >> m;     for (int i = 0; i < m; ++i) {       int v, d, x;       cin >> v >> d >> x;       v--;       query[v].push_back({d, x});     }     dfs();     for (int i = 0; i < n; ++i) cout << ans[i] <<    ;   }
#include <bits/stdc++.h>   using namespace std;   using LL = long long;   int a[25];   LL dp[25][5], l, r;   LL dfs(int pos, int cnt, bool zero, bool limit) {     if (pos == -1) return 1;     if (!limit && !zero && dp[pos][cnt] != -1) return dp[pos][cnt];     int up = limit ? a[pos] : 9;     if (cnt == 3) up = 0;     LL ans = 0;     for (int i = 0; i <= up; ++i)       ans += dfs(pos - 1, cnt + (i == 0 ? 0 : 1), zero && i == 0,                  limit && i == a[pos]);     if (!limit && !zero) dp[pos][cnt] = ans;     return ans;   }   LL solve(LL x) {     int pos = 0;     while (x) {       a[pos++] = x % 10;       x /= 10;     }     return dfs(pos - 1, 0, true, true);   }   int main() {     int T;     LL l, r;     scanf( %d , &T);     while (T--) {       memset(dp, -1, sizeof dp);       scanf( %I64d%I64d , &l, &r);       printf( %I64d n , solve(r) - solve(l - 1));     }     return 0;   }