malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   bool can(bool print, int t, long long S, const vector<pair<int, int> >& bugs,            const vector<pair<int, pair<int, int> > >& st) {     priority_queue<pair<int, int>, vector<pair<int, int> >,                    greater<pair<int, int> > >         pq;     int ind = bugs.size() - 1;     int stind = st.size() - 1;     vector<int> ans(bugs.size());     long long cost = 0;     while (ind >= 0) {       while (stind >= 0 and st[stind].first >= bugs[ind].first) {         pq.push(pair<int, int>(st[stind].second.first, st[stind].second.second));         --stind;       }       if (pq.empty()) return false;       long long c = pq.top().first;       int indans = pq.top().second;       pq.pop();       cost += c;       if (cost > S) return false;       for (int i = 0; ind >= 0 and i < t; ++i) {         ans[bugs[ind].second] = indans;         --ind;       }     }     if (print) {       for (int i = 0; i < int(bugs.size()); ++i) cout << (i ?     :   ) << ans[i];       cout << endl;     }     return true;   }   int main() {     int n, m, s;     cin >> n >> m >> s;     vector<pair<int, int> > bugs(m);     for (int i = 0; i < m; ++i) {       cin >> bugs[i].first;       bugs[i].second = i;     }     vector<pair<int, pair<int, int> > > st(n);     for (int i = 0; i < n; ++i) cin >> st[i].first;     for (int i = 0; i < n; ++i) {       cin >> st[i].second.first;       st[i].second.second = i + 1;     }     sort(bugs.begin(), bugs.end());     sort(st.begin(), st.end());     int low = 1, hi = m + 1;     while (low < hi) {       int mid = (low + hi) / 2;       if (can(false, mid, s, bugs, st))         hi = mid;       else         low = mid + 1;     }     if (low == m + 1)       cout <<  NO  << endl;     else {       cout <<  YES  << endl;       can(true, low, s, bugs, st);     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e6 + 10;   int n, m, q, pos[MAX], bit[MAX], res[MAX], XOR[MAX];   pair<int, int> cache[MAX], a[MAX], b[MAX];   struct Node {     int lef, rig, tt;     bool operator<(const Node& other) const { return this->lef < other.lef; }   };   Node query[MAX];   void up(int i) {     int val = a[i].first;     while (i <= n) {       bit[i] ^= val;       i += i & (-i);     }   }   int get(int i) {     int res = 0;     while (i) {       res ^= bit[i];       i -= i & (-i);     }     return res;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %d , &cache[i].first);       a[i].first = cache[i].first;       cache[i].second = i;     }     sort(cache + 1, cache + 1 + n);     for (int i = 1; i <= n; ++i) {       if (i == 1 || cache[i].first > cache[i - 1].first) ++m;       a[cache[i].second].second = m;     }     for (int i = 1; i <= n; ++i) {       b[i] = pair<int, int>(pos[a[i].second], i);       pos[a[i].second] = i;       XOR[i] = XOR[i - 1] ^ a[i].first;     }     sort(b + 1, b + 1 + n);     scanf( %d , &q);     for (int i = 1; i <= q; ++i) {       scanf( %d %d , &query[i], &query[i].rig);       query[i].tt = i;     }     sort(query + 1, query + 1 + q);     int j = 1;     for (int i = 1; i <= q; ++i) {       while (j <= n && b[j].first < query[i].lef) up(b[j++].second);       res[query[i].tt] = XOR[query[i].rig] ^ XOR[query[i].lef - 1];       res[query[i].tt] ^= get(query[i].rig) ^ get(query[i].lef - 1);     }     for (int i = 1; i <= q; ++i) printf( %d n , res[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a = 0, l[101], r[101], k;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> l[i] >> r[i];     }     cin >> k;     for (int i = 0; i < n; i++) {       if (k <= r[i]) {         a++;       }     }     cout << a;   }
#include <bits/stdc++.h>   using namespace std;   int main(void) {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<int> ans1, ans2;       string a, b;       cin >> a >> b;       a = a +  0 ;       b = b +  0 ;       for (int i = 0; i < n; i++) {         if (a[i] != a[i + 1]) ans1.push_back(i);       }       for (int i = 0; i < n; i++) {         if (b[i] != b[i + 1]) ans2.push_back(i);       }       cout << ans1.size() + ans2.size() <<    ;       for (int i = 0; i < ans1.size(); i++) cout << ans1[i] + 1 <<    ;       for (int i = ans2.size() - 1; i >= 0; i--) cout << ans2[i] + 1 <<    ;       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long p, x, a, b, ni, ans;   void e_gcd(long long a, long long b, long long &x, long long &y) {     if (b == 0) {       x = 1;       y = 0;       return;     }     e_gcd(b, a % b, x, y);     int tmp = x;     x = y;     y = tmp - (a / b) * y;     return;   }   int main() {     cin >> a >> b >> p >> x;     long long i, j, s;     e_gcd(a, p, ni, s);     a = 1;     for (j = 1; j <= p - 1; j++) {       a = a * ni % p;       i = (j - b * a % p + p) % p;       long long n = i * (p - 1) + j;       if (n <= x) ans += (x - n) / (p * (p - 1)) + 1;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     int *a = new int[n];     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     int m;     scanf( %d , &m);     int bred[10000];     for (int i = 0; i < 10000; i++) bred[i] = 0;     for (int i = 0; i < m; i++) {       int b;       scanf( %d , &b);       for (int j = 0; j < n; j++) {         if (b % a[j] != 0) continue;         bred[b / a[j]]++;       }     }     for (int i = 9999; i >= 0; i--) {       if (bred[i] != 0) {         printf( %d , bred[i]);         break;       }     }     return 0;   }
#include <bits/stdc++.h>   inline int rd(int f = 1, int x = 0, char ch =    ) {     while (!isdigit(ch = getchar()))       if (ch ==  - ) f = -1;     while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar();     return f * x;   }   const int N = 1e5 + 5;   int n, a[N], ans;   int main() {     for (int T = rd(); T--;) {       n = rd(), ans = 0;       for (int i = 1; i <= n; ++i) a[i] = rd();       for (int i = 2; i <= n; ++i) ans |= a[i - 1] <= a[i];       puts(ans ?  YES  :  NO );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, k, q, a[200005], f[200005];   int main() {     cin >> n >> k >> q;     for (int i = 1; i <= n; i++) {       long long l, r;       cin >> l >> r;       a[l]++;       a[r + 1]--;     }     for (int i = 1; i <= 200000; i++) a[i] += a[i - 1];     for (int i = 1; i <= 200000; i++) {       f[i] += f[i - 1];       if (a[i] >= k) {         f[i]++;       }     }     for (int i = 1; i <= q; i++) {       long long l, r;       cin >> l >> r;       cout << f[r] - f[l - 1] << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   constexpr int INF = 2e9;   int main() {     int t;     t = 1;     while (t--) {       int n;       string s;       cin >> n;       cin >> s;       int res = 0;       for (int d = 25; d >= 0; d--) {         string tmp =   ;         for (int i = 0; i < s.size(); i++) {           int now = s[i] -  a ;           if (now != d) {             tmp += s[i];           } else {             if (tmp.back() -  a  == d - 1) {               res++;             } else {               tmp += s[i];             }           }         }         swap(s, tmp);         tmp =   ;         for (int i = s.size() - 1; i >= 0; i--) {           int now = s[i] -  a ;           if (now != d) {             tmp += s[i];           } else {             if (tmp.back() -  a  == d - 1) {               res++;             } else {               tmp += s[i];             }           }         }         reverse(tmp.begin(), tmp.end());         swap(s, tmp);       }       cout << res << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MAX1 = 3e5 + 10;   long long a, b, c, d, e, cnt, x, y, z, l, r, flag, num[MAX1], mod = 1e10 + 7;   string s;   char p[MAX1];   long long sta(long long n) {     for (int i = 1; i < 1000000; ++i) {       if (i * (i - 1) / 2 == n) return i;     }     return 0;   }   int main() {     cin >> a >> b >> c >> d;     x = sta(a);     y = sta(d);     if (a == 0) {       if (b == 0 && c == 0 && x && y) {         for (int i = 0; i < y; ++i) cout << 1;         return 0;       } else         x = 1;     }     if (d == 0) {       if (b == 0 && c == 0 && x && y) {         for (int i = 0; i < x; ++i) cout << 0;         return 0;       } else         y = 1;     }     if (x == 0 || y == 0) {       cout <<  Impossible ;       return 0;     }     if (x * y != b + c) {       cout <<  Impossible ;       return 0;     }     cnt = b / y;     b -= cnt * y;     x -= cnt;     for (long long i = 0; i < cnt; ++i) cout << 0;     for (long long i = 0; i < y - b; ++i) cout << 1;     y -= y - b;     if (x && b) cout << 0, --x;     for (long long i = 0; i < y; ++i) cout << 1;     for (long long i = 0; i < x; ++i) cout << 0;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long bigpow(long long x, long long n) {     if (n == 0) return 1;     long long temp = bigpow(x, n / 2);     return n % 2 == 0 ? (temp * temp) % 1000000009                       : (x * ((temp * temp) % 1000000009)) % 1000000009;   }   int main() {     long long n, m, k, x, t, p, q, gaps, groups;     cin >> n >> m >> k;     gaps = n - m;     groups = m % (k - 1) == 0 ? m / (k - 1) : m / (k - 1) + 1;     if (gaps >= groups - 1)       cout << m << endl;     else {       x = n - gaps * k;       t = 2 * (bigpow(2, x / k) - 1) * k + x % k;       t += gaps * (k - 1);       cout << t % 1000000009 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long x = 0, f = 1;     char s = getchar();     while (s <  0  || s >  9 ) {       if (s ==  - ) f *= -1;       s = getchar();     }     while (s >=  0  && s <=  9 ) {       x = (x << 1) + (x << 3) + s -  0 ;       s = getchar();     }     return x * f;   }   int n = read(), w[5], dp[1005][630], s[15],       c[15] = {0, 125, 25, 5, 1, 300, 60, 12, 465, 93, 624};   bool p[6][1005];   int main() {     for (int i = 1; i < 5; i++) w[i] = read();     char ss = getchar();     for (int i = 1; i < 5; i++)       for (int j = 1; j <= n; j++) {         while (ss !=  .  && ss !=  * ) ss = getchar();         p[i][j] = (ss ==  * );         ss = getchar();       }     memset(dp, 0x3f3f3f3f, sizeof(dp));     dp[1][0] = 0;     int b[5] = {0, 125, 25, 5, 1};     for (int i = 1; i < 11; i++) {       if (i < 5)         s[i] = w[1];       else if (i > 4 && i < 8)         s[i] = w[2];       else if (i > 7 && i < 10)         s[i] = w[3];       else         s[i] = w[4];     }     for (int i = 1; i <= n; i++) {       for (int j = 0; j < 625; j++) {         int a[5] = {0, j / 125, j / 25 % 5, j / 5 % 5, j % 5};         if (max(max(a[1], a[2]), max(a[3], a[4])) > n - i + 1) continue;         for (int o = 1; o < 5; o++)           if (a[o] > 0 && !p[o][i + a[o] - 1])             dp[i][j] = min(dp[i][j], dp[i][j - b[o]]);         if (min(min(a[1], a[2]), min(a[3], a[4])) > 0)           dp[i + 1][j - 156] = min(dp[i + 1][j - 156], dp[i][j]);         for (int k = 1; k < 11; k++) {           int b[5] = {0, c[k] / 125, c[k] / 25 % 5, c[k] / 5 % 5, c[k] % 5},               l = 0;           for (int o = 1; o < 5; o++) l = l * 5 + max(a[o], b[o]);           dp[i][l] = min(dp[i][l], dp[i][j] + s[k]);         }       }     }     printf( %d n , dp[n + 1][0]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9;   const int MOD = 1e9 + 7;   const int N = 0;   int a[5], m;   long long sum(int len, int x) {     return 1LL * len * x - 1LL * (x + 1) * x / 2 + x;   }   long long cal(int x, int y, int bar, int len) {     if (len < 0) return 0;     int R = min(bar - y, len), L = min(len - (bar - x), R);     long long ans = 0;     if (L >= 0)       ans += 1LL * (L + 1) * (bar - x + 1);     else       L = -1;     ans += sum(len, R) - sum(len, L);     return ans;   }   long long solve(int x, int y, int z, int len) {     int tmp = max(max(y, z) + 1, x);     len -= tmp - x;     x = tmp;     long long ans = 0;     for (auto i = 0; i <= len; i++) {       int cur = x + i, rem = min(2 * (cur - 1) - y - z, len - i);       if (rem > cur - y - z)         ans += cal(y, z, cur - 1, rem) - cal(y, z, cur - 1, (cur - y - z));     }     return ans;   }   long long solve2(int x, int y, int z, int len) {     int tmp = max(x, y);     len -= 2 * tmp - x - y;     x = tmp;     if (x <= z) len -= 2 * (z + 1 - x), x = z + 1;     long long ans = 0;     if (len >= 0)       for (auto i = 0; i <= len / 2; i++) {         int rem = len - 2 * i;         ans += min(x + i - 1 - z, rem) + 1;       }     return ans;   }   int main() {     for (auto i = 0; i <= 2; i++) cin >> a[i];     cin >> m;     long long ans = 0;     for (auto i = 0; i <= 2; i++)       ans += solve(a[i], a[(i + 1) % 3], a[(i + 2) % 3], m);     for (auto i = 0; i <= 2; i++)       ans += solve2(a[i], a[(i + 1) % 3], a[(i + 2) % 3], m);     int tmp = *max_element(a, a + 3), v = 0;     for (auto i = 0; i <= 2; i++) v += tmp - a[i];     if (v <= m) ans += (m - v) / 3 + 1;     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     int a[k];     for (int i = 0; i < k; i++) cin >> a[i];     list<int> leader;     for (int i = 1; i <= n; i++) leader.insert(leader.end(), i);     int l = 1;     int i = 0;     int begin = 0;     while (k--) {       l = (leader.size() + a[i] + begin) % leader.size();       list<int>::iterator pnlist = leader.begin();       advance(pnlist, l);       if (k == 0)         cout << *pnlist << endl;       else         cout << *pnlist <<    ;       leader.erase(pnlist);       begin = l;       i++;     }   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     while (b) {       a %= b;       swap(a, b);     }     return a;   }   int main() {     int n;     cin >> n;     vector<int> q(n);     for (int i = 0; i < n; ++i) cin >> q[i];     vector<int> cost(n, -1);     int m;     cin >> m;     for (int i = 0; i < m; ++i) {       int a, b, c;       cin >> a >> b >> c;       if (cost[b - 1] == -1 || cost[b - 1] > c) {         cost[b - 1] = c;       }     }     int ans = 0, head = 0;     for (int i = 0; i < n; ++i) {       if (cost[i] != -1)         ans += cost[i];       else         head++;     }     if (head > 1)       cout << -1 << endl;     else {       if (!head) {         int maxx = cost[0];         for (int i = 1; i < n; ++i) maxx = max(maxx, cost[i]);         ans -= maxx;       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   vector<int> g[200002];   vector<pair<int, pair<int, int> > > first[200002];   int lvl[200002];   int p[20][200002];   int h[20][200002];   int d[200002][2];   inline int lca(int v1, int v2) {     if (lvl[v1] < lvl[v2]) swap(v1, v2);     for (int i = 20 - 1; i >= 0; --i) {       if (lvl[p[i][v1]] >= lvl[v2]) {         v1 = p[i][v1];       }     }     if (v1 == v2) return v1;     for (int i = 20 - 1; i >= 0; --i) {       if (p[i][v1] != p[i][v2]) {         v1 = p[i][v1];         v2 = p[i][v2];       }     }     return p[0][v1];   }   void dfs(int v = 0, int level = 0, int pr = 0) {     lvl[v] = level;     p[0][v] = pr;     for (int i = 1; i < 20; ++i) p[i][v] = p[i - 1][p[i - 1][v]];     for (const int& v2 : g[v]) {       dfs(v2, level + 1, v);     }   }   inline int getit(int v, int k) {     if (h[k][v] != -1) return h[k][v];     return h[k][v] = getit(p[k - 1][v], k - 1) + getit(v, k - 1);   }   inline int get(int v, int k) {     if (k < 0) return 0;     int res = 0;     for (int i = 20 - 1; i >= 0; --i) {       if ((k & (1 << i)) > 0) {         res += getit(v, i);         k ^= (1 << i);         v = p[i][v];       }     }     return res;   }   void go(int v = 0) {     for (const int& v2 : g[v]) {       go(v2);       d[v][0] += max(d[v2][0], d[v2][1]);     }     for (const int& v2 : g[v]) {       h[0][v2] = d[v][0] - max(d[v2][0], d[v2][1]);     }     for (const auto& t : first[v]) {       int cost = t.first;       int v1 = t.second.first;       int v2 = t.second.second;       int w = -d[v][0] + get(v1, lvl[v1] - lvl[v]) + get(v2, lvl[v2] - lvl[v]) +               d[v1][0] + d[v2][0] + cost;       d[v][1] = max(d[v][1], w);     }   }   int main() {     memset(h, -1, sizeof(h));     scanf( %d%d , &n, &m);     for (int i = 0; i < n - 1; ++i) {       int t;       scanf( %d , &t);       --t;       g[t].push_back(i + 1);     }     dfs();     for (int i = 0; i < m; ++i) {       int v1, v2, cost;       scanf( %d%d%d , &v1, &v2, &cost);       --v1, --v2;       int lcav = lca(v1, v2);       first[lcav].push_back(make_pair(cost, make_pair(v1, v2)));     }     go();     printf( %d n , max(d[0][0], d[0][1]));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int t[2000002];   int longestPrefix(string &s) {     t[0] = 0;     for (int pos = 1; pos < s.length(); ++pos) {       int prev = t[pos - 1];       while (prev > 0 && s[pos] != s[prev]) {         prev = t[prev - 1];       }       if (s[pos] == s[prev]) {         t[pos] = prev + 1;       } else {         t[pos] = prev;       }     }     return t[s.length() - 1];   }   int main() {     int t;     cin >> t;     while (t-- > 0) {       string s;       cin >> s;       int lindex = 0, rindex = s.length();       while (lindex < rindex && s[lindex] == s[rindex - 1]) {         ++lindex;         --rindex;       }       if (lindex >= rindex) {         cout << s << endl;         continue;       }       string mid = s.substr(lindex, rindex - lindex);       string rmid = mid;       reverse(rmid.begin(), rmid.end());       string pre = mid +  *  + rmid;       string suf = rmid +  *  + mid;       int pref = longestPrefix(pre);       int suff = longestPrefix(suf);       int len = max(pref, suff);       for (int i = 0; i < lindex; ++i) {         cout << s[i];       }       if (pref >= suff) {         for (int i = lindex; i < lindex + pref; ++i) {           cout << s[i];         }       } else {         for (int i = rindex - suff; i < rindex; ++i) {           cout << s[i];         }       }       for (int i = rindex; i < s.length(); ++i) {         cout << s[i];       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int V[200010];   char vowel[] =  aeiouAEIOU ;   int v(int a, int k) {     if (k == 0) return 0;     int x = V[a + k - 1];     if (a > 0) x -= V[a - 1];     return x;   }   int f(int a, int k) { return 2 * k - 3 * v(a, k); }   int g(int k) { return f(0, k); }   bool Good(int a, int k) { return f(a, k) >= 0; }   bool is_vowel(char c) {     for (int i = 0; i < 10; i++) {       if (vowel[i] == c) return true;     }     return false;   }   bool sf(const int& a, const int& b) {     if (g(a) < g(b)) return true;     if (g(a) > g(b)) return false;     return a < b;   }   int Q[200010];   vector<int> P;   int R[200010];   int my_bin_search(int s, string S) {     int a = 0;     int b = P.size() - 1;     while (a <= b) {       int k = (a + b) / 2;       if (P[k] == s)         return k;       else if (sf(P[k], s))         a = k + 1;       else         b = k - 1;     }     throw  element not found ;   }   void create_data(string S) {     int N = S.length();     for (int a = 0; a <= N; a++) {       P.push_back(a);     }     sort(P.begin(), P.end(), sf);     for (int x = 0; x < P.size(); x++) {       R[P[x]] = x;     }     Q[0] = P[0];     for (unsigned int x = 1; x < P.size(); x++) {       Q[x] = min(Q[x - 1], P[x]);     }   }   int main() {     string S;     cin >> S;     int N = S.length();     V[0] = 0;     for (unsigned int i = 0; i < S.length(); i++) {       if (i > 0) V[i] = V[i - 1];       if (is_vowel(S[i])) V[i]++;     }     create_data(S);     int bestk = 0;     for (int a = 0; a <= N; a++) {       int x = R[a];       int b = Q[x];       bestk = max(bestk, a - b);     }     if (bestk == 0) {       cout <<  No solution  << endl;       return 0;     }     int found = 0;     for (int a = 0; (a + bestk) <= N; a++) {       if (Good(a, bestk)) {         found++;       }     }     cout << bestk <<     << found << endl;   }
#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1);   void read(int& x) {     x = 0;     int f = 1;     char ch = getchar();     while ((ch <  0  || ch >  9 ) && ch !=  - ) ch = getchar();     if (ch ==  - ) f = -1, ch = getchar();     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     x *= f;   }   int n, f[200005], g[200005], els[200005];   vector<int> E[200005];   int power(int a, int b, int p) {     int s = 1, w = a;     while (b) {       if (b & 1) s = (long long)s * w % p;       w = (long long)w * w % p;       b >>= 1;     }     return s;   }   vector<int> F[200005], B[200005];   void dfs(int now) {     f[now] = 1;     for (int i = (0); i < (E[now].size()); i++) {       dfs(E[now][i]),           f[now] = (long long)f[now] * (f[E[now][i]] + 1) % 1000000007;       F[now].push_back(f[E[now][i]] + 1), B[now].push_back(f[E[now][i]] + 1);     }     for (int i = (1); i < (E[now].size()); i++)       F[now][i] = (long long)F[now][i - 1] * F[now][i] % 1000000007;     for (int i = (E[now].size() - 2); i >= (0); i--)       B[now][i] = (long long)B[now][i + 1] * B[now][i] % 1000000007;     if (E[now].size() == 1) {       els[E[now][0]] = 1;       return;     }     for (int i = (0); i < (E[now].size()); i++) {       if (i == 0)         els[E[now][i]] = B[now][i + 1];       else if (i + 1 == E[now].size())         els[E[now][i]] = F[now][i - 1];       else         els[E[now][i]] = (long long)B[now][i + 1] * F[now][i - 1] % 1000000007;     }   }   void work(int now) {     for (int i = (0); i < (E[now].size()); i++) {       g[E[now][i]] = ((long long)g[now] * els[E[now][i]] + 1) % 1000000007;       work(E[now][i]);     }   }   int main() {     read(n);     for (int i = (2); i <= (n); i++) {       int x;       read(x);       E[x].push_back(i);     }     dfs(1);     g[1] = 1;     work(1);     for (int i = (1); i <= (n); i++)       printf( %lld  , (long long)f[i] * g[i] % 1000000007);     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string n;   int i, j, a[9][7], x, y;   int main() {     cin >> n;     for (i = n.size() - 1; i >= 0; i--) {       x = n[i] - 48;       y = max(y, x);       for (j = 0; j < x; j++) a[j][7 + i - n.size()] = 1;     }     cout << y << endl;     for (i = 0; i < y; cout <<    , i++)       for (j = 0, x = 0; j < 7; j++) {         if (a[i][j] != 0) x = 1;         if (x != 0) cout << a[i][j];       }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long s = 0, w = 1;     register char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) w = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 )       s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();     return s * w;   }   long long n;   string s;   signed main() {     n = read();     cin >> s;     for (register long long i = 2; i <= n; i++) {       if (n % i) continue;       for (register long long j = 0; j < i / 2; j++) swap(s[j], s[i - j - 1]);     }     cout << s << endl;     return 0;   }