malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   vector<unsigned int> vc;   unsigned long long n, T;   void LIS(unsigned int ll, unsigned int hh, unsigned long long &len,            unsigned long long &offset) {     vector<unsigned int> dp_nn;     vector<unsigned int> dp_nn_plus_n;     dp_nn.resize(ll);     dp_nn_plus_n.resize(hh);     for (unsigned int i = 0; i < hh; ++i) dp_nn_plus_n[i] = 1;     for (unsigned int i = 0; i < ll; ++i) dp_nn[i] = 1;     for (unsigned int i = 0; i < hh; ++i) {       for (unsigned int j = 0; j < i; ++j) {         if (vc[i % n] >= vc[j % n]) {           dp_nn_plus_n[i] = max(dp_nn_plus_n[i], dp_nn_plus_n[j] + 1);           if (i < ll) dp_nn[i] = max(dp_nn[i], dp_nn[j] + 1);         }       }     }     sort(dp_nn_plus_n.begin(), dp_nn_plus_n.end());     sort(dp_nn.begin(), dp_nn.end());     unsigned long long h = dp_nn_plus_n[dp_nn_plus_n.size() - 1];     unsigned long long l = dp_nn[dp_nn.size() - 1];     offset = h - l;     len = l;     return;   }   int main() {     cin >> n >> T;     for (unsigned long long i = 0; i < n; ++i) {       unsigned int x;       cin >> x;       vc.push_back(x);     }     unsigned long long mx = max(n, T);     unsigned long long mn = min(n, T);     unsigned long long lim = mn * n + n;     unsigned long long delta = 0;     unsigned long long L = 0;     LIS(mn * n, lim, L, delta);     unsigned long long pad = (mx - n) * delta;     cout << L + pad << endl;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> fail(string s) {     int n = s.size();     vector<int> z(n);     int l = 0, r = 0;     for (int i = 1; i < n; ++i) {       if (i <= r) z[i] = min(z[i - l], r - i + 1);       while (z[i] + i < n && s[z[i] + i] == s[z[i]]) ++z[i];       if (z[i] + i - 1 > r) {         l = i;         r = z[i] + i - 1;       }     }     return z;   }   string s;   vector<int> z;   vector<pair<int, int> > ans;   int A[100005];   int main() {     ios_base::sync_with_stdio(false);     cout.tie(0);     cin.tie(0);     int n, m, i, j, k, x, y;     cin >> s;     z = fail(s);     n = s.size();     z[0] = n;     for (i = 0; i < n; ++i) A[z[i]]++;     for (i = n - 1; i >= 0; --i) A[i] += A[i + 1];     for (i = n - 1; i >= 0; --i) {       if (z[i] == (n - i)) {         ans.push_back(make_pair(z[i], A[z[i]]));       }     }     sort(ans.begin(), ans.end());     cout << ans.size() << endl;     for (auto it : ans) {       cout << it.first <<     << it.second << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     function<long long(long long, long long)> power = [&](long long x,                                                           long long y) {       if (y == 0) {         return 1LL;       } else {         long long z = power(x, y / 2);         return y % 2 == 0 ? (z * z) % 998244353                           : ((z * z) % 998244353 * x) % 998244353;       }     };     auto div = [&](long long x) { return power(x, 998244353 - 2); };     long long n, m;     cin >> n >> m;     vector<bool> a((size_t)n);     vector<long long> w((size_t)n);     for (long long i = 0; i < n; i++) {       long long v;       cin >> v;       a[i] = v == 1;     }     for (long long i = 0; i < n; i++) {       cin >> w[i];     }     long long zeros = 0, ones = 0;     for (long long i = 0; i < n; i++) {       if (a[i]) {         ones += w[i];       } else {         zeros += w[i];       }     }     map<tuple<bool, long long, long long, long long, long long>, long long> dp;     function<long long(bool, long long, long long, long long, long long)> f =         [&](bool q, long long b, long long z, long long o, long long j) {           if (j >= m) {             return b;           }           auto it = dp.find({q, b, z, o, j});           if (it != dp.end()) {             return it->second;           }           long long r = 0;           if (q) {             r += b * f(q, b + 1, z, o, j + 1);             r += z * f(q, b, z - 1, o, j + 1);             r += o * f(q, b, z, o + 1, j + 1);           } else {             r += b * f(q, b - 1, z, o, j + 1);             r += z * f(q, b, z - 1, o, j + 1);             r += o * f(q, b, z, o + 1, j + 1);           }           r %= 998244353;           r *= div(b + z + o);           r %= 998244353;           return dp[{q, b, z, o, j}] = r;         };     for (long long i = 0; i < n; i++) {       cout << f(a[i], w[i], a[i] ? zeros : zeros - w[i],                 a[i] ? ones - w[i] : ones, 0)            << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char buf[1000][1005];   int main() {     int N;     scanf( %d , &N);     int T[N];     pair<int, int> T2[N];     for (int i = 0; i < (N); i++) {       scanf( %d , &T[i]);       T2[i].first = T[i];       T2[i].second = i;     }     sort(T2, T2 + N);     if (T2[0].first == 0) {       printf( NO n );       return 0;     }     for (int i = 0; i < (T2[0].first); i++) buf[0][i] =  0 ;     buf[0][T2[0].first] = 0;     for (int i = 1; i < N; i++) {       for (int j = 0; j < (T2[i - 1].first); j++) buf[i][j] = buf[i - 1][j];       int k = T2[i - 1].first - 1;       while (k >= 0 && buf[i][k] ==  1 ) {         buf[i][k] =  0 ;         k--;       }       if (k < 0) {         printf( NO n );         return 0;       }       buf[i][k] =  1 ;       for (int j = T2[i - 1].first; j < T2[i].first; j++) buf[i][j] =  0 ;       buf[i][T2[i].first] = 0;     }     int rev[N];     for (int i = 0; i < (N); i++) rev[T2[i].second] = i;     printf( YES n );     for (int i = 0; i < (N); i++) printf( %s n , buf[rev[i]]);   }
#include <bits/stdc++.h>   using namespace std;   struct ii {     int a, b;     bool operator<(ii o) const { return make_tuple(a, b) < make_tuple(o.a, o.b); }   };   struct iii {     int a, b, c;     bool operator<(iii o) const {       return make_tuple(a, b, c) < make_tuple(o.a, o.b, o.c);     }   };   int TC, N, M, K, Q, x, y, z;   int arr[35005], par[35005], now[35005], st[4 * 35005], lz[4 * 35005],       dp[55][35005];   void build(int p, int l, int r, int rem) {     if (l == r) {       st[p] = dp[rem][l];       lz[p] = 0;       return;     }     int m = (l + r) >> 1;     build(p << 1, l, m, rem);     build(p << 1 | 1, m + 1, r, rem);     st[p] = max(st[p << 1], st[p << 1 | 1]);     lz[p] = 0;   }   void update(int p, int l, int r, int b1, int b2, int v) {     if (lz[p]) {       st[p] += lz[p];       if (l < r) {         lz[p << 1] += lz[p];         lz[p << 1 | 1] += lz[p];       }       lz[p] = 0;     }     if (b1 <= l && r <= b2) {       st[p] += v;       if (l < r) {         lz[p << 1] += v;         lz[p << 1 | 1] += v;       }       return;     }     if (r < b1 || b2 < l) return;     int m = (l + r) >> 1;     update(p << 1, l, m, b1, b2, v);     update(p << 1 | 1, m + 1, r, b1, b2, v);     st[p] = max(st[p << 1], st[p << 1 | 1]);   }   int query(int p, int l, int r, int b1, int b2) {     if (lz[p]) {       st[p] += lz[p];       if (l < r) {         lz[p << 1] += lz[p];         lz[p << 1 | 1] += lz[p];       }       lz[p] = 0;     }     if (b1 <= l && r <= b2) {       return st[p];     }     if (r < b1 || b2 < l) return 0;     int m = (l + r) >> 1;     return max(query(p << 1, l, m, b1, b2), query(p << 1 | 1, m + 1, r, b1, b2));   }   int main() {     scanf( %d%d , &N, &K);     for (int i = 0; i <= N; i++) now[i] = N;     for (int i = 0; i < N; i++) scanf( %d , &arr[i]);     for (int i = N - 1; i >= 0; i--) {       par[i] = now[arr[i]];       now[arr[i]] = i;     }     for (int rem = 1; rem <= K; rem++) {       build(1, 0, N, rem - 1);       for (int pos = N; pos >= 0; pos--) {         if (pos == N) {           dp[rem][pos] = 0;         } else {           update(1, 0, N, pos + 1, par[pos], 1);           dp[rem][pos] = query(1, 0, N, pos + 1, N - rem + 1);         }       }     }     printf( %d n , dp[K][0]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int key[300];   int main() {     int n, k, x, i;     scanf( %d%d , &n, &k);     memset(key, -1, sizeof key);     while (n--) {       scanf( %d , &x);       if (key[x] == -1) {         for (i = x - 1; i >= 0 && key[i] == -1 && x - i < k; i--)           ;         if (i >= 0 && x - i < k && x - key[i] < k)           key[x] = key[i];         else {           i++;           key[i] = key[x] = i;         }       }       printf( %d%c , key[x], n ?     :   n );     }   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( sse4 )   using namespace std;   template <class T>   bool ckmin(T& a, const T& b) {     return b < a ? a = b, 1 : 0;   }   template <class T>   bool ckmax(T& a, const T& b) {     return a < b ? a = b, 1 : 0;   }   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const int MOD = 1000000007;   const char nl =   n ;   const int MX = 100001;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int T;     cin >> T;     while (T--) {       int N;       cin >> N;       int A[N], B[N];       for (int i = 0; i < (N); i++) cin >> A[i];       for (int i = 0; i < (N); i++) cin >> B[i];       int S = 0;       int last = B[0];       for (int i = 1; i < (4 * N + 5); i++) {         int cur = B[(i + N - 1) % N] - last;         last = A[i % N] - cur;         ckmax(last, 0);         if (last > B[i % N]) {           S = i;           last = B[i % N];         }       }       if (S < 2 * N) {         cout <<  YES  << nl;       } else {         cout <<  NO  << nl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int a[210000];   void work() {     int cnt[33];     memset((cnt), (0), sizeof(cnt));     int xorsum = 0;     cin >> n;     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);       xorsum ^= a[i];       for (int j = 0; j <= 30; j++) cnt[j] += (a[i] >> j) & 1;     }     for (int i = 30; i >= 0; i--) {       if ((xorsum >> i) & 1) {         if ((cnt[i] - 1) % 4 == 0) {           printf( WIN n );           return;         } else {           if (n & 1) {             printf( LOSE n );             return;           } else {             printf( WIN n );             return;           }         }       }     }     printf( DRAW n );   }   int main() {     int t;     cin >> t;     while (t--) {       work();     }     return ~~(0 ^ 0 ^ 0);   }
#include <bits/stdc++.h>   using namespace std;   const int maxl = 2e5 + 10;   int n, m, cnt, tot, cas, ans;   int a[maxl], b[maxl], num[maxl * 32];   int ind[maxl * 32], sz[maxl * 32], tr[maxl * 32][2];   bool vis[maxl], pr[maxl];   char s[maxl];   vector<int> e[maxl];   inline void prework() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       int u = 0, c;       for (int j = 30; j >= 0; j--) {         c = (a[i] >> j) & 1;         if (!tr[u][c]) tr[u][c] = ++tot;         u = tr[u][c];         ++num[u];       }       ind[u] = i;     }   }   inline int dfs(int u) {     if (!tr[u][0] && !tr[u][1]) return 1;     int l = 0, r = 0;     if (tr[u][0]) l = dfs(tr[u][0]);     if (tr[u][1]) r = dfs(tr[u][1]);     if (!tr[u][1]) return l;     if (!tr[u][0]) return r;     return max(l, r) + 1;   }   inline void mainwork() { ans = n - dfs(0); }   inline void print() { printf( %d n , ans); }   int main() {     int t = 1;     for (cas = 1; cas <= t; cas++) {       prework();       mainwork();       print();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long mod = 1000000007;   long long power(long long n, long long k) {     long long ans = 1;     while (k) {       if (k & 1) ans = (ans * n) % mod;       k /= 2;       n = (n * n) % mod;     }     return ans;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     int ar[n];     for (int i = 0; i < int(n); i++) cin >> ar[i];     int l[n], r[n], m[n];     l[0] = 1;     for (int i = 1; i < int(n); i++) l[i] = min(ar[i], l[i - 1] + 1);     r[n - 1] = 1;     for (int i = n - 2; i > -1; i--) r[i] = min(r[i + 1] + 1, ar[i]);     int ans = 0;     for (int i = 0; i < int(n); i++) {       m[i] = min(l[i], r[i]);       ans = max(ans, m[i]);     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int i, j, k, n;     cin >> n;     vector<long double> probs(n);     for (i = 0; i < n; i++) {       cin >> probs[i];     }     sort(probs.begin(), probs.end());     reverse(probs.begin(), probs.end());     long double prob0 = 1;     long double prob1 = 0.;     for (i = 0; i < n; i++) {       long double p = prob1;       p = probs[i] * prob0 + p * (1 - probs[i]);       if (p > prob1) {         prob1 = p;         prob0 = (1 - probs[i]) * prob0;       }     }     printf( %.9lf , double(prob1 + 0.0000000001));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long long inf = 10000000;   inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }   inline bool isLeapYear(long long year) {     return (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0);   }   inline void normal(long long &a) {     a %= MOD;     (a < 0) && (a += MOD);   }   inline long long modMul(long long a, long long b) {     a %= MOD, b %= MOD;     normal(a), normal(b);     return (a * b) % MOD;   }   inline long long modAdd(long long a, long long b) {     a %= MOD, b %= MOD;     normal(a), normal(b);     return (a + b) % MOD;   }   inline long long modSub(long long a, long long b) {     a %= MOD, b %= MOD;     normal(a), normal(b);     a -= b;     normal(a);     return a;   }   inline long long modPow(long long b, long long p) {     long long r = 1;     while (p) {       if (p & 1) r = modMul(r, b);       b = modMul(b, b);       p >>= 1;     }     return r;   }   inline long long modInverse(long long a) { return modPow(a, MOD - 2); }   inline long long modDiv(long long a, long long b) {     return modMul(a, modInverse(b));   }   inline bool checkBit(long long n, int i) { return n & (1LL << i); }   inline long long setBit(long long n, int i) {     return n | (1LL << i);     ;   }   inline long long resetBit(long long n, int i) { return n & (~(1LL << i)); }   int dx[] = {0, 0, 1, -1};   int dy[] = {1, -1, 0, 0};   void input(long long n, const long long a[], int co = 0) {     long long i = 1;     for (; i <= n; i++) {       if (co == 0)         scanf( %lld , &a[i]);       else         printf( %lld  , a[i]);     }   }   int n, k;   int dp[55][2], a[55], sm;   int dfs(int ps, int k) {     if (ps == n) return 0;     int &rs = dp[ps][k];     if (rs != -1) return rs;     rs = 0;     if (k == 0)       rs = max(a[ps] + dfs(ps + 1, 1), dfs(ps + 1, 0));     else       rs = min(a[ps] + dfs(ps + 1, 1), dfs(ps + 1, 0));     return rs;   }   bool cmp() {}   void solve() {     memset(dp, -1, sizeof dp);     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);       sm += a[i];     }     int rs = dfs(0, 0);     printf( %d %d n , sm - rs, rs);   }   int main() {     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long val;   int visid;   const int mod = 1e9 + 7;   long long dp[60][10005];   long long Inv[100];   int vis[60][10005];   long long fp(long long b, long long p) {     if (p == 0) return 1;     long long tmp = fp(b, p / 2);     if (p % 2) return (((tmp * tmp) % mod) * b) % mod;     return (tmp * tmp) % mod;   }   long long solve(int cur, int k) {     if (k == 0) return fp(val, cur);     long long &ret = dp[cur][k];     if (vis[cur][k] == visid) return ret;     vis[cur][k] = visid;     ret = 0;     for (int i = 0; i <= cur; i++) {       ret += solve(i, k - 1) * Inv[cur + 1] % mod;       ret %= mod;     }     return ret;   }   long long n, ans = 1;   int k;   void go(long long x) {     int cnt = 0;     while (n % x == 0) {       cnt++;       n /= x;     }     visid++;     val = x;     ans *= solve(cnt, k);     ans %= mod;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     for (int i = 0; i <= 60; i++) Inv[i] = fp(i, mod - 2);     cin >> n >> k;     long long x = 2;     while (x * x <= n) {       if (n % x == 0) go(x);       x++;     }     if (n != 1) go(n);     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long dp[114514][16];   int N, M;   char s[114514];   long long res;   int main() {     scanf( %d%d , &N, &M);     scanf( %s , &s);     dp[0][2] = 1;     for (int(i) = 0; (i) < (N); (i)++)       for (int(b) = (1); (b) < (16); (b)++)         if (dp[i][b]) {           for (int(j) = 0; (j) < (M); (j)++) {             int nb = 0;             if (b % 2 == 1 && s[i - 1] == j +  a ) nb |= 1;             if (b % 2 == 1 && s[i] == j +  a ) nb |= 8;             if (b / 2 % 2 == 1 && s[i] == j +  a ) nb |= 2;             if (b / 2 % 2 == 1) nb |= 1;             if (b / 2 % 2 == 1 && i + 1 < N && s[i + 1] == j +  a ) nb |= 4;             if (b / 4 % 2 == 1) nb |= 8;             if (b / 4 % 2 == 1 && i + 1 < N && s[i + 1] == j +  a ) nb |= 4;             if (b >= 8 && s[i] == j +  a ) nb |= 8;             if (b / 2 % 2 == 1) nb |= 8;             dp[i + 1][nb] += dp[i][b];           }         }     for (int(i) = (8); (i) < (16); (i)++) res += dp[N][i];     cout << res - 1 + dp[N][1] + dp[N][4] + dp[N][5] << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     char c;     bool ch = false;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> c;         if (c ==  C  || c ==  M  || c ==  Y ) {           ch = true;           break;         }       }     }     if (ch) {       cout <<  #Color  << endl;     } else {       cout <<  #Black&White  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     while (cin >> n) {       bool flag = false;       int sum = 0;       while (n) {         if (n % 10 == 4 || n % 10 == 7)           n /= 10, sum++;         else           n /= 10;       }       if ((sum == 4 || sum == 7))         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   void fastio() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);   }   const long long int N = 100010;   long long int cnt[N], f[N];   int main() {     fastio();     long long int n, temp;     cin >> n;     long long int ar[n];     memset(cnt, 0, sizeof(cnt));     for (int i = 0; i < n; i++) {       cin >> temp;       cnt[temp]++;     }     f[0] = 0;     f[1] = cnt[1];     for (int i = 2; i < N; i++) {       f[i] = max(f[i - 1], f[i - 2] + cnt[i] * i);     }     cout << f[N - 1];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k = 0;     string s, t;     cin >> n;     cin >> s >> t;     vector<int> vect;     for (int i = 0; i < n; i++) {       if (s[i] == t[i])         continue;       else {         int flag = -1;         for (int j = i + 1; j < n; j++) {           if (s[j] == t[i]) {             flag = j;             break;           }         }         if (flag == -1) {           cout <<  -1 ;           return 0;         }         for (int j = flag - 1; j >= i; j--) {           swap(s[j], s[j + 1]);           vect.push_back(j + 1);           k++;         }       }     }     cout << k << endl;     for (int i = 0; i < k; i++) cout << vect[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   using namespace std;   const int N = 207;   const int K = 1007;   const long long mod = 1e9 + 7;   long long dp[2][N][K];   long long a[N];   int n, k;   int main() {     cin >> n >> k;     for (int i = 1; i <= n; i++) scanf( %lld , &a[i]);     dp[0][0][0] = 1;     sort(a + 1, a + n + 1);     int cur = 0, prv = 0;     for (int i = 1; i <= n; i++) {       int d = a[i] - a[i - 1];       prv = cur;       cur ^= 1;       for (int j = 0; j <= i; j++) {         for (int c = 0; c <= k; c++) {           dp[cur][j][c] = 0;           if (j && c - (j - 1) * d >= 0)             dp[cur][j][c] += dp[prv][j - 1][c - (j - 1) * d];           if (c - (j + 1) * d >= 0)             dp[cur][j][c] += dp[prv][j + 1][c - (j + 1) * d] * (j + 1);           if (c - j * d >= 0) dp[cur][j][c] += dp[prv][j][c - j * d] * (j + 1);           dp[cur][j][c] %= mod;         }       }     }     long long ans = 0;     for (int c = 0; c <= k; c++) ans += dp[cur][0][c];     cout << ans % mod;   }
#include <bits/stdc++.h>   using namespace std;   int arr[3000];   int main() {     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     int minn = 99999;     int maxx = -999;     for (int i = 0; i < n - 1; i++) {       minn = min(minn, arr[i]);       if (arr[i] <= arr[i + 1])         maxx = max(maxx, (m / minn) * arr[i + 1] + m % minn);     }     cout << max(maxx, m);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, k;   int d[188];   int par[188];   vector<int> g[188];   int dp[188][188];   int pos[188];   int ans[188];   void build(int x, int pre) {     par[x] = pre;     for (int i = (0); i < (g[x].size()); ++i) {       int to = g[x][i];       if (to == pre) {         g[x].erase(g[x].begin() + i, g[x].begin() + i + 1);         i--;         continue;       }       build(to, x);     }   }   void dfs(int x) {     for (int i = (0); i < (g[x].size()); ++i) {       int to = g[x][i];       dfs(to);     }     for (int y = (0); y < (n); ++y) {       int z = y;       while (z != x && z != -1) z = par[z];       if (z == -1) continue;       z = y;       int cur = 0, lst = -1, dis = 0;       while (1) {         cur += (dis ? d[dis] : k);         dis++;         for (int i = (0); i < (g[z].size()); ++i) {           int to = g[z][i];           if (to == lst) continue;           cur += dp[to][dis];         }         if (z == x) break;         lst = z;         z = par[z];       }       if (cur < dp[x][0]) {         dp[x][0] = cur;         pos[x] = y;       }     }     for (int dis = (1); dis < (n); ++dis) {       dp[x][dis] = dp[x][0];       int cur = d[dis];       for (int i = (0); i < (g[x].size()); ++i) {         int to = g[x][i];         cur += dp[to][dis + 1];       }       if (cur < dp[x][dis]) {         dp[x][dis] = cur;       }     }   }   void getans(int x, int dis, int lst) {     if (dp[x][dis] != dp[x][0]) {       ans[x] = lst;       for (int i = (0); i < (g[x].size()); ++i) {         int to = g[x][i];         getans(to, dis + 1, lst);       }       return;     }     int y = pos[x];     int z = y;     dis = 0;     lst = -1;     while (1) {       ans[z] = y;       dis++;       for (int i = (0); i < (g[z].size()); ++i) {         int to = g[z][i];         if (to == lst) continue;         getans(to, dis, y);       }       if (z == x) break;       lst = z;       z = par[z];     }   }   int main() {     memset(dp, 0x3f, sizeof(dp));     cin >> n >> k;     for (int i = (1); i < (n); ++i) cin >> d[i];     for (int i = (1); i < (n); ++i) {       int a, b;       cin >> a >> b;       a--;       b--;       g[a].push_back(b);       g[b].push_back(a);     }     build(0, -1);     dfs(0);     cout << dp[0][0] << endl;     getans(0, 0, -1);     for (int i = (0); i < (n); ++i) {       cout << ans[i] + 1 << (i == n - 1 ?   n  :    );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 5000 + 10;   int main() {     int n, k;     int a[maxn];     scanf( %d%d , &n, &k);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     int sum = 0;     int maxs = 0;     double maxa = 0;     for (int i = k; i <= n; i++) {       for (int j = 0; j < i; j++) sum += a[j];       maxs = sum;       for (int j = 1; j < n - i + 1; j++) {         sum = sum - a[j - 1] + a[j + i - 1];         maxs = max(maxs, sum);       }       double a = maxs * 1.0 / i;       maxa = max(maxa, a);       sum = 0;     }     printf( %lf n , maxa);     return 0;   }