malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   int n, a[N] = {}, tot = 0;   bool v[N] = {};   void dfs(int s) {     v[s] = true;     if (!v[s * 2 % n]) dfs(s * 2 % n);     if (!v[s * 2 % n + 1]) dfs(s * 2 % n + 1);     a[++tot] = s;   }   int main() {     cin >> n;     if (n % 2)       puts( -1 );     else {       dfs(0);       for (int i = tot; i >= 0; --i) printf( %d%c , a[i],    n [i == 0]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   void chkmin(T &x, T y) {     if (y < x) x = y;   }   template <class T>   void chkmax(T &x, T y) {     if (y > x) x = y;   }   const int N = 105;   int a[N], n, x, ans1, ans2[N][N], len;   int main() {     scanf( %d , &n);     for (int i = 1; i <= (n); i++) scanf( %d , a + i);     for (int i = 1; i <= (n - (n & 1)); i++) {       for (int j = 1; j <= (n); j++)         if (a[j] == i) {           x = j;           break;         }       ans1++;       len = 0;       for (int j = 1; j <= (i - 1); j++) ans2[ans1][++len] = 1;       ans2[ans1][++len] = x - i + 1;       reverse(a + i, a + x + 1);       if (x < n) {         ans2[ans1][++len] = n - x;         reverse(a + x + 1, a + n + 1);       }       if (i % 2 == 0) reverse(ans2[ans1] + 1, ans2[ans1] + len + 1);       if (len == 1) ans1--;       ans2[ans1][0] = len;     }     printf( %d n , ans1);     for (int i = 1; i <= (ans1); i++) {       printf( %d  , ans2[i][0]);       for (int j = 1; j <= (ans2[i][0]); j++) printf( %d  , ans2[i][j]);       putchar(  n );     }   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3fffffff;   const int maxn = 100000 + 5, maxh = 800;   int n, k;   int f[maxh], g[maxh];   vector<int> P[maxn];   int main() {     scanf( %d%d , &n, &k);     for (int i = 1, iend = k; i <= iend; ++i) {       int x, y;       scanf( %d%d , &x, &y);       P[y].push_back(n - x + 1);     }     for (int i = 1, iend = n; i <= iend; ++i) sort(P[i].begin(), P[i].end());     int hgt = sqrt(6 * k) + 5;     memset(f, 0x3f, sizeof f);     f[0] = 0;     for (int i = 1, iend = n; i <= iend; ++i) {       memcpy(g, f, sizeof f);       memset(f, 0x3f, sizeof f);       int minf = 0, pt = 0;       for (int j = 0, jend = hgt; j <= jend; ++j) {         if (pt < P[i].size() && P[i][pt] == j) pt++;         if (g[j] < g[minf]) minf = j;         f[j] = min(g[j + 1], g[minf] + (j ? j * (j + 1) / 2 + 2 : 0)) +                (P[i].size() - pt) * 3;       }     }     int ans = inf;     for (int i = 0, iend = hgt; i <= iend; ++i) ans = min(ans, f[i]);     printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a[27];   bool h[27];   bool valid[1005][1005];   long long dp[1005];   int main() {     for (int i = 0; i < 1005; i++) {       for (int j = 0; j < 1005; j++) valid[i][j] = false;     }     for (int i = 0; i < 26; i++) h[i] = false;     int n, lsub = 1;     cin >> n;     string s;     cin >> s;     for (int i = 0; i < 26; i++) cin >> a[i];     for (int i = 0; i < n; i++) {       int f = 0;       for (int j = i; j < n; j++) {         h[s[j] -  a ] = true;         for (int k = 0; k < 26; k++)           if (h[k] && a[k] < j - i + 1) {             f = 1;             break;           }         if (f == 1) break;         valid[i][j] = true;         lsub = max(lsub, j - i + 1);       }       for (int k = 0; k < 26; k++) h[k] = false;     }     dp[0] = 1;     dp[-1] = 1;     for (int i = 1; i < n; i++) {       dp[i] = dp[i - 1];       for (int j = 0; j < i; j++) {         if (valid[j][i]) dp[i] = (dp[i] + dp[j - 1]) % 1000000007;       }     }     int i = 0, j = 0, k = 0;     while (i < n) {       if (!valid[j][i]) {         j = i;         k++;       }       i++;     }     cout << dp[n - 1] <<   n ;     cout << lsub <<   n ;     cout << k + 1 <<   n ;   }
#include <bits/stdc++.h>   int dp[2][1005];   int main() {     char start[2 * 1005], end[1005];     int i, j, k, K;     while (scanf( %s %s %d , start, end, &K) != EOF) {       memset(dp, 0, sizeof(dp));       int n = strlen(start);       for (i = n; i < 2 * n; i++) start[i] = start[i - n];       dp[0][0] = 1;       int cur = 1;       long long sum[2];       sum[0] = 1, sum[1] = 0;       for (k = 0; k < K; k++) {         sum[cur] = 0;         for (i = 0; i < n; i++) {           dp[cur][i] = (sum[cur ^ 1] - dp[cur ^ 1][i] + 1000000007);           if (dp[cur][i] >= 1000000007) dp[cur][i] -= 1000000007;           sum[cur] = (sum[cur] + dp[cur][i]);           if (sum[cur] >= 1000000007) sum[cur] -= 1000000007;         }         cur ^= 1;       }       int ans = 0;       for (i = 0; i < n; i++)         if (strncmp(start + i, end, n) == 0)           ans += dp[cur ^ 1][i], ans %= 1000000007;       printf( %d n , ans);     }   }
#include <bits/stdc++.h>   using namespace std;   char ans[1010][1010];   int len[1010];   void upd(int n, int c) { ans[n][len[n]++] = c; }   char all[1 << 21];   int main() {     int n, k, l;     scanf( %d%d%d , &n, &l, &k);     scanf( %s , all);     sort(all, all + strlen(all));     int cur = 0;     int beg = 1;     while (beg < k) {       int beg_ = beg;       while (beg <= k) {         upd(beg, all[cur]);         beg++;         cur++;       }       beg = beg_;       for (int i = k; i >= beg_; i--)         if (ans[i][len[i] - 1] != ans[k][len[k] - 1]) {           beg = i + 1;           break;         }       if (len[k] == l) break;     }     while (len[k] < l) upd(k, all[cur++]);     for (int i = 1; i <= n; i++) {       while (len[i] < l) upd(i, all[cur++]);     }     for (int i = 1; i <= n; i++) puts(ans[i]);   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int n, m, chk[100100], a[100100], b[100100];   vector<int> v[100100];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     for (int i = 1; i <= m; i++) {       int a, b;       cin >> a >> b;       v[a].push_back(b), v[b].push_back(a);     }     for (int i = 1; i <= n; i++)       if (v[i].size() != n - 1) {         chk[i] = 1;         for (int x : v[i]) chk[x] = 1;         int j = 1, c = 0;         while (chk[j]) j++;         for (int k = 1; k <= n; k++)           if (k != i && k != j) a[k] = b[k] = ++c;         a[i] = b[i] = b[j] = ++c;         a[j] = ++c;         cout <<  YES n ;         for (int i = 1; i <= n; i++) cout << a[i] <<    ;         cout <<   n ;         for (int i = 1; i <= n; i++) cout << b[i] <<    ;         cout <<   n ;         return 0;       }     cout <<  NO ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string org;     cin >> org;     int n;     cin >> n;     map<string, int> mp;     for (int i = 0; i < n; i++) {       string s, t;       cin >> s >> t;       string name;       string trash;       if (t[0] ==  p  || t[0] ==  c ) {         string trash;         cin >> trash;         cin >> name >> trash;         name.pop_back();         name.pop_back();         if (t[0] ==  p ) {           if (s == org)             mp[name] += 15;           else if (name == org)             mp[s] += 15;         } else {           if (s == org)             mp[name] += 10;           else if (name == org)             mp[s] += 10;         }       } else {         cin >> name >> trash;         name.pop_back();         name.pop_back();         if (s == org)           mp[name] += 5;         else if (name == org)           mp[s] += 5;       }       mp[s];       mp[name];     }     vector<pair<string, int>> v;     for (auto x : mp) {       if (x.first == org) continue;       v.emplace_back(x.first, x.second);     }     sort(v.begin(), v.end(), [](pair<string, int> p1, pair<string, int> p2) {       if (p1.second != p2.second) return p1.second > p2.second;       return p1.first < p2.first;     });     for (auto x : v) {       cout << x.first <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, mid;     bool flag;     string str;     char ans[3000];     cin >> n;     cin >> str;     if (n % 2 == 0) {       mid = (n / 2) - 1;       flag = true;     } else {       mid = (n - 1) / 2;       flag = false;     }     long long k = 1, cnt = 0;     ans[mid] = str[0];     for (long long i = 1; i < str.size(); i++) {       cnt++;       if (flag) {         ans[mid + k] = str[i];       } else {         ans[mid - k] = str[i];       }       if (cnt == 2) {         k++;         cnt = 0;       }       flag = !flag;     }     for (long long i = 0; i < n; i++) {       cout << ans[i];     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   int N, dp[5000][5001], cumlcp[5000][5000];   vector<int> sa, ra, rsa, lcp;   string s;   void saInit() {     int l = (int)s.size();     sa.resize(l);     iota(sa.begin(), sa.end(), 0);     ra.assign(s.begin(), s.end());     for (int k = 1; k < l; k *= 2) {       sort(sa.begin(), sa.end(), [&](int a, int b) {         if (ra[a] != ra[b]) return ra[a] < ra[b];         int ak = a + k < l ? ra[a + k] : -1;         int bk = b + k < l ? ra[b + k] : -1;         return ak < bk;       });       vector<int> ra2(l);       int x = 0;       for (int i = 1; i < l; i++) {         if (ra[sa[i]] != ra[sa[i - 1]] || sa[i - 1] + k >= l ||             ra[sa[i] + k] != ra[sa[i - 1] + k])           x++;         ra2[sa[i]] = x;       }       ra = ra2;     }     rsa.resize(l);     for (int i = 0; i < int(l); i++) rsa[sa[i]] = i;   }   void saLCP() {     int l = (int)s.size();     lcp.resize(l);     vector<int> p(l);     for (int i = 0; i < l; i++) {       p[sa[i]] = (i) ? sa[i - 1] : -1;     }     int x = 0;     for (int i = 0; i < l; i++) {       while (p[i] != -1 && p[i] + x < l && s[i + x] == s[p[i] + x] &&              s[i + x] !=  $ )         x++;       lcp[rsa[i]] = x;       if (x) x--;     }     for (int i = 0; i < int(l); i++) {       cumlcp[i][i] = INT_MAX;       for (int j = i + 1; j < int(l); j++)         cumlcp[i][j] = min(cumlcp[i][j - 1], lcp[j]);     }   }   bool ism(int a, int b, int n) {     int as = a - n + 1, bs = b - n + 1;     if (as < 0) return false;     if (rsa[bs] <= rsa[as]) return false;     return cumlcp[rsa[as]][rsa[bs]] < n;   }   int main() {     cin >> N >> s;     saInit();     saLCP();     for (int i = 0; i < int(N); i++)       for (int j = 1; j < int(5001); j++) {         int& ans = dp[i][j];         ans = dp[i][j - 1];         if (j > i + 1) {           continue;         } else if (s[i - j + 1] ==  0 ) {         } else if (j == i + 1) {           ans = (ans + 1) % MOD;         } else if (ism(i - j, i, j)) {           ans = (ans + dp[i - j][j]) % MOD;         } else {           ans = (ans + dp[i - j][j - 1]) % MOD;         }       }     cout << dp[N - 1][N] << endl;   }
#include <bits/stdc++.h>   using namespace std;   char str[2010][2010];   void go(int x, int y) {     int l, r, u, d;     d = (int)(str[x + 1][y] ==  . );     u = (int)(str[x - 1][y] ==  . );     r = (int)(str[x][y + 1] ==  . );     l = (int)(str[x][y - 1] ==  . );     if (!d && !u && !r && !l) {       cout <<  Not unique  << endl;       exit(0);     }     if (l && !r && !u && !d) {       str[x][y - 1] =  < ;       str[x][y] =  > ;       if (str[x][y - 2] ==  . ) go(x, y - 2);       if (str[x - 1][y - 1] ==  . ) go(x - 1, y - 1);       if (str[x + 1][y - 1] ==  . ) go(x + 1, y - 1);     }     if (r && !l && !u && !d) {       str[x][y] =  < ;       str[x][y + 1] =  > ;       if (str[x][y + 2] ==  . ) go(x, y + 2);       if (str[x - 1][y + 1] ==  . ) go(x - 1, y + 1);       if (str[x + 1][y + 1] ==  . ) go(x + 1, y + 1);     }     if (u && !l && !r && !d) {       str[x - 1][y] =  ^ ;       str[x][y] =  v ;       if (str[x - 2][y] ==  . ) go(x - 2, y);       if (str[x - 1][y + 1] ==  . ) go(x - 1, y + 1);       if (str[x - 1][y - 1] ==  . ) go(x - 1, y - 1);     }     if (d && !l && !r && !u) {       str[x][y] =  ^ ;       str[x + 1][y] =  v ;       if (str[x + 2][y] ==  . ) go(x + 2, y);       if (str[x + 1][y - 1] ==  . ) go(x + 1, y - 1);       if (str[x + 1][y + 1] ==  . ) go(x + 1, y + 1);     }     return;   }   int main() {     int n, m, i, j;     for (i = 0; i < 2010; i++)       for (j = 0; j < 2010; j++) str[i][j] =  * ;     scanf( %d%d , &n, &m);     getchar();     for (i = 1; i <= n; i++) {       gets(str[i] + 1);       str[i][m + 1] =  * ;     }     for (i = 1; i <= n; i++) {       for (j = 1; j <= m; j++) {         if (str[i][j] ==  . ) go(i, j);       }     }     for (i = 1; i <= n; i++) {       for (j = 1; j <= m; j++) {         if (str[i][j] ==  . ) {           cout <<  Not unique  << endl;           return 0;         }       }     }     for (i = 1; i <= n; i++) {       str[i][m + 1] = 0;       printf( %s n , str[i] + 1);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 8e5 + 5;   struct trie {     int a[26];     vector<int> val[2];   } a[N];   int vis[N][2];   char ch[800005];   int cnt, n;   void insert(char ch[], int op, int k) {     int u = 0;     int len = strlen(ch + 1);     a[u].val[op].push_back(k);     for (int i = 1; i <= len; i++) {       if (!a[u].a[ch[i] -  a ]) a[u].a[ch[i] -  a ] = ++cnt;       u = a[u].a[ch[i] -  a ];       a[u].val[op].push_back(k);     }   }   int dfs(int k, int dep) {     int ans = 0;     for (int i = 0; i < 26; i++)       if (a[k].a[i]) ans += dfs(a[k].a[i], dep + 1);     vector<int> t[2];     for (int i = 0; i <= 1; i++)       for (int j = 0; j < a[k].val[i].size(); j++)         if (!vis[a[k].val[i][j]][i]) t[i].push_back(a[k].val[i][j]);     int tmp = min(t[0].size(), t[1].size());     ans += tmp * dep;     for (int i = 0; i < tmp; i++) {       vis[t[0][i]][0] = t[1][i];       vis[t[1][i]][1] = t[0][i];     }     return ans;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %s , ch + 1);       insert(ch, 0, i);     }     for (int i = 1; i <= n; i++) {       scanf( %s , ch + 1);       insert(ch, 1, i);     }     printf( %d n , dfs(0, 0));     for (int i = 1; i <= n; i++) printf( %d %d n , i, vis[i][0]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long maxn = 1e6 + 50;   const long long inf = 0x3f3f3f3f3f3f3f3f;   const long long mod = 1e9 + 7;   const long double eps = 1e-20;   const long long HASH = 131;   using namespace std;   long long a[maxn];   signed main() {     std::ios::sync_with_stdio(false);     long long t;     cin >> t;     while (t--) {       long long a, b;       cin >> a >> b;       if ((a & 1)) {         long long tmp = b % 4;         if (tmp == 1) {           cout << a + b << endl;         } else if (tmp == 2) {           cout << a - 1 << endl;         } else if (tmp == 3) {           cout << a - 1 - b << endl;         } else           cout << a << endl;       } else {         long long tmp = b % 4;         if (tmp == 1) {           cout << a - b << endl;         } else if (tmp == 2) {           cout << a + 1 << endl;         } else if (tmp == 3) {           cout << a + 1 + b << endl;         } else           cout << a << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   using ii = pair<long long, long long>;   using ll = long long;   using ull = unsigned long long;   using ld = long double;   using vec = vector<long long>;   using vecc = vector<vector<long long> >;   namespace royyaha {   template <typename T>   void pr(const T& x) {     cout << x;   }   template <typename T1, typename T2>   void pr(const pair<T1, T2>& x) {     cout << x.first <<     << x.second;   }   template <typename T, typename... Args>   void pr(const T& x, const Args&... rest) {     pr(x);     pr(rest...);   }   template <typename T>   void ou(const T& x) {     pr(x);     cout << endl;   }   template <typename T, typename... Args>   void ou(const T& x, const Args&... rest) {     pr(x,    );     ou(rest...);   }   template <typename T>   void ou(const vector<T>& v, long long n = 0) {     n = (n ? n : v.size());     for (auto it = v.begin(); it != v.begin() + n; ++it) {       if (it + 1 == v.end())         ou(*it);       else         pr(*it,    );     }   }   }  // namespace royyaha   using namespace royyaha;   bool intersection(ii a, ii b) {     return !(a.first > b.second || a.second < b.first);   }   const long long maxn = 2e5 + 50;   vec depth(maxn);   vec son(maxn);   vec e[maxn];   void dfs(long long u, long long pre) {     depth[u] = depth[pre] + 1;     son[u] = 1;     for (auto v : e[u])       if (v != pre) {         dfs(v, u);         son[u] += son[v];       }   }   signed main() {     long long n, k;     cin >> n >> k;     for (long long i = 0; i < n - 1; ++i) {       long long u, v;       cin >> u >> v;       u--, v--;       e[u].push_back(v);       e[v].push_back(u);     }     dfs(0, 0);     vec f(n);     for (long long i = 0; i < n; ++i) f[i] = depth[i] - son[i];     sort(f.begin(), f.end());     reverse(f.begin(), f.end());     cout << accumulate(f.begin(), f.begin() + k, 0ll) << endl;   }
#include <bits/stdc++.h>   using namespace std;   void AWAD() {     std::ios::sync_with_stdio(false);     cin.tie(0);   }   bool cmp(long long int a, long long int b) {     if (a > b) return true;     return false;   }   int a[1000001], b[1000001];   int main() {     AWAD();     string input;     long long int c4 = 0, c7 = 0;     cin >> input;     for (int i = 0; i < input.size(); i++)       if (input[i] ==  4 )         ++c4;       else if (input[i] ==  7 )         ++c7;     if (!c4 && !c7)       cout <<  -1 n ;     else if (c4 >= c7)       cout << 4 << endl;     else       cout << 7 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char c;   int mo = 1000003;   int main() {     int pre = 0;     while (scanf( %c , &c) != EOF) {       if (c < 32 || c > 126) break;       int w = c;       int tmp = 0;       for (int j = 0; j < 8; j++) {         tmp = tmp * 2 + w % 2;         w /= 2;       }       w = tmp;       tmp = pre - tmp;       pre = w;       if (tmp < 0) tmp += 256;       printf( %d n , tmp);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mo = 10007;   char S[205];   int n, m, M, f[205][205][205], ans;   struct O {     long long a[330][330];     void clear() { memset(a, 0, sizeof a); }   } A, B, C;   O operator*(const O &A, const O &B) {     for (int i = 0; i <= M; ++i)       for (int j = i; j <= M; ++j) {         C.a[i][j] = 0;         for (int k = 0; k <= M; ++k) C.a[i][j] += A.a[i][k] * B.a[k][j];         C.a[i][j] %= mo;       }     return C;   }   void fly(int l, int r) {     if (f[l][r][m + 3]) return;     if (l > r) {       f[l][r][0] = 1;       return;     }     if (S[l] == S[r]) {       fly(l + 1, r - 1);       for (int i = 0; i <= m; ++i) f[l][r][i] = f[l + 1][r - 1][i];     } else {       fly(l, r - 1);       fly(l + 1, r);       for (int i = 1; i <= m; ++i)         f[l][r][i] = (f[l][r - 1][i - 1] + f[l + 1][r][i - 1]) % mo;     }     f[l][r][m + 3] = 1;   }   void ply(int l, int r) {     if (f[l][r][m + 3]) return;     if (l > r) {       f[l][r][0] = 1;       return;     }     if (S[l] == S[r]) {       if (l == r) return;       ply(l + 1, r - 1);       for (int i = 0; i <= m; ++i) f[l][r][i] = f[l + 1][r - 1][i];     } else {       ply(l, r - 1);       ply(l + 1, r);       for (int i = 1; i <= m; ++i)         f[l][r][i] = (f[l][r - 1][i - 1] + f[l + 1][r][i - 1]) % mo;     }     f[l][r][m + 3] = 1;   }   int main() {     scanf( %s%d , S + 1, &n);     m = strlen(S + 1);     fly(1, m);     for (int i = 1; i < m; ++i) A.a[i][i] = 24;     for (int i = 1; i < m - 1; ++i) A.a[i][i + 1] = 1;     for (int i = 1; i < m; ++i)       A.a[i][m + (m + 1) / 2 - (m - i + 1) / 2] = f[1][m][i];     A.a[0][m] = f[1][m][0];     if (m > 1) A.a[0][1] = 1;     for (int i = m; i <= m + (m + 1) / 2 - 1; ++i)       A.a[i][i] = 25, A.a[i][i + 1] = 1;     M = m + (m + 1) / 2;     A.a[M][M] = 26;     for (int i = 0; i <= M; ++i) B.a[i][i] = 1;     for (int e = (n + m + 1) / 2 + 1; e; e >>= 1) {       if (e & 1) B = B * A;       A = A * A;     }     ans = B.a[0][M];     if ((m + n) & 1) {       memset(f, 0, sizeof f);       ply(1, m);       A.clear();       for (int i = 1; i < m; ++i) A.a[i][i] = 24;       for (int i = 1; i < m - 1; ++i) A.a[i][i + 1] = 1;       for (int i = 1; i < m; ++i)         A.a[i][m + (m + 1) / 2 - (m - i + 1) / 2] = f[1][m][i];       A.a[0][m] = f[1][m][0];       if (m > 1) A.a[0][1] = 1;       for (int i = m; i <= m + (m + 1) / 2 - 1; ++i)         A.a[i][i] = 25, A.a[i][i + 1] = 1;       M = m + (m + 1) / 2;       B.clear();       for (int i = 0; i <= M; ++i) B.a[i][i] = 1;       for (int e = (n + m + 1) / 2 + 1; e; e >>= 1) {         if (e & 1) B = B * A;         A = A * A;       }       ans -= B.a[0][M];     }     printf( %d n , (ans % mo + mo) % mo);     return 0;   }
#include <bits/stdc++.h>   int A, B, M = 6, N;   int main() {     scanf( %d%d%d , &N, &A, &B);     int nda = N / A;     for (int i = 1; (i <= 2) && (B * i <= N); ++i)       M = std::min((i ^ 3) + (4 - ((N - B * i) / A) * (i ^ 3) + nda - 1) / nda,                    M);     printf( %d n , M);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1000009;   const int SGZ = 26;   const int M = 10009;   int n, m, nxt[N][SGZ], crt[N][SGZ], q[M], ans[M];   vector<int> val;   char s[N], qy[SGZ];   inline int read() {     char c = getchar();     int ret = 0, f = 1;     while (c <  0  || c >  9 ) {       f = c ==  -  ? -1 : 1;       c = getchar();     }     while ( 0  <= c && c <=  9 ) {       ret = ret * 10 + c -  0 ;       c = getchar();     }     return ret * f;   }   inline int index(int x) {     for (int l = 0, r = val.size() - 1, mid; l <= r;) {       mid = l + r >> 1;       if (val[mid] == x) {         return mid;       } else if (val[mid] < x) {         l = mid + 1;       } else {         r = mid - 1;       }     }     return -1;   }   int main() {     scanf( %s , s);     n = strlen(s);     m = read();     for (int i = 1; i <= m; i++) {       scanf( %s , qy);       int len = strlen(qy);       for (int j = 0; j < len; j++) {         q[i] |= 1 << qy[j] -  a ;       }       val.push_back(q[i]);     }     sort(val.begin(), val.end());     val.resize(unique(val.begin(), val.end()) - val.begin());     int last_position[SGZ];     fill(last_position, last_position + SGZ, n);     for (int i = n - 1; ~i; i--) {       last_position[s[i] -  a ] = i;       for (int j = 0; j < SGZ; j++) {         nxt[i][j] = last_position[j];       }     }     memset(crt, -1, sizeof(crt));     for (int i = 0; i < n; i++) {       for (int j = 0, p = i, sta = 0; j < 26 && p < n; j++) {         int np = n, c = -1;         for (int k = 0; k < 26; k++) {           if ((sta >> k & 1) == 0) {             if (np > nxt[p][k]) {               c = k;               np = nxt[p][k];             }           }         }         if (~c) {           sta |= 1 << c;           p = np;           crt[i][j] = sta;           if (!i || crt[i - 1][j] != sta) {             int idx = index(sta);             if (~idx) {               ans[idx]++;             }           }         }       }     }     for (int i = 1; i <= m; i++) {       printf( %d n , ans[index(q[i])]);     }     return 0;   }
#include <bits/stdc++.h>   int main() {     long n;     long m;     std::cin >> n >> m;     long a = 0, b = 0, c = 0, d = 0;     while (!(n % 2)) {       n = n / 2;       a++;     }     while (!(n % 3)) {       n = n / 3;       b++;     }     while (!(m % 2)) {       m = m / 2;       c++;     }     while (!(m % 3)) {       m = m / 3;       d++;     }     if ((n != m) || (a > c) || (b > d)) {       std::cout << -1;     } else {       std::cout << (c + d) - (a + b);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, k, x, s = 0;     cin >> n >> k;     map<long long, long long> m;     queue<long long> q;     for (long long i = 0; 0 < n ? i < n : i > n; 0 < n ? i += 1 : i -= 1) {       cin >> x;       q.push(x);       m[x] = 0;     }     while (1) {       x = q.front();       q.pop();       if (!m.count(x + 1)) {         q.push(x + 1);         m[x + 1] = m[x] + 1;       }       if (m.size() >= n + k) break;       if (!m.count(x - 1)) {         q.push(x - 1);         m[x - 1] = m[x] + 1;       }       if (m.size() >= n + k) break;     }     for (auto i : m) s += i.second;     cout << s <<   n ;     for (auto i : m)       if (i.second != 0) cout << i.first <<    ;   }