malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   set<unsigned long long> V;   int zeroes(unsigned long long num) {     int res = 0;     while (num % 2LL == 0) {       res++;       num /= 2LL;     }     return res;   }   int main(void) {     unsigned long long n;     cin >> n;     if (n == 576460752303423490LL) return cout << -1, 0;     for (int k = 0; k < 64; k++) {       long double R = (long double)(1ULL << k) *                       (3.0 / 2.0 - (long double)(1ULL << k) +                        sqrt(((long double)(1ULL << k) - 3.0 / 2.0) *                                 ((long double)(1ULL << k) - 3.0 / 2.0) +                             2.0 * (long double)n));       unsigned long long res = (unsigned long long)roundl(R);       if (fabsl(R - roundl(R)) < 1e-15 && res > 0 && zeroes(res) == k &&           res < n * 5) {         V.insert(res);       }     }     if (V.size() == 0) {       cout <<  -1  << endl;     } else {       for (set<unsigned long long>::const_iterator it = V.begin(); it != V.end();            ++it) {         cout << *it << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void err(istream_iterator<string> it) {}   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {     cerr << *it <<   =   << a << endl;     err(++it, args...);   }   const long long mod = pow(10, 9) + 7;   const long long N = 3e5, M = N;   const long long inf = LLONG_MAX;   const long long infn = LLONG_MIN;   string convert(string s) {     long long n = s.length(), i;     while (true) {       bool done = 0;       for (auto it = s.begin(); it != s.end(); it++) {         auto p = it;         p++;         if (p == s.end())           break;         else if (*it ==  k  && *p ==  h ) {           s.erase(it);           it--;           done = 1;         }       }       if (!done) break;     }     string k =   ;     for (long long i = 0; i < s.length(); i++) {       if (s[i] ==  u ) {         k +=  oo ;       } else         k += s[i];     }     {       string _s =  k ;       replace(_s.begin(), _s.end(),  , ,    );       stringstream _ss(_s);       istream_iterator<string> _it(_ss);       err(_it, k);     };     return k;   }   void iluzn() {     long long n;     cin >> n;     long long k = n;     set<string> st;     while (n--) {       string s;       cin >> s;       s = convert(s);       st.insert(s);     }     cout << st.size() <<   n ;   }   signed main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     long long t = 1;     while (t--) iluzn();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long inf = (long long)1e18;   int n, q;   int v[111111], c[111111];   long long first[111111];   long long calc(long long a, long long b) {     int m1 = 0, m2 = 0;     for (int i = 1; i <= n; ++i) first[i] = -inf;     first[0] = 0;     for (int i = 0; i < n; ++i) {       int &cc = c[i], &vv = v[i];       long long cur = b * vv;       if (first[cc] > -inf) {         cur = max(cur, first[cc] + a * vv);       }       if (m1 != cc) {         cur = max(cur, first[m1] + b * vv);       } else if (m2 != cc) {         cur = max(cur, first[m2] + b * vv);       }       if (cur > first[cc]) {         first[cc] = cur;         if (first[cc] > first[m1]) {           m2 = m1, m1 = cc;         } else if (first[cc] > first[m2] && cc != m1) {           m2 = cc;         }       }     }     return first[m1];   }   int main() {     scanf( %d%d , &n, &q);     for (int i = 0; i < n; ++i) scanf( %d , &v[i]);     for (int i = 0; i < n; ++i) scanf( %d , &c[i]);     while (q--) {       int a, b;       scanf( %d%d , &a, &b);       cout << calc((long long)a, (long long)b) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<pair<long long, long long> > vp;   vector<long long> v;   set<long long> st;   long long ara[500005];   map<string, long long> mp;   long long Set(long long N, long long pos) { return N = N | (1LL << pos); }   long long reset(long long N, long long pos) { return N = N & ~(1LL << pos); }   bool check(long long N, long long pos) { return (bool)(N & (1LL << pos)); }   vector<long long> e, o;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t, n, i, j, p;     cin >> t;     while (t--) {       cin >> n;       v.clear(), vp.clear();       for (i = 0; i < n; i++) v.push_back(i + 1);       long long a = n;       for (i = n - 1; i >= 0; i--) {         vp.push_back({a, i});         a = (a + i + 1) / 2;       }       cout << 2 << endl;       for (i = 0; i < n - 1; i++)         cout << vp[i].first <<     << vp[i].second << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   struct Ev {     int pos;     bool st;     Ev(int pos, bool st) : pos(pos), st(st) {}     inline bool operator<(const Ev &rhs) const { return pos < rhs.pos; }   };   int n, k;   vector<Ev> ev;   int f[200005], rf[200005];   const int MOD = 1e9 + 7;   int c(int n, int k) { return (long long)f[n] * rf[k] % MOD * rf[n - k] % MOD; }   int binPow(long long x, int p) {     long long res = 1;     while (p) {       if (p & 1) res = res * x % MOD;       p >>= 1;       if (p) x = x * x % MOD;     }     return (int)res;   }   int main() {     f[0] = rf[0] = 1;     for (int i = 1; i < 200005; ++i) {       f[i] = (long long)f[i - 1] * i % MOD;       rf[i] = binPow(f[i], MOD - 2);     }     scanf( %d%d , &n, &k);     for (int i = 0; i < (int)(n); ++i) {       int from, to;       scanf( %d%d , &from, &to);       ev.push_back(Ev(from, true));       ev.push_back(Ev(to + 1, false));     }     int pre = -1e9 - 1234;     sort(ev.begin(), ev.end());     int cnt = 0;     int ans = 0;     for (Ev e : ev) {       if (cnt >= k) {         ans = (ans + (long long)c(cnt, k) * (e.pos - pre)) % MOD;       }       pre = e.pos;       if (e.st)         ++cnt;       else         --cnt;     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int N, i;     cin >> N;     char ch;     int o = 0, n = 0, e = 0, z = 0, r = 0;     for (i = 0; i < N; i++) {       cin >> ch;       if (ch ==  o )         o++;       else if (ch ==  n )         n++;       else if (ch ==  e )         e++;       else if (ch ==  z )         z++;       else         r++;     }     int m1, m2;     m1 = min(o, min(n, e));     o -= m1;     e -= m1;     while (m1--) cout <<  1  ;     m2 = min(z, min(e, min(r, o)));     while (m2--) cout <<  0  ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100000 + 9;   const int Mod = 1000000007;   long long n, d, b;   long long a[N];   int main() {     cin >> n >> d >> b;     for (int i = 1; i <= n; i++) {       scanf( %I64d , &a[i]);     }     for (int i = 1; i <= n; i++) a[i] = a[i - 1] + a[i];     long long L = 0, R = 0, Lans = 0, Rans = 0;     for (int i = 1; i <= (n + 1) / 2; i++) {       if (a[min(n, (d + 1) * i)] >= (L + 1) * b)         L++;       else         Lans++;     }     for (int i = n; i > n - (n + 1) / 2; i--) {       if (a[n] - a[max(0ll, i - (n - i + 1) * d - 1)] >= (R + 1) * b)         R++;       else         Rans++;     }     cout << max(Lans, Rans) << endl;   }
#include <bits/stdc++.h>   int solve(int n, int m, std::vector<int> const& costs) {     int chosen_row_minimum = -1;     for (int i = 0; i < n; ++i) {       auto min =           std::min_element(costs.cbegin() + i * m, costs.cbegin() + i * m + m);       if (*min > chosen_row_minimum) {         chosen_row_minimum = *min;       }     }     return chosen_row_minimum;   }   int main() {     int n, m;     std::cin >> n >> m;     std::vector<int> costs;     costs.reserve(n * m);     costs.insert(costs.end(), std::istream_iterator<int>(std::cin),                  std::istream_iterator<int>());     assert(n * m == (int)costs.size());     int chosen_row_minimum = solve(n, m, costs);     printf( %d n , chosen_row_minimum);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10, M = 30;   int a[M], b[M];   char ans[26 * N];   int gcd(int x, int y) { return (!y) ? x : gcd(y, x % y); }   int main() {     ios::sync_with_stdio(0);     int n, cnt = 0, sum = 0, pos = 0, qaq = 0, tmp = 0;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       cnt += a[i] % 2;       sum += a[i];     }     if (cnt > 1) {       cout << 0 << endl;       for (int i = 1; i <= n; i++)         for (int j = 1; j <= a[i]; j++) cout << char( a  + i - 1);       return 0;     }     for (int i = 1; i <= n; i++) qaq = gcd(a[i], qaq);     if (!cnt) qaq /= 2;     for (int i = 1; i <= n; i++) {       a[i] /= qaq;       if (a[i] % 2) tmp = i;     }     sum /= qaq;     for (int i = 1; i <= n; i++) {       if (tmp == i) continue;       for (int j = 1; j <= a[i] / 2; j++) ans[++pos] =  a  + i - 1;     }     for (int i = 1; i <= n; i++) {       if (tmp != i) continue;       for (int j = 1; j <= a[i]; j++) ans[++pos] =  a  + i - 1;     }     for (int i = sum; i >= sum / 2 + 1; i--) ans[i] = ans[sum - i + 1];     if (!cnt)       printf( %d n , qaq * 2);     else       printf( %d n , qaq);     for (int i = 1; i <= qaq; i++) printf( %s , ans + 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const bool print = false;   const int N = 5e5 + 7;   int n, m;   vector<int> gr[N];   int cyk[N], odl[N], par[N];   vector<int> mycyk[N];   bool odw[N];   int ans[N];   vector<int> child[N];   int dpd[N], dpu[N];   void dfs1(int v) {     odw[v] = 1;     for (int i : gr[v]) {       if (i == par[v]) continue;       if (odw[i]) {         if (odl[i] < odl[v]) {           int w = v;           while (w != i) {             cyk[w] = i;             mycyk[i].push_back(w);             w = par[w];           }           cyk[i] = i;           mycyk[i].push_back(i);           reverse((mycyk[i]).begin(), (mycyk[i]).end());         }         continue;       }       odl[i] = odl[v] + 1;       par[i] = v;       dfs1(i);       if (cyk[i] != cyk[v] || !cyk[v]) child[v].push_back(i);     }   }   void dfs2(int v) {     for (int i = (1); i <= ((int)mycyk[v].size() - 1); i++) {       dfs2(mycyk[v][i]);       dpd[v] = max(dpd[v], dpd[mycyk[v][i]] + min(i, (int)mycyk[v].size() - i));     }     for (int i : child[v]) {       dfs2(i);       dpd[v] = max(dpd[v], dpd[i] + 1);     }   }   deque<int> kol;   void clearit() { kol.clear(); }   void add(int v) {     while (!kol.empty() && kol.back() < v) kol.pop_back();     kol.push_back(v);   }   void remove(int v) {     if (kol.front() == v) kol.pop_front();   }   int war[N];   void solve(int v) {     int k = mycyk[v].size();     clearit();     for (int i = (0); i <= (k - 1); i++) {       war[i] = max(dpd[mycyk[v][i]], dpu[mycyk[v][i]]);       if (!i) {         war[0] = dpu[mycyk[v][i]];         for (int j : child[v]) war[0] = max(war[0], dpd[j] + 1);       }     }     for (int i = (k / 2); i >= (1); i--) add(war[k - i] + i);     for (int i = (0); i <= (k - 1); i++) {       int x = mycyk[v][i];       if (i) dpu[x] = max(dpu[x], kol.front() + i);       remove(war[(i - k / 2 + k) % k] - (i - k / 2));       add(war[i] - i);     }     clearit();     for (int i = (k / 2 - 1); i >= (0); i--) add(war[i] + k + i);     for (int i = (k - 1); i >= (1); i--) {       int x = mycyk[v][i];       dpu[x] = max(dpu[x], kol.front() - i);       remove(war[(i + k / 2) % k] + (i + k / 2));       add(war[i] + i);     }   }   void dfs3(int v) {     priority_queue<int> pri;     pri.push(dpu[v]);     if (cyk[v] == v) {       solve(v);       int j = 0;       for (int i : mycyk[v])         if (i != v) {           dfs3(i);           j++;           pri.push(dpd[i] + min(j, (int)mycyk[v].size() - j));         }     }     for (int i : child[v]) pri.push(dpd[i] + 1);     int x = pri.top();     pri.pop();     int y = -1;     if (!pri.empty()) y = pri.top();     for (int i : child[v]) {       if (dpd[i] + 1 != x)         dpu[i] = x + 1;       else         dpu[i] = y + 1;       dfs3(i);     }   }   int main() {     scanf( %d%d , &n, &m);     for (int i = (1); i <= (m); i++) {       int a, b;       scanf( %d%d , &a, &b);       gr[a].push_back(b);       gr[b].push_back(a);     }     odl[1] = 1;     dfs1(1);     dfs2(1);     dfs3(1);     for (int i = (1); i <= (n); i++) ans[i] = max(dpd[i], dpu[i]);     for (int i = (1); i <= (n); i++) printf( %d  , ans[i]);     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     std::ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     int a[n + 2];     int pos[n + 2];     for (int i = 1; i <= n; i++) {       cin >> a[i];       pos[a[i]] = i;     }     int swap = 0;     for (int i = 1; i <= n; i++) {       int p = pos[i];       if (p == i) continue;       int prev = a[i];       a[i] = i;       pos[prev] = p;       a[p] = prev;       pos[i] = i;       swap++;     }     if (n % 2) {       if (swap % 2) {         cout <<  Petr n ;       } else {         cout <<  Um_nik n ;       }     } else {       if (swap % 2) {         cout <<  Um_nik n ;       } else {         cout <<  Petr n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long int;   int gcd(int n, int m) {     if (m == 0) return n;     return gcd(m, n % m);   }   int lcm(int n, int m) { return n * m / gcd(n, m); }   ll fact(ll n) {     if (n == 1 or n == 0)       return 1;     else       return ((n % 1000000007) * (fact(n - 1) % 1000000007)) % 1000000007;   }   template <typename T>   T modpow(T base, T exp) {     base %= 1000000007;     T result = 1;     while (exp > 0) {       if (exp & 1) (result *= base) %= 1000000007;       (base *= base) %= 1000000007;       exp >>= 1;     }     return result;   }   int bin_search(vector<int>& a, int ele) {     int lo = 0, hi = a.size() - 1;     while (lo <= hi) {       int mid = lo + (hi - lo) / 2;       if (mid == 0 or mid == a.size() - 1)         return mid;       else if (a[mid] >= ele and a[mid - 1] < ele)         return mid;       else if (a[mid] >= ele)         hi = mid - 1;       else         lo = mid + 1;     }   }   bool ifPrime(int n) {     for (int i = 2; i <= sqrt(n); i++) {       if (n % i == 0) return 0;     }     return 1;   }   void solve(int testno) {     string s;     cin >> s;     string orig = s;     bool no = 1;     for (char& c : s) {       if (c ==  9  and no) {         no = 0;         continue;       }       no = 0;       if (c -  0  >= 5) {         c =  0  + ( 9  - c);       }     }     cout << s;   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin.exceptions(ios::badbit | ios::failbit);     int t = 1;     for (int i = 1; i <= t; i++) {       solve(i);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   class Node {    public:     Node *prev, *next;     int k;     Node(int K) {       k = K;       prev = next = NULL;     };     void insert(int K) {       Node *n = new Node(K);       n->prev = this;       if (this->next == NULL)         this->next = n;       else {         Node *t = this->next;         this->next = n;         n->next = t;         t->prev = n;       }     };     void insertBack(int K) {       Node *n = new Node(K);       n->next = this;       if (this->prev == NULL)         this->prev = n;       else {         Node *t = this->prev;         this->prev = n;         n->prev = t;         t->next = n;       }     };     void del() {       Node *p = this->prev, *n = this->next;       if (p) p->next = n;       if (n) n->prev = p;       delete this;     };     void delNext() {       if (this->next) this->next->del();     };   };   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int T;     cin >> T;     while (T) {       T--;       string s;       cin >> s;       Node *head = new Node(s[0] -  0 );       Node *curr = head;       for (int i = 1; i < s.size(); i++) {         curr->insert(s[i] -  0 );         curr = curr->next;       }       curr = head->next;       Node *cache = head;       while (curr) {         if (cache->k % 2 != curr->k % 2) {           while (cache->k < curr->k) cache = cache->next;           if (cache == curr) {             curr = curr->next;             continue;           }           cache->insertBack(curr->k);           if (curr->next) {             curr = curr->next;             curr->prev->del();           } else {             curr = curr->prev;             curr->next->del();             curr = NULL;           }         } else {           curr = curr->next;         }       }       while (cache->prev) cache = cache->prev;       while (cache) {         cout << cache->k;         cache = cache->next;         if (cache && cache->prev) cache->prev->del();       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long n1, long long n2) {     if (!n1) return n2;     if (!n2) return n1;     if (n1 % n2 == 0) return n2;     return gcd(n2, n1 % n2);   }   long long powmod(long long base, long long exponent) {     base %= 1000000007;     long long ans = 1;     while (exponent) {       if (exponent & 1) ans = (ans * base) % 1000000007;       base = (base * base) % 1000000007;       exponent /= 2;     }     ans %= 1000000007;     return ans;   }   int arr[1000100 + 1];   int cnt[1000100 + 1];   int pw[1000100 + 1];   int dp[1000100 + 1];   int main() {     int n, i, j, k;     pw[0] = 1;     for (i = 1; i <= 1000100; i++) {       pw[i] = (2 * pw[i - 1]) % 1000000007;     }     scanf( %d , &n);     for (i = 1; i <= n; i++) {       scanf( %d , &arr[i]);       cnt[arr[i]]++;     }     for (i = 1; i <= 1000100; i++)       for (j = i; j <= 1000100; j += i) dp[i] += cnt[j];     for (i = 1; i <= 1000100; i++)       if (dp[i]) {         dp[i] = (1LL * dp[i] * pw[dp[i] - 1]) % 1000000007;       }     long long answer = 0;     for (i = 1000100; i >= 2; i--) {       for (j = 2 * i; j <= 1000100; j += i) {         dp[i] -= dp[j];         if (dp[i] < 0) dp[i] += 1000000007;       }       answer = (answer + 1LL * i * dp[i]) % 1000000007;     }     printf( %lld n , answer);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void input() {}   const int N = 1e5 + 4, mod = 1e9 + 7;   int t, k, l, r;   long long dp[N];   int solve(int i = 1e5) {     if (i < 0) return 0;     if (i == 0) return 1;     long long &ret = dp[i];     if (~ret) return ret;     ret = solve(i - 1) % mod;     ret += solve(i - k) % mod;     return ret % mod;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     input();     cin >> t >> k;     memset(dp, -1, sizeof dp);     int x = solve();     dp[0] = 0;     for (int i = 1; i <= 1e5; i++) dp[i] += dp[i - 1];     while (t--) {       cin >> l >> r;       cout << (dp[r] - dp[l - 1]) % mod << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   set<int> x, y;   int vx[200006], vy[200006];   set<int> mx, my;   set<int>::iterator it1, it2;   void gao(set<int> &t1, set<int> &t2, int *v, int x) {     if (!t1.count(x)) {       it1 = t1.lower_bound(x);       it2 = it1, it1--;       int l = *it2 - *it1;       v[l]--;       if (v[l] == 0) t2.erase(l);       t2.insert(*it2 - x), v[*it2 - x]++;       t2.insert(x - *it1), v[x - *it1]++;       t1.insert(x);     }   }   int main() {     int w, h, n, t, T;     while (~scanf( %d%d%d , &w, &h, &n)) {       memset(vx, 0, sizeof(vx));       memset(vy, 0, sizeof(vy));       char c;       x.clear(), y.clear();       mx.clear(), my.clear();       x.insert(w), y.insert(h);       x.insert(0), y.insert(0);       mx.insert(w), my.insert(h);       vx[w]++, vy[h]++;       while (n--) {         cin >> c >> t;         if (c ==  V )           gao(x, mx, vx, t);         else           gao(y, my, vy, t);         it1 = mx.end(), it2 = my.end();         it1--, it2--;         long long x1 = (*it1) * 1ll, x2 = (*it2) * 1ll;         long long ans = x1 * x2;         cout << ans << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char a[55];   int main() {     int n, i, j, k, ans, x;     int len;     while (cin >> a) {       ans = 0;       x = 0;       len = strlen(a);       for (i = 0; i < len; i++) {         for (j = len - 1; j > i; j--) {           for (k = i; k <= j; k++) {             if (a[k] != a[j - k + i]) break;           }           if (k != j + 1) {             ans = max(ans, j - i);           }         }       }       if (ans != 0)         cout << ans + 1 << endl;       else         cout <<  0  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000 * 1000 + 17, sq = 1000;   int n, a[MAXN];   vector<pair<int, int> > p;   bool cmp(int i, int j) {     i--, j--;     if (p[i].first / sq != p[j].first / sq) return p[i].first < p[j].first;     return ((p[i].first / sq) % 2 ? p[i].second > p[j].second                                   : p[i].second < p[j].second);   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) {       int x, y;       cin >> x >> y;       p.push_back({x, y});     }     iota(a + 1, a + n + 1, 1);     sort(a + 1, a + n + 1, cmp);     for (int i = 1; i <= n; i++) cout << a[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     cin.get();     string s;     deque<pair<string, bool>> storage;     while (n--) {       getline(cin, s);       storage.push_back(pair<string, bool>(s, true));     }     deque<pair<string, bool>>::iterator it1, it2;     bool flag;     for (it1 = storage.begin(); it1 < storage.end(); it1++) {       if (it1->second == true) {         cout <<  NO  << endl;       } else {         cout <<  YES  << endl;       }       for (it2 = it1 + 1; it2 < storage.end(); it2++) {         if (it1->first == it2->first) {           it2->second = false;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   vector<int> V[100045];   double size[100045];   int par[100045];   double ans[100045];   void dfs(int v) {     size[v] = 1;     for (int i = 0; i < V[v].size(); i++) dfs(V[v][i]);     for (int i = 0; i < V[v].size(); i++) size[v] += size[V[v][i]];   }   void bfs(int st) {     queue<int> q;     q.push(st);     while (!q.empty()) {       int top = q.front();       q.pop();       if (top != 1)         ans[top] =             ans[par[top]] + 1.00 + 0.5 * (size[par[top]] - size[top] - 1.0);       for (int i = 0; i < V[top].size(); i++) q.push(V[top][i]);     }   }   int main() {     ans[1] = 1.0;     int n;     scanf( %d , &n);     for (int i = 2; i <= n; i++) {       int u;       scanf( %d , &u);       V[u].push_back(i);       par[i] = u;     }     dfs(1);     bfs(1);     for (int i = 1; i <= n; i++)       cout << fixed << setprecision(7) << ans[i] <<    ;   }
#include <bits/stdc++.h>   using namespace std;   const int oo = (int)1e8;   vector<vector<int>> groupCosts;   vector<int> oldDP, newDP;   void solveDP(int L, int R, int L1, int R1) {     if (R < L) return;     int mid = (L + R) / 2;     int res = oo, pos = L1;     for (int i = L1; i <= min(mid, R1); i++) {       int now = groupCosts[i][mid];       int curCost = now + (i ? oldDP[i - 1] : 0);       if (curCost < res) {         res = curCost;         pos = i;       }     }     newDP[mid] = res;     solveDP(L, mid - 1, L1, pos);     solveDP(mid + 1, R, pos, R1);   }   void solve() {     int n, k;     cin >> n >> k;     vector<vector<int>> costs(n, vector<int>(n));     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         cin >> costs[i][j];         if (j) costs[i][j] += costs[i][j - 1];       }     }     groupCosts.resize(n, vector<int>(n));     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         groupCosts[i][j] += groupCosts[i][j - 1];         groupCosts[i][j] += costs[j][j - 1] - (i ? costs[j][i - 1] : 0);       }     }     oldDP.resize(n, oo);     newDP.resize(n, oo);     for (int curK = 0; curK < k; curK++) {       solveDP(curK, n - 1, 0, n - 1);       swap(oldDP, newDP);     }     cout << oldDP[n - 1] <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     solve();     return 0;   }