malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int a[100005], n, sum = 0, tp = 0, ans = -(1 << 30);   int main() {     scanf( %d , &n);     for (register int i = 1; i <= n; ++i) scanf( %d , &a[i]), sum += a[i];     for (register int i = 1; i <= n; ++i)       if (tp + a[i] < 0)         tp = 0;       else         ans = max(ans, tp + a[i]), tp += a[i];     ans = max(0, ans);     printf( %d n , max(ans * 2 - sum, sum));   }
#include <bits/stdc++.h>   using namespace std;   using namespace std;   const int MaxN = 100005, NA = -1, MaxC = 0x3F3F3F3F;   int a[MaxN];   int b[MaxN], c[MaxN];   bool f[MaxN];   int d, e, g, m, n;   int main(void) {     int i;     while (scanf(  %d %d , &n, &m) != EOF) {       memset(b, 0, sizeof(b));       memset(c, 0, sizeof(c));       d = e = 0;       for (i = 1; i <= n; i++) {         scanf(  %d , &a[i]);         if (a[i] > 0)           d++, b[abs(a[i])]++;         else           e++, c[abs(a[i])]++;       }       memset(f, 0, sizeof(f));       g = 0;       for (i = 1; i <= n; i++)         if (b[i] + e - c[i] == m) g++, f[i] = true;       assert(g > 0);       for (i = 1; i <= n; i++)         if (a[i] > 0) {           if (!f[abs(a[i])])             printf( Lie n );           else if (g > 1)             printf( Not defined n );           else             printf( Truth n );         } else {           if (!f[abs(a[i])])             printf( Truth n );           else if (g > 1)             printf( Not defined n );           else             printf( Lie n );         }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dp[5000 + 1][5000 + 1];   int f[5000 + 1][5000 + 1];   int a[5000 + 1];   int N, Q;   int main() {     int i, j, len;     cin >> N;     for (i = 1; i <= N; i++) cin >> a[i];     for (i = 1; i <= N; i++) dp[i][i] = f[i][i] = a[i];     for (len = 2; len <= N; len++)       for (i = 1; i <= N - len + 1; i++) {         j = i + len - 1;         f[i][j] = f[i + 1][j] ^ f[i][j - 1];         dp[i][j] = max(f[i][j], max(dp[i + 1][j], dp[i][j - 1]));       }     cin >> Q;     while (Q--) {       cin >> i >> j;       cout << dp[i][j] <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 0x3f3f3f3f;   const double PI = acos(-1.0);   const double eps = 1e-10;   const long long M = 1e9 + 7;   const long long N = 1e5 + 5;   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     while (t--) {       long long a, b, c, s[5];       cin >> a >> b >> c;       long long minx = INF;       for (long long i = 1; i <= 11000; i++) {         for (long long j = i; j <= 11000; j += i) {           for (long long k = j; k <= 11000; k += j) {             long long tmp = abs(a - i) + abs(b - j) + abs(c - k);             if (tmp < minx) {               minx = tmp;               s[1] = i;               s[2] = j;               s[3] = k;             }           }         }       }       cout << minx << endl;       cout << s[1] <<     << s[2] <<     << s[3] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   const int K = 12;   int n, k, q;   int arr[K][N];   int who[N][K];   int nrr[N * K][K];   int siz;   vector<int> lol[N];   int when[1 << K];   int parent[N * K];   bitset<1 << K> bit[N + K];   int idx[N * K];   int main() {     scanf( %d %d %d , &n, &k, &q);     for (int i = 0; i < k; ++i) {       for (int j = 0; j < n; ++j) {         scanf( %d , &arr[i][j]);       }     }     for (int i = 0; i < n; ++i) {       vector<int> tmp;       for (int j = 0; j < k; ++j) {         tmp.emplace_back(arr[j][i]);       }       sort(tmp.begin(), tmp.end());       for (int j = 0; j < k; ++j) {         for (int x = 0; x < k; ++x) {           nrr[siz][x] = (arr[x][i] > tmp[j]);         }         who[i][j] = siz;         ++siz;       }       lol[i].swap(tmp);     }     memset(when, -1, sizeof(when));     for (int i = 0; i < siz; ++i) {       int mask = 0;       for (int j = 0; j < k; ++j) {         if (nrr[i][j]) {           mask |= 1 << j;         }       }       parent[i] = when[mask];       if (when[mask] == -1) {         when[mask] = i;       }     }     int cnt = 0;     for (int i = 0; i < siz; ++i) {       if (parent[i] == -1) {         idx[i] = cnt++;       }     }     for (int i = 0; i < siz; ++i) {       if (parent[i] != -1) {         continue;       }       parent[i] = i;       for (int j = 0; j < k; ++j) {         if (nrr[i][j]) {           bit[j].set(idx[i]);         }       }     }     int who = k;     while (q--) {       int type, x, y;       scanf( %d %d %d , &type, &x, &y);       if (type == 1) {         bit[who] = bit[x - 1] | bit[y - 1];         ++who;       } else if (type == 2) {         bit[who] = bit[x - 1] & bit[y - 1];         ++who;       } else {         int ans = lol[y - 1][k - 1];         ;         for (int j = 0; j < k; ++j) {           int idx = ::idx[parent[::who[y - 1][j]]];           if (!bit[x - 1].test(idx)) {             ans = min(ans, lol[y - 1][j]);           }         }         printf( %d n , ans);       }     }   }
#include <bits/stdc++.h>   using namespace std;   void fastio() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);   }   long long int suma(long long int n) {     long long int temp = n;     long long int sum1 = 0;     while (temp != 0) {       sum1 += (temp % 10);       temp = temp / 10;     }     return sum1;   }   int main() {     fastio();     long long int q;     cin >> q;     while (q--) {       long long int n;       cin >> n;       unordered_map<long long int, long long int> mp, count;       std::vector<long long int> arr(n);       for (long long int i = 0; i < n; i++) {         cin >> arr[i];         mp[arr[i]]++;       }       priority_queue<long long int> pq;       for (auto it = mp.begin(); it != mp.end(); it++) pq.push(it->second);       long long int sum = 0;       while (!pq.empty()) {         if (count[pq.top()] == 0) {           count[pq.top()]++;           sum += pq.top();           pq.pop();         } else {           long long int temp = pq.top();           pq.pop();           if (temp > 1) pq.push(temp - 1);         }       }       cout << sum << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     int m;     int sum = 0;     int a[100005];     int rec[100005] = {0};     cin >> n >> m;     for (int i = 0; i < m; i++) {       cin >> a[i];     }     for (int i = 0; i < m; i++) {       int ss = a[i];       if (rec[ss] == 0) {         rec[ss]++;         sum++;         if (sum == n) {           cout << 1;           for (int j = 1; j <= n; j++) {             rec[j]--;             if (rec[j] == 0) {               sum--;             }           }         } else {           cout << 0;         }       } else {         rec[ss]++;         cout << 0;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int pow(int a, int k) {     if (k == 0) return 1;     int r = pow(a, k / 2);     if (k % 2 == 0) return r * r;     return r * r * a;   }   int main() {     int n, ans = 1;     scanf( %d , &n);     for (int i = 1; (pow(2, i) - 1) * pow(2, i - 1) <= n; i++) {       int v = (pow(2, i) - 1) * pow(2, i - 1);       if (n % v == 0) ans = v;     }     printf( %d , ans);   }
#include <bits/stdc++.h>   const double pi = acos(-1.0);   const int max_n = 1e5 + 5;   template <class Q>   void getint(Q &res, char ch = getchar()) {     while (!isdigit(ch) && ch !=  - ) ch = getchar();     bool flag = true;     if ( -  == ch) flag = false, ch = getchar();     for (res = 0; isdigit(ch); ch = getchar()) res = res * 10 + ch - 48;     if (!flag) res = -res;   }   void putint(int x) {     int i = 0, a[10];     bool flag = true;     if (x < 0) {       flag = false;       x = -x;     } else if (x == 0) {       a[i++] = 0;     }     while (x > 0) {       a[i++] = x % 10;       x /= 10;     }     if (flag == false) putchar( - );     for (int j = i - 1; j >= 0; --j) putchar(a[i] + 48);   }   int mmax(int a, int b) { return a > b ? a : b; }   int mmin(int a, int b) { return a < b ? a : b; }   int gcd(int a, int b) {     while (b) {       b ^= a ^= b ^= a %= b;     }     return a;   }   int n;   char s[1005], t[1005];   int a[10], b[10];   int main() {     std::cin >> n;     std::cin >> s >> t;     for (int i = 0; i < n; ++i) {       a[t[i] -  0 ]++;       b[t[i] -  0 ]++;     }     int ans1 = 0, ans2 = 0;     for (int i = 0; i < n; ++i) {       int f = 0;       for (int j = s[i] -  0 ; j <= 9; ++j) {         if (a[j] > 0) {           a[j]--;           f = 1;           break;         }       }       if (f == 0) ans1++;       for (int j = s[i] -  0  + 1; j <= 9; ++j) {         if (b[j] > 0) {           b[j]--;           ans2++;           break;         }       }     }     std::cout << ans1 << std::endl << ans2;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int sz, n;     cin >> sz >> n;     int sx, sy, tx, ty;     cin >> sx >> sy >> tx >> ty;     vector<vector<pair<int, int>>> g(n + 2);     g[n].emplace_back(n + 1, abs(tx - sx) + abs(ty - sy));     vector<int> x(n), y(n);     for (int i = 0; i < n; i++) {       cin >> x[i] >> y[i];       g[n].emplace_back(i, min(abs(x[i] - sx), abs(y[i] - sy)));       g[i].emplace_back(n + 1, abs(tx - x[i]) + abs(ty - y[i]));     }     vector<int> order(n);     iota(order.begin(), order.end(), 0);     for (int rot = 0; rot < 2; rot++) {       sort(order.begin(), order.end(), [&](int i, int j) { return x[i] < x[j]; });       for (int z = 0; z < n - 1; z++) {         int i = order[z];         int j = order[z + 1];         g[i].emplace_back(j, x[j] - x[i]);         g[j].emplace_back(i, x[j] - x[i]);       }       swap(x, y);     }     priority_queue<pair<int, int>> q;     vector<int> dist(n + 2, (int)2e9);     dist[n] = 0;     q.emplace(0, n);     while (!q.empty()) {       auto pr = q.top();       q.pop();       int expected = -pr.first;       int v = pr.second;       if (dist[v] != expected) {         continue;       }       for (const auto& pr : g[v]) {         int to = pr.first;         int cost = pr.second;         if (dist[v] + cost < dist[to]) {           dist[to] = dist[v] + cost;           q.emplace(-dist[to], to);         }       }     }     cout << dist[n + 1] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int DBG = 0, INF = int(1e9);   int main() {     ios_base::sync_with_stdio(0);     cout.setf(ios::fixed);     int n;     cin >> n;     vector<int> a(n);     for (auto& x : a) cin >> x;     int mx = *max_element(a.begin(), a.end());     for (int q = 0; q < mx; ++q) {       for (int i = 0; i < n; ++i) {         if (a[i] > 0) {           cout <<  P ;           --a[i];         }         if (i < n - 1) cout <<  R ;       }       for (int i = 0; i < n - 1; ++i) cout <<  L ;     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int f[8000];   char s[8000];   int main() {     scanf( %s , s);     int n = strlen(s), m = n;     if (s[0] ==  *  || s[0] ==  / ) {       puts( 0 );       return 0;     }     f[m] = 1;     for (int i = 0; i < n; i++)       if (!isdigit(s[i]))         if (s[i + 1] ==  *  || s[i + 1] ==  /  || i == n - 1) {           puts( 0 );           return 0;         } else           m--;       else if (!isdigit(s[i + 1]))         for (int j = m + n; j > m; j--) f[j - 1] = (f[j - 1] + f[j]) % 1000003;     printf( %d n , f[m]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     string str1, str2, ans1, ans2;     cin >> str1 >> str2;     ans1 = str1;     ans2 = str2;     cout << ans1 <<     << ans2 << endl;     cin >> n;     while (n--) {       cin >> str1 >> str2;       if (str1 == ans1) {         ans1 = str2;       } else         ans2 = str2;       cout << ans1 <<     << ans2 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       if (n == 1) {         int x;         cin >> x;         cout <<  YES ;       } else {         vector<int> a(n);         bool flag = true;         cin >> a[0];         for (int i = 1; i < n; ++i) {           cin >> a[i];           if ((a[i] % 2) != (a[i - 1] % 2)) {             flag = false;           }         }         if (flag) {           cout <<  YES ;         } else {           cout <<  NO ;         }       }       cout <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     long long n, k;     cin >> n >> k;     vector<long long> ans(n);     set<pair<long long, long long>> demid;     for (int i = 0; i < k; i++) {       long long s, m;       cin >> s >> m;       demid.insert({s + m, i});     }     for (int i = 0; i < n - k; i++) {       long long s, m;       pair<long long, long long> now;       cin >> s >> m;       now = *demid.begin();       demid.erase(demid.begin());       ans[now.second] = now.first;       demid.insert({max(s, now.first) + m, i + k});     }     while (demid.size()) {       pair<long long, long long> now;       now = *demid.begin();       demid.erase(demid.begin());       ans[now.second] = now.first;     }     for (int i = 0; i < n; i++) {       cout << ans[i] << endl;     }     return 0;   }
#include <bits/stdc++.h>   int main() {     long int n;     scanf( %ld , &n);     long int a[n + 1], i, sum = 0;     for (i = 0; i < n; i++) {       scanf( %ld , &a[i]);       sum = sum + a[i];     }     if (sum % n == 0) {       printf( %ld n , n);     } else {       printf( %ld n , n - 1);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 100;   long long a[N], f[N], g[N], r1, r2, r3, d;   int n;   long long nkb() { return min(r1, r2); }   long long cnkb(int i) { return min(r2, r1 * a[i] + nkb()); }   long long clear_go(int i) {     return min(r1 * a[i] + r3, cnkb(i) + d + d + nkb());   }   void Solve() {     cin >> n >> r1 >> r2 >> r3 >> d;     r1 = min(r1, r3);     for (int i = 1; i <= n; ++i) cin >> a[i];     for (int i = 1; i <= n; ++i) f[i] = 1e18;     f[0] = 0;     f[1] = clear_go(1);     for (int i = 2; i <= n; ++i) {       f[i] = f[i - 1] + clear_go(i) + d;       if (i > 1) {         f[i] = min(f[i], f[i - 2] + cnkb(i - 1) + d + cnkb(i) + d + nkb() + d +                              nkb() + d * (i != 2));       }     }     g[n + 1] = 0;     g[n] = clear_go(n);     for (int i = n - 1; i >= 1; --i) {       g[i] = g[i + 1] + 2ll * d + min(cnkb(i) + nkb(), clear_go(i));     }     long long ans = min(g[1], f[n]);     for (int i = 1; i < n; ++i) {       ans = min(ans, f[i] + d + g[i + 1]);     }     cout << ans <<   n ;   }   int main() {     int test = 1;     while (test--) Solve();   }
#include <bits/stdc++.h>   using namespace std;   int gcd(long long a, long long b) {     if (b == 0) {       return a;     } else {       return gcd(b, a % b);     }   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     ;     long long i, j, k, n, m, t = 1;     cin >> t;     while (t--) {       string s;       cin >> s;       n = s.size();       map<char, long long> make_pair;       long long mx = INT_MIN;       for (i = 0; i < n; i++) {         make_pair[s[i]]++;       }       for (char c =  0 ; c <=  9 ; c++) {         if (make_pair[c] > mx) {           mx = make_pair[c];         }       }       for (char c1 =  0 ; c1 <  9 ; c1++) {         for (char c2 = c1 + 1; c2 <=  9 ; c2++) {           k = 0;           char prev =  $ ;           for (i = 0; i < n; i++) {             if (s[i] == c1) {               if (prev == c2) {                 prev = c1;                 k++;               } else if (prev ==  $ ) {                 prev = c1;                 k++;               }             } else if (s[i] == c2) {               if (prev == c1) {                 prev = c2;                 k++;               } else if (prev ==  $ ) {                 prev = c2;                 k++;               }             }           }           if (k > mx && k % 2 == 0) {             mx = k;           } else if ((k - 1) > mx && (k - 1) % 2 == 0) {             mx = k - 1;           }         }       }       cout << s.size() - mx << endl;     }     return 0;   }
#include <bits/stdc++.h>   struct point {     int x, y;     inline point operator+(const point &a) const { return {x + a.x, y + a.y}; }     inline point operator-(const point &a) const { return {x - a.x, y - a.y}; }     inline int operator^(const point &a) const { return x * a.x + y * a.y; }     inline int operator*(const point &a) const { return x * a.y - y * a.x; }     inline bool operator<(const point &a) const {       return x == a.x ? y > a.y : x < a.x;     }   };   void input(point *arr, int n) {     for (int i = 0; i < n; i++) scanf( %d%d , &arr[i].x, &arr[i].y);   }   void convex_hull(point *vec, int n, point *res, int &tp) {     tp = 0;     std::sort(vec, vec + n);     for (int i = 0; i < n; i++) {       while (tp >= 2 && (res[tp - 1] - vec[i]) * (res[tp - 2] - vec[i]) >= 0)         tp--;       res[tp++] = vec[i];     }     int orig = tp--;     for (int i = n - 1; i >= 0; i--) {       while (tp > orig && (res[tp - 1] - vec[i]) * (res[tp - 2] - vec[i]) >= 0)         tp--;       res[tp++] = vec[i];     }     tp--;   }   point edge[40005];   int ecnt;   void get_edge(point *arr, int l, int r) {     edge[ecnt++] = {l, r};     if (r - l + 1 <= 2) return;     double mx = -1e18;     int pos = -1;     for (int i = l + 1; i < r; i++) {       double d = (double)((arr[i] - arr[l]) ^ (arr[i] - arr[r]));       d /= (arr[l] - arr[i]) * (arr[l] - arr[r]);       if (d > mx) {         mx = d;         pos = i;       }     }     get_edge(arr, l, pos);     get_edge(arr, pos, r);   }   bool solve(point *A, int n, point *b, int m) {     static point a[40005];     convex_hull(A, n, a, n);     ecnt = 0;     get_edge(a, 0, n - 1);     for (int j = 0; j < ecnt; j++) {       int l = edge[j].x, r = edge[j].y;       double lp = -1e18, rp = 1e18;       for (int i = 0; i < n && lp < rp; i++) {         if (i == l || i == r) continue;         int x = (a[i] - a[l]) ^ (a[i] - a[r]);         int y = (a[l] - a[i]) * (a[l] - a[r]);         if (!y) continue;         double t = (double)x / y;         if (y < 0)           rp = std::min(rp, t);         else           lp = std::max(lp, t);       }       for (int i = 0; i < m && lp < rp; i++) {         int x = (b[i] - a[l]) ^ (b[i] - a[r]);         int y = (a[l] - b[i]) * (a[l] - a[r]);         if (!y) {           if (x > 0) continue;           if (x <= 0) {             lp = 1e18;             break;           }         }         double t = (double)x / y;         if (y > 0)           rp = std::min(rp, t);         else           lp = std::max(lp, t);       }       if (lp < rp) return true;     }     return false;   }   point a[40005], b[40005];   int main() {     int n, m;     scanf( %d%d , &n, &m);     input(a, n);     input(b, m);     if (n == 1 || m == 1) {       puts( YES );       return 0;     }     puts(solve(a, n, b, m) || solve(b, m, a, n) ?  YES  :  NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 5e6 + 10;   const int mod = 998244353;   long long a[maxn], b[maxn], n, m, sum1, sum2, res1, res2;   long long dp[3030][3030];   inline long long qm(long long a, long long b, long long res = 1) {     for (a %= mod; b; b >>= 1, a = a * a % mod)       if (b & 1) res = res * a % mod;     return res;   }   int main() {     scanf( %I64d%I64d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %I64d , &a[i]);     }     for (int i = 1; i <= n; i++) {       scanf( %I64d , &b[i]);       if (a[i] == 1)         sum1 += b[i];       else         sum2 += b[i];     }     dp[1][1] = sum1 * qm(sum1 + sum2, mod - 2) % mod;     dp[1][0] = sum2 * qm(sum1 + sum2, mod - 2) % mod;     for (int i = 1; i < m; i++) {       for (int j = 0; j <= i; j++) {         int tmp = i - j;         dp[i + 1][j + 1] =             (dp[i + 1][j + 1] +              dp[i][j] * (sum1 + j) % mod * qm(sum1 + sum2 + j - tmp, mod - 2)) %             mod;         dp[i + 1][j] = (dp[i + 1][j] + dp[i][j] * max(0LL, sum2 - tmp) % mod *                                            qm(sum1 + sum2 + j - tmp, mod - 2)) %                        mod;       }     }     for (int i = 0; i <= m; i++) {       res1 = (res1 + dp[m][i] * (sum1 + i) % mod) % mod;       res2 = (res2 + dp[m][i] * max(0LL, sum2 - m + i) % mod) % mod;     }     for (int i = 1; i <= n; i++) {       if (a[i]) {         printf( %I64d n , res1 * b[i] % mod * qm(sum1, mod - 2) % mod);       } else {         printf( %I64d n , res2 * b[i] % mod * qm(sum2, mod - 2) % mod);       }     }   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   const T& max(const T& a, const T& b, const T& c) {     return max(a, max(b, c));   }   template <class T>   const T& min(const T& a, const T& b, const T& c) {     return min(a, min(b, c));   }   struct sp {     bool operator()(const pair<string, int>& a, const pair<string, int>& b) {       if (a.second != b.second) {         return (a.second > b.second);       }       return (a.first < b.first);     }   };   long long stoi(string& str) {     istringstream second(str);     long long i;     second >> i;     return i;   }   string itos(long long i) {     stringstream second;     second << i;     return second.str();   }   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }   long long poww(long long a, long long b) {     long long res = 1;     for (int i = 1; i <= b; i++) res *= a;     return res;   }   long long sumOfDigs(string s) {     long long sum = 0;     for (int i = 0; i < s.length(); i++) sum += s[i] -  0 ;     return sum;   }   long long mod = 1000000007;   using namespace std;   long long a[100001];   int fn(int x) {     if (x == 0)       return 0;     else if (x & 1) {       return (fn(x >> 1) + 1);     } else       return fn(x >> 1);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     ;     int n;     cin >> n;     int x;     for (int i = 1; i <= n; i++) {       cin >> x;       a[fn(x)]++;     }     long long s = 0;     for (int i = 0; i < 100001; i++) {       if (a[i] > 1) {         s += (a[i] * (a[i] - 1)) / 2;       }     }     cout << s << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int ms = 1001000;   bool hole[ms];   int main() {     std::ios_base::sync_with_stdio(false);     std::cin.tie(NULL);     long long n, m, k;     cin >> n;     if (n == 1 || n == 2) {       cout << 0;       return 0;     }     cout << (n + 1) / 2 - 1;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int i, x, ans, num, n, fa[2001];     while (scanf( %d , &n) != EOF) {       for (i = 1; i <= n; i++) {         scanf( %d , &fa[i]);       }       ans = 1;       for (i = 1; i <= n; i++) {         num = 1;         x = i;         while (fa[x] != -1) {           num++;           x = fa[x];         }         if (num > ans) ans = num;       }       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   const double eps = 1e-12;   int n, k, h;   struct lemming {     int w, v, id;     bool operator<(const lemming &rhs) const {       if (w != rhs.w) return w < rhs.w;       return v < rhs.v;     }   } a[maxn];   vector<int> ans;   int dcmp(double x) {     if (fabs(x) < eps) return x;     return x > 0 ? 1 : -1;   }   bool ok(double t) {     vector<int> v;     for (int i = 1, j = 1; i <= n; i++) {       if (dcmp(t - (double)h * j / a[i].v) < 0) continue;       v.emplace_back(a[i].id);       j++;       if (j > k) break;     }     if (v.size() < k) return 0;     ans = v;     return 1;   }   int main() {     scanf( %d %d %d , &n, &k, &h);     for (int i = 1; i <= n; i++) scanf( %d , &a[i].w), a[i].id = i;     for (int i = 1; i <= n; i++) scanf( %d , &a[i].v);     sort(a + 1, a + 1 + n);     double l = 0, r = 1e9;     for (int i = 0; i < 150; i++) {       double mid = (l + r) / 2;       if (ok(mid))         r = mid;       else         l = mid;     }     for (auto i : ans) printf( %d  , i);   }