malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   map<char, int> mp1;   int main() {     ios_base::sync_with_stdio(0);     string s, p, q;     long long int a, b, c, d, i, j, k, u, v, w = 0, x, y, z;     cin >> p;     for (i = 0; i < p.length(); i++) mp1[p[i]] = 1;     cin >> s;     cin >> k;     while (k--) {       w = 0;       cin >> q;       if (s.length() > q.length() + 1) {         cout <<  NO  << endl;         continue;       }       for (i = 0; i < q.length() && i < s.length(); i++) {         if (q[i] == s[i]) continue;         if (s[i] ==  ?  && mp1[q[i]] == 1) continue;         if (s[i] ==  * ) {           w = 1;           v = s.length() - 1;           for (u = q.length() - 1; v > i && u >= i; u--, v--) {             if (q[u] == s[v]) continue;             if (s[v] ==  ?  && mp1[q[u]] == 1) continue;             break;           }         } else {           cout <<  NO  << endl;           w = -1;           break;         }         if (v != i) {           w = -1;           cout <<  NO  << endl;           break;         }         for (j = u; j >= i; j--) {           if (mp1[q[j]] == 0) continue;           break;         }         if (j >= i) {           w = -1;           cout <<  NO  << endl;           break;         }         i = q.length() - 1;       }       if (w == -1) continue;       if (i != q.length()) {         cout <<  NO  << endl;         continue;       }       if (s.length() == q.length() + 1 && w == 0 && s[q.length()] !=  * ) {         cout <<  NO  << endl;         continue;       }       cout <<  YES  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e6 + 7;   const long long MOD = 1e9 + 7;   template <class T>   bool umin(T& a, T b) {     if (a > b) {       a = b;       return 1;     }     return 0;   }   template <class T>   bool umax(T& a, T b) {     if (a < b) {       a = b;       return 1;     }     return 0;   }   template <class T>   bool umod(T& a, T b) {     a += b;     while (a < 0) a += MOD;     a %= MOD;     return 1;   }   int las, n, cur, cost[N], m, cst;   vector<int> v[N];   vector<long long> par[N];   long long ans;   void merge(int x) {     v[x].push_back(0);     int l = x * 2, r = x * 2 + 1;     int a = 0, b = 0;     while (a < int(v[l].size()) && b < int(v[r].size())) {       if (v[l][a] + cost[l] <= v[r][b] + cost[r])         v[x].push_back(v[l][a] + cost[l]), a++;       else         v[x].push_back(v[r][b] + cost[r]), b++;     }     while (a < int(v[l].size())) v[x].push_back(v[l][a] + cost[l]), a++;     while (b < int(v[r].size())) v[x].push_back(v[r][b] + cost[r]), b++;     par[x].push_back(0LL);     for (int i = 1; i < int(v[x].size()); i++)       par[x].push_back(par[x][i - 1] + v[x][i]);   }   void dfs(int x) {     if (x > n) return;     dfs(x * 2);     dfs(x * 2 + 1);     merge(x);   }   long long get(int x, int y) {     if (x > n || y <= 0) return 0;     int ind = upper_bound(v[x].begin(), v[x].end(), y) - v[x].begin();     return 0LL + (1LL * ind * y) - par[x][ind - 1];   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 2; i <= n; i++) scanf( %d , &cost[i]);     dfs(1);     while (m--) {       int aa, bb;       scanf( %d%d , &aa, &bb);       las = -1, cur = aa, ans = 0, cst = bb;       while (las != 1 && cst > 0) {         if (las != cur * 2) ans += get(cur * 2, cst - cost[cur * 2]);         if (las != cur * 2 + 1) ans += get(cur * 2 + 1, cst - cost[cur * 2 + 1]);         ans += cst;         cst -= cost[cur];         las = cur;         cur /= 2;       }       printf( %lld n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 10;   int a[maxn], x[maxn], y[maxn], sk[maxn], top, cnt;   int main() {     int n, P, ly = -1, fl = 0;     scanf( %d , &n), P = n;     for (int i = 1; i <= n; i++) scanf( %d , a + i);     for (int i = n; i >= 1; i--) {       if (a[i] == 1) {         sk[++top] = x[++cnt] = P--;         y[cnt] = i;         if (!fl) ly = i;       } else if (a[i] == 2) {         if (top <= 0) return puts( -1 ), 0;         x[++cnt] = sk[top--];         y[cnt] = i;         if (!fl) ly = i;         P = min(P, x[cnt] - 1);       } else if (a[i] == 3) {         if (ly == -1) return puts( -1 ), 0;         x[++cnt] = P;         y[cnt] = ly;         x[++cnt] = P;         y[cnt] = ly = i;         if (!fl) top--;         fl = 1;         P--;       }     }     printf( %d n , cnt);     for (int i = 1; i <= cnt; i++) printf( %d %d n , x[i], y[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct point {     double x, y;   };   int main() {     point p;     double a, b, c, d;     point v;     scanf( %lf%lf%lf%lf%lf%lf%lf%lf , &p.x, &p.y, &v.x, &v.y, &a, &b, &c, &d);     double lenth = sqrt(v.x * v.x + v.y * v.y);     v.x /= lenth;     v.y /= lenth;     a /= 2;     c /= 2;     point q;     q.x = p.x + v.x * b;     q.y = p.y + v.y * b;     printf( %.10f %.10f n , q.x, q.y);     q.x = p.x - v.y * a;     q.y = p.y + v.x * a;     printf( %.10f %.10f n , q.x, q.y);     q.x = p.x - v.y * c;     q.y = p.y + v.x * c;     printf( %.10f %.10f n , q.x, q.y);     point w;     w.x = q.x - v.x * d;     w.y = q.y - v.y * d;     printf( %.10f %.10f n , w.x, w.y);     q.x = w.x + v.y * c * 2;     q.y = w.y - v.x * c * 2;     printf( %.10f %.10f n , q.x, q.y);     q.x = p.x + v.y * c;     q.y = p.y - v.x * c;     printf( %.10f %.10f n , q.x, q.y);     q.x = p.x + v.y * a;     q.y = p.y - v.x * a;     printf( %.10f %.10f n , q.x, q.y);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long N, M, K, R, l, r, A, B, X, Y, Z, C, D, Q, a, b, c, d, i, j, k, first,       mx, ans, cnt, T, P;   void solve() {     cin >> N >> K;     long long A[N];     long long lar = INT_MIN, sma = INT_MAX;     for (long long int i = 0; i < N; i++) {       cin >> A[i];       lar = max(lar, A[i]);       sma = min(sma, A[i]);     }     for (long long int i = 0; i < N; i++) {       A[i] = lar - A[i];     }     if (K % 2 == 0) {       for (long long int i = 0; i < N; i++) {         A[i] = lar - sma - A[i];       }     }     for (long long int i = 0; i < N; i++) {       cout << A[i] <<    ;     }     cout <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t = 1;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long mini(long long a, long long b) {     if (a < b) return a;     return b;   }   int main() {     ios_base::sync_with_stdio(0);     int n;     cin >> n;     vector<long long> a(n);     for (int i = 0; i < n; ++i) cin >> a[i];     sort(a.begin(), a.end());     reverse(a.begin(), a.end());     for (int i = 1; i < n; ++i) a[i] += a[i - 1];     vector<long long> odp(n, 0);     for (int i = 1; i <= n - 1; ++i) {       for (long long il = 1, pos = 0, w = 0; pos < n; pos += il, il *= i, ++w) {         odp[i] += w * a[mini(n - 1, pos + il - 1)];         if (pos != 0) odp[i] -= w * a[pos - 1];       }     }     int q;     cin >> q;     for (int i = 0; i < q; ++i) {       int k;       cin >> k;       k = mini(k, n - 1);       cout << odp[k] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9;   const long long INFLL = 2e18;   const int MOD = 1e8 + 7;   const int N = 4e5 + 10;   int fx[8] = {+0, +0, +1, -1, +1, +1, -1, -1};   int fy[8] = {+1, -1, +0, +0, +1, -1, +1, -1};   int timer;   int used[N];   int tin[N], low[N];   char bridge;   vector<int> g[N];   void dfsAP(int v, int p = -1) {     if (bridge) return;     used[v] = 1;     tin[v] = low[v] = ++timer;     for (int to : g[v]) {       if (p == to) continue;       if (!used[to]) {         dfsAP(to, v);         low[v] = min(low[v], low[to]);         if (tin[v] < low[to]) bridge = 1;       } else {         low[v] = min(low[v], tin[to]);       }     }     used[v] = 2;   }   void dfsCC(int v, int p = -1) {     used[v] = 1;     for (int to : g[v]) {       if (p == to) continue;       if (!used[to]) {         dfsCC(to, v);         printf( %d %d n , v, to);       } else if (used[to] == 1) {         printf( %d %d n , v, to);       }     }     used[v] = 2;   }   void solve(int n) {     dfsAP(1);     if (bridge) {       puts( 0 );       return;     }     fill(used, used + n + 1, 0);     dfsCC(1);   }   int main() {     int n, m, u, v;     scanf( %d %d , &n, &m);     for (int i = 0; i < m; ++i) {       scanf( %d %d , &u, &v);       g[u].push_back(v);       g[v].push_back(u);     }     solve(n);   }
#include <bits/stdc++.h>   using namespace std;   int main(int argc, char** argv) {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int a, b, c;       cin >> a >> b >> c;       int sum1 = a + b;       int cnt = 0;       while (sum1 <= c) {         if (a > b) swap(a, b);         a += b;         cnt++;         sum1 += b;       }       cout << cnt + 1 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int g[100000];   int res[100000];   int main() {     int N;     scanf( %d , &N);     ;     g[0] = 0;     g[1] = 0;     res[0] = res[1] = -1;     for (int(n) = 2; n < (int)N + 1; n++) {       set<int> s;       vector<int> v;       for (int i = 2; i * i <= 2 * n; i++) {         if ((2 * n) % i == 0) {           v.push_back(i);           v.push_back((2 * n) / i);         }       }       res[n] = -1;       for (__typeof(v).begin() it = v.begin(); it != v.end(); it++) {         int help = 2 * n / (*it) + *it - 1;         if (help % 2 == 0 && help / 2 >= *it && help / 2 < n) {           int num = 0;           for (int m = 0; m < *it; m++) {             num = num ^ g[help / 2 - m];           }           if (num == 0) {             res[n] = res[n] == -1 ? *it : min(res[n], *it);           }           s.insert(num);         }       }       int sol = 0;       while (s.find(sol) != s.end()) {         sol++;       }       g[n] = sol;     }     if (g[N] == 0) {       puts( -1 );     } else {       printf( %d n , res[N]);     }   }
#include <bits/stdc++.h>   using namespace std;   int n, type[100001], a[100001], lead[100001], cur[100001];   bool vs[100001];   void input() {     scanf( %d , &n);     for (int i = 1, _b = n; i <= _b; i++) scanf( %d , &type[i]);     int x;     memset(lead, 0, sizeof(lead));     memset(a, 0, sizeof(a));     for (int i = 1, _b = n; i <= _b; i++) {       scanf( %d , &x);       a[x] = i;       lead[x]++;     }   }   void dfs(int i) {     vs[i] = true;     if (type[i]) {       cur[i] = 1;       return;     }     if (lead[a[i]] != 1 && !type[a[i]]) return;     if (!vs[a[i]]) dfs(a[i]);     if (cur[a[i]]) cur[i] = cur[a[i]] + 1;   }   void process() {     memset(vs, false, sizeof(vs));     memset(cur, 0, sizeof(cur));     for (int i = 0, _b = n; i <= _b; i++)       if (lead[i] != 1 && !type[i]) vs[i] = true;     for (int i = 1, _b = n; i <= _b; i++) {       if (!vs[i]) dfs(i);     }     int ans = 0;     int st = 0;     for (int i = 1, _b = n; i <= _b; i++) {       if (ans < cur[i]) {         ans = cur[i];         st = i;       }     }     cout << ans << endl;     while (!type[st]) {       printf( %d  , st);       st = a[st];     }     cout << st;   }   int main() {     input();     process();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct stra {     int x, y, z;   } arr[100000];   bool cmp(stra a, stra b) { return a.x > b.x; }   bool cmp1(stra a, stra b) { return a.y < b.y; }   int n, k = 1, g = 1;   int main() {     std::ios::sync_with_stdio(false);     cin >> n;     for (int i = 0; i <= n - 1; i++) {       cin >> arr[i].x;       arr[i].y = i;     }     sort(arr, arr + n, cmp);     arr[0].z = 1;     for (int i = 1; i <= n - 1; i++) {       if (arr[i - 1].x != arr[i].x) {         k = i + 1;         arr[i].z = k;       } else {         arr[i].z = k;       }     }     sort(arr, arr + n, cmp1);     for (int i = 0; i <= n - 1; i++) {       cout << arr[i].z <<    ;     }   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   const long long N = 1e6 + 10;   const long double eps = 1e-9;   const long long inf = 1e18;   long long a[N], b[N], c[N], d[N];   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, k;     long long m;     cin >> n >> m >> k;     long long a[m];     for (long long i = 0; i < m; ++i) cin >> a[i];     long long s = 0, i = 0, j = 0, k1 = k;     while (j < m) {       while (a[j] <= k1 + i) j++;       if (i == j) {         s--;         k1 = ((a[j] - i) / k) * k;         if ((a[j] - i) % k) k1 += k;       }       i = j;       s++;     }     cout << s;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   double b[10], a[10], c[10] = {500, 1000, 1500, 2000, 2500};   double Max(double x, double y) { return x > y ? x : y; }   int main() {     int n, m1, m2, m3, m4, m5, i, j, k;     while (~scanf( %lf , &a[0])) {       for (i = 1; i < 5; i++) scanf( %lf , &a[i]);       for (i = 0; i < 5; i++) scanf( %lf , &b[i]);       double ans = 0;       for (i = 0; i < 5; i++) {         ans +=             Max(0.3 * c[i], (1 - (a[i] * 1.0 / (250 * 1.0))) * c[i] - 50 * b[i]);       }       int x, y;       scanf( %d %d , &x, &y);       ans += x * 100;       ans -= y * 50;       printf( %.0lf n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void s() { puts( Stannis ); }   void d() { puts( Daenerys ); }   int main() {     int n, k;     scanf( %d %d , &n, &k);     int odd = 0;     int even = 0;     long long tot = 0;     for (int i = 0; i < n; i++) {       int x;       scanf( %d , &x);       if (x % 2 == 0)         even++;       else         odd++;       tot += (long long)x;     }     int move = n - k;     if (n == k) {       if (tot % 2LL == 0) {         d();       } else {         s();       }     } else {       if (move % 2 == 1) {         if (move < odd && move < even) {           s();         } else {           if (move / 2 >= odd) {             d();           } else {             if (move / 2 >= even && ((move - even) + odd) % 2 == 0) {               d();             } else {               s();             }           }         }       } else {         if (move < odd && move < even) {           d();         } else {           if (move / 2 >= even && ((move - even) + odd) % 2 == 1) {             s();           } else {             d();           }         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 201110;   int lab[N], val[N];   vector<int> gr[N];   map<string, int> mp;   int n, m, q;   int root(int u) {     if (lab[u] < 0)       return u;     else       return lab[u] = root(lab[u]);   }   void join(int type, int u, int v) {     if (lab[u] < lab[v]) {       lab[u] += lab[v];       lab[v] = u;       for (int i = 0; i < gr[v].size(); i++) {         gr[u].push_back(gr[v][i]);         val[gr[v][i]] *= type;       }       gr[v].clear();     } else {       lab[v] += lab[u];       lab[u] = v;       for (int i = 0; i < gr[u].size(); i++) {         gr[v].push_back(gr[u][i]);         val[gr[u][i]] *= type;       }       gr[u].clear();     }   }   string read() {     char ch;     string ans =   ;     while (ch = getchar()) {       if ( a  <= ch && ch <=  z ) break;     }     ans = ans + ch;     while (ch = getchar()) {       if (ch <  a  || ch >  z ) break;       ans = ans + ch;     }     return ans;   }   int main() {     scanf( %d%d%d , &n, &m, &q);     int k = 0;     string st;     int type, u, v;     for (int i = 1; i <= n; i++) {       val[i] = 1;       gr[i].push_back(i);       st = read();       mp[st] = i;     }     memset(lab, 255, sizeof(lab));     for (int i = 1; i <= m; i++) {       scanf( %d , &type);       st = read();       u = mp[st];       st = read();       v = mp[st];       if (root(u) != root(v)) {         if ((val[u] == val[v] && type == 1) || (val[u] != val[v] && type == 2))           join(1, root(u), root(v));         else           join(-1, root(u), root(v));         puts( YES );       } else {         if ((val[u] != val[v] && type == 1) || (val[u] == val[v] && type == 2))           puts( NO );         else           puts( YES );       }     }     for (int i = 1; i <= q; i++) {       st = read();       u = mp[st];       st = read();       v = mp[st];       if (root(u) != root(v))         printf( 3 n );       else {         if (val[u] == val[v])           printf( 1 n );         else           printf( 2 n );       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 50;   deque<int> dq;   bool is[N], can[N];   vector<vector<int> > adj(N);   int n, m, d, cur, mx, ans[N], x;   void dfs(int u, int p) {     ans[u] = ans[p] + 1;     can[u] &= (ans[u] <= d);     if (ans[u] > mx && is[u]) mx = ans[u], x = u;     for (auto v : adj[u])       if (v != p) dfs(v, u);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> d;     ans[0] = -1;     memset(can, 1, sizeof can);     for (int i = 0; i < m; i++) cin >> x, is[x] = 1;     for (int i = 1, u, v; i < n; i++) {       cin >> u >> v;       adj[u].push_back(v);       adj[v].push_back(u);     }     dq.push_front(x);     while (dq.size()) {       int now = dq.front();       dfs(now, 0);       dq.pop_front();       if (now != x) dq.push_front(x);     }     int s = 0;     for (int i = 1; i <= n; i++) s += can[i];     cout << s;   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   const int MAXN = 100000;   int n;   int x[MAXN];   int ret[MAXN];   bool used[MAXN + 1];   void run() {     scanf( %d , &n);     for (int i = (0); i < (n); ++i) scanf( %d , &x[i]);     memset(ret, -1, sizeof(ret));     memset(used, false, sizeof(used));     for (int i = (0); i < (n); ++i)       if (1 <= x[i] && x[i] <= n && !used[x[i]]) ret[i] = x[i], used[x[i]] = true;     int at = 1;     for (int i = (0); i < (n); ++i)       if (ret[i] == -1) {         while (used[at]) ++at;         ret[i] = at++;       }     for (int i = (0); i < (n); ++i) {       if (i != 0) printf(   );       printf( %d , ret[i]);     }     puts(  );   }   int main() {     run();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T gcd(T a, T b) {     if (a < 0) return gcd(-a, b);     if (b < 0) return gcd(a, -b);     return (b == 0) ? a : gcd(b, a % b);   }   template <class T>   inline T lcm(T a, T b) {     if (a < 0) return lcm(-a, b);     if (b < 0) return lcm(a, -b);     return a * (b / gcd(a, b));   }   template <class T>   inline T sqr(T x) {     return x * x;   }   template <class T>   T power(T N, T P) {     return (P == 0) ? 1 : N * power(N, P - 1);   }   long long toInt64(string s) {     long long r = 0;     istringstream sin(s);     sin >> r;     return r;   }   double LOG(long long N, long long B) { return (log10l(N)) / (log10l(B)); }   string itoa(long long a) {     if (a == 0) return  0 ;     string ret;     for (long long i = a; i > 0; i = i / 10) ret.push_back((i % 10) + 48);     reverse(ret.begin(), ret.end());     return ret;   }   vector<string> token(string a, string b) {     const char *q = a.c_str();     while (count(b.begin(), b.end(), *q)) q++;     vector<string> oot;     while (*q) {       const char *e = q;       while (*e && !count(b.begin(), b.end(), *e)) e++;       oot.push_back(string(q, e));       q = e;       while (count(b.begin(), b.end(), *q)) q++;     }     return oot;   }   template <class T>   inline T __cin() {     T ret;     cin >> ret;     return ret;   }   int isvowel(char s) {     s = tolower(s);     if (s ==  a  || s ==  e  || s ==  i  || s ==  o  || s ==  u ) return 1;     return 0;   }   int isupper(char s) {     if (s >=  A  and s <=  Z ) return 1;     return 0;   }   int Set(int N, int pos) { return N = N | (1 << pos); }   int reset(int N, int pos) { return N = N & ~(1 << pos); }   int check(int N, int pos) { return (N & (1 << pos)); }   int toggle(int N, int pos) {     if (check(N, pos)) return N = reset(N, pos);     return N = Set(N, pos);   }   void pbit(int N) {     printf( ( );     for (int i = 10; i >= 0; i--) {       bool x = check(N, i);       cout << x;     }     puts( ) );   }   int main() {     int n = 9;     cin >> n;     long long ans = -1;     for (int i = max(n - 100, 1); i <= n; i++) {       for (int j = max(n - 100, 1); j <= n; j++) {         for (int k = max(n - 100, 1); k <= n; k++) {           long long lc = lcm((long long)i, lcm((long long)j, (long long)k));           ans = max(ans, lc);         }       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, j, line[35], column[35], var, count;     cin >> n;     for (i = 1; i <= n; ++i) line[i] = column[i] = 0;     for (i = 1; i <= n; ++i)       for (j = 1; j <= n; ++j) {         cin >> var;         line[i] += var;         column[j] += var;       }     count = 0;     for (i = 1; i <= n; ++i)       for (j = 1; j <= n; ++j) {         if (column[i] > line[j]) count++;       }     cout << count;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const int N = 1020;   int main() {     int n;     cin >> n;     if (n % 2 == 0) {       cout << -1 << endl;     } else {       cout << 0;       for (int i = 1; i < n; i++) {         cout <<     << i;       }       cout << endl;       cout << 0;       for (int i = 1; i < n; i++) {         cout <<     << i;       }       cout << endl;       cout << 0;       for (int i = 1; i < n; i++) {         cout <<     << (i + i) % n;       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int min(int a, int b) {     if (a <= b) {       return a;     } else {       return b;     }   }   int max(int a, int b) {     if (a >= b) {       return a;     } else {       return b;     }   }   int main() {     int l, r, a;     cin >> l >> r >> a;     int MAX, MIN;     int count;     MAX = max(l, r);     MIN = min(l, r);     MIN += a;     if (MIN > MAX) {       count = (2 * MAX) + ((MIN - MAX) / 2) * 2;     } else {       count = MIN * 2;     }     cout << count << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dp[1002][20002];   int main() {     ios_base::sync_with_stdio;     int n, m, x, y, i, j, a;     cin >> n;     long long ans = 0;     for (i = 1; i <= n; i++) {       cin >> a;       dp[i][10000 + a]++;       dp[i][10000 - a]++;       for (j = 0; j < a; j++) {         dp[i][j] = dp[i - 1][j + a];       }       for (j = 20000; j > 20000 - a; j--) {         dp[i][j] = dp[i - 1][j - a];       }       for (j = a; j <= 20000 - a; j++) {         dp[i][j] = (dp[i - 1][j - a] + dp[i - 1][j + a]) % 1000000007;       }       dp[i][10000 + a] = (dp[i][10000 + a] + 1) % 1000000007;       ;       dp[i][10000 - a] = (dp[i][10000 - a] + 1) % 1000000007;       ans = (ans + dp[i][10000]) % 1000000007;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 3;   int n;   vector<int> G[N];   int h[N], cnt[N];   int res = 0;   void dfs(int u, int p) {     cnt[h[u]]++;     for (int v : G[u])       if (v != p) {         h[v] = h[u] + 1;         dfs(v, u);       }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 1; i <= n - 1; ++i) {       int x;       cin >> x;       G[x].push_back(i + 1);     }     h[1] = 1;     dfs(1, 0);     for (int i = 1; i <= n; ++i) res += (cnt[i] % 2);     cout << res;   }