malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 157;   int f[N][N];   int main() {     int n;     scanf( %d , &n);     f[0][0] = 1;     f[1][0] = 0;     f[1][1] = 1;     for (int i = 2; i <= n; i++) {       for (int j = 0; j <= i - 2; j++) f[i][j] = f[i - 2][j];       for (int j = 0; j <= i - 1; j++) {         f[i][j + 1] = (f[i][j + 1] + f[i - 1][j]) & 1;       }     }     printf( %d n , n);     for (int i = 0; i <= n; i++) printf( %d%c , f[n][i], i == n ?   n  :    );     n--;     printf( %d n , n);     for (int i = 0; i <= n; i++) printf( %d%c , f[n][i], i == n ?   n  :    );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:64000000 )   int n;   pair<int, int> a[1 << 10];   int b[1 << 10];   int ans[1 << 10][1 << 10];   int len[1 << 10];   void answer(string s) {     puts(s.c_str());     if (s ==  NO ) exit(0);     for (int i = 0; i < n; ++i) {       for (int j = 0; j < len[i]; ++j) printf( %d , ans[i][j]);       puts(  );     }     exit(0);   }   void init() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d , &a[i].first);       a[i].second = i;     }     sort(a, a + n);   }   void add(int x) {     int dif = 1;     while (x >= 0 && dif) {       ++b[x];       dif = 0;       if (b[x] == 2) {         dif = 1;         b[x] = 0;       }       --x;     }     if (dif) answer( NO );   }   int main() {     init();     memset(b, 0, sizeof b);     for (int i = 0; i < n; ++i) {       int x = a[i].second;       len[x] = a[i].first;       for (int j = 0; j < a[i].first; ++j) {         ans[x][j] = b[j];       }       if (i == n - 1) break;       add(a[i].first - 1);     }     answer( YES );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const int MAX = 2e6 + 5;   int ftree[MAX] = {0};   int sum[MAX] = {0};   int query(int node) {     int sum = 0;     while (node > 0) {       sum += ftree[node];       node -= (node & -node);     }     return sum;   }   void update(int node, int diff, int &mx) {     while (node <= mx) {       ftree[node] += diff;       node += (node & -node);     }   }   int bsearch(int &n, int s) {     int l = 1;     int r = n;     while (l <= r) {       int m = (l + r) >> 1;       int p = query(m);       if (p < s)         l = m + 1;       else         r = m - 1;     }     return l;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     memset(ftree, 0, sizeof(ftree));     memset(sum, 0, sizeof(sum));     int n;     cin >> n;     for (int i = (1); i <= (n); ++i) {       update(i, 1, n);     }     int p;     for (int i = 0; i < (int)(n); ++i) {       cin >> p;       int less = query(p + 1) - 1;       sum[i] += less;       update(p + 1, -1, n);     }     for (int i = (1); i <= (n); ++i) {       update(i, 1, n);     }     for (int i = 0; i < (int)(n); ++i) {       cin >> p;       int less = query(p + 1) - 1;       sum[i] += less;       update(p + 1, -1, n);     }     for (int i = 0; i < n; ++i) {       int carry = sum[n - i - 1] / (i + 1);       sum[n - i - 2] += carry;       sum[n - i - 1] %= (i + 1);       update(i + 1, 1, n);     }     for (int i = 0; i < (int)(n); ++i) {       int f = bsearch(n, sum[i] + 1);       cout << (f - 1) <<    ;       update(f, -1, n);     }     cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int Maxn = 1000000;   const int Inf = 0x3f3f3f3f;   int n, m, k;   pair<int, int> edge[Maxn + 5];   int a[Maxn + 5];   map<pair<int, int>, int> mp;   int deg[Maxn + 5], sz[Maxn + 5], st[Maxn + 5], col[Maxn + 5];   vector<pair<int, int> > g[Maxn + 5];   int ans[Maxn + 5];   void match(int u, int fa, int from, int to) {     for (int i = 0; i < (int)g[u].size(); i++) {       if (g[u][i].first == from) {         g[u][i].first = to;         match(g[u][i].second, u, to, from);       }     }     for (int i = 0; i < (int)g[u].size(); i++) {       if (g[u][i].second == fa) {         g[u][i].first = from;       }     }   }   int main() {     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i <= n; i++) {       scanf( %*d );     }     for (int i = 1; i <= m; i++) {       int u, v;       scanf( %d%d , &u, &v);       if (u > v) {         swap(u, v);       }       edge[i] = make_pair(u, v + n);       deg[u]++;       deg[v + n]++;     }     n = (n << 1);     st[0] = 1;     for (int i = 1; i <= n; i++) {       sz[i] = (deg[i] - 1) / k + 1;       st[i] = st[i - 1] + sz[i - 1];     }     for (int i = 1; i <= m; i++) {       int u = edge[i].first, v = edge[i].second;       g[st[u]].push_back(make_pair(Inf, st[v]));       g[st[v]].push_back(make_pair(Inf, st[u]));       edge[i] = make_pair(st[u], st[v]);       mp[edge[i]] = i;       col[u]++;       col[v]++;       if (col[u] == k) {         st[u]++;         col[u] = 0;       }       if (col[v] == k) {         st[v]++;         col[v] = 0;       }     }     for (int i = 1; i <= m; i++) {       int u = edge[i].first, v = edge[i].second;       int pos_u = 0, pos_v = 0;       sort(g[u].begin(), g[u].end());       sort(g[v].begin(), g[v].end());       for (int j = 0; j < (int)g[u].size(); j++) {         if (j + 1 != g[u][j].first) {           pos_u = j + 1;           break;         }       }       for (int j = 0; j < (int)g[v].size(); j++) {         if (j + 1 != g[v][j].first) {           pos_v = j + 1;           break;         }       }       for (int j = 0; j < (int)g[u].size(); j++) {         if (g[u][j].second == v) {           g[u][j].first = pos_u;         }       }       match(v, u, pos_u, pos_v);     }     for (int i = 1; i <= st[n]; i++) {       for (int j = 0; j < (int)g[i].size(); j++) {         if (i < g[i][j].second) {           ans[mp[make_pair(i, g[i][j].second)]] = g[i][j].first;         }       }     }     for (int i = 1; i <= m; i++) {       printf( %d n , ans[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > vertices;   vector<pair<int, int> > edges;   int main() {     int v;     cin >> v;     int a, b;     queue<int> q;     for (int i = 0; i < v; i++) {       cin >> a >> b;       vertices.push_back(make_pair(a, b));       if (a == 1) {         q.push(i);       }     }     int size = v;     while (q.empty() == false) {       int i = q.front();       q.pop();       if (vertices[i].first == 1) {         int ver = vertices[i].second;         edges.push_back(make_pair(i, ver));         vertices[ver].first--;         vertices[ver].second ^= i;         if (vertices[ver].first == 1) {           q.push(ver);         }       }     }     cout << edges.size() << endl;     for (int i = 0; i < edges.size(); i++) {       cout << edges[i].first <<     << edges[i].second << endl;     }     return 0;   }
#include <bits/stdc++.h>   using std::max;   const int N = 3e5 + 5;   template <typename T>   void read(T &x) {     bool neg = false;     unsigned char c = getchar();     for (; (c ^ 48) > 9; c = getchar())       if (c ==  - ) neg = true;     for (x = 0; (c ^ 48) < 10; c = getchar()) x = (x << 3) + (x << 1) + (c ^ 48);     if (neg) x = -x;   }   struct line {     int next, to, w;   } e[2 * N];   int n, q, hd[N], cnt, a[N], b[N], fa[N], dep[N], siz[N], hc[N], top[N];   long long s[N], f[N], g[N], h[N], c[N], ff[N];   void adline(int u, int v, int w) {     e[cnt].to = v;     e[cnt].w = w;     e[cnt].next = hd[u];     hd[u] = cnt++;   }   void dfs1(int u) {     hc[u] = -1;     s[u] = s[fa[u]] + a[u] - b[u];     for (int i = hd[u]; ~i; i = e[i].next) {       int v = e[i].to;       if (v == fa[u]) continue;       fa[v] = u;       b[v] = e[i].w;       dep[v] = dep[u] + 1;       dfs1(v);       siz[u] += siz[v];       if (!~hc[u] || siz[v] > siz[hc[u]]) hc[u] = v;       f[u] += max(0ll, f[v] + a[v] - 2 * b[v]);     }     ++siz[u];   }   void dfs2(int u) {     long long sum = (ff[u] = f[u]) + g[u] + a[u];     h[u] = max(h[u], 0ll);     if (~hc[u]) {       int v = hc[u];       top[v] = top[u];       g[v] = max(0ll, sum - 2 * b[v] - max(0ll, h[v] = f[v] + a[v] - 2 * b[v]));       dfs2(v);     }     for (int i = hd[u]; ~i; i = e[i].next) {       int v = e[i].to;       if (v == fa[u] || v == hc[u]) continue;       g[v] = max(0ll, sum - 2 * b[v] - max(0ll, h[v] = f[v] + a[v] - 2 * b[v]));       dfs2(top[v] = v);     }   }   void dfs3(int u) {     for (int i = hd[u]; ~i; i = e[i].next) {       int v = e[i].to;       if (v == fa[u]) continue;       f[v] += f[u];       h[v] += h[u];       dfs3(v);     }   }   int lca(int u, int v) {     while (top[u] != top[v]) {       if (dep[top[u]] > dep[top[v]])         u = fa[top[u]];       else         v = fa[top[v]];     }     return dep[u] < dep[v] ? u : v;   }   int main() {     read(n);     read(q);     for (int i = 0, i_end = n; i < i_end; ++i) read(a[i]);     for (int i = 0, i_end = n; i < i_end; ++i) hd[i] = -1;     for (int i = 0, i_end = n - 1; i < i_end; ++i) {       int u, v, w;       read(u);       read(v);       read(w);       adline(--u, --v, w);       adline(v, u, w);     }     dfs1(0);     dfs2(0);     dfs3(0);     while (q--) {       int u, v, m;       long long ans;       read(u);       read(v);       --u, --v;       m = lca(u, v);       ans = s[u] + s[v] - 2 * s[m] + a[m];       ans += f[u] + f[v] - 2 * f[m] + g[m];       ans -= h[u] + h[v] - 2 * h[m] - ff[m];       printf( %lld n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string s[6] = { 170 ,  020 ,  200 ,  110 ,  050 ,  080 };   int main() {     int n;     cin >> n;     if (n < 3)       cout << -1;     else if (n == 3)       cout << 210;     else {       cout << 1;       for (int i = 0; i < n - 4; i++) cout << 0;       cout << s[n % 6];     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string s1[10], s2[10], score[10];   map<string, int> mp;   string name[10];   int a[10][10];   bool better(int x, int y) {     int n;     int sx = 0, px = 0, mx = 0, sy = 0, py = 0, my = 0;     for (n = 0; n < 4; n++)       if (n != x) {         if (a[x][n] > a[n][x])           sx += 3;         else if (a[x][n] == a[n][x])           sx++;         px += a[x][n];         mx += a[n][x];       }     for (n = 0; n < 4; n++)       if (n != y) {         if (a[y][n] > a[n][y])           sy += 3;         else if (a[y][n] == a[n][y])           sy++;         py += a[y][n];         my += a[n][y];       }     if (sx != sy) return (sx > sy);     if (px - mx != py - my) return (px - mx > py - my);     if (px != py) return (px > py);     return (x < y);   }   bool check(int x, int y) {     int n;     int b = mp[ BERLAND ];     int c;     int rank = 1;     for (n = 0; n < 4; n++)       if (n != b && a[b][n] == -1) c = n;     a[b][c] = x;     a[c][b] = y;     for (n = 0; n < 4; n++)       if (n != b && better(n, b)) rank++;     a[b][c] = -1, a[c][b] = -1;     return (rank <= 2);   }   int main() {     int i, j;     for (i = 0; i < 5; i++) {       cin >> s1[i] >> s2[i] >> score[i];     }     for (i = 0; i < 5; i++) mp[s1[i]] = mp[s2[i]] = 0;     i = 0;     for (__typeof((mp).begin()) itr = (mp).begin(); itr != (mp).end(); itr++) {       (itr->second) = i;       name[i] = (itr->first);       i++;     }     memset(a, -1, sizeof(a));     for (i = 0; i < 5; i++) {       int x = mp[s1[i]], y = mp[s2[i]];       for (j = 0; j < score[i].size(); j++)         if (score[i][j] ==  : ) score[i][j] =    ;       istringstream ss(score[i]);       ss >> a[x][y] >> a[y][x];     }     for (int diff = 1; diff < 100; diff++) {       for (int a = 0; a < 100; a++) {         int b = a + diff;         if (check(b, a)) {           cout << b <<  :  << a << endl;           return 0;         }       }     }     cout <<  IMPOSSIBLE  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace ::std;   const long double PI = acos(-1);   const long long MOD = 1000000000 + 7;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   long long add(long long a, long long b, long long m = MOD) {     if (a >= m) a %= m;     if (b >= m) b %= m;     if (a < 0) a += m;     if (b < 0) b += m;     long long res = a + b;     if (res >= m or res <= -m) res %= m;     if (res < 0) res += m;     return res;   }   long long mul(long long a, long long b, long long m = MOD) {     if (a >= m) a %= m;     if (b >= m) b %= m;     if (a < 0) a += m;     if (b < 0) b += m;     long long res = a * b;     if (res >= m or res <= -m) res %= m;     if (res < 0) res += m;     return res;   }   long long pow_mod(long long a, long long b, long long m = MOD) {     long long res = 1LL;     a = a % m;     while (b) {       if (b & 1) res = mul(res, a, m);       b >>= 1;       a = mul(a, a, m);     }     return res;   }   long long fastexp(long long a, long long b) {     long long res = 1LL;     while (b) {       if (b & 1) res = res * a;       b >>= 1;       a *= a;     }     return res;   }   int gcdExtendido(int a, int b, int *x, int *y) {     if (a == 0) {       *x = 0;       *y = 1;       return b;     }     int x1, y1;     int gcd = gcdExtendido(b % a, a, &x1, &y1);     *x = y1 - (b / a) * x1;     *y = x1;     return gcd;   }   int modInverso(int a, int m) {     int x, y;     int g = gcdExtendido(a, m, &x, &y);     if (g != 1)       return -1;     else       return (x % m + m) % m;   }   const int M = 300000 + 5;   int N, n, m;   vector<int> G[M];   map<pair<int, int>, int> E;   void clearAll() {     for (int i = 1; i <= n; i++) {       G[i].clear();     }   }   int main() {     int t;     scanf( %d , &(t));     int a, b;     while (t--) {       scanf( %d %d , &(N), &(m));       n = N + N + N;       bool forest = true;       E.clear();       vector<bool> used(n + 1, false);       vector<int> matching;       for (int i = 1; i <= m; i++) {         scanf( %d %d , &(a), &(b));         if (a > b) swap(a, b);         G[a].emplace_back(b);         G[b].emplace_back(a);         E[make_pair(a, b)] = i;       }       for (int u = 1; u <= n; u++) {         if (used[u]) continue;         for (int i = 0; i < G[u].size(); i++) {           int v = G[u][i];           if (!used[v]) {             matching.emplace_back(E[make_pair(min(u, v), max(u, v))]);             used[u] = used[v] = true;             break;           }         }       }       if (matching.size() >= N) {         puts( Matching );         for (int i = 0; i < N; i++) {           printf( %d%c , matching[i], (i + 1 == N ?   n  :    ));         }       } else {         puts( IndSet );         int cnt = N;         for (int i = 1; i <= n; i++) {           if (cnt == 0) break;           if (!used[i]) {             cnt -= 1;             printf( %d%c , i, (cnt ?     :   n ));           }         }       }       if (t) clearAll();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, f = 0;     cin >> n;     for (int i = 1; i < 50; i++) {       if ((i * (i + 1)) / 2 == n) {         f = 1;         break;       }       if (i > n) break;     }     if (f)       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long long MAXN = 1e5 + 3;   const long long inf = 2e9;   long long max(long long a, long long b) {     if (a > b)       return a;     else       return b;   }   long long min(long long a, long long b) {     if (a < b)       return a;     else       return b;   }   long long dx[] = {1, -1, 0, 0};   long long dy[] = {0, 0, -1, 1};   bool cmp(pair<long long, long long> p1, pair<long long, long long> p2) {     if (p1.first < p2.first)       return true;     else if (p1.first == p2.first) {       if (p1.second < p2.second) return true;       return false;     }     return false;   }   void solve() {     long long n;     cin >> n;     long long li, ri, di;     for (long long i = (long long)0; i < (long long)n; ++i) {       cin >> li >> ri >> di;       long long t1 = li / di;       long long t2 = ri / di;       if (li % di == 0) t1--;       t2++;       if (t1 >= 1)         cout << di <<   n ;       else         cout << t2 * di <<   n ;     }   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long nT = 1;     for (long long i = (long long)1; i <= (long long)nT; ++i) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   struct node {     int c, h, i;     friend bool operator<(const node &a, const node &b) {       if (a.c != b.c) return a.c < b.c;       return a.h > b.h;     }   } t[N];   struct node2 {     int s, t, i, size;     friend bool operator<(const node2 &a, const node2 &b) {       return a.size > b.size;     }   } prepare[N];   int n, ss[N], rest[N], cnt, ans1, ans2;   long long sum[N], Max;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d %d , &t[i].c, &t[i].h);       t[i].i = i;     }     sort(t + 1, t + n + 1);     for (int i = 1; i <= n; i++) {       int s = 0, j;       for (j = i + 1; t[j].c == t[i].c && j <= n; j++)         ;       ss[++cnt] = j - i;       prepare[cnt].s = i, prepare[cnt].t = j;       prepare[cnt].i = cnt, prepare[cnt].size = j - i;       i = j - 1;     }     sort(prepare + 1, prepare + cnt + 1);     for (int i = 1; i <= cnt; i++) rest[i] = prepare[i].size;     for (int p = cnt, s = 0; p > 1;) {       int delta = 10000000;       for (int i = p; i > 0; i--) delta = min(delta, rest[i]);       for (int i = p; i > 0; i--) {         for (int j = 1; j <= delta; j++) sum[i] += t[prepare[i].s + s + j - 1].h;         rest[i] -= delta;       }       s += delta;       for (int i = p; i > 0; i--)         if (rest[i] > 0) sum[i] += t[prepare[i].s + s].h;       int p1 = 0, p2 = 0;       for (int i = p; i > 0; i--)         if (sum[i] > sum[p1])           p2 = p1, p1 = i;         else if (sum[i] == sum[p1])           p2 = i;         else if (sum[i] > sum[p2])           p2 = i;       if (sum[p1] + sum[p2] > Max) Max = sum[p1] + sum[p2], ans1 = p1, ans2 = p2;       for (int i = p; i > 0; i--)         if (rest[i] > 0) sum[i] -= t[prepare[i].s + s].h;       while (rest[p] == 0 && p > 0) p--;     }     cout << Max << endl;     if (ss[prepare[ans1].i] == ss[prepare[ans2].i]) {       printf( %d n , ss[prepare[ans1].i] * 2);       for (int i = 1; i < ss[prepare[ans1].i]; i++)         printf( %d %d  , t[prepare[ans1].s + i - 1].i,                t[prepare[ans2].s + i - 1].i);       printf( %d %d n , t[prepare[ans1].t - 1].i, t[prepare[ans2].t - 1].i);     } else {       if (ss[prepare[ans1].i] > ss[prepare[ans2].i]) swap(ans1, ans2);       printf( %d n%d , ss[prepare[ans1].i] * 2 + 1, t[prepare[ans2].s].i);       for (int i = 1; i <= ss[prepare[ans1].i]; i++)         printf(  %d %d , t[prepare[ans1].s + i - 1].i, t[prepare[ans2].s + i].i);       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct congressman {     int votes;     int last_vote;     int nr_of_order;     bool operator<(const congressman &other) const {       if (votes == other.votes) return last_vote > other.last_vote;       return votes < other.votes;     };   } v[105];   int n, k, m, a, pos[105];   bool elected(int i) {     int better = n - i;     int t = m - a;     for (int j = i - 1; j >= 1; j--)       if (t >= v[i].votes - v[j].votes + 1)         t -= v[i].votes - v[j].votes + 1, better++;       else         break;     return (better < k && v[i].votes != 0);   }   bool notelectible(int i) {     int last = i;     for (int j = i + 1; j <= n; j++)       if (v[i].votes + m - a > v[j].votes)         last = j;       else         break;     if (v[i].votes + m - a == 0) return 1;     return (last < n - k + 1);   }   int main() {     int i, j;     cin >> n >> k >> m >> a;     for (i = 1; i <= a; i++) {       cin >> j;       v[j].votes++;       v[j].last_vote = max(v[j].last_vote, i);     }     for (i = 1; i <= n; i++) v[i].nr_of_order = i;     sort(v + 1, v + n + 1);     for (i = 1; i <= n; i++) pos[v[i].nr_of_order] = i;     for (i = 1; i <= n; i++) {       int r = 0;       if (elected(pos[i]))         r = 1;       else if (notelectible(pos[i]))         r = 3;       else         r = 2;       cout << r <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a[100100];     vector<vector<int> > b1;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     if (n < 3) {       cout << 0;       return 0;     }     for (int i = a[1] - 1; i <= a[1] + 1; i++) {       for (int j = a[2] - 1; j <= a[2] + 1; j++) {         vector<int> a1(n + 1, 0);         a1[1] = i;         a1[2] = j;         int k = j - i, b = 0;         for (int j = 3; j <= n; j++) {           a1[j] = a1[j - 1] + k;           if (abs(a1[j] - a[j]) > 1) {             b = 1;             break;           }         }         if (b == 1) continue;         b1.push_back(a1);       }     }     int k = 0, min1 = 1000000;     for (int i = 0; i < b1.size(); i++) {       k = 0;       for (int j = 1; j <= n; j++) {         if (a[j] != b1[i][j]) k++;       }       min1 = min(k, min1);     }     if (b1.size() == 0)       cout << -1;     else       cout << min1;   }
#include <bits/stdc++.h>   #pragma warning(disable : 4996)   using namespace std;   const int N = (int)(2e6 + 20);   const int L = 1 << 6;   const long long int M = (long long int)(1e9 + 7);   const double E = 1e-7;   int a[N];   int main() {     ios_base::sync_with_stdio(0);     long long int n, m;     cin >> n >> m;     int tm = m;     if (n > 3) {       int f = 0, l = n - 1;       m--;       vector<int> v(n - 1);       for (int i = 0; i < n - 1; ++i) {         v[i] = m & 1;         m /= 2;       }       for (int i = 0; i < n - 1; ++i) {         if (v[n - i - 2])           a[l--] = i + 1;         else           a[f++] = i + 1;       }       a[f] = n;       for (int i = 0; i < n; ++i) cout << a[i] <<    ;       cout << endl;       return 0;     }     m = tm;     long long int maxV = 0;     vector<int> v(n);     for (int i = 0; i < n; ++i) v[i] = i + 1;     do {       long long int curV = 0;       for (int i = 0; i < n; ++i) {         int minV = v[i];         for (int j = i; j < n; ++j) {           minV = min(minV, v[j]);           curV += minV;         }       }       maxV = max(curV, maxV);     } while (next_permutation(v.begin(), v.end()));     for (int i = 0; i < n; ++i) v[i] = i + 1;     int cnt = 0;     do {       long long int curV = 0;       for (int i = 0; i < n; ++i) {         int minV = v[i];         for (int j = i; j < n; ++j) {           minV = min(minV, v[j]);           curV += minV;         }       }       if (curV == maxV) {         ++cnt;       }       if (cnt == m && true) {         for (int i = 0; i < n; ++i) cout << v[i] <<    ;         return 0;       }     } while (next_permutation(v.begin(), v.end()));     cout << cnt;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2020;   vector<int> g[MAXN];   int maxDep = -1;   void DFS(int v, int depth) {     if (depth > maxDep) maxDep = depth;     for (int i = 0; i < g[v].size(); i++) DFS(g[v][i], depth + 1);   }   int main() {     int n, a;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a;       if (a != -1) g[i].push_back(a);     }     for (int i = 1; i <= n; i++) DFS(i, 1);     cout << maxDep << endl;     return 0;   }