malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int arr[1000000];   map<pair<int, int>, int> mp;   int cnt[1000000];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long n;     cin >> n;     long long ans = 0;     for (int i = 0; i < n; i++) {       cin >> arr[i + 1];       ans += arr[i + 1];     }     int q;     cin >> q;     for (int i = 0; i < q; i++) {       int s, t, u;       cin >> s >> t >> u;       if (mp[make_pair(s, t)]) {         cnt[mp[make_pair(s, t)]]--;         if (cnt[mp[make_pair(s, t)]] < arr[mp[make_pair(s, t)]]) {           ans++;         }       }       cnt[u]++;       mp[make_pair(s, t)] = u;       if (cnt[u] <= arr[u]) ans--;       cout << max(ans, n) << endl;     }   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:167772160 )   using namespace std;   int n, i, j, a, b, x[100001], y[100001], v, k, uns[100001], p, q, w[6];   int findd(int l, int r, int xx) {     int t;     t = (l + r) / 2;     if (l == r) {       if (x[l] == xx)         return l;       else         return -1;     } else {       if (x[t] >= xx)         return findd(l, t, xx);       else         return findd(t + 1, r, xx);     }   }   int main() {     cin >> n;     cin >> a >> b;     if (a > b) {       p = 1;       q = 2;     } else {       p = 2;       q = 1;     }     for (i = 0; i < n; i++) {       cin >> x[i];       y[i] = x[i];     }     sort(x, x + n);     if (a == b) {       for (i = 1; i <= a; i++) cout << 1 <<    ;       for (i = 1; i <= b; i++) cout << 2 <<    ;       cout << endl;       return 0;     }     memset(w, 0, sizeof(w));     for (i = 0; i < n; i++) uns[i] = q;     k = 0;     v = max(a, b);     for (i = 0; i < v; i++) w[x[i]]++;     if (p == 1) {       for (i = 0; i < n; i++) {         if (w[y[i]]) {           uns[i] = p;           k++;           w[y[i]]--;         }       }     } else {       for (i = n - 1; i >= 0; i--) {         if (w[y[i]]) {           uns[i] = p;           k++;           w[y[i]]--;         }       }     }     for (i = 0; i < n; i++) cout << uns[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int D[1 << 20], cnt[20][20];   bool chk[1 << 20];   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ((void)0);     ((void)0);     ((void)0);     int N, M;     queue<int> Q;     string s;     cin >> N >> M >> s;     for (int i = 1; i < N; i++)       if (s[i - 1] != s[i]) {         cnt[s[i - 1] -  a ][s[i] -  a ]++;         cnt[s[i] -  a ][s[i - 1] -  a ]++;       }     memset(D, 0x7f, sizeof(D));     chk[0] = true;     D[0] = 0;     Q.push(0);     while (!Q.empty()) {       int b = Q.front(), bc = __builtin_popcount(b) + 1;       Q.pop();       for (int i = 0; i < M; i++)         if (~b & (1 << i)) {           int diff = 0;           for (int j = 0; j < M; j++) {             if (b & (1 << j))               diff += bc * cnt[i][j];             else               diff -= bc * cnt[i][j];           }           D[b | (1 << i)] = min(D[b | (1 << i)], D[b] + diff);           if (!chk[b | (1 << i)]) {             chk[b | (1 << i)] = true;             Q.push(b | (1 << i));           }         }     }     cout << D[(1 << M) - 1] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool compare(string &s1, string &s2) { return s1.size() < s2.size(); }   void solve() {     int n;     cin >> n;     vector<string> s(n);     for (int i = 0; i < n; i++) cin >> s[i];     sort(s.begin(), s.end(), compare);     for (int i = 0; i < n - 1; i++)       if (s[i + 1].find(s[i]) == -1) {         cout <<  NO n ;         return;       }     cout <<  YES n ;     for (int i = 0; i < n; i++) cout << s[i] << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int t = 1;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   long long f[500500], fact[500500];   int C[2222][2222], used[500500], can[500500], a[500500];   int n, t, u;   int main() {     scanf( %d , &n);     for (int i = 0; i <= n; i++)       for (int j = 0; j <= i; j++)         if ((j == 0) || (j == i))           C[i][j] = 1;         else {           C[i][j] = C[i - 1][j] + C[i - 1][j - 1];           if (C[i][j] >= 1000000007) C[i][j] -= 1000000007;         }     fact[0] = 1;     for (int i = 1; i <= n; i++) fact[i] = (fact[i - 1] * i) % 1000000007;     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     for (int i = 0; i < n; i++)       if (a[i] > 0) used[a[i]] = 1;     for (int i = 0; i < n; i++)       if (a[i] < 0) can[i] = (!used[i + 1]);     for (int i = 0; i < n; i++) t += can[i];     for (int i = 0; i < n; i++) u += (a[i] < 0);     for (int i = n; i >= 0; i--)       if (i > t)         f[i] = 0;       else if (i == t)         f[i] = fact[u - i];       else {         f[i] = (fact[u - i] * C[t][i]) % 1000000007;         for (int j = i + 1; j <= t; j++) {           int r = (f[j] * C[j][i]) % 1000000007;           f[i] -= r;           if (f[i] < 0) f[i] += 1000000007;         }       }     cout << f[0] << endl;   }
#include <bits/stdc++.h>   #include <iostream>   using namespace std;      #define db cout <<  debugging... n ;   #define db1(x) cout << #x <<   =   << x <<   n    #define db2(x, y) cout << #x <<   =   << x <<  ,   << #y <<   =   <<y <<   n    #define db3(x, y, z) cout << #x <<   =   << x <<  ,   << #y <<   =   << y <<  ,   << #z <<   =   << z <<   n    #define dbvec(a) cout << #a <<  :  ; for (auto x: a) cout << x <<    ; cout <<   n       #define int long long   #define pb push_back   #define all(x) x.begin(), x.end()   #define endl   n    #define fileio freopen( input.txt ,  r , stdin); freopen( output.txt ,  w , stdout)   #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)   const int MOD = 1000000007;      int32_t main() {       fastio;       // fileio;          int t;       cin >> t;          while (t--) {              int n;           cin >> n;              bool b = true;              for (int i = 0; i < n; ++i) {               int x;               cin >> x;                  // db3(t, n, x);                  int sqrtt = sqrt(x);               sqrtt *= sqrtt;                  if (sqrtt != x) {                   b = false;               }           }              if (b) {               cout <<  NO n ;           } else {               cout <<  YES n ;           }          }          return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int dx[] = {0, 0, -1, 1};   int dy[] = {1, -1, 0, 0};   char s[100002];   void Print(long long x) {     printf( %lld n , x);     exit(0);   }   bool ok(long long x1, long long y1, long long x2, long long y2, long long day) {     return (abs(x2 - x1) + abs(y2 - y1) <= day);   }   long long bs(long long addX, long long addY, int n, long long x1, long long y1,                long long x2, long long y2) {     long long i = 0, p = 1LL << 31;     while (p) {       if (i + p &&           !ok(x1 + addX * (i + p), y1 + addY * (i + p), x2, y2, (i + p) * n))         i += p;       p >>= 1;     }     return i;   }   int main() {     long long x1, y1, x2, y2;     int n;     scanf( %lld%lld%lld%lld%d n%s , &x1, &y1, &x2, &y2, &n, &s);     long long addX = 0, addY = 0;     for (int i = 0; i < n; ++i) {       int d;       if (s[i] ==  U )         d = 0;       else if (s[i] ==  D )         d = 1;       else if (s[i] ==  L )         d = 2;       else if (s[i] ==  R )         d = 3;       addX += dx[d];       addY += dy[d];       if (abs(x2 - x1 - addX) + abs(y2 - y1 - addY) <= (i + 1)) Print(i + 1);     }     long long cnt = bs(addX, addY, n, x1, y1, x2, y2);     if (cnt > 1) --cnt;     x1 += cnt * addX;     y1 += cnt * addY;     long long day = cnt * n;     for (int t = 0; t < 20; ++t) {       for (int i = 0; i < n; ++i) {         int d;         ++day;         if (s[i] ==  U )           d = 0;         else if (s[i] ==  D )           d = 1;         else if (s[i] ==  L )           d = 2;         else if (s[i] ==  R )           d = 3;         x1 += dx[d];         y1 += dy[d];         if (abs(x2 - x1) + abs(y2 - y1) <= day) Print(day);       }     }     printf( -1 n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int recur_depth = 0;   const long long sz = 14, isz = 2e6 + 10, mod = 1e9 + 7;   long long p[sz], win[sz][sz], scc[(1 << sz)], n;   long long fastPow(long long x, long long n, long long MOD) {     long long ret = 1;     while (n) {       if (n & 1) ret = (ret * x) % MOD;       x = (x * x) % MOD;       n >>= 1;     }     return ret % MOD;   }   inline long long inv(long long x) { return fastPow(x, mod - 2, mod); }   long long prob(long long from, long long to) {     long long ret = 1;     for (long long i = 0; i < n; ++i) {       for (long long j = 0; j < n; ++j) {         if ((from >> i & 1) && (to >> j & 1)) ret = (ret * win[i][j]) % mod;       }     }     return ret;   }   int main() {     std::ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     cin >> n;     for (long long i = 0; i < n; ++i) cin >> p[i];     for (long long i = 0; i < n; ++i)       for (long long j = 0; j < n; ++j)         win[i][j] = (p[i] * inv(p[i] + p[j])) % mod;     long long ans = 0, lim = (1 << n) - 1;     for (int mask = 0; mask <= lim; mask++) {       scc[mask] = 1;       for (int i = mask; i > 0; i = (i - 1) & mask) {         if (i == mask) continue;         scc[mask] -= (scc[i] * prob(i, mask ^ i)) % mod;         if (scc[mask] < 0) scc[mask] += mod;       }       long long win_prob = (scc[mask] * __builtin_popcount(mask)) % mod;       win_prob = (win_prob * prob(mask, lim ^ mask)) % mod;       ans += win_prob;       if (ans >= mod) ans -= mod;     }     cout << ans <<   n ;     return 0;   }
#include <algorithm>   #include <array>   #include <bitset>   #include <cctype>   #include <chrono>   #include <cmath>   #include <ctime>   #include <deque>   #include <fstream>   #include <functional>   #include <iomanip>   #include <iostream>   #include <iso646.h>   #include <iterator>   #include <list>   #include <map>   #include <memory>   #include <numeric>   /*                           mnciitbhu                        */   //   //  |    /| |    |    --  |  |  -------  |⎻⎻   |   |  |    |   //  |   / | |    |   /    |  |     |     |   |  |   |  |    |   //  |   /  | |    |  (     |  |     |     |--<   |---|  |    |   //  |      | |    |       |  |     |     |   |  |   |     /   //  |      | |     |    --  |  |     |     |__/   |   |    --   //   #include <queue>   #include <ratio>   #include <regex>   #include <set>   #include <sstream>   #include <stack>   #include <string>   #include <type_traits>   #include <unordered_map>   #include <unordered_set>   #include <utility>   #include <valarray>   #include <vector>   using namespace std;   using namespace std::chrono;   using ll = long long;   using ull = unsigned long long;   using ld = long double;   #if not defined(ONLINE_JUDGE) && not defined(_MSVC_LANG) && defined(DEBUG_)   #include  myconfig.hpp    #else   #define LOL(x) ;   #define LOLX(...) ;   #endif   #if not defined(DEBUG_)   #endif      int main()    {    ios::sync_with_stdio(false);    cin.tie(0);       string s;    cin >> s;    if(s.length() == 1)    {     cout << s;     return 0;    }    for(int i = 0; i < s.size() - 1; ++i)    {     if(i < s.size() - 2 and s[i] == s[i + 1] and s[i] == s[i + 2])     {      if(s[i] ==  z )       s[i + 1] =  a ;      else       s[i + 1] =  z ;     }     else if(s[i] == s[i + 1])     {      if(i != 0)       {       if(s[i - 1] !=  d  and s[i + 1] !=  d )        s[i] =  d ;       else if(s[i - 1] !=  e  and s[i + 1] !=  e )        s[i] =  e ;       else        s[i] =  f ;      }      else      {       if(s[i + 1] ==  d )        s[i] =  e ;       else        s[i] =  d ;      }     }    }    cout << s;       return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<pair<int, int>> v;     for (int i = 0; i < n; i++) {       int l, r;       cin >> r >> l;       v.push_back(make_pair(l, r));     }     sort(v.begin(), v.end());     reverse(v.begin(), v.end());     int len = v.size();     long long k = 1, sum = 0, i = 0;     while (k--) {       sum += v[i].second;       k += v[i].first;       i++;       if (i == len) break;     }     cout << sum << endl;     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:16000000 )   using namespace std;   long long mod = 998244353;   long double inf = 1e9;   long double eps = 1e-8;   long double pi = acos(-1);   ifstream in( input.txt );   ofstream out( output.txt );   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, k;     cin >> n >> k;     string s;     cin >> s;     if (k == 0) {       cout << s;     } else {       if (s.size() == 1) {         cout << 0;         return 0;       }       if (s[0] !=  1 ) {         s[0] =  1 ;         k--;       }       for (int i = 1; i < n; i++) {         if (k == 0) break;         if (s[i] !=  0 ) {           s[i] =  0 ;           k--;         }       }       cout << s;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 101010;   int a[N];   int b[N];   int c[N];   int n;   long long ans;   void init() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %1d , a + i);       c[i] = a[i];     }     for (int i = 1; i <= n; i++) {       scanf( %1d , b + i);     }     for (int i = 1; i < n; i++) {       int delta = c[i] - b[i];       c[i] -= delta;       c[i + 1] -= delta;       ans += abs(delta);     }   }   void check(int now, int add) {     if (ans == 0) return;     if (0 <= a[now + 1] + add && a[now + 1] + add <= 9) {       printf( %d %d n , now, add);       a[now] += add;       a[now + 1] += add;       ans--;       return;     }     check(now + 1, -add);     if (ans == 0) return;     printf( %d %d n , now, add);     a[now] += add;     a[now + 1] += add;     ans--;   }   void work() {     printf( %lld n , ans);     if (ans > 100000) ans = 100000;     for (int i = 1; i < n && ans > 0; i++)       while (a[i] != b[i] && ans) check(i, (b[i] > a[i]) ? 1 : -1);   }   int main() {     init();     if (c[n] == b[n])       work();     else       printf( -1 );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 300010;   class cmp {    public:     bool operator()(const pair<long long int, long long int> &a,                     const pair<long long int, long long int> &b) {       if (a.first == b.first) return a.second > b.second;       return a.first < b.first;     }   };   long long int a[N], b[N], fact[N];   long long int mod = 998244353;   void cal() {     fact[1] = 1;     for (long long int i = 2; i < N; i++) {       fact[i] = ((fact[i - 1] % mod) * (i % mod)) % mod;     }   }   bool sort1(const pair<long long int, long long int> &x,              const pair<long long int, long long int> &y) {     if (x.first == y.first) return x.second < y.second;     return x.first < y.first;   }   void solve() {     long long int n;     cin >> n;     cal();     memset(a, 0, sizeof(a));     memset(b, 0, sizeof(b));     long long int i, x, y, f = 0;     vector<pair<long long int, long long int>> v;     for (i = 0; i < n; i++) {       cin >> x >> y;       a[x]++;       b[y]++;       v.push_back({x, y});       if (a[x] == n || b[y] == n) f = 1;     }     if (f) {       cout <<  0  << endl;       return;     }     long long int ans = fact[n];     long long int ans1 = 1;     for (i = 1; i < N; i++) {       if (a[i]) {         long long int cnt = fact[a[i]];         ans1 = ((ans1 % mod) * (cnt % mod)) % mod;       }     }     ans = (ans - ans1 + mod) % mod;     long long int ans2 = 1;     for (i = 1; i < N; i++) {       if (b[i]) {         long long int cnt = fact[b[i]];         ans2 = ((ans2 % mod) * (cnt % mod)) % mod;       }     }     ans = (ans - ans2 + mod) % mod;     sort(v.begin(), v.end(), sort1);     long long int k = 0;     for (i = 0; i < n - 1; i++) {       if (v[i].second > v[i + 1].second) {         k = 1;         break;       }     }     if (k == 0) {       ans1 = 1;       for (i = 0; i < n;) {         long long int j = i;         long long int cnt = 0;         while (j < n && v[i].first == v[j].first && v[i].second == v[j].second) {           j++;           cnt++;         }         i = j;         cnt = fact[cnt];         ans1 = ((ans1 % mod) * (cnt % mod)) % mod;       }       ans = (ans + ans1) % mod;     }     cout << ans << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     int t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[100009], c[100009], b[100009], d[100009];   long long ksm(long long a, long long n, long long d) {     long long ans;     ans = 1;     while (n > 0) {       if (n % 2 == 1) ans = (ans * a) % d;       a = a * a % d;       n = n / 2;     }     return ans % d;   }   long long ksm2(long long a, long long n) {     long long ans;     ans = 1;     while (n > 0) {       if (n % 2 == 1) {         if (a > 1e5) return 0;         ans = ans * a;       }       if (ans > 1e5) return 0;       if (a > 1e5) return 0;       a = a * a;       n = n / 2;     }     return ans;   }   int main() {     int n, k;     cin >> n >> k;     for (int i = 1; i <= n; i++) {       cin >> a[i];       c[i] = 1;       b[i] = 1;       int gg = a[i];       for (int j = 2; j <= sqrt(gg); j++)         if (a[i] % j == 0) {           int g = 0;           while (a[i] % j == 0) {             g++;             a[i] /= j;           }           g = g % k;           b[i] *= ksm(j, g, 1e18 + 9);           c[i] *= ksm2(j, (k - g) % k);         }       if (a[i] != 1) {         b[i] *= a[i];         c[i] *= ksm2(a[i], k - 1);       }       d[b[i]]++;     }     long long ans = 0;     for (int i = 1; i <= n; i++) {       if (c[i] != 0) {         ans += d[c[i]];         if (c[i] == b[i]) ans--;       }     }     ans /= 2;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1000010;   long long s1[N], s2[N];   int p, q, n, b[N], d[N];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %I64d , &s1[i]), s1[i] += s1[i - 1];     for (int i = 1; i <= n; i++) scanf( %I64d , &s2[i]), s2[i] += s2[i - 1];     for (int i = 0; i <= n; i++) {       while (s1[i] > s2[p] && p <= n) p++;       if (s1[i] <= s2[p] && b[s2[p] - s1[i]]) {         q = b[s2[p] - s1[i]] - 1;         printf( %d n , i - q);         for (int j = q + 1; j <= i; j++) printf( %d  , j);         q = d[s2[p] - s1[i]];         putchar(  n );         printf( %d n , p - q);         for (int j = q + 1; j <= p; j++) printf( %d  , j);         return 0;       } else         b[s2[p] - s1[i]] = i + 1, d[s2[p] - s1[i]] = p;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 10;   const int len = 700, MAX = 1e7 + 10;   int n, m, k, a[maxn];   int f[MAX], g[MAX];   long long ans[maxn];   struct query {     int l, r, id;   } q[maxn];   bool operator<(const query &a, const query &b) {     if ((a.l - 1) / len != (b.l - 1) / len) return a.l < b.l;     return a.r < b.r;   }   void enter() {     cin >> n >> m >> k;     for (int i = 1; i <= n; ++i) cin >> a[i];     for (int i = 1; i <= m; ++i) {       cin >> q[i].l >> q[i].r;       q[i].id = i;     }     sort(q + 1, q + m + 1);   }   int lim(int i) { return ((i - 1) / len + 1) * len; }   void solve() {     long long ret = 0;     int rgt = 0, it, cur = 0;     g[0] = 1;     for (int i = 1; i <= m; ++i) {       if (rgt < lim(q[i].l)) {         rgt = lim(q[i].l);         it = rgt + 1;         memset(f, 0, sizeof(f));         f[0] = 1;         cur = 0;         ret = 0;       }       if (q[i].r <= rgt) {         long long tmp = 0;         for (int j = q[i].l, v = 0; j <= q[i].r; ++j) {           v ^= a[j];           tmp += g[v ^ k];           ++g[v];         }         ans[q[i].id] = tmp;         for (int j = q[i].l, v = 0; j <= q[i].r; ++j) {           v ^= a[j];           --g[v];         }         continue;       }       while (it <= q[i].r) {         cur ^= a[it++];         ret += f[cur ^ k];         ++f[cur];       }       long long save = ret;       --f[0];       for (int j = rgt, v = 0; j >= q[i].l; --j) {         v ^= a[j];         ret += f[v ^ k];         ret += g[v ^ k];         ++g[v];       }       ++f[0];       ans[q[i].id] = ret;       for (int j = rgt, v = 0; j >= q[i].l; --j) {         v ^= a[j];         --g[v];       }       ret = save;     }   }   int main() {     ios_base ::sync_with_stdio(0);     enter();     solve();     for (int i = 1; i <= m; ++i) printf( %I64d n , ans[i]);   }
#include <bits/stdc++.h>   using namespace std;   bool G[30][30];   int main() {     int T;     scanf( %d , &T);     while (T--) {       int n, p;       scanf( %d%d , &n, &p);       memset(G, 0, sizeof(G));       for (int i = 0; i < n; ++i)         G[i][(i + 1) % n] = G[(i + 1) % n][i] = G[i][(i + 2) % n] =             G[(i + 2) % n][i] = 1;       for (int step = 3; p; ++step) {         for (int i = 0; p && i < n; ++i) {           G[i][(i + step) % n] = G[(i + step) % n][i] = 1;           --p;         }       }       for (int i = 0; i < n; ++i)         for (int j = i + 1; j < n; ++j)           if (G[i][j]) printf( %d %d n , i + 1, j + 1);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7, lg = 20, N = 1e5 + 5;   int ans[N];   bool vis[N];   vector<pair<int, int> > g[N];   struct node {     node *ch[11];     node *sp[lg];     int val, lvl, last;     node() {       memset(ch, 0, sizeof ch);       memset(sp, 0, sizeof sp);       val = lvl = last = 0;     }   };   struct cmp {     bool operator()(const pair<node *, int> a, const pair<node *, int> b) const {       if (b.first->lvl != a.first->lvl) return a.first->lvl < b.first->lvl;       node *u = (node *)b.first;       node *v = (node *)a.first;       for (int i = lg - 1; i >= 0; i--) {         if (u->sp[i] != v->sp[i]) {           u = u->sp[i];           v = v->sp[i];         }       }       if (v->last != u->last) return v->last < u->last;       return a.second < b.second;     }   };   vector<int> digits[N];   void build() {     for (int i = 1; i < N; i++) {       int j = i;       while (j) digits[i].push_back(j % 10), j /= 10;       reverse(digits[i].begin(), digits[i].end());     }   }   void build(node *a) {     for (int i = 1; i < lg; i++) {       a->sp[i] = a->sp[i - 1]->sp[i - 1];     }   }   void dij() {     node *root = new node();     root->sp[0] = root;     build(root);     set<pair<node *, int>, cmp> st;     st.insert({root, 1});     while (st.size()) {       node *cur = (*st.begin()).first;       int temp = (*st.begin()).second;       st.erase(st.begin());       if (vis[temp] == 0) {         vis[temp] = 1;         ans[temp] = cur->val;       } else         continue;       for (int i = 0; i < g[temp].size(); i++) {         int v = g[temp][i].first;         int cost = g[temp][i].second;         node *temp = cur;         for (auto dig : digits[cost]) {           if (!temp->ch[dig]) {             temp->ch[dig] = new node();             temp->ch[dig]->lvl = temp->lvl + 1;             temp->ch[dig]->val = ((temp->val * 1ll * 10) % mod + dig) % mod;             temp->ch[dig]->sp[0] = temp;             temp->ch[dig]->last = dig;             build(temp->ch[dig]);           }           temp = temp->ch[dig];         }         st.insert({temp, v});       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     build();     int n, m;     cin >> n >> m;     for (int i = 1; i <= m; i++) {       int u, v;       cin >> u >> v;       g[u].push_back({v, i});       g[v].push_back({u, i});     }     dij();     for (int i = 2; i <= n; i++) cout << ans[i] <<   n ;     return 0;   }