malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int mpow(int base, int exp);   void ipgraph(int m);   void dfs(int u, int par);   const long long mod = 1000000007 * 1LL * 1000000007;   const int N = 1e6 + 3, M = N;   vector<int> g[N];   int a[N];   long long h[N], val[N];   vector<pair<int, int> > E;   long long r() { return rand() * 32000 + rand(); }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int i, n, k, j, m;     cin >> n >> m;     srand(1234);     for (i = 1; 1 < n + 1 ? i < n + 1 : i > n + 1; 1 < n + 1 ? i += 1 : i -= 1)       h[i] = (r() * r() + r() + r()) % mod;     ipgraph(m);     long long ans = 0;     for (pair<int, int> e : E) {       int u = e.first, v = e.second;       val[u] = (val[u] + mod - h[v]) % mod;       val[v] = (val[v] + mod - h[u]) % mod;       ans += val[u] == val[v];       val[u] = (val[u] + h[v]) % mod;       val[v] = (val[v] + h[u]) % mod;     }     vector<long long> fin;     for (i = 1; 1 < n + 1 ? i < n + 1 : i > n + 1; 1 < n + 1 ? i += 1 : i -= 1)       fin.push_back(val[i]);     sort(fin.begin(), fin.end());     long long c = 1;     for (i = 1; 1 < fin.size() ? i < fin.size() : i > fin.size();          1 < fin.size() ? i += 1 : i -= 1) {       if (fin[i] == fin[i - 1])         c++;       else         ans += c * (c - 1) / 2, c = 1;     }     ans += c * (c - 1) / 2;     cout << ans << endl;     return 0;   }   int mpow(int base, int exp) {     base %= mod;     int result = 1;     while (exp > 0) {       if (exp & 1) result = ((long long)result * base) % mod;       base = ((long long)base * base) % mod;       exp >>= 1;     }     return result;   }   void ipgraph(int m) {     int i, u, v;     for (i = 0; i < m; i++) {       cin >> u >> v;       val[u] = (val[u] + h[v]) % mod;       val[v] = (h[u] + val[v]) % mod;       E.push_back({u, v});       u++, v++;       g[u - 1].push_back(v - 1);       g[v - 1].push_back(u - 1);     }   }   void dfs(int u, int par) {     for (int v : g[u]) {       if (v == par) continue;       dfs(v, u);     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, m, k;       cin >> n >> m >> k;       int card_to_person = n / k;       if (card_to_person >= m) {         cout << m <<   n ;         continue;       }       int tmp = (m - card_to_person) / (k - 1);       if ((m - card_to_person) % (k - 1) != 0) {         tmp++;       }       cout << card_to_person - tmp <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 1000005;   int N;   vector<int> G[MAX_N];   int cyid[MAX_N], Q[MAX_N];   vector<vector<int>> cycles, newcycles;   void find_cycle(int s, int curid) {     cyid[s] = curid;     cycles.back().push_back(s);     for (int i = 0; i < G[s].size(); i++) {       if (cyid[G[s][i]] == -1) {         find_cycle(G[s][i], curid);       }     }   }   void get_cycles() {     fill(cyid + 1, cyid + N + 1, -1);     int nCycles = 0;     for (int i = 1; i <= N; i++) {       if (cyid[i] == -1) {         cycles.push_back(vector<int>());         find_cycle(i, ++nCycles);       }     }   }   void construct_root_permutation() {     int numEven = 0, numOdd = 0;     for (vector<int> p : cycles) {       if (p.size() % 2 == 0)         numEven++;       else         numOdd++;     }     if (numEven % 2 == 1) {       printf( -1 n );       return;     }     sort(cycles.begin(), cycles.end(),          [](vector<int> a, vector<int> b) { return a.size() < b.size(); });     for (int i = 0; i < cycles.size();) {       if (cycles[i].size() % 2 == 1) {         if (cycles[i].size() == 1)           newcycles.push_back({cycles[i][0]});         else {           vector<int> newcyk;           int ptr1 = 0, ptr2 = (cycles[i].size() - 1) / 2 + 1;           for (int j = 0; j < cycles[i].size() / 2; j++) {             newcyk.push_back(cycles[i][ptr1++]);             newcyk.push_back(cycles[i][ptr2++]);           }           newcyk.push_back(cycles[i][ptr1]);           newcycles.emplace_back(newcyk);         }         i++;       } else {         if (i + 1 < cycles.size()) {           if (cycles[i].size() != cycles[i + 1].size()) {             printf( -1 n );             return;           } else {             vector<int> merged;             for (int j = 0; j < cycles[i].size(); j++) {               merged.push_back(cycles[i][j]);               merged.push_back(cycles[i + 1][j]);             }             newcycles.emplace_back(merged);             i += 2;           }         } else {           printf( -1 n );           return;         }       }     }     for (int i = 0; i < newcycles.size(); i++) {       if (newcycles[i].size() == 1)         Q[newcycles[i][0]] = newcycles[i][0];       else {         newcycles[i].push_back(newcycles[i][0]);         for (int j = 0; j < newcycles[i].size() - 1; j++) {           int next = newcycles[i][j + 1];           Q[newcycles[i][j]] = next;         }       }     }     for (int i = 1; i <= N; i++) printf( %d  , Q[i]);     printf(  n );   }   int main() {     scanf( %d , &N);     for (int i = 1; i <= N; i++) {       int pi;       scanf( %d , &pi);       G[i].push_back(pi);     }     get_cycles();     construct_root_permutation();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   using vv = vector<vector<T>>;   template <class T>   inline bool MX(T &l, const T &r) {     return l < r ? l = r, 1 : 0;   }   template <class T>   inline bool MN(T &l, const T &r) {     return l > r ? l = r, 1 : 0;   }   const long long MOD = 1e9 + 7;   int N;   long long C[114514];   long long T[114514];   vector<long long> ds, es;   int main() {     scanf( %d , &N);     for (int(i) = 0; (i) < (N); ++(i)) {       scanf( %lld , &C[i]);       if (i > 0) ds.emplace_back(C[i] - C[i - 1]);     }     for (int(i) = 0; (i) < (N); ++(i)) {       scanf( %lld , &T[i]);       if (i > 0) es.emplace_back(T[i] - T[i - 1]);     }     sort((ds).begin(), (ds).end());     sort((es).begin(), (es).end());     if (C[0] != T[0]) {       puts( No );       return 0;     }     assert((int)ds.size() == N - 1);     assert((int)es.size() == N - 1);     for (int(i) = 0; (i) < (N - 1); ++(i)) {       if (ds[i] != es[i]) {         puts( No );         return 0;       }     }     puts( Yes );   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int N, M, x, y;     cin >> N >> M >> x >> y;     x--;     y--;     cout << x + 1 <<     << y + 1 << endl;     for (int i = 1; i < x; i++) cout << i + 1 <<     << y + 1 << endl;     for (int i = x + 1; i < N; i++) cout << i + 1 <<     << y + 1 << endl;     cout << 1 <<     << y + 1 << endl;     int uneven = 0;     for (int j = 0; j < M; j++) {       if (j == y) {         uneven = 1;         continue;       }       if (j % 2 == uneven) {         for (int i = 0; i < N; i++) {           cout << i + 1 <<     << j + 1 << endl;         }       }       if (j % 2 != uneven) {         for (int i = N - 1; i > -1; i--) {           cout << i + 1 <<     << j + 1 << endl;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxN = 20, inf = 1000 * 1000 * 1000;   int i, n, ans, t, j, k, a[maxN], b[maxN], c[maxN], d[maxN], nul, h;   bool f;   string s;   int main() {     getline(cin, s);     n = s.length();     for (i = 0; i < n; ++i) {       ++a[s[i] -  0 ];     }     j = 0;     ans = 0;     k = 0;     for (i = 1; i <= 9; ++i) {       for (j = 0; j < 10; ++j) {         b[j] = a[j];         c[j] = a[j];       }       t = 0;       if (b[i] > 0 && c[10 - i] > 0) {         --b[i];         --c[10 - i];         ++t;         for (j = 0; j < 10; ++j) {           t += min(b[j], c[9 - j]);         }         if (t > ans) {           ans = t;           k = i;         }       }     }     for (i = 0; i < 10; ++i) {       b[i] = a[i];       c[i] = a[i];     }     f = false;     if (b[k] > 0 && c[10 - k] > 0) {       --b[k];       --c[10 - k];       f = true;     }     h = min(c[0] - min(b[9], c[0]), b[0] - min(b[0], c[9]));     for (i = 0; i < b[0] - h - min(b[0], c[9]); ++i) {       cout << 0;     }     for (i = 1; i < 10; ++i) {       for (j = 0; j < b[i] - min(b[i], c[9 - i]); ++j) {         cout << i;         ++d[i];       }     }     for (i = 0; i < 10; ++i) {       for (j = 0; j < min(b[i], c[9 - i]); ++j) {         cout << i;         ++d[i];       }     }     if (f) {       cout << k;       ++d[k];     }     for (i = 0; i < h; ++i) {       cout << 0;       ++d[0];     }     cout << endl;     for (i = 0; i < c[0] - h - min(b[9], c[0]); ++i) {       cout << 0;     }     for (i = 1; i < 10; ++i) {       for (j = 0; j < c[i] - min(b[9 - i], c[i]); ++j) {         cout << i;         --d[i];       }     }     for (i = 9; i >= 0; --i) {       for (j = 0; j < min(b[9 - i], c[i]); ++j) {         cout << i;         --d[i];       }     }     if (f) {       cout << 10 - k;       --d[10 - k];     }     for (i = 0; i < h; ++i) {       cout << 0;       --d[0];     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100010;   int a[10];   int main() {     int T, N, ans;     scanf( %d , &T);     while (T--) {       scanf( %d , &N);       ans = 1;       for (int i = 0; i <= 30; i++)         if (N & (1 << i)) ans *= 2;       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     scanf( %d , &t);     while (t--) {       int n, m;       scanf( %d%d , &n, &m);       int x, ans = 0;       for (int i = 0; i < n; i++) {         scanf( %d , &x);         ans += x;       }       if (ans == m)         printf( YES n );       else         printf( NO n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxN = 2000 * 100 + 10;   map<int, int> val;   int a[maxN];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       val[a[i]]++;     }     sort(a, a + n);     n = unique(a, a + n) - a;     cout << a[n - 1] - a[0] <<    ;     if (n == 1)       cout << 1LL * val[a[0]] * (val[a[0]] - 1) / 2 << endl;     else       cout << 1LL * val[a[0]] * val[a[n - 1]] << endl;   }
#include <bits/stdc++.h>   #define ff first   #define ss second   #define endl   n    using namespace std;   const long long INF = (long long) 1e18;   const int mod = (int) 1e9+7;   const int MAXN = (int) 3.5e4+5;      typedef long long ll;   typedef unsigned long long ull;   typedef pair<int,int> pii;   typedef pair<ll,ll> pll;   ll n, lst[MAXN], nx[MAXN], pr[MAXN], a[MAXN];   set<ll> idx[MAXN];   ll dp[105][MAXN];   ll t[101][4*MAXN], lazy[101][4*MAXN];   int x;   void push(int v){       if(lazy[x][v] == 0)           return;       lazy[x][2*v] += lazy[x][v];       lazy[x][2*v + 1] += lazy[x][v];       t[x][2*v] += lazy[x][v];       t[x][2*v + 1] += lazy[x][v];       lazy[x][v] = 0;   }      void upd(int v, int tl, int tr, int l, int r, ll val){       if(l > r)           return;       if(tl == l && tr == r){           t[x][v] += val;           lazy[x][v] += val;       }else{           push(v);           int tm = (tl + tr) / 2;           upd(2*v, tl, tm, l, min(tm, r), val);           upd(2*v+1, tm + 1, tr, max(tm + 1, l), r, val);           t[x][v] = max(t[x][2*v], t[x][2*v + 1]);       }   }      ll que(int v, int tl, int tr, int l, int r){       if(l > r)           return -INF;       if(tl == l && tr == r)           return t[x][v];       else {           push(v);           int tm = (tl + tr) / 2;           return max(que(2*v, tl, tm, l, min(tm, r)), que(2*v+1, tm + 1, tr, max(tm + 1, l), r));       }   }   int main(){       ios_base::sync_with_stdio(false);       cin.tie(nullptr);cout.tie(nullptr);          #ifdef Local           freopen( C:/Users/Admin/Desktop/Yazilim/C/IO/int.txt , r ,stdin);           freopen( C:/Users/Admin/Desktop/Yazilim/C/IO/out.txt , w ,stdout);       #endif       ll k;       cin>>n>>k;       ll top = 0;       for(ll i = 1; i <= n; i++){           cin>>a[i];           if(lst[a[i]] != 0)               top += i - lst[a[i]];           pr[i] = lst[a[i]];           lst[a[i]] = i;       }       memset(lst, 0x7f, sizeof(lst));          for(int i = n; i >= 1; i--){           nx[i] = min(n + 1, lst[a[i]]);           lst[a[i]] = i;       }          memset(dp, 0xf7, sizeof(dp));       dp[0][0] = 0;       ll mx = 0;       for(int i = 1; i < k; i++){           x = i - 1;           ll cev = 0;           for(ll j = 1; j <= n; j++){               if(j != 1)                   if(pr[j - 1] != 0)                       upd(1, 0, n, pr[j - 1] + 1, j - 1, j - 1 - pr[j - 1]);               dp[i][j] = que(1, 0, n, 0, j - 1) + cev;               upd(1, 0, n, j, j, dp[i - 1][j] - cev);               //cerr<<dp[i][j]<<   ;               mx = max(mx, dp[i][j]);                  if(pr[j] != 0)                   cev -= j - pr[j];               if(nx[j] != n + 1)                   cev += nx[j] - j;           }       }          cout<<top - mx<<endl;             #ifdef Local           cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<<   milliseconds  ;       #endif   }
#include <bits/stdc++.h>   using namespace std;   void sort(int temp[2000], int start, int end) {     int flag;     for (int i = start; i < end - 1; i++) {       for (int j = start; j < end - i - 1; j++) {         if (temp[j] < temp[j + 1]) {           flag = temp[j];           temp[j] = temp[j + 1];           temp[j + 1] = flag;         }       }     }   }   int main() {     int n, k, arr[2000], count = 0;     cin >> n;     cin >> k;     cout <<   n ;     for (int i = 0; i < n; i++) cin >> arr[i];     sort(arr, 0, n);     for (int i = 0; i < n; i += k) count = count + (2 * (arr[i] - 1));     cout <<   n  << count;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 10;   int m, n, t, ans;   pair<int, int> a[N];   vector<pair<int, int>> v;   int main() {     scanf( %d , &t);     while (t--) {       scanf( %d%d , &n, &m);       ans = 0;       v.clear();       for (int i = 1; i <= n; i++) scanf( %d , &a[i].first), a[i].second = i;       sort(a + 1, a + n + 1);       for (int i = 1; i < n; i++) {         v.push_back(make_pair(a[i].second, a[i + 1].second));         ans += a[i].first + a[i + 1].first;       }       v.push_back(make_pair(a[n].second, a[1].second));       ans += a[n].first + a[1].first;       if (v.size() > m || n == 2) {         puts( -1 );         continue;       }       for (int i = v.size() + 1; i <= m; i++) {         v.push_back(make_pair(a[1].second, a[2].second));         ans += a[1].first + a[2].first;       }       printf( %d n , ans);       for (int i = 0; i < v.size(); i++)         printf( %d %d n , v[i].first, v[i].second);     }   }
#include <bits/stdc++.h>   using namespace std;   string A, B;   bool is_divisor(const string &a, const string &b) {     int sa = a.size(), sb = b.size();     for (int i = 0; i < sb; i += sa) {       if (b.substr(i, sa) != a) return false;     }     return true;   }   int process(const string &a, const string &b) {     int sz = a.size();     vector<int> divi;     for (int i = 1; i < sqrt(sz) + 1; ++i) {       if (sz % i == 0) {         divi.push_back(i);         if (i * i != sz) divi.push_back(sz / i);       }     }     set<string> s;     for (int i = 0; i < divi.size(); ++i)       if (is_divisor(a.substr(0, divi[i]), a)) s.insert(a.substr(0, divi[i]));     sz = b.size();     divi.clear();     for (int i = 1; i < sqrt(sz) + 1; ++i) {       if (sz % i == 0) {         divi.push_back(i);         if (i * i != sz) divi.push_back(sz / i);       }     }     int ans = 0;     set<string> ss;     for (int i = 0; i < divi.size(); ++i)       if (is_divisor(b.substr(0, divi[i]), b)) ss.insert(b.substr(0, divi[i]));     for (string a : s)       if (ss.find(a) != ss.end()) ++ans;     return ans;   }   int main() {     char a[100001];     scanf(  %s , a);     A = string(a);     scanf(  %s , a);     B = string(a);     cout << process(A, B) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<string, string> mmap;   map<string, string>::iterator it;   int main() {     int t;     cin >> t;     while (t--) {       string a;       string b;       cin >> a >> b;       if (mmap[b] !=   ) {         for (it = mmap.begin(); it != mmap.end(); it++) {           if (it->first == b) {             mmap.erase(it);             break;           }         }       }       int flag = 0;       for (it = mmap.begin(); it != mmap.end(); it++) {         if (it->second == a) {           it->second = b;           flag = 1;           break;         }       }       if (!flag) mmap[a] = b;     }     int flag = 0;     for (it = mmap.begin(); it != mmap.end(); it++)       if (it->second ==   ) flag++;     cout << mmap.size() - flag << endl;     for (it = mmap.begin(); it != mmap.end(); it++)       if (it->second !=   ) cout << it->first <<     << it->second << endl;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> g[100010];   long long int weight[100010], add[100010], sub[100010];   int n;   void dfs(int mom, int u) {     for (vector<int>::iterator v = g[u].begin(); v != g[u].end(); v++)       if (*v != mom) {         dfs(u, *v);         add[u] = max(add[*v], add[u]);         sub[u] = max(sub[u], sub[*v]);       }     weight[u] += add[u] - sub[u];     if (weight[u] < 0)       add[u] -= weight[u];     else       sub[u] += weight[u];   }   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int u, v;       scanf( %d %d , &u, &v);       g[u].push_back(v), g[v].push_back(u);     }     for (int i = 1; i <= n; i++) scanf( %I64d , weight + i);     dfs(-1, 1);     printf( %I64d n , add[1] + sub[1]);   }
#include <bits/stdc++.h>   using namespace std;   const int inf = (int)1e9;   const long long llinf = (long long)3e18;   const int N = (int)1e5 + 111;   const long double PI = (long double)acos(-1);   int main() {     int n, cur, num, ans = 0;     scanf( %d , &n);     vector<int> a(n);     vector<char> us(n, 0);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     sort(a.begin(), a.end());     for (int i = 0; i < n; i++)       if (us[i] == 0) {         cur = i;         num = 0;         while (cur < n) {           if (us[cur] == 1 || a[cur] < num)             cur++;           else {             num++;             us[cur] = 1;           }         }         ans++;       }     printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   int x[10];   int cp, dp;   using namespace std;   void print() {     for (int i = 0; i < 10; ++i) {       cout << x[i];       if (i == 9)         cout <<   n ;       else         cout <<    ;     }   }   int pp(char a, int &dp) {     if (a ==  < ) {       dp = -1;       return -2;     } else if (a ==  > ) {       dp = 1;       return -2;     } else       return a -  0 ;   }   void work(int l, int r, string ch1) {     cp = l;     dp = 1;     int temp;     bool ins = true;     while (cp >= l && cp <= r) {       temp = pp(ch1[cp], dp);       if (temp >= 0) {         x[temp]++;         ch1[cp]--;         cp += dp;       } else {         if (temp == -1) cp += dp;         if (temp == -2) {           int cpt = cp;           cp += dp;           if (cp < l || cp > r) break;           int temp1 = pp(ch1[cp], dp);           while (temp1 == -1) {             cp += dp;             temp1 = pp(ch1[cp], dp);           }           if (cp < l || cp > r) break;           if (temp1 == -2) ch1[cpt] =  0  - 1;           if (temp1 >= 0) x[temp1]++, ch1[cp]--, cp += dp;         }       }     }     print();   }   int main() {     int n, q;     string ch;     cin >> n >> q;     cin >> ch;     for (int i = 0; i < q; ++i) {       int l, r;       cin >> l >> r;       l--, r--;       memset(x, 0, sizeof(x));       if (l == r) {         int pk = ch[l];         if (pk ==  <  || pk ==  > )           print();         else           x[pk -  0 ]++, print();       } else         work(l, r, ch);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void Swap(int &a, int &b) {     a = a ^ b;     b = a ^ b;     a = a ^ b;   }   int Max(int a, int b) {     if (a > b) return a;     return b;   }   int Scan() {     int res = 0;     char ch;     ch = getchar();     if (ch >=  0  && ch <=  9 ) res = ch -  0 ;     while ((ch = getchar()) >=  0  && ch <=  9 ) res = res * 10 + (ch -  0 );     return res;   }   int main() {     int T = Scan();     int X = 0, Y = 0;     while (T--) {       char c;       cin >> c;       int a = Scan();       int b = Scan();       if (a < b) Swap(a, b);       if (c ==  + )         X = Max(X, a), Y = Max(Y, b);       else if (a >= X && b >= Y)         cout <<  YES n ;       else         cout <<  NO n ;     }   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     string s;     cin >> s;     cout << s[0];     for (int i = 1; i < s.size() - 1; i += 2) {       cout << s[i];     }     cout << s.back();     cout <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t_;     cin >> t_;     while (t_--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long r = 1000000007;   int h[10];   int n, k, m, i, j;   long long a[100001], b[100001];   long long ans, x, y, z, c1, c2;   int main() {     cin >> n >> k;     for (i = 1; i <= n / k; i++) cin >> a[i];     for (i = 1; i <= n / k; i++) cin >> b[i];     h[0] = 1;     for (i = 1; i <= 9; i++) h[i] = h[i - 1] * 10;     ans = 1;     for (i = 1; i <= n / k; i++) {       x = 9;       for (j = 2; j <= k; j++) x = x * 10 + 9;       c1 = x / a[i] + 1;       x = b[i] * h[k - 1];       z = x % a[i];       if (z > 0) x = x + (a[i] - z);       y = b[i];       for (j = 2; j <= k; j++) y = y * 10 + 9;       z = y % a[i];       if (z > 0) y = y - z;       c2 = (y - x) / a[i] + 1;       ans = ans * (c1 - c2) % r;     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T gcd(T a, T b) {     while (b) {       a = a % b;       swap(a, b);     }     return a;   }   int pre[1000010];   int GetN(int n) {     if (pre[n] > 0) return pre[n];     if (n < 10) {       pre[n] = n;       return n;     }     int temp = n;     int product = 1;     while (n > 0) {       int rem = n % 10;       product *= rem == 0 ? 1 : rem;       n = n / 10;     }     return pre[temp] = GetN(product);   }   int dp[1000010][10];   void Precal() {     for (int i = 1; i < 1000010; i++) {       int res = GetN(i);       dp[i][res] = 1;       for (int k = 1; k <= 9; k++) {         dp[i][k] = dp[i][k] + dp[i - 1][k];         if (dp[i][0] == 1) {           cout << i <<     << k;           int v;           cin >> v;           exit(0);         }       }     }   }   int main() {     Precal();     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       int l, r, k;       cin >> l >> r >> k;       cout << dp[r][k] - dp[l - 1][k] << endl;       ;     }     int v;     cin >> v;     return 0;   }