malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include<bits/stdc++.h>   using namespace std;   #define N 1500009   #define INF 5e8   #define mymin(x,y) (x>=y?y:x)   #define mymax(x,y) (x>=y?x:y)   typedef long long int LL;   map<LL, int> mp[3];   int a[4][N];   struct din{       int ap, id;   }dn[4][N];   bool cmp(din af, din bf){       return af.ap < bf.ap;   }   int main() {    std::ios::sync_with_stdio(0); std::cin.tie(0);       int n[4];       for(int i = 0; i < 4; i++) cin >> n[i];       for(int i = 0; i < 4; i++){           for(int j = 0; j < n[i]; j++){               cin >> dn[i][j].ap;               dn[i][j].id = j + 1;           }       }       for(int i = 0; i < 3; i++){           int m; cin >> m;           for(int j = 0; j < m; j++){               int x, y; cin >> x >> y;               mp[i][1ll * x * N + y] = 1;           }       }       for(int i = 2; i >= 0; i--){           // cout << i <<     << n[i] << endl;           // cout << dn[3][0].id <<     << mp[2][0 * N + 1] << endl;           sort(dn[i + 1], dn[i + 1] + n[i + 1], cmp);           for(int j = 0; j < n[i]; j++){               int ind = 0;               while(ind < n[i + 1] && mp[i][1ll * (j + 1) * N + dn[i + 1][ind].id]) ind++;               if(ind == n[i + 1]) dn[i][j].ap = INF;               else dn[i][j].ap += dn[i + 1][ind].ap;               // cout << dn[i][j].ap <<    ;           }           // cout << endl;       }       sort(dn[0], dn[0] + n[0], cmp);       if(dn[0][0].ap >= INF) cout << -1 << endl;       else cout << dn[0][0].ap << endl;    return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int di[] = {-1, -1, -1, 0, 1, 1, 1, 0, 0},             dj[] = {-1, 0, 1, 1, 1, 0, -1, -1, 0};   int st[20][20][20] = {};   bool fr[20][20][20 * 20] = {};   int n;   void file_open() {     freopen( input.txt ,  r , stdin);     freopen( output.txt ,  w , stdout);   }   void xuli() {     queue<int> q1, q2, q3;     q1.push(7);     q2.push(0);     q3.push(0);     while (!q1.empty()) {       int u = q1.front(), v = q2.front(), k = q3.front() + 1, tK = k;       if (k > 9) k = 9;       q1.pop();       q2.pop();       q3.pop();       for (int i = 0; i < 9; ++i) {         int d = u + di[i], e = v + dj[i];         if (d >= 0 && d < 8 && e >= 0 && e < 8) {           if (st[d][e][k] == 0 && st[d][e][k - 1] == 0 && !fr[d][e][tK]) {             fr[d][e][tK] = 1;             q1.push(d);             q2.push(e);             q3.push(tK);             if (d == 0 && e == 7) {               printf( WIN );               return;             }           }         }       }     }     printf( LOSE );   }   int main() {     char c[20][20] = {};     for (int i = 0; i < 8; ++i) {       for (int j = 0; j < 8; ++j) {         scanf( %c , &c[i][j]);         if (c[i][j] ==  S ) {           int u = 0;           while (u + i < 8) {             st[i + u][j][u] = 1;             ++u;           }         }       }       scanf(  n );     }     xuli();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long arr1[100][10000], arr[10000];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t, i, j, k, n, m, x, y, z, a, b, mx;     cin >> t;     while (t--) {       cin >> n;       for (i = 0; i < n; i++) {         cin >> arr[i];       }       for (i = 1; i < 27; i++) {         x = 0;         for (j = 0; j < n; j++) {           if (arr[j] == i) {             x++;             arr1[i][j] = x;           } else {             arr1[i][j] = x;           }         }       }       mx = 1;       for (i = 0; i < n; i++) {         for (j = i + 1; j < n; j++) {           if (arr[j] == arr[i] &&               (arr1[arr[i]][i]) == (arr1[arr[i]][n - 1] - arr1[arr[i]][j] + 1)) {             x = arr1[arr[i]][i] + arr1[arr[i]][n - 1] - arr1[arr[i]][j] + 1;             for (k = 1; k <= 26; k++) {               y = arr1[k][j - 1] - arr1[k][i];               z = x + y;               mx = max(z, mx);             }           }         }       }       cout << mx << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int n, a[1001][10], cnt, ans[1001];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d%d%d%d%d , &a[i][0], &a[i][1], &a[i][2], &a[i][3], &a[i][4]);     }     if (n > 11) {       printf( 0 );       return 0;     }     for (int i = 1; i <= n; i++) {       bool flg = 0;       for (int j = 1; j <= n; j++)         if (i != j)           for (int k = j + 1; k <= n; k++)             if (k != i) {               int mx = 0;               double mmx = 0, mmy = 0;               for (int p = 0; p < 5; p++) {                 mx += (a[i][p] - a[j][p]) * (a[i][p] - a[k][p]);                 mmx += (a[i][p] - a[j][p]) * (a[i][p] - a[j][p]);                 mmy += (a[i][p] - a[k][p]) * (a[i][p] - a[k][p]);               }               mmx = sqrt(mmx);               mmy = sqrt(mmy);               if (acos((double)mx / (mmx * mmy)) * 2 <= acos(-1) - 1e-8) flg = 1;             }       if (!flg) ans[++cnt] = i;     }     printf( %d n , cnt);     for (int i = 1; i <= cnt; i++) printf( %d n , ans[i]);   }
#include <bits/stdc++.h>   long long int mod = 1000000000 + 7;   long long int inf = 1000000000000000000;   using namespace std;   int main() {     iostream::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int ans = 1, a;       cin >> a;       for (int i = 0; i < 31; i++) {         if ((a >> i) & 1) ans *= 2;       }       cout << ans <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 5002, NP = 1e9;   int Add[MAXN], MyResult[MAXN], MyCheck[MAXN];   bool check(int n, vector<pair<int, pair<int, pair<int, int> > > > A) {     for (int i = 0; i < A.size(); i++) {       int t = A[i].first, s = A[i].second.first, e = A[i].second.second.first,           v = A[i].second.second.second;       if (t == 1) {         for (int i = s - 1; i <= e - 1; i++) {           MyCheck[i] += v;         }       } else {         int mx = MyCheck[s - 1];         for (int i = s - 1; i <= e - 1; i++) mx = max(mx, MyCheck[i]);         if (mx != v) return 0;       }     }     return 1;   }   int main() {     int t, n, m, s, e, v;     vector<pair<int, pair<int, pair<int, int> > > > A;     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) MyCheck[i] = MyResult[i] = NP;     while (m--) {       scanf( %d%d%d%d , &t, &s, &e, &v);       A.push_back(make_pair(t, make_pair(s, make_pair(e, v))));       if (t == 1) {         for (int i = s - 1; i <= e - 1; i++) Add[i] += v;       } else {         for (int i = s - 1; i <= e - 1; i++)           MyResult[i] = min(MyResult[i], v - Add[i]);       }     }     for (int i = 0; i < n; i++) MyCheck[i] = MyResult[i];     if (check(n, A)) {       printf( YES n );       for (int i = 0; i < n; i++) {         if (i) printf(   );         printf( %d , MyResult[i]);       }       printf(  n );     } else       printf( NO n );   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     for (; t; t--) {       int n;       cin >> n;       vector<int> a(n);       for (int i = 0; i < n; i++) cin >> a[i];       vector<int> gist(3);       for (int i = 0; i < n; i++) gist[a[i] % 3]++;       while (gist[1] > 0 && gist[2] > 0) {         gist[1]--;         gist[2]--;         gist[0]++;       }       while (gist[1] - 3 >= 0) {         gist[1] -= 3;         gist[0]++;       }       while (gist[2] - 3 >= 0) {         gist[2] -= 3;         gist[0]++;       }       cout << gist[0] <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 1000000000;   long long mod = 1000000007LL;   long long mod2 = 998244353LL;   int n;   bool mat[2005][2005];   int cntr[2005], cntc[2005];   int cnt[2005];   int main() {     cin >> n;     memset(mat, false, sizeof(mat));     memset(cntr, 0, sizeof(cntr));     memset(cntc, 0, sizeof(cntc));     memset(cnt, 0, sizeof(cnt));     for (int i = 1; i <= n; ++i) {       string s;       cin >> s;       for (int j = 1; j <= n; ++j) {         mat[i][j] = (s[j - 1] ==  1 );       }     }     int ans = 0;     for (int i = 1; i <= n; ++i) {       for (int j = n; j >= i; --j) {         if (j == i) continue;         bool x = ((cntr[i] + cntc[j]) % 2 > 0);         if (mat[i][j] != x) {           ans++;           cntr[i]++;           cntc[j]++;         }       }     }     for (int i = 1; i <= n; ++i) {       cnt[i] += cntr[i] + cntc[i];     }     memset(cntr, 0, sizeof(cntr));     memset(cntc, 0, sizeof(cntc));     for (int i = n; i >= 1; --i) {       for (int j = 1; j <= i; ++j) {         if (j == i) continue;         bool x = ((cntr[i] + cntc[j]) % 2 > 0);         if (mat[i][j] != x) {           ans++;           cntr[i]++;           cntc[j]++;         }       }     }     for (int i = 1; i <= n; ++i) {       cnt[i] += cntr[i] + cntc[i];     }     for (int i = 1; i <= n; ++i) {       bool x = (cnt[i] % 2 > 0);       if (mat[i][i] != x) {         ans++;       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename _T>   inline void _DBG(const char *s, _T x) {     cerr << s <<   =   << x <<   n ;   }   template <typename _T, typename... args>   void _DBG(const char *s, _T x, args... a) {     while (*s !=  , ) cerr << *s++;     cerr <<   =   << x <<  , ;     _DBG(s + 1, a...);   }   const int N = 1e5 + 7;   vector<int> G[N];   int dist[N];   bool vis[N];   void dfs(int v, int d) {     vis[v] = true;     dist[v] = d;     for (auto &u : G[v]) {       if (!vis[u]) {         dfs(u, d + 1);       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int n;     cin >> n;     for (int i = 1; i < n; i++) {       int u, v;       cin >> u >> v;       G[u].push_back(v);       G[v].push_back(u);     }     int root = -1;     for (int i = 1; i <= n; i++) {       if ((int)(G[i]).size() == 1) {         root = i;         break;       }     }     dfs(root, 0);     int parity = dist[root] % 2;     bool good = true;     for (int i = 2; i <= n; i++) {       if ((int)(G[i]).size() == 1 && dist[i] % 2 != parity) {         good = false;       }     }     if (good) {       cout << 1 <<    ;     } else {       cout << 3 <<    ;     }     int edges = n - 1;     int leaves = 0;     set<int> leaf_parents;     for (int i = 1; i <= n; i++) {       if ((int)(G[i]).size() == 1) {         leaves++;       } else {         for (auto &u : G[i]) {           if ((int)(G[u]).size() == 1) {             leaf_parents.insert(i);           }         }       }     }     cout << edges - leaves + (int)(leaf_parents).size() <<   n ;     return 0;   }
#include <bits/stdc++.h>   int N, Q;   int a[300005];   int p[300005];   int oop[1100005];   int ui, uv;   void update(int n, int nl, int nr) {     if (nl == ui && ui + 1 == nr) {       oop[n] = uv;     } else {       int mid = (nl + nr) / 2;       if (ui < mid)         update(n * 2 + 1, nl, mid);       else         update(n * 2 + 2, mid, nr);       oop[n] = oop[n * 2 + 1] + oop[n * 2 + 2];     }   }   int ql, qr;   int query(int n, int nl, int nr) {     if (qr <= nl || nr <= ql)       return 0;     else if (ql <= nl && nr <= qr)       return oop[n];     else {       int mid = (nl + nr) / 2;       return query(n * 2 + 1, nl, mid) + query(n * 2 + 2, mid, nr);     }   }   int main() {     scanf( %d , &N);     a[0] = p[0] = 0;     for (int i = 1; i <= N; i++) {       scanf( %d , &a[i]);       p[a[i]] = i;     }     a[N + 1] = p[N + 1] = N + 1;     for (int i = 1; i < N; i++) {       ui = i;       uv = p[i] > p[i + 1];       update(0, 0, N + 2);     }     scanf( %d , &Q);     for (int i = 0; i < Q; i++) {       int t, x, y;       scanf( %d%d%d , &t, &x, &y);       if (t == 1) {         ql = x, qr = y;         printf( %d n , query(0, 0, N + 2) + 1);       } else {         std::swap(a[x], a[y]);         p[a[x]] = x;         p[a[y]] = y;         ui = a[x] - 1;         uv = p[a[x] - 1] > p[a[x]];         update(0, 0, N + 2);         ui = a[x];         uv = p[a[x]] > p[a[x] + 1];         update(0, 0, N + 2);         ui = a[y] - 1;         uv = p[a[y] - 1] > p[a[y]];         update(0, 0, N + 2);         ui = a[y];         uv = p[a[y]] > p[a[y] + 1];         update(0, 0, N + 2);       }     }   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ii = pair<int, int>;   constexpr int MAXN = 5 + 50;   constexpr ll INF = 1000000000000000002LL;   namespace dsu {   int f[MAXN], sz[MAXN];   void build(int n) {     fill(sz, sz + n, 1);     for (int i = (int)0; i < (int)n; ++i) f[i] = i;   }   int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); }   bool join(int x, int y) {     if ((x = find(x)) == (y = find(y))) return false;     if (sz[x] < sz[y]) swap(x, y);     sz[x] += sz[y];     f[y] = x;     return true;   }   bool connected(int i, int j) { return find(i) == find(j); }   }  // namespace dsu   ll memo[MAXN], f[MAXN];   int res[MAXN];   bitset<MAXN> used;   ll add(ll a, ll b) {     if (a + b >= INF) return INF;     return a + b;   }   ll mul(ll a, ll b) {     long double ans = (long double)(a) * (long double)(b);     if (ans >= INF) return INF;     return a * b;   }   ll dp(int len) {     ll& ans = memo[len];     if (~ans) {       assert(ans >= 0);       return ans;     }     if (len == 0) return ans = 1;     ans = 0;     for (int i = 1; i <= len; ++i)       ans = add(ans, mul(dp(len - i), f[max(0, i - 2)]));     return ans;   }   void rebuild(int len, ll k, int pos, int n) {     if (len == 0) {       assert(pos == n);       return;     }     ll ans = 0;     for (int i = 1; i <= len; ++i) {       ll ol = ans;       ans = add(ans, mul(dp(len - i), f[max(0, i - 2)]));       if (k <= ans) {         k -= ol;         ll j = k / dp(len - i);         while (mul(j, dp(len - i)) < k) ++j;         k -= mul(j - 1, dp(len - i));         res[pos] = i + pos;         dsu::build(MAXN);         used.reset();         for (int posin = 2; posin <= i; ++posin) {           int put = -1;           ll ac = 0, olac;           for (int num = 1; num < i; ++num) {             if (dsu::connected(num, posin) || used[num]) continue;             olac = ac;             ac = add(ac, f[max(0, i - posin - 1)]);             if (j <= ac) {               put = num;               break;             }           }           assert(put != -1);           res[pos + posin - 1] = put + pos;           used[put] = true;           dsu::join(put, posin);           j -= olac;         }         rebuild(len - i, k, i + pos, n);         return;       }     }     assert(false);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     f[0] = 1;     for (int i = (int)1; i < (int)MAXN; ++i) {       if (f[i - 1] == INF) {         f[i] = f[i - 1];       } else {         f[i] = min(INF, 1LL * i * f[i - 1]);       }     }     memset(memo, -1, sizeof memo);     int tc;     cin >> tc;     while (tc--) {       int n;       ll k;       cin >> n >> k;       if (k <= dp(n)) {         rebuild(n, k, 0, n);         for (int i = (int)0; i < (int)n; ++i) cout << res[i] <<    ;       } else {         cout << -1;       }       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:1024000000,1024000000 )   using namespace std;   vector<int> a[100005];   int dp[100005], n, t;   int main() {     for (int i = 2; i <= 100000; i++)       for (int j = 1; j * i <= 100000; j++) a[i * j].push_back(i);     while (cin >> n) {       memset(dp, 0, sizeof(dp));       for (int i = 0; i < n; i++) {         cin >> t;         int mx = 0;         for (int j = 0; j < a[t].size(); j++) {           mx = max(mx, dp[a[t][j]]);         }         for (int j = 0; j < a[t].size(); j++) {           dp[a[t][j]] = mx + 1;         }       }       cout << max(1, *max_element(dp, dp + 100001)) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, sum, cnt[10];   bool check;   void ghi() {     bool check = false;     for (int i = 9; i > -1; i--) {       if (cnt[i] == 0) continue;       if (i != 0) check = true;       if (!i && !check) cnt[i] = 1;       for (int j = 1; j <= cnt[i]; j++) printf( %d , i);     }     printf(  n );   }   int main() {     if (0) {       freopen( a.inp ,  r , stdin);     };     scanf( %d , &n);     int x;     for (int i = 0; i < n; i++) {       scanf( %d , &x);       cnt[x]++;       sum += x;       if (x == 0) check = true;     }     if (!check) {       printf( -1 n );       return 0;     }     if (sum % 3 == 1) {       for (int i = 0; i < 10; i++) {         if (i % 3 != 1 || cnt[i] == 0) continue;         cnt[i]--;         ghi();         return 0;       }       for (int i = 0; i < 10; i++) {         if (i % 3 != 2 || cnt[i] == 0) continue;         cnt[i]--;         for (int j = i; j < 10; j++) {           if (j % 3 != 2 || cnt[j] == 0) continue;           cnt[j]--;           ghi();           return 0;         }       }     } else if (sum % 3 == 2) {       for (int i = 0; i < 10; i++) {         if (i % 3 != 2 || cnt[i] == 0) continue;         cnt[i]--;         ghi();         return 0;       }       for (int i = 0; i < 10; i++) {         if (i % 3 != 1 || cnt[i] == 0) continue;         cnt[i]--;         for (int j = i; j < 10; j++) {           if (j % 3 != 1 || cnt[j] == 0) continue;           cnt[j]--;           ghi();           return 0;         }       }     } else       ghi();   }
#include <bits/stdc++.h>   using namespace std;   int nA, nB, m, k, ans, x, y, c1, c2, cnt;   int deg[1310 << 1], be[190010], w[1310], w2[1310];   int id[10005][1310], f[10005][1310];   void rv(int x, int c1, int c2) {     swap(f[x][c1], f[x][c2]);     swap(id[x][c1], id[x][c2]);     be[id[x][c2]] = c2;     if (f[x][c2]) rv(f[x][c2], c2, c1);   }   int main() {     scanf( %d%d%d , &nA, &m, &k);     nB = nA;     int foo;     for (int i = 1; i <= nA; i++) scanf( %d , &foo);     for (int i = 1; i <= m; ++i) {       scanf( %d%d , &x, &y);       if (x < y) swap(x, y);       if (deg[x] % k == 0) w[x] = ++cnt;       if (deg[nA + y] % k == 0) w2[y] = ++cnt;       deg[x]++, deg[nA + y]++;       x = w[x], y = w2[y];       c1 = 0, c2 = 0;       for (int j = 1; j <= k; ++j)         if (!f[x][j]) {           c1 = j;           break;         }       for (int j = 1; j <= k; ++j)         if (!f[y][j]) {           c2 = j;           break;         }       if (f[y][c1]) rv(y, c1, c2);       f[x][c1] = y;       id[x][c1] = i;       f[y][c1] = x;       id[y][c1] = i;       be[i] = c1;     }     for (int i = 1; i <= m; ++i) printf( %d  , be[i]);     putchar(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100100;   int N, M;   int app[MAXN];   char type[MAXN];   int P[MAXN];   bool check(int leader) {     set<int> users;     users.insert(leader);     for (int i = 0; i < M; i++) {       if (type[i] ==  + )         users.insert(P[i]);       else         users.erase(P[i]);       if (!users.empty() && users.find(leader) == users.end()) return false;     }     return true;   }   int main() {     cin >> N >> M;     for (int i = 0; i < M; i++) cin >> type[i] >> P[i];     int offp = 0;     for (int i = 0; i < M; i++) {       if (type[i] ==  -  && !app[P[i]]) offp = P[i];       app[P[i]] = true;     }     if (offp != 0) {       if (check(offp)) app[offp] = false;     } else {       if (check(P[0])) app[P[0]] = false;     }     int total = 0;     for (int i = 1; i <= N; i++) total += !app[i];     cout << total <<   n ;     for (int i = 1; i <= N; i++)       if (!app[i]) cout << i <<    ;     return 0;   }
#include <bits/stdc++.h>      using namespace std;   typedef long long ll;      const int N = 1e6 + 9;      int main () {       int t;       cin >> t;       while (t--) {           ll n, last;           cin >> n;           for (ll i = 0; i < 33; i++) {               if (n & (1ll << i))                   last = i;           }           cout << ((1ll << last) - 1ll) <<   n ;       }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int total, n;     cin >> total >> n;     vector<int> v(n);     for (int i = 0; i < n; i++) cin >> v[i];     int ans = 0;     for (int i = 0; i < n - 1; i++) {       ans += (total - v[i]);     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     vector<int> v;     int total, num, i, koita = 0;     scanf( %d , &total);     for (i = 0; i < total; i++) {       scanf( %d , &num);       v.push_back(num);     }     int maximum = v[0];     int minimum = v[0];     for (i = 1; i < total; i++) {       num = v[i];       if (num > maximum) {         maximum = num;         koita++;       }       if (num < minimum) {         minimum = num;         koita++;       }     }     printf( %d n , koita);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n], b[n], c = 0, x = 0, y = 0, z = 0, s = 0;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (a[i] == 1) {         x++;       }     }     for (int i = 0; i < n; i++) {       cin >> b[i];       if (a[i] != b[i]) {         c = 1;       }       if (b[i] == 1) {         y++;       }     }     for (int i = 0; i < n; i++) {       if (a[i] == 1 && b[i] == 0) {         z++;       }     }     if (c == 0 || x == 0 || z == 0) {       cout <<  -1  << endl;     } else {       for (int i = 1;;) {         if (s > y) {           cout << i - 1 << endl;           break;         } else {           s = z * i + (x - z);           i++;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 9;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long s[maxn];   int f[maxn], F[maxn], p[maxn];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %lld , &s[i]);     }     for (int i = 2; i <= n; ++i) {       scanf( %d , &p[i]);     }     for (int i = n; i > 1; --i) {       s[p[i]] += s[i];     }     for (int i = n; i; --i) {       long long t = s[1] / gcd(s[1], s[i]);       if (t <= n) {         ++f[t];       }     }     for (int i = n; i; --i) {       for (int j = i; (j += i) <= n;) {         f[j] += f[i];       }     }     int ans = 0;     F[1] = 1;     for (int i = 1; i <= n; ++i) {       if (f[i] == i) {         ans += F[i];         for (int j = i * 2; j <= n; j += i) {           F[j] += F[i];         }       }     }     printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int i, j, k, n, m;   int fa[200010], an[200010];   vector<int> a[200010];   pair<int, int> f[200010];   inline void P(int &x, int y) { x = 1ll * x * y % 1000000007; }   inline void merge(pair<int, int> &a, pair<int, int> b) {     P(a.first, b.first);     int g = (2ll * b.first + b.second) % 1000000007;     P(a.second, g);   }   inline void gao(pair<int, int> &a) {     a.second = (a.second - a.first) % 1000000007;   }   inline void ch(pair<int, int> &a, pair<int, int> b) {     a.first = 1ll * a.first * b.first % 1000000007;     a.second = 1ll * a.second * b.second % 1000000007;   }   void dfs(int x) {     f[x] = make_pair(1, 1);     for (auto i : a[x]) {       if (fa[x] == i) continue;       fa[i] = x;       dfs(i);       merge(f[x], f[i]);     }     gao(f[x]);   }   void huan(int x) {     an[x] = (f[x].first + f[x].second) % 1000000007;     int t = 0, i, len = a[x].size() + 5;     vector<pair<int, int> > g(len), f1(len), f2(len);     for (auto i : a[x]) g[++t] = f[i];     f1[0] = make_pair(1, 1);     for (i = 1; i <= t; i++) f1[i] = f1[i - 1], merge(f1[i], g[i]);     f2[t + 1] = make_pair(1, 1);     for (i = t; i; i--) f2[i] = f2[i + 1], merge(f2[i], g[i]);     int _ = 0;     for (auto i : a[x]) {       _++;       if (fa[x] == i) continue;       pair<int, int> v = f1[_ - 1];       ch(v, f2[_ + 1]);       gao(v);       swap(f[x], v);       pair<int, int> tmp = f[i];       f[i].second = (f[i].second + f[i].first) % 1000000007;       merge(f[i], f[x]);       gao(f[i]);       huan(i);       swap(f[x], v);       f[i] = tmp;     }   }   int main() {     scanf( %d , &n);     for (i = 1; i <= n - 1; i++) {       int x;       scanf( %d , &x);       a[x].push_back(i + 1);       a[i + 1].push_back(x);     }     dfs(1);     huan(1);     for (i = 1; i <= n; i++) printf( %d  , (an[i] + 1000000007) % 1000000007);     printf(  n );     return 0;   }