malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int n, m, a, b, ans[400];   string s[400];   long long calc(int pos, int res) {     for (int i = res + 1; i <= 10; i++) {       for (int j = 0; j < 1 << i; j++) {         string t =   ;         for (int k = 0; k < i; k++) t = t + (char)(((j >> k) & 1) +  0 );         if (s[pos].find(t) == -1) {           ans[pos] = i - 1;           return i - 1;         }       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin >> n;     for (int i = 1; i <= n; i++) cin >> s[i];     cin >> m;     for (int i = 1; i <= m; i++) {       cin >> a >> b;       s[n + i] = s[a] + s[b];       if (s[n + i].length() > 1000)         s[n + i] = s[n + i].substr(0, 500) +                    s[n + i].substr(s[n + i].length() - 500, 500);       cout << calc(n + i, max(ans[a], ans[b])) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1000000007;   long long dp[5010][5010];   char s[5010], z[5010];   long long solve() {     int M = strlen(s), N = strlen(z);     for (int i = 0; i <= M; i++) dp[i][0] = 0;     for (int i = 0; i <= N; i++) dp[0][i] = 0;     for (int i = 1; i <= M; i++)       for (int j = 1; j <= N; j++) {         dp[i][j] = dp[i][j - 1];         if (s[i - 1] == z[j - 1])           dp[i][j] = (dp[i][j] + dp[i - 1][j - 1] + 1) % mod;       }     long long ans = 0;     for (int i = 0; i <= M; i++) ans = (ans + dp[i][N]) % mod;     return ans;   }   int main() {     scanf( %s %s , s, z);     int ans = solve();     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[] = {0,  1,  1, 1, 2,   1, 2, 1, 5,  2, 2,  1, 5,  1, 2,  1, 14, 1, 5, 1,              5,  2,  2, 1, 15,  2, 2, 5, 4,  1, 4,  1, 51, 1, 2,  1, 14, 1, 2, 2,              14, 1,  6, 1, 4,   2, 2, 1, 52, 2, 5,  1, 5,  1, 15, 2, 13, 2, 2, 1,              13, 1,  2, 4, 267, 1, 4, 1, 5,  1, 4,  1, 50, 1, 2,  3, 4,  1, 6, 1,              52, 15, 2, 1, 15,  1, 2, 1, 12, 1, 10, 1, 4,  2};   int main() {     int n;     cin >> n;     cout << a[n] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int Max_n = 2e5 + 10;   const int Max_m = 4e5 + 10;   int f[Max_n];   struct A {     long long val;     int pos;     bool operator<(const A &a) const { return val < a.val; }   } a[Max_n];   struct Edge {     int u, v;     long long cost;     bool operator<(const Edge &edge) const { return cost < edge.cost; }   } edge[Max_m * 2];   int Find(int v) {     if (f[v] == v) return v;     return f[v] = Find(f[v]);   }   bool Merge(int m, int n) {     int t1 = Find(m);     int t2 = Find(n);     if (t1 != t2) {       f[t1] = t2;       return true;     }     return false;   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     int cnt = 0;     for (int i = 1; i <= n; i++) f[i] = i;     for (int i = 1; i <= n; i++) {       scanf( %lld , &a[i].val);       a[i].pos = i;     }     sort(a + 1, a + n + 1);     for (int i = 2; i <= n; i++) {       edge[cnt].u = a[1].pos;       edge[cnt].v = a[i].pos;       edge[cnt++].cost = a[1].val + a[i].val;       edge[cnt].u = a[i].pos;       edge[cnt].v = a[1].pos;       edge[cnt++].cost = a[1].val + a[i].val;     }     for (int i = 1; i <= m; i++) {       int u, v;       long long cost;       scanf( %d%d%lld , &u, &v, &cost);       edge[cnt].u = u;       edge[cnt].v = v;       edge[cnt++].cost = cost;       edge[cnt].u = v;       edge[cnt].v = u;       edge[cnt++].cost = cost;     }     sort(edge, edge + cnt);     long long ans = 0;     int edgeCnt = 0;     for (int i = 0; i < cnt; i++) {       if (Merge(edge[i].u, edge[i].v)) {         ans += edge[i].cost;         edgeCnt++;       }       if (edgeCnt == n - 1) break;     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int defence[4];   int atack[4];   int main() {     for (int i = 0; i < 4; i++) cin >> defence[i] >> atack[i];     int maximum = max(defence[0], defence[1]);     maximum = max(maximum, atack[0]);     maximum = max(maximum, atack[1]);     if (defence[0] > atack[2] && defence[0] > atack[3] && atack[1] > defence[2] &&         atack[1] > defence[3]) {       cout <<  Team 1 ;       return 0;     }     if (defence[1] > atack[2] && defence[1] > atack[3] && atack[0] > defence[2] &&         atack[0] > defence[3]) {       cout <<  Team 1 ;       return 0;     }     if ((defence[0] + atack[1]) < (defence[1] + atack[0])) {       if (defence[1] < atack[3] && atack[0] < defence[2]) {         cout <<  Team 2 ;         return 0;       } else if (defence[1] < atack[2] && atack[0] < defence[3]) {         cout <<  Team 2 ;         return 0;       }     } else {       if (defence[0] < atack[3] && atack[1] < defence[2]) {         cout <<  Team 2 ;         return 0;       } else if (defence[0] < atack[2] && atack[1] < defence[3]) {         cout <<  Team 2 ;         return 0;       }     }     cout <<  Draw ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, k, q;   int x[411111], y[411111], a[411111], b[411111], aa[411111], bb[411111];   int ans[411111];   int mi[2000222];   void init(int pos, int l, int r) {     mi[pos] = -1;     if (l == r) return;     init(pos + pos, l, (l + r) / 2);     init(pos + pos + 1, (l + r) / 2 + 1, r);   }   void mod(int pos, int l, int r, int x, int v) {     if (x < l || x > r) return;     if (l == r) {       mi[pos] = v;       return;     }     mod(pos + pos, l, (l + r) / 2, x, v);     mod(pos + pos + 1, (l + r) / 2 + 1, r, x, v);     mi[pos] = min(mi[pos + pos], mi[pos + pos + 1]);   }   int fin(int pos, int l, int r, int ll, int rr) {     ll = max(ll, l);     rr = min(rr, r);     if (ll > rr) return 1e9;     if (l == ll && r == rr) return mi[pos];     return min(fin(pos + pos, l, (l + r) / 2, ll, rr),                fin(pos + pos + 1, (l + r) / 2 + 1, r, ll, rr));   }   void solve() {     vector<pair<int, int> > ev;     for (int i = 0; i < k; i++) {       ev.push_back(make_pair(y[i], -(i + 1)));     }     for (int i = 0; i < q; i++) {       ev.push_back(make_pair(bb[i], i + 1));     }     sort(ev.begin(), ev.end());     init(1, 0, n - 1);     for (int i = 0; i < ev.size(); i++) {       int id = ev[i].second;       if (id < 0) {         id = (-id) - 1;         mod(1, 0, n - 1, x[id], y[id]);       } else {         id = id - 1;         if (fin(1, 0, n - 1, a[id], aa[id]) >= b[id]) ans[id] = 1;       }     }   }   int main() {     cin >> n >> m >> k >> q;     for (int i = 0; i < k; i++) {       scanf( %d%d , &x[i], &y[i]);       x[i]--;       y[i]--;     }     for (int i = 0; i < q; i++) {       scanf( %d%d%d%d , &a[i], &b[i], &aa[i], &bb[i]);       a[i]--;       b[i]--;       aa[i]--;       bb[i]--;       ans[i] = 0;     }     solve();     for (int i = 0; i < k; i++) swap(x[i], y[i]);     for (int i = 0; i < q; i++) {       swap(a[i], b[i]);       swap(aa[i], bb[i]);     }     swap(n, m);     solve();     for (int i = 0; i < q; i++)       if (ans[i])         puts( YES );       else         puts( NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0;     bool t = false;     char ch = getchar();     while ((ch <  0  || ch >  9 ) && ch !=  - ) ch = getchar();     if (ch ==  - ) t = true, ch = getchar();     while (ch <=  9  && ch >=  0 ) x = x * 10 + ch - 48, ch = getchar();     return t ? -x : x;   }   int n, Q, lans;   struct Line {     int v, next, w;   } e[100100 << 1];   int h[100100], cnt = 1;   inline void Add(int u, int v, int w) {     e[cnt] = (Line){v, h[u], w};     h[u] = cnt++;   }   struct Tree {     int rt, p[19][100100], dfn[100100], low[100100], ln[100100], md[100100],         dep[100100], tim;     void dfs(int u, int ff) {       p[0][u] = ff;       ln[dfn[u] = ++tim] = u;       md[u] = dep[u];       for (int i = 1; i < 19; ++i) p[i][u] = p[i - 1][p[i - 1][u]];       for (int i = h[u]; i; i = e[i].next) {         int v = e[i].v;         if (v == ff) continue;         dep[v] = dep[u] + e[i].w;         dfs(v, u);         md[u] = max(md[u], md[v]);       }       low[u] = tim;     }     pair<int, int> mx[100100 << 2];     int tag[100100 << 2];     void pushup(int now) { mx[now] = max(mx[(now << 1)], mx[(now << 1 | 1)]); }     void Build(int now, int l, int r) {       if (l == r) {         mx[now] = make_pair(dep[ln[l]], ln[l]);         return;       }       int mid = (l + r) >> 1;       Build((now << 1), l, mid);       Build((now << 1 | 1), mid + 1, r);       pushup(now);     }     void Modify(int now, int l, int r, int L, int R, int w) {       if (L <= l && r <= R) {         mx[now].first += w;         tag[now] += w;         return;       }       int mid = (l + r) >> 1;       if (L <= mid) Modify((now << 1), l, mid, L, R, w);       if (R > mid) Modify((now << 1 | 1), mid + 1, r, L, R, w);       pushup(now);       mx[now].first += tag[now];     }     int ans[100100], vis[100100];     void pre(int _rt) {       rt = _rt;       dfs(rt, 0);       Build(1, 1, n);       for (int i = 2; i <= n; ++i) {         ans[i] = ans[i - 1] + mx[1].first;         for (int j = mx[1].second; j && !vis[j]; j = p[0][j])           vis[j] = i, Modify(1, 1, n, dfn[j], low[j], dep[p[0][j]] - dep[j]);       }     }     int Solve(int x, int y) {       y = min(y, n);       if (vis[x] <= y) return ans[y];       int u = x;       for (int i = 18; ~i; --i)         if (vis[p[i][x]] > y) x = p[i][x];       x = p[0][x];       return ans[y] + md[u] - dep[x] -              min(dep[x], min(ans[y] - ans[y - 1], md[x] - dep[x]));     }   } T1, T2;   int mx, rt;   void dfs(int u, int ff, int dep) {     if (dep > mx) mx = dep, rt = u;     for (int i = h[u]; i; i = e[i].next)       if (e[i].v != ff) dfs(e[i].v, u, dep + e[i].w);   }   int main() {     n = read();     Q = read();     for (int i = 1, u, v, w; i < n; ++i)       u = read(), v = read(), w = read(), Add(u, v, w), Add(v, u, w);     mx = 0;     dfs(1, 0, 0);     T1.pre(rt);     while (Q--) {       int u = (read() + lans - 1) % n + 1, v = (read() + lans - 1) % n + 1;       printf( %d n , lans = T1.Solve(u, v << 1));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int inf = 1e9 + 7;   const long long int inf2 = inf * inf;   priority_queue<long long int, vector<long long int>, greater<long long int>>       mnheap;   priority_queue<long long int> mxheap;   long long int gcd(long long int x, long long int y) {     if (x == 0) return y;     return gcd(y % x, x);   }   int is_prime(long long int x) {     if (x < 2) return 0;     for (long long int i = 2; i * i <= x; i++) {       if (x % i == 0) return 0;     }     return 1;   }   inline long long int modpw(long long int x, long long int y, long long int z) {     long long int res = 1;     x = x % z;     while (y) {       if (y & 1) res = (res * x) % z;       x = (x * x) % z;       y /= 2;     }     return res;   }   inline long long int modinv(long long int x, long long int z) {     return modpw(x, z - 2, z);   }   long long int lcm(long long int x, long long int y) {     return (x * y) / gcd(x, y);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       int dp[n][m];       string st[n];       for (int i = 0; i < n; i++) cin >> st[i];       int cnt = 0;       for (int i = 0; i < n - 1; i++) {         if (st[i][m - 1] ==  R ) cnt++;       }       for (int i = 0; i < m - 1; i++) {         if (st[n - 1][i] ==  D ) cnt++;       }       cout << cnt << endl;     }   }
#include <bits/stdc++.h>   int main() {     char s[150];     int o = 1, z = 0, a[150];     scanf( %s , &s);     for (int i = 0; i < strlen(s); i++) {       a[i] = s[i] -  0 ;     }     for (int i = 0; i < strlen(s) - 1; i++) {       if (a[i] == a[i + 1]) {         o++;         if (o == 7) {           printf( YES n );           return 0;         }       } else         o = 1;     }     printf( NO n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mxn = 1e5 + 5;   int n, a[mxn], c[mxn];   bool vis[mxn];   int main() {     scanf( %d , &n);     for (int(i) = (int)(1); (i) <= (int)(n); ++(i)) scanf( %d , a + i);     int cnt = 0;     for (int(i) = (int)(n); (i) >= (int)(1); --(i)) {       c[i] = c[i + 1] + (vis[a[i]] == 0);       vis[a[i]] = 1;     }     long long ans = 0;     memset(vis, 0, sizeof(vis));     for (int(i) = (int)(1); (i) <= (int)(n); ++(i))       if (!vis[a[i]]) {         vis[a[i]] = 1;         ans += c[i + 1];       }     return 0 * printf( %lld n , ans);   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 7;   int a[N], n, q;   long long sum[N << 2][11], mul[11] = {1};   long long SUM[11], LA[11];   int lazy[N << 2][11];   void pushup(int rt) {     for (int i = 0; i < 10; ++i) {       sum[rt][i] = sum[rt << 1][i] + sum[rt << 1 | 1][i];     }   }   void pushdown(int rt) {     for (int i = 0; i < 10; ++i)       SUM[i] = sum[rt << 1][i], LA[i] = lazy[rt << 1][i];     for (int i = 0; i < 10; ++i) {       int u = i, v = lazy[rt][i];       if (u == v) continue;       for (int j = 0; j < 10; ++j) {         if (lazy[rt << 1][j] == u) {           LA[j] = lazy[rt][i];         }       }       SUM[lazy[rt][i]] += sum[rt << 1][i];       SUM[i] -= sum[rt << 1][i];     }     for (int i = 0; i < 10; ++i)       sum[rt << 1][i] = SUM[i], lazy[rt << 1][i] = LA[i];     for (int i = 0; i < 10; ++i)       SUM[i] = sum[rt << 1 | 1][i], LA[i] = lazy[rt << 1 | 1][i];     for (int i = 0; i < 10; ++i) {       int u = i, v = lazy[rt][i];       if (u == v) continue;       for (int j = 0; j < 10; ++j) {         if (lazy[rt << 1 | 1][j] == u) {           LA[j] = lazy[rt][i];         }       }       SUM[lazy[rt][i]] += sum[rt << 1 | 1][i];       SUM[i] -= sum[rt << 1 | 1][i];     }     for (int i = 0; i < 10; ++i)       sum[rt << 1 | 1][i] = SUM[i], lazy[rt << 1 | 1][i] = LA[i];     for (int i = 0; i < 10; ++i) lazy[rt][i] = i;   }   void build(int l, int r, int rt) {     for (int i = 0; i < 10; ++i) lazy[rt][i] = i;     if (l == r) {       int x = a[l], index = 0;       while (x) {         int y = x % 10;         x /= 10;         sum[rt][y] += mul[index];         index++;       }       return;     }     int mid = (l + r) >> 1;     build(l, mid, rt << 1);     build(mid + 1, r, rt << 1 | 1);     pushup(rt);   }   void update(int l, int r, int rt, int L, int R, int x, int y) {     if (L <= l && r <= R) {       for (int j = 0; j < 10; ++j) {         if (lazy[rt][j] == x) {           lazy[rt][j] = y;           sum[rt][y] += sum[rt][x];           sum[rt][x] = 0;         }       }       return;     }     pushdown(rt);     int mid = (l + r) >> 1;     if (L <= mid) update(l, mid, rt << 1, L, R, x, y);     if (R > mid) update(mid + 1, r, rt << 1 | 1, L, R, x, y);     pushup(rt);   }   long long query(int l, int r, int rt, int L, int R) {     if (L <= l && r <= R) {       long long ret = 0;       for (int i = 0; i < 10; ++i) ret += sum[rt][i] * i;       return ret;     }     pushdown(rt);     int mid = (l + r) >> 1;     long long ret = 0;     if (L <= mid) ret += query(l, mid, rt << 1, L, R);     if (R > mid) ret += query(mid + 1, r, rt << 1 | 1, L, R);     return ret;   }   int main() {     for (int i = 1; i < 11; ++i) mul[i] = mul[i - 1] * 10;     scanf( %d%d , &n, &q);     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);     }     build(1, n, 1);     while (q--) {       int op, L, R, x, y;       scanf( %d , &op);       if (op == 1) {         scanf( %d%d%d%d , &L, &R, &x, &y);         if (x == y) continue;         update(1, n, 1, L, R, x, y);       } else {         scanf( %d%d , &L, &R);         printf( %lld n , query(1, n, 1, L, R));       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1ll << 32;   const int mod = 1e9 + 7;   inline int add(int x, int y) {     x += y;     if (x >= mod) return x - mod;     return x;   }   inline int sub(int x, int y) {     x -= y;     if (x < 0) return x + mod;     return x;   }   inline int mul(int x, int y) { return (x * 1ll * y) % mod; }   inline int power(int x, int y) {     int ans = 1;     while (y) {       if (y & 1) ans = mul(ans, x);       x = mul(x, x);       y >>= 1;     }     return ans;   }   inline int inv(int x) { return power(x, mod - 2); }   const long long FACTORIAL_SIZE = 1.1e6;   long long fact[FACTORIAL_SIZE], ifact[FACTORIAL_SIZE];   void gen_factorial(long long n) {     fact[0] = fact[1] = ifact[0] = ifact[1] = 1;     for (long long i = 2; i <= n; i++) {       fact[i] = (i * fact[i - 1]) % mod;     }     ifact[n] = inv(fact[n]);     for (long long i = n - 1; i >= 2; i--) {       ifact[i] = ((i + 1) * ifact[i + 1]) % mod;     }   }   long long nck(long long n, long long k) {     long long den = (ifact[k] * ifact[n - k]) % mod;     return (den * fact[n]) % mod;   }   const int N = 300000;   long long f(string s) {     if (s ==  Tetrahedron ) return 4;     if (s ==  Cube ) return 6;     if (s ==  Octahedron ) return 8;     if (s ==  Dodecahedron ) return 12;     if (s ==  Icosahedron ) return 20;   }   void solve() {     long long n;     cin >> n;     long long ans = 0;     for (long long i = 0; i < n; i++) {       string s;       cin >> s;       ans += f(s);     }     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long tc = 1;     int i = 1;     while (tc--) {       solve();       i++;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n;   bool isvalid(long long x) {     if (x >= 0 && x <= n - 1)       return true;     else       return false;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     vector<long long> a(n);     for (long long i = 0; i < n; i++) {       cin >> a[i];     }     sort(a.begin(), a.end());     vector<long long> b(n);     b[0] = a[n - 1];     long long i = n - 2;     long long j = n - 3;     long long right = 1;     long long left = n - 1;     while (true) {       if (isvalid(i)) {         b[right] = a[i];         right++;         i -= 2;       }       if (isvalid(j)) {         b[left] = a[j];         left--;         j -= 2;       }       if (isvalid(i) == false && isvalid(j) == false) break;     }     bool done = true;     if (b[0] >= b[1] + b[n - 1]) {       done = false;     }     if (b[n - 1] >= b[n - 2] + b[0]) {       done = false;     }     for (long long i = 1; i <= n - 2; i++) {       if (b[i] >= b[i - 1] + b[i + 1]) {         done = false;         break;       }     }     if (!done) {       cout <<  NO             <<   n ;     } else {       cout <<  YES             <<   n ;       for (long long i = 0; i < n; i++) {         cout << b[i] <<    ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int ans;   int main() {     int d, n, u, i, prev;     cin >> d >> n;     for (i = 0; i < n; i++) {       cin >> u;       if (i and prev != 1) ans += d - prev + 1;       prev = u + 1;       if (prev > d) prev -= d;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int ans = 1e9;       for (int i = 1; i * i <= n; i++) {         ans = min(ans, i - 1 + (n - i + i - 1) / i);       }       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   const int n = 7;   const int msiz = 1 << n;   const int mod = 1000000007;   int a[n];   int ans[msiz];   long long int tans[msiz];   struct matrix {     long long int cont[msiz][msiz];     matrix operator*(const matrix& r) const {       matrix p;       int i, j, k;       for (i = 0; i < msiz; i++) {         for (j = 0; j <= i; j++) {           p.cont[i][j] = 0;           for (k = 0; k < msiz; k++) {             p.cont[i][j] += cont[i][k] * r.cont[k][j];             p.cont[i][j] %= mod;           }         }       }       for (i = 0; i < msiz; i++) {         for (j = i + 1; j < msiz; j++) {           p.cont[i][j] = p.cont[j][i];         }       }       return p;     }   };   matrix q[4];   matrix pwr(int x) {     matrix res;     if (x == 0) {       int i, j;       for (i = 0; i < msiz; i++) {         for (j = 0; j < msiz; j++) {           if (i == j)             res.cont[i][j] = 1;           else             res.cont[i][j] = 0;         }       }       return res;     }     res = pwr(x / 4);     res = res * res;     res = res * res;     if (x % 4 != 0) res = res * q[x % 4];     return res;   }   int main() {     int i, j, k, l;     matrix p;     for (i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     for (i = 0; i < msiz; i++) {       ans[i] = 0;     }     ans[0] = 1;     for (i = n; i > 0; i--) {       for (j = 0; j < msiz; j++) {         for (k = 0; k < msiz; k++) {           p.cont[j][k] = 0;         }       }       for (j = 0; j < (1 << i); j++) {         for (k = 0; k < (1 << i); k++) {           for (l = 0; l < (1 << (i - 1)); l++) {             if ((j | k | l | (l << 1)) == (1 << i) - 1) p.cont[j][k]++;           }         }       }       q[1] = p;       q[2] = p * p;       q[3] = q[2] * p;       p = pwr(a[i - 1]);       for (j = 0; j < msiz; j++) {         tans[j] = 0;         for (k = 0; k < msiz; k++) {           tans[j] += ans[k] * p.cont[j][k];           tans[j] %= mod;         }       }       for (j = 0; j < msiz; j++) ans[j] = tans[j];     }     printf( %d , ans[0]);   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int max_n = 1e5 + 5;   string q[max_n];   int dig[10][2];   int main() {     string s;     cin >> s;     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) cin >> q[i];     for (int i = 0; i <= 9; i++) {       dig[i][0] = i;       dig[i][1] = 10;     }     for (int i = n; i >= 1; i--) {       int d = q[i][0] -  0 ;       int len = q[i].length();       int sum = 0, pw = 1;       for (int j = 3; j < len; j++) {         int k = q[i][j] -  0 ;         sum = (1LL * sum * dig[k][1] % mod + dig[k][0]) % mod;         pw = 1LL * pw * dig[k][1] % mod;       }       dig[d][0] = sum;       dig[d][1] = pw;     }     int len = s.length();     int ans = 0;     for (int i = 0; i < len; i++) {       int d = s[i] -  0 ;       ans = (1LL * ans * dig[d][1] % mod + dig[d][0]) % mod;     }     printf( %d n , ans);     return 0;   }