malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int ROW[] = {+0, +0, -1, +1};   int COL[] = {+1, -1, +0, +0};   int X[] = {+0, +0, +1, -1, -1, +1, -1, +1};   int Y[] = {-1, +1, +0, +0, +1, +1, -1, -1};   int KX[] = {-2, -2, -1, -1, 1, 1, 2, 2};   int KY[] = {-1, 1, -2, 2, -2, 2, -1, 1};   long long calc(long long num, long long val, long long cnt1, long long cnt2) {     while (cnt1 >= cnt2) {       num /= val;       cnt1--;     }     return num;   }   int main() {     int t;     scanf( %d , &t);     while (t--) {       long long p, q, n, m;       scanf( %lld %lld , &p, &q);       n = p;       m = q;       if (p % q) {         printf( %lld n , p);         continue;       }       map<long long, long long> mp, mpp;       for (long long i = 2; i * i <= q; i++) {         if (q % i) continue;         while (q % i == 0) {           mp[i]++;           q /= i;         }       }       if (q > 1) mp[q]++;       long long ans = 1LL;       for (auto it : mp) {         while (p % it.first == 0) {           p /= it.first;           mpp[it.first]++;         }         ans = max(ans, calc(n, it.first, mpp[it.first], it.second));       }       printf( %lld n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string s;   int poz, sol;   int main() {     sol = INT_MAX;     cin >> s;     int n = s.size();     for (int c = 1; c <= 26; c++) {       char ch = c +  a  - 1;       poz = -1;       int maxx = 0;       for (int i = 0; i < n; i++) {         if (s[i] == ch) {           if (i - poz > maxx) maxx = i - poz;           poz = i;         }       }       if (n - poz > maxx) maxx = n - poz;       if (sol > maxx) sol = maxx;     }     cout << sol;     return 0;   }
#include <bits/stdc++.h>   int main() {     int n, m;     int sum = 0;     int a, b;     int i = 0;     int x[1010] = {0}, y[1010] = {0};     scanf( %d %d , &n, &m);     while (m-- > 0) {       scanf( %d %d , &a, &b);       y[a] = 1;       x[b] = 1;     }     for (i = 2; i <= n - 1; i++) {       if (x[i] == 0) sum++;       if (y[i] == 0) sum++;     }     if (n % 2 == 1 && x[n / 2 + 1] == 0 && y[n / 2 + 1] == 0) sum--;     printf( %d n , sum);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long n, w;     cin >> n >> w;     vector<long long> arr(n);     for (long long i = 0; i < n; ++i) cin >> arr[i];     vector<long long> runsum(n);     long long min_elem = arr[0];     long long max_elem = arr[0];     vector<long long> run(n);     long long cur = 0;     long long tillnow = -1e9;     for (long long i = 0; i < n; ++i) {       cur = max(arr[i], cur + arr[i]);       tillnow = max(tillnow, cur);     }     if (tillnow > w) {       cout << 0 << endl;       return 0;     }     max_elem = tillnow;     cur = 0;     tillnow = 1e9;     for (long long i = 0; i < n; ++i) {       cur = min(arr[i], cur + arr[i]);       tillnow = min(tillnow, cur);     }     if (tillnow < -w) {       cout << 0 << endl;       return 0;     }     min_elem = tillnow;     long long answer = w - max(abs(max_elem), abs(min_elem)) + 1;     cout << answer << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void ASS(bool bb) {     if (!bb) {       ++*(int*)0;     }   }   #pragma comment(linker,  /STACK:106777216 )   int main() {     int a, b, m;     cin >> a >> b >> m;     for (int i = 0; i < (int)(min(a + 1, m)); i++) {       int x = i * (long long)1000000000 % m;       x = (m - x) % m;       if (x > b) {         printf( 1 %09d n , i);         return 0;       }     }     cout << 2 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int start, ed = 0, sz = 130000000;   long long marked[(130000000 / 64) + 5];   vector<int> primes;   inline bool check(int pos) { return !(marked[pos / 64] & (1LL << (pos % 64))); }   int pos;   bool isPrime(int n) {     if (n != 2 and n % 2 == 0) return false;     int sq = sqrt(n);     for (int i = 3; i <= sq; i += 2) {       if (n % i == 0) return false;     }     return true;   }   void genPrimes(int n) {     int sq = sqrt(n);     for (int i = 2; i <= sq; i++) {       if (isPrime(i)) primes.push_back(i);     }   }   void segSieve(int L, int R) {     if (L <= 1 and R >= 1)       pos = 1 - start, marked[pos / 64] |= (1LL << (pos % 64));     int sq = sqrt(R), st;     for (int i = 0; primes[i] <= sq and i < primes.size(); i++) {       if (L <= primes[i])         st = primes[i] + primes[i];       else         st = ((L + primes[i] - 1) / primes[i]) * primes[i];       for (int j = st; j <= R; j += primes[i]) {         pos = j - start, marked[pos / 64] |= (1LL << (pos % 64));       }     }   }   unsigned int ans = 0, a, b, c, d;   inline unsigned int F(unsigned int x) { return x * (x * (a * x + b) + c) + d; }   void call(int n) {     int sum = 0;     long long cur;     for (int i = 2; i <= n; i++) {       if (i > ed) {         memset(marked, 0, sizeof(marked));         start = ed + 1;         ed = start + sz - 1;         segSieve(start, min(ed, 300000000));       }       if (!check(i - start)) continue;       cur = i, sum = 0;       while (cur <= n) {         sum += (n / cur);         cur *= i;       }       ans += sum * F(i);     }   }   int main() {     int n;     cin >> n >> a >> b >> c >> d;     genPrimes(n);     call(n);     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct node {     int l, r;     int num;   } Treex[4000009], Treey[4000009];   map<int, int> vis;   int i;   int tot = 1;   int Tot = 1;   int x, y;   char str[5];   void update_y(int ll, int rr, int c, int l, int r, int t) {     if (ll <= l && r <= rr)       Treey[t].num = max(Treey[t].num, c);     else {       if (ll <= ((l + r) >> 1)) {         if (!Treey[t].l) Treey[t].l = ++tot;         update_y(ll, rr, c, l, ((l + r) >> 1), Treey[t].l);       }       if (rr > ((l + r) >> 1)) {         if (!Treey[t].r) Treey[t].r = ++tot;         update_y(ll, rr, c, ((l + r) >> 1) + 1, r, Treey[t].r);       }     }   }   void update_x(int ll, int rr, int c, int l, int r, int t) {     if (ll <= l && r <= rr)       Treex[t].num = max(Treex[t].num, c);     else {       if (ll <= ((l + r) >> 1)) {         if (!Treex[t].l) Treex[t].l = ++Tot;         update_x(ll, rr, c, l, ((l + r) >> 1), Treex[t].l);       }       if (rr > ((l + r) >> 1)) {         if (!Treex[t].r) Treex[t].r = ++Tot;         update_x(ll, rr, c, ((l + r) >> 1) + 1, r, Treex[t].r);       }     }   }   void query_x(int c, int l, int r, int rt) {     i = max(i, Treex[rt].num);     if (l == r) return;     if (((l + r) >> 1) >= c)       query_x(c, l, ((l + r) >> 1), Treex[rt].l);     else       query_x(c, ((l + r) >> 1) + 1, r, Treex[rt].r);   }   void query_y(int c, int l, int r, int rt) {     i = max(i, Treey[rt].num);     if (l == r) return;     if (((l + r) >> 1) >= c)       query_y(c, l, ((l + r) >> 1), Treey[rt].l);     else       query_y(c, ((l + r) >> 1) + 1, r, Treey[rt].r);   }   int main() {     int n, q;     scanf( %d%d , &n, &q);     update_x(0, n, 0, 0, n, 1);     update_y(0, n, 0, 0, n, 1);     while (q--) {       scanf( %d%d%s , &x, &y, str);       if (vis[x]) {         puts( 0 );       } else {         vis[x] = 1;         i = 0;         if (str[0] ==  U ) {           query_x(x, 0, n, 1);           printf( %d n , y - i);           update_y(i, y, x, 0, n, 1);         } else {           query_y(y, 0, n, 1);           printf( %d n , x - i);           update_x(i, x, y, 0, n, 1);         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long PINF = 1E9;   const long long NINF = -1E9;   const long long M = 1E9 + 7;   const double EPS = 1E-9;   const double PI = 2 * acos(0);   void print_arr(const vector<long long> &a) {     for (int i = 0; i < (int)a.size(); i++) cout << a[i] <<    ;     cout <<   n ;   }   int m;   vector<long long> weights, ans;   bool visited[1001][11][11];   void dfs(int step, int balance, int prev_weight) {     if (visited[step][balance][prev_weight]) return;     visited[step][balance][prev_weight] = true;     if (step == m) {       cout <<  YES             <<   n ;       print_arr(ans);       exit(0);     }     for (int i = 0; i < (int)weights.size(); i++) {       int w = weights[i];       if (prev_weight != w && abs(balance) < w) {         ans[step] = w;         if (step % 2 == 0)           dfs(step + 1, balance + w, w);         else           dfs(step + 1, balance - w, w);       }       ans[step] = 0;     }     visited[step][balance][prev_weight] = false;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     string s;     cin >> s;     for (int i = 0; i < 10; i++) {       if (s[i] ==  1 ) weights.push_back(i + 1);     }     cin >> m;     ans.resize(m);     dfs(0, 0, 0);     cout <<  NO           <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T bigmod(T p, T e, T M) {     long long ret = 1;     for (; e > 0; e >>= 1) {       if (e & 1) ret = (ret * p) % M;       p = (p * p) % M;     }     return (T)ret;   }   template <class T>   inline T gcd(T a, T b) {     if (b == 0) return a;     return gcd(b, a % b);   }   template <class T>   inline T modinverse(T a, T M) {     return bigmod(a, M - 2, M);   }   template <class T>   inline T lcm(T a, T b) {     a = abs(a);     b = abs(b);     return (a / gcd(a, b)) * b;   }   template <class T, class X>   inline bool getbit(T a, X i) {     T t = 1;     return ((a & (t << i)) > 0);   }   template <class T, class X>   inline T setbit(T a, X i) {     T t = 1;     return (a | (t << i));   }   template <class T, class X>   inline T resetbit(T a, X i) {     T t = 1;     return (a & (~(t << i)));   }   inline long long power(long long a, long long b) {     long long multiply = 1;     for (int i = (0); i < (b); i++) {       multiply *= a;     }     return multiply;   }   vector<int> v[102];   int main() {     int n, m, x;     int first = 0, second = 0;     cin >> n;     for (int i = (0); i < (n); i++) {       cin >> m;       for (int j = (0); j < (m); j++) {         cin >> x;         v[i].push_back(x);       }     }     vector<int> rest;     for (int i = (0); i < (n); i++) {       if (v[i].size() % 2 == 0) {         for (int j = (0); j < (v[i].size() / 2); j++) first += v[i][j];         for (int j = (v[i].size() / 2); j < (v[i].size()); j++) second += v[i][j];       } else {         for (int j = (0); j < (v[i].size() / 2); j++) first += v[i][j];         for (int j = (v[i].size() / 2 + 1); j < (v[i].size()); j++)           second += v[i][j];       }     }     for (int j = (0); j < (n); j++) {       if (v[j].size() % 2 == 0) continue;       rest.push_back(v[j][v[j].size() / 2]);     }     sort(rest.begin(), rest.end(), greater<int>());     for (int j = (0); j < (rest.size()); j++) {       if (j % 2 == 0)         first += rest[j];       else         second += rest[j];     }     cout << first <<     << second << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct edge {     int t, nxt;   } e[600010];   int n, cnt, be[300010], mn_mx[300010], f, vid[300010], tot;   void add(const int& x, const int& y) {     e[++cnt].t = y, e[cnt].nxt = be[x], be[x] = cnt;   }   void dfs(const int& x) {     if (!be[x]) return (void)(++tot, vid[x] = 1);     if (mn_mx[x]) {       vid[x] = 1e9;       for (int i = be[x]; i; i = e[i].nxt)         dfs(e[i].t), vid[x] = min(vid[x], vid[e[i].t]);     } else       for (int i = be[x]; i; i = e[i].nxt) dfs(e[i].t), vid[x] += vid[e[i].t];   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d , &mn_mx[i]);     for (int i = 2; i <= n; ++i) scanf( %d , &f), add(f, i);     dfs(1), printf( %d , tot - vid[1] + 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int mod = 1000000007;   long long int MAX = 1e18;   void solve() {     long long int n;     scanf( %lld , &n);     long long int a[n];     vector<pair<long long int, long long int> > v(n), ans;     for (long long int i = 0; i < n; i++) {       long long int num;       scanf( %lld , &num);       a[i] = num;       v[i] = {num - 1, i};     }     sort(begin(v), end(v));     for (long long int i = n / 2, j = n / 2 - 1; i < n; i++, j--) {       if (v[i].second > i) {         ans.push_back({v[i].second + 1, 1});         ans.push_back({1, i + 1});         ans.push_back({v[i].second + 1, 1});         v[a[i] - 1].second = v[i].second;         swap(a[i], a[v[i].second]);       } else if (v[i].second < i) {         ans.push_back({v[i].second + 1, n});         ans.push_back({n, 1});         ans.push_back({1, i + 1});         ans.push_back({n, 1});         ans.push_back({v[i].second + 1, n});         v[a[i] - 1].second = v[i].second;         swap(a[i], a[v[i].second]);       }       if (v[j].second < j) {         ans.push_back({v[j].second + 1, n});         ans.push_back({j + 1, n});         ans.push_back({n, v[j].second + 1});         v[a[j] - 1].second = v[j].second;         swap(a[j], a[v[j].second]);       } else if (v[j].second > j) {         ans.push_back({v[j].second + 1, 1});         ans.push_back({1, n});         ans.push_back({j + 1, n});         ans.push_back({n, 1});         ans.push_back({v[j].second + 1, 1});         v[a[j] - 1].second = v[j].second;         swap(a[j], a[v[j].second]);       }     }     cout << ans.size() << endl;     for (long long int i = 0; i < ans.size(); i++)       printf( %lld %lld n , ans[i].first, ans[i].second);   }   int main() {     long long int t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, c = 0;     cin >> n;     long long int d;     cin >> d;     long long int s[n + 5];     for (long long int i = 0; i < n; i++) {       cin >> s[i];     }     sort(s, s + n);     for (long long int i = 0; i < n - 1; i++) {       for (long long int j = i + 1; j < n; j++) {         if (s[j] - s[i] <= d) {           c++;         }       }     }     cout << c * 2 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long power(long long x, long long y, long long p);   inline int D() {     int t;     scanf( %d , &t);     return t;   }   inline long long llD() {     long long t;     scanf( %lld , &t);     return t;   }   const int N = 1e6 + 5;   long long arr[N], cost[N];   int main() {     long long n = llD(), k = llD(), l = 1, r = 0, mid = -1;     for (int i = 0; i < n; ++i) r += pow(2, i);     while (mid != k) {       mid = (l + r) / 2;       if (mid > k)         r = mid - 1, --n;       else if (mid < k)         l = mid + 1, --n;     }     printf( %lld , n);   }   long long power(long long x, long long y, long long p) {     long long res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }
#include <bits/stdc++.h>   using namespace std;   const int M = 1e6 + 20;   struct Edge {     int to, w, next;   } edge[M];   int head[M], cnt, fa[M];   inline void add(int u, int v, int w) {     edge[++cnt].to = v, edge[cnt].w = w, edge[cnt].next = head[u], head[u] = cnt;   }   long long mxp[M];   int val[M];   long long dfs1(int now) {     mxp[now] = val[now];     for (int i = head[now]; i; i = edge[i].next) {       if (edge[i].to == fa[now]) continue;       fa[edge[i].to] = now,       mxp[now] = max(mxp[now], val[now] - edge[i].w + dfs1(edge[i].to));     }     return mxp[now];   }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d , &val[i]);     for (int i = 1; i <= n - 1; ++i) {       int u, v, w;       scanf( %d%d%d , &u, &v, &w), add(u, v, w), add(v, u, w);     }     dfs1(1);     long long ans = 0;     for (int i = 1; i <= n; ++i) {       long long mx1 = 0, mx2 = 0;       for (int j = head[i]; j; j = edge[j].next) {         if (edge[j].to == fa[i]) continue;         long long c = mxp[edge[j].to] - edge[j].w;         if (c > mx1)           mx2 = mx1, mx1 = c;         else if (c > mx2)           mx2 = c;       }       ans = max(ans, val[i] + mx1 + mx2);     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int main() {     int n;     scanf( %d , &n);     vector<vector<pair<int, int>>> a(n);     for (int i = 0; i < n - 1; i++) {       int u, v;       scanf( %d %d , &u, &v);       --u, --v;       a[u].emplace_back(v, i);       a[v].emplace_back(u, i);     }     vector<int> lev(n, 1), pr(n);     function<void(int, int)> dfs = [&](int u, int p) {       pr[u] = p;       for (auto [v, id] : a[u]) {         if (v != p) {           lev[v] = 1 + lev[u];           dfs(v, u);         }       }     };     dfs(0, -1);     vector<vector<int>> sp(n, vector<int>(22, -1));     for (int i = 0; i < 22; i++) {       for (int j = 0; j < n; j++) {         if (i == 0) {           sp[j][i] = pr[j];         } else if (sp[j][i - 1] != -1) {           sp[j][i] = sp[sp[j][i - 1]][i - 1];         }       }     }     function<int(int, int)> lca = [&](int u, int v) {       if (lev[u] < lev[v]) {         swap(u, v);       }       int lg = 0;       while ((1 << lg) <= lev[u]) {         ++lg;       }       --lg;       for (int i = lg; i >= 0; i--) {         if (lev[u] >= lev[v] + (1 << i)) {           u = sp[u][i];         }       }       if (u == v) {         return u;       }       for (int i = lg; i >= 0; i--) {         if (sp[u][i] != sp[v][i]) {           u = sp[u][i];           v = sp[v][i];         }       }       return (u == v) ? u : pr[u];     };     int k;     scanf( %d , &k);     vector<int> val(n);     for (int i = 0; i < k; i++) {       int u, v;       scanf( %d %d , &u, &v);       --u, --v;       int g = lca(u, v);       ++val[u], ++val[v];       val[g] -= 2;     }     vector<int> ans(n - 1);     function<void(int, int)> dfs2 = [&](int u, int p) {       for (auto [v, id] : a[u]) {         if (v != p) {           dfs2(v, u);           val[u] += val[v];           ans[id] = val[v];         }       }     };     dfs2(0, -1);     for (int v : ans) {       printf( %d  , v);     }     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 200010;   const int MODD = 1000000007;   struct Stop {     int s, t;     bool operator<(const Stop &ss) const { return t < ss.t; }   } bus[MAXN];   int n, m, nn, dp[MAXN], sum[MAXN];   int main() {     while (scanf( %d%d , &n, &m) != EOF) {       map<int, int> stops;       stops[0] = stops[n] = 0;       for (int i = 0; i < m; ++i) {         scanf( %d%d , &bus[i].s, &bus[i].t);         stops[bus[i].s] = stops[bus[i].t] = 0;       }       nn = 0;       for (map<int, int>::iterator it = stops.begin(); it != stops.end(); ++it)         it->second = ++nn;       sort(bus, bus + m);       int bi = 0;       dp[1] = sum[1] = 1;       for (int i = 2; i <= nn; ++i) {         dp[i] = 0;         for (; bi < m && stops[bus[bi].t] == i; ++bi) {           int ms = stops[bus[bi].s];           int mt = stops[bus[bi].t];           dp[i] = ((long long)dp[i] + sum[mt - 1] - sum[ms - 1] + MODD) % MODD;         }         sum[i] = ((long long)sum[i - 1] + dp[i]) % MODD;       }       printf( %d n , dp[nn]);     }     return 0;   }
#include <bits/stdc++.h>   const int N = 1e6;   const long long mod = 998244353;   const int INF = 0x7fffffff;   const int inf = 0x3f3f3f3f;   using namespace std;   void exgcd(long long a, long long b, long long &x, long long &y) {     if (b == 0) {       x = 1;       y = 0;       return;     }     exgcd(b, a % b, y, x);     y -= a / b * x;   }   long long getlnverse(long long x, long long y) {     long long res, tmp;     exgcd(x, y, res, tmp);     return (res + y) % y;   }   long long a[N + 5];   long long cal(long long n, long long m) {     long long tmp1 = getlnverse(a[m], mod);     tmp1 = a[n] * tmp1 % mod;     long long tmp2 = getlnverse(a[n - m], mod);     return tmp1 * tmp2 % mod;   }   long long qpow(long long a, long long b) {     long long sum = 1;     while (b) {       if (b & 1) {         sum = (sum * a) % mod;         b--;       }       b /= 2;       a = a * a % mod;     }     return sum;   }   int main() {     std::ios::sync_with_stdio(false);     long long n, ans2 = 0;     cin >> n;     a[0] = 1;     for (int i = 1; i <= n; i++) {       a[i] = i * a[i - 1] % mod;     }     for (long long i = 1; i <= n; i++) {       ans2 +=           (((cal(n, i) * qpow(-1, i)) % mod) *            (qpow((qpow(3, n - i) - 1), n) + mod - qpow(3, n * (n - i))) % mod) %           mod;       ans2 = ans2 % mod;     }     long long ans1 =         (2 * (qpow(3, n * n) - qpow((mod + qpow(3, n) - 3) % mod, n) + mod)) %         mod;     cout << (3 * mod + ans1 - (3 * ans2)) % mod << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, top, tot, cnt;   int fir[202020], nxt[202020 << 1], to[202020 << 1];   int dfn[202020], fa[202020], st[202020];   struct evol {     int v, nm;   } l1[202020], l2[202020];   void add(int x, int y) {     nxt[++cnt] = fir[x];     fir[x] = cnt;     to[cnt] = y;   }   void dfs(int x) {     dfn[x] = ++tot;     l1[x] = l2[x] = (evol){tot, x};     for (int i = fir[x]; i; i = nxt[i])       if (to[i] != fa[x]) {         if (!dfn[to[i]]) {           fa[to[i]] = x;           dfs(to[i]);           if (l1[to[i]].v < l1[x].v) {             if (l2[to[i]].v < l1[x].v)               l1[x] = l1[to[i]], l2[x] = l2[to[i]];             else               l2[x] = l1[x], l1[x] = l1[to[i]];           } else if (l1[to[i]].v < l2[x].v)             l2[x] = l1[to[i]];         } else if (dfn[to[i]] < l1[x].v)           l2[x] = l1[x], l1[x] = (evol){dfn[to[i]], x};         else if (dfn[to[i]] < l2[x].v)           l2[x] = (evol){dfn[to[i]], x};       }     if (l2[x].v < dfn[x]) {       puts( YES );       int ed = l2[x].v;       top = 0;       for (int i = x;; i = fa[i]) {         st[++top] = i;         if (dfn[i] == ed) {           ed = i;           break;         }       }       printf( %d  , top);       for (int i = 1; i <= top; i++) printf( %d  , st[i]);       puts(  );       st[top = 1] = ed;       for (int i = l2[x].nm; st[top] != x; i = fa[i]) st[++top] = i;       printf( %d  , top);       while (top) printf( %d  , st[top--]);       puts(  );       dfn[0] = tot + 1;       for (int i = ed; dfn[st[top]] > l1[x].v; i = fa[i]) st[++top] = i;       for (int i = l1[x].nm; st[top] != x; i = fa[i]) st[++top] = i;       printf( %d  , top);       while (top) printf( %d  , st[top--]);       puts(  );       exit(0);     }   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       int x, y;       scanf( %d%d , &x, &y);       add(x, y);       add(y, x);     }     for (int i = 1; i <= n; i++)       if (!dfn[i]) dfs(i);     puts( NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 10;   int k, q;   long long f[10], dp[maxn];   void update(long long v, long long w) {     for (int i = 1000000; i >= w; i--) dp[i] = max(dp[i], dp[i - w] + v);     return;   }   void solve(long long v, long long w) {     int num = min((long long)k, 1000000 / w);     for (int i = 0; (1 << i) <= num; i++) {       int c = (1 << i);       update(v * c, w * c);       num -= c;     }     if (num) update(v * num, w * num);     return;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     cin >> k;     k = 3 * (k - 1);     for (int i = 0; i <= 5; i++) cin >> f[i];     for (int i = 0; i <= 1000000; i++) {       int cur = 0, x = i;       while (x) {         int low = x % 10;         if (low % 3 == 0) {           dp[i] += f[cur] * (low / 3);         }         x /= 10;         ++cur;       }     }     int sz = 1;     for (int i = 0; i <= 5; i++) {       solve(f[i], sz * 3);       sz *= 10;     }     cin >> q;     while (q--) {       int n;       cin >> n;       cout << dp[n] <<   n ;     }     return 0;   }