malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 400, D = 8;   int vis[N][N];   int T[30];   bool used[N][N][D][6][31];   struct obj {     int x, y, d, t, i;     void move() {       if (d == 0 || d == 1 || d == 7) x++;       if (d == 5 || d == 4 || d == 3) x--;       if (d == 1 || d == 2 || d == 3) y++;       if (d == 5 || d == 6 || d == 7) y--;       t--;     }     obj splitL() { return {x, y, (d + 1) % D, T[i + 1], i + 1}; }     obj splitR() { return {x, y, (d + D - 1) % D, T[i + 1], i + 1}; }     bool check(bool set = false) {       if (set) used[x][y][d][t][i] = true;       return used[x][y][d][t][i];     }   };   queue<obj> q;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> T[i];     q.push({N / 2, N / 2, 0, T[0] - 1, 0});     while (not q.empty()) {       auto curr = q.front();       q.pop();       if (curr.check()) continue;       curr.check(true);       vis[curr.x][curr.y] = 1;       if (curr.t == 0) {         if (curr.i == n) continue;         q.push(curr.splitL());         q.push(curr.splitR());         continue;       }       curr.move();       q.push(curr);     }     int ans = 0;     for (int x = 0; x < N; x++) {       for (int y = 0; y < N; y++) {         ans += vis[x][y];       }     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long int;   using vi = vector<int>;   const ll INF = 1e9 + 7;   void solution() {     int n;     cin >> n;     if (n == 1) {       cout <<  -1 n ;       return;     } else {       cout <<  2 ;       n -= 1;       while (n--) {         cout <<  3 ;       }     }     cout << endl;   }   int main() {     int test;     cin >> test;     while (test--) {       solution();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100005, logN = 18;   int n, q, l, r, tim;   struct vec {     int x, y, num;     bool operator<(const vec &A) const { return x < A.x || x == A.x && y > A.y; }   } a[N];   inline long long calc(vec *a) { return a->x + 1LL * tim * a->y; }   inline long long cross(vec &a, vec &b, vec &c) {     return (long long)(b.x - a.x) * (c.y - a.y) -            (long long)(b.y - a.y) * (c.x - a.x);   }   vec mem[N * logN * 2], *newmem = mem;   struct data {     vec *st, *en;   } t[N * 4];   void build(int i, int beg, int end) {     t[i].st = newmem;     if (end - beg == 1) {       scanf( %d%d , &t[i].st->x, &t[i].st->y);       t[i].st->num = end;       newmem++;       t[i].en = newmem;       return;     }     int mid = beg + end >> 1;     build(i << 1, beg, mid);     build(i << 1 | 1, mid, end);     t[i].st = t[i].en = newmem;     for (vec *l = t[i << 1].st, *r = t[i << 1 | 1].st;          l < t[i << 1].en || r < t[i << 1 | 1].en;)       if (l < t[i << 1].en && (r == t[i << 1 | 1].en || *l < *r)) {         while (t[i].en - t[i].st > 1 && cross(t[i].en[-2], t[i].en[-1], *l) >= 0)           t[i].en--;         *t[i].en++ = *l++;       } else {         while (t[i].en - t[i].st > 1 && cross(t[i].en[-2], t[i].en[-1], *r) >= 0)           t[i].en--;         *t[i].en++ = *r++;       }     newmem = t[i].en;   }   vec *query(int i, int beg, int end) {     if (r <= beg || l >= end) return a;     if (l <= beg && r >= end) {       vec *a = t[i].st, *b = t[i].en - 1;       long long fa = calc(a), fb = calc(b);       while (b - a + 1 >= 3) {         vec *mid1 = a + (b - a + 1) / 3, *mid2 = b - (b - a + 1) / 3;         long long f1 = calc(mid1), f2 = calc(mid2);         if (fa <= f1 && f1 <= f2)           a = mid1, fa = f1;         else if (fb <= f2 && f2 <= f1)           b = mid2, fb = f2;         else           puts( Error );       }       vec *res = b;       for (; a < b; a++)         if (calc(res) < calc(a)) res = a;       return res;     }     int mid = beg + end >> 1;     vec *a = query(i << 1, beg, mid), *b = query(i << 1 | 1, mid, end);     return calc(a) > calc(b) ? a : b;   }   int main() {     scanf( %d%d , &n, &q);     build(1, 0, n);     while (q--) {       scanf( %d%d%d , &l, &r, &tim);       l--;       printf( %d n , query(1, 0, n)->num);     }   }
#include <bits/stdc++.h>   using namespace std;   int ans = 1000000005, rans = 0, bans = 0;   int numr[20], numb[20], color[20];   int dp[70005][160];   bool life[70005][160];   int nowr, nowb, tempr, tempb;   char s[6];   int nex[20];   void ok(int x) {     int now;     nowr = nowb = now = 0;     while (x) {       if (x % 2) {         if (color[now])           nowb++;         else           nowr++;       }       x /= 2;       now++;     }   }   int main() {     int n;     cin >> n;     int maxx = 1 << n, maxxx = n * (1 + n) / 2;     nex[0] = 1;     life[0][0] = 1;     for (int i = 1; i < n; i++) nex[i] = nex[i - 1] * 2;     for (int i = 0; i < n; i++) {       scanf( %s , s);       if (s[0] ==  R )         color[i] = 0;       else         color[i] = 1;       scanf( %d%d , numr + i, numb + i);       rans += numr[i];       bans += numb[i];     }     for (int i = 0; i < maxx; i++) {       ok(i);       for (int j = 0; j < n; j++) {         if ((nex[j] & i) == 0) {           tempr = min(nowr, numr[j]);           tempb = min(nowb, numb[j]);           for (int k = 0; k <= maxxx; k++)             if (life[i][k]) {               dp[i + nex[j]][k + tempr] =                   max(dp[i + nex[j]][k + tempr], dp[i][k] + tempb);               life[i + nex[j]][k + tempr] = 1;             }         }       }     }     for (int i = 0; i < maxxx; i++)       if (life[maxx - 1][i]) {         ans = min(ans, max(rans - i, bans - dp[maxx - 1][i]));       }     cout << ans + n << endl;     return 0;   }
#include<bits/stdc++.h>   using namespace std;      typedef long double ld;   typedef long long int ll;   typedef pair<int, int> pi;   typedef pair<long long, long long> pll;      #define endl   n    #define ff first   #define ss second   #define pb push_back   #define int long long   #define sz(v) (int)v.size()   #define inf 2147483647   #define llinf 9223372036854775807   #define all(v) v.begin(),v.end()   #define bp(n) __builtin_popcountll(n)   #define f(i,l,r) for(long long i=l;i<=r;i++)   #define rf(i,r,l) for(long long i=r;i>=l;i--)   #define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)      template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os <<  { ; string sep; for (const auto &x : v) os << sep << x, sep =  ,  ; return os <<  } ; }   template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os <<  { ; string sep; for (const auto &x : arr) os << sep << x, sep =  ,  ; return os <<  } ; }   template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os <<  (  << p.first <<  ,   << p.second <<  ) ; }      void dbg_out() { cout << endl; }   template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cout <<     << H; dbg_out(T...); }         const int N = 3e5 + 5, mod = 1e9 + 7, bit = 61;      mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());      int getRand(int l, int r)   {    uniform_int_distribution<int> uid(l, r);    return uid(rng);   }            signed main()   {    fast;         #ifndef ONLINE_JUDGE    freopen( input.txt ,  r , stdin);    freopen( output.txt ,  w , stdout);   #endif       int t = 1;    cin >> t;    f(tc, 1, t)    {     int n, m, x;     cin >> n >> m >> x;     int r = (x % n);     if (r == 0)     {      r = n;     }     int c = ((x - r) / (n)) + 1;     cout << (r - 1) * m + c << endl;    }    return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9;   const int N = 55;   int n, cnt[N];   vector<pair<int, int> > adj[N];   void dfs(int u, int p, int depth, vector<pair<int, int> > &leaves) {     bool leaf = 1;     for (auto e : adj[u]) {       int v, c;       tie(v, c) = e;       if (v == p) continue;       dfs(v, u, depth + c, leaves);       leaf = 0;     }     if (leaf) leaves.emplace_back(u, depth);   }   int dp[N][N], best[N][N];   int go(int root, int pre, int total, int put) {     vector<pair<int, int> > leaves;     dfs(root, pre, 0, leaves);     int sz = ((int)(leaves).size());     for (int from = (int)(sz + 1) - 1; from >= ((int)0); from--) {       for (int left = (int)(0); left < ((int)put + 1); left++) {         if (from == sz) {           best[from][left] = (left ? -INF : INF);         } else {           best[from][left] = best[from + 1][left];           int l = leaves[from].first, cost = leaves[from].second;           for (int pick = 1; pick <= left; pick++) {             best[from][left] =                 max(best[from][left],                     min(cost + dp[l][total - pick], best[from + 1][left - pick]));           }         }       }     }     return best[0][put];   }   void dfsSize(int u, int p) {     for (auto e : adj[u]) {       int v, c;       tie(v, c) = e;       if (v == p) continue;       dfsSize(v, u);       cnt[u] += cnt[v];     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int _ = 0; _ < (int)(n - 1); _++) {       int u, v, c;       cin >> u >> v >> c;       u--;       v--;       adj[u].emplace_back(v, c);       adj[v].emplace_back(u, c);     }     int s;     cin >> s;     s--;     int m;     cin >> m;     for (int _ = 0; _ < (int)(m); _++) {       int u;       cin >> u;       cnt[u - 1]++;     }     for (int total = 1; total <= m; total++) {       for (int u = 0; u < (int)(n); u++) {         dp[u][total] = go(u, u, total, total);       }     }     dfsSize(s, -1);     int ans = INF;     for (auto e : adj[s]) {       int v, c;       tie(v, c) = e;       ans = min(ans, c + go(v, s, m, cnt[v]));     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using i32 = int32_t;   using i64 = int64_t;   using pii = std::pair<i32, i32>;   using pll = std::pair<i64, i64>;   int dp[5000];   int iv[5000];   bool used[5000];   int div_up(int a, int b) { return (a + b - 1) / b; }   void log_pour(int n, int s, int d) {     if (n > 0) {       printf( %d %d %d n , n, s + 1, d + 1);     }   }   int main() {     int n, k, v;     scanf( %d%d%d , &n, &k, &v);     for (int i = 0; i < k; i++) {       dp[i] = -1;     }     int vmax = 0;     deque<int> q;     for (int i = 0; i < n; i++) {       scanf( %d , &iv[i]);       if (iv[i] == 0) continue;       auto v_mod = iv[i] % k;       if (dp[v_mod] < 0 || i < dp[v_mod]) {         dp[v_mod] = i;         q.push_back(v_mod);       }       vmax += iv[i];     }     if (vmax < v) {       printf( NO n );       return 0;     }     if (v == 0) {       printf( YES n );       log_pour(div_up(iv[0], k), 0, 1);       return 0;     }     if (v % k == 0) {       printf( YES n );       for (int i = 1; i < n; i++) {         log_pour(div_up(iv[i], k), i, 0);       }       log_pour(v / k, 0, 1);       return 0;     }     while (!q.empty()) {       auto v_mod = q.front();       q.pop_front();       assert(dp[v_mod] >= 0);       for (int i = dp[v_mod] + 1; i < n; i++) {         if (iv[i] == 0) continue;         auto v2 = (v_mod + iv[i]) % k;         if (dp[v2] < 0 || i < dp[v2]) {           dp[v2] = i;           q.push_back(v2);         }       }     }     if (dp[v % k] < 0) {       printf( NO n );       return 0;     }     printf( YES n );     int v0 = 0;     int r = v % k;     int j0 = dp[r];     do {       assert(dp[r] >= 0);       used[dp[r]] = true;       v0 += iv[dp[r]];       if (dp[r] != j0) {         log_pour(div_up(iv[dp[r]], k), dp[r], j0);       }       r = (k + r - iv[dp[r]] % k) % k;     } while (v0 % k != v % k);     for (int j = dp[j0]; v0 % k != v % k; j = dp[j]) {       used[j] = true;       v0 += iv[j];       log_pour(div_up(iv[j], k), dp[j], j0);     }     assert(v0 % k == v % k);     int j1 = -1;     int v1 = 0;     for (int i = 0; i < n; i++) {       if (used[i]) continue;       v1 += iv[i];       if (j1 < 0) {         j1 = i;       } else {         log_pour(div_up(iv[i], k), i, j1);       }     }     if (v0 > v) {       log_pour((v0 - v) / k, j0, (j0 + 1) % n);     } else if (v0 < v) {       assert(j1 >= 0);       log_pour((v - v0) / k, j1, j0);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int id[110001];   int ans[1000001];   int main() {     int n, m, i, number, t;     while (scanf( %d %d , &n, &m) != EOF) {       number = 0;       memset(id, 0, sizeof(id));       memset(ans, 0, sizeof(ans));       for (i = 0; i < n; i++) {         scanf( %d , &t);         if (!i)           id[number++] = t;         else if (id[number - 1] != t)           id[number++] = t;       }       for (i = 0; i < number; i++) {         if (i == 0 || i == number - 1)           ans[id[i]]++;         else if (id[i - 1] == id[i + 1])           ans[id[i]] += 2;         else           ans[id[i]] += 1;       }       int sum = 0, h = 0;       for (i = 1; i <= m; i++) {         if (ans[i] > sum) {           sum = ans[i];           h = i;         }       }       printf( %d n , h);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   class Task {    public:     char invert(char c) {       if (c ==  W ) return  B ;       return  W ;     }     void shift_left(string& s, int k) {       int n = s.length();       string t = s;       for (int i = 0; i < n; i++) t[i] = s[(i + k) % n];       s = t;     }     void shift_left(vector<bool>& v, int k) {       int n = v.size();       auto w = v;       for (int i = 0; i < n; i++) w[i] = v[(i + k) % n];       v = w;     }     void solve() {       int n, k;       cin >> n >> k;       string s;       cin >> s;       vector<bool> unstable(n);       for (int i = 0; i < n; i++) {         if (s[(i + 1) % n] != s[i] && s[(i - 1 + n) % n] != s[i]) {           unstable[i] = true;         }       }       bool all_stable = true;       for (int i = 0; i < n; i++) {         if (unstable[i]) {           all_stable = false;           break;         }       }       if (all_stable) {         cout << s <<   n ;         return;       }       int stable = -1;       for (int i = 0; i < n; i++) {         if (!unstable[i]) {           stable = i;           break;         }       }       if (stable == -1) {         k %= 2;         for (int i = 0; i < n; i++) {           if (k % 2 == 1) {             cout << invert(s[i]);           } else {             cout << s[i];           }         }         cout <<   n ;         return;       }       if (stable == 0) {         stable = n - 1;         while (stable > 0 && !unstable[stable]) stable--;         stable = (stable + 1) % n;         shift_left(s, stable);         shift_left(unstable, stable);       } else {         shift_left(s, stable);         shift_left(unstable, stable);       }       for (int i = 2; i < n;) {         if (unstable[i]) {           int j;           for (j = i; j < n && unstable[j]; j++)             ;           for (int t = i; t < min(i + k, i + (j - i + 1) / 2); t++)             s[t] = s[(i - 1 + n) % n];           for (int t = j - 1; t >= max(j - k, j - (j - i + 1) / 2); t--)             s[t] = s[j % n];           if (k % 2 == 1) {             for (int t = min(i + k, i + (j - i + 1) / 2);                  t < max(j - k, j - (j - i + 1) / 2); t++)               s[t] = invert(s[t]);           }           i = j;         } else {           i++;         }       }       shift_left(s, n - stable);       cout << s <<   n ;     }   };   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     int T = 1;     for (int t = 1; t <= T; t++) {       (new Task())->solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 101;   long long n;   pair<long long, long long> a[N];   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (long long i = 0; i < n; ++i) cin >> a[i].first >> a[i].second;     long long p;     cin >> p;     for (long long i = n - 1; i >= 0; --i) {       if (a[i].first <= p) {         cout << n - i <<   n ;         exit(0);       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main(void) {     long long n, k;     cin >> n >> k;     long long len = (1LL << n) - 1;     while (true) {       long long mid = len / 2 + 1;       if (k == mid) break;       if (k > mid) k -= mid;       n--;       len = (1LL << n) - 1;     }     cout << n << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long Mod = 1000000007LL;   const int N = 3e2 + 10;   const long long Inf = 2242545357980376863LL;   const long long Log = 30;   long long t1, t2, t3;   long long Get(long long x, long long y) {     if (x < y) return t2;     if (x == y) return t1;     return t3;   }   long long a[N][N];   long long ps1[N][N], ps2[N][N], ps3[N][N], ps4[N][N];   set<pair<long long, long long> > st;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, m, t;     cin >> n >> m >> t;     cin >> t1 >> t2 >> t3;     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 = 2; j <= m; j++)         ps1[i][j] = ps1[i][j - 1] + Get(a[i][j - 1], a[i][j]);     for (int i = 1; i <= n; i++)       for (int j = m - 1; j >= 1; j--)         ps2[i][j] = ps2[i][j + 1] + Get(a[i][j + 1], a[i][j]);     for (int i = n - 1; i >= 1; i--)       for (int j = 1; j <= m; j++)         ps3[i][j] = ps3[i + 1][j] + Get(a[i + 1][j], a[i][j]);     for (int i = 2; i <= n; i++)       for (int j = 1; j <= m; j++)         ps4[i][j] = ps4[i - 1][j] + Get(a[i - 1][j], a[i][j]);     long long mn = Inf;     long long x1 = 1, y1 = 1, x2 = 3, y2 = 3;     for (int i1 = 1; i1 <= n; i1++)       for (int i2 = i1 + 2; i2 <= n; i2++) {         st.clear();         for (int j = 2; j <= m; j++) {           long long V = ps1[i1][j] - ps4[i1][j] + ps4[i2][j] - ps2[i2][j];           long long R = t - V;           auto it = st.lower_bound({R, -1});           pair<long long, long long> Q;           if (st.size()) {             if (it != st.end()) {               Q = *it;               if (abs(t - (V + Q.first)) < mn) {                 mn = abs(t - (V + Q.first));                 x2 = i2;                 x1 = i1;                 y2 = j;                 y1 = it->second;               }             }             if (it != st.begin()) {               it--;               Q = *it;               if (abs(t - (V + Q.first)) < mn) {                 mn = abs(t - (V + Q.first));                 x2 = i2;                 x1 = i1;                 y2 = j;                 y1 = it->second;               }             }           }           st.insert(               {-ps1[i1][j - 1] + ps3[i1][j - 1] - ps3[i2][j - 1] + ps2[i2][j - 1],                j - 1});         }       }     cout << x1 <<     << y1 <<     << x2 <<     << y2 <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using std::string;   int main() {     int n;     cin >> n;     string s;     cin >> s;     int f = 0;     for (int i = 0; i < s.size() - 1; i++) {       if (s[i + 1] < s[i]) {         for (int j = i + 1; j < s.size(); j++) s[j - 1] = s[j];         f = 1;         break;       }     }     s.pop_back();     cout << s;   }
#include <bits/stdc++.h>   using namespace std;   int n, k, q, x;   map<int, int> M;   map<int, int>::iterator it;   int main() {     scanf( %d %d , &n, &k);     for (int i = (1); i <= (n); i++) {       int a;       scanf( %d , &a);       for (int j = (0); j <= (k); j++) {         if (!M.count(a * j))           M[a * j] = j;         else           M[a * j] = min(M[a * j], j);       }     }     scanf( %d , &q);     while (q--) {       scanf( %d , &x);       int res = 99;       for (it = M.begin(); it != M.end(); it++) {         int v = (*it).first, c = (*it).second;         if (M.count(x - v)) {           int cc = M[x - v];           res = min(res, c + cc);         }       }       if (res > k) res = -1;       printf( %d n , res);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, ans = 0;   vector<int> a[100005];   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       int k, x;       cin >> k;       while (k--) {         cin >> x;         a[i].push_back(x);       }       sort(a[i].begin(), a[i].end());     }     a[0] = a[n];     a[n + 1] = a[1];     for (int i = 1; i <= n; i++) {       for (int j = 1; j < a[i].size(); j++) {         if (upper_bound(a[i - 1].begin(), a[i - 1].end(), a[i][j]) -                 lower_bound(a[i - 1].begin(), a[i - 1].end(), a[i][j - 1]) !=             upper_bound(a[i + 1].begin(), a[i + 1].end(), a[i][j]) -                 lower_bound(a[i + 1].begin(), a[i + 1].end(), a[i][j - 1]))           ans++;       }     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( -O2 )   using namespace std;   const long double PI = acos(-1);   const int MOD = 998244353, LIM = 2e5 + 5;   const long double EPS = 1e-9;   const int mod = 1000000007;   int main() {     double l, p, q;     std::cin >> l >> p >> q;     double ans = l * p;     ans /= p + q;     std::cout << std::fixed << std::setprecision(9) << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, m, t;     cin >> n >> k >> m >> t;     for (int i = 0; i < t; i++) {       int a, b;       cin >> a >> b;       if (a == 0 && b < k) {         k -= b;         n -= b;       } else if (a == 1 && b <= k) {         k++;         n++;       } else if (a == 0 && b >= k) {         n = b;       } else if (a == 1 && b > k) {         n++;       }       cout << n <<     << k << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 5;   const int mod = 1e9 + 7;   int n, a, b;   double ans;   vector<vector<int>> g(N);   void dfs(int u, int par, int depth) {     ans += 1.0 / depth;     for (auto v : g[u])       if (v != par) dfs(v, u, depth + 1);   }   int main() {     cin >> n;     for (int i = 1; i < n; i++) {       cin >> a >> b;       g[a].push_back(b);       g[b].push_back(a);     }     dfs(1, 1, 1);     cout << fixed << setprecision(9) << ans;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1005000;   int A[maxn], sum[maxn][10];   int dfs(int u) {     if (u < 10) return u;     if (A[u]) return A[u];     int now = 1, tmp = u;     while (u) {       if (u % 10 != 0) now *= u % 10;       u /= 10;     }     return A[tmp] = dfs(now);   }   int main() {     for (int i = 1; i <= 1000000; i++) A[i] = dfs(i);     for (int i = 1; i <= 1000000; i++) {       for (int j = 1; j <= 9; j++) {         if (A[i] == j)           sum[i][j] = sum[i - 1][j] + 1;         else           sum[i][j] = sum[i - 1][j];       }     }     int Q;     cin >> Q;     while (Q--) {       int l, r, k;       scanf( %d%d%d , &l, &r, &k);       cout << sum[r][k] - sum[l - 1][k] << endl;     }   }
#include <bits/stdc++.h>   int tcase, m;   long long n;   int gao(long long x) {     int ret = 0;     for (; x; x /= 10) ret += x % 10;     return ret;   }   int main() {     scanf( %d , &tcase);     while (tcase--) {       scanf( %lld%d , &n, &m);       if (gao(n) <= m) {         printf( 0 n );         continue;       }       long long x = 10;       while (gao(n + (x - n % x)) > m) x *= 10;       printf( %lld n , x - n % x);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1010;   int n, k, m;   int p10[maxn];   inline void init() {     p10[0] = 1;     for (register int i = 1; i <= 1000; i++) {       p10[i] = (p10[i - 1] * 10) % k;     }   }   long long f[1010][110][2];   long long dfs(long long pos, long long statu, bool fg) {     if (pos == n + 1) {       if (fg) return 1;       return 0;     }     if (~f[pos][statu][fg]) {       return f[pos][statu][fg];     }     long long ans = 0;     if (pos != n) ans += dfs(pos + 1, statu, fg);     for (register int i = 1; i <= 9; i++) {       ans += dfs(pos + 1, (statu + i * p10[pos - 1]) % k,                  fg || (!((statu + i * p10[pos - 1]) % k)));       ans %= m;     }     f[pos][statu][fg] = ans;     return ans;   }   int main() {     memset(f, -1, sizeof(f));     scanf( %d%d%d , &n, &k, &m);     init();     printf( %lld n , dfs(1, 0, 0));     return 0;   }