malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   void lwr(string& s) {     for (int i = 0; i < s.size(); i++) {       if (s[i] >=  A  and s[i] <=  Z ) s[i] = s[i] -  A  +  a ;     }   }   pair<int, int> _rank(const string& s) {     int ret = 0;     for (int i = 0; i < s.size(); i++) ret += s[i] ==  r ;     return pair<int, int>(ret, (int)s.size());   }   map<string, int> who;   const int N = 300010;   pair<int, int> val[N];   vector<int> g[N], gt[N];   int vis[N];   int c[N];   vector<int> ts;   void dfs(int u) {     vis[u] = 1;     for (int v : g[u])       if (!vis[v]) dfs(v);     ts.push_back(u);   }   pair<int, int> valc[N];   void dfst(int u, int cmp) {     vis[u] = 2;     c[u] = cmp;     valc[cmp] = min(valc[cmp], val[u]);     for (int v : gt[u])       if (vis[v] != 2) dfst(v, cmp);   }   vector<int> gc[N];   pair<int, int> best[N];   pair<int, int> solve(int u) {     if (best[u].first != 0x3f3f3f3f) return best[u];     best[u] = valc[u];     for (int v : gc[u]) best[u] = min(best[u], solve(v));     return best[u];   }   int main() {     ios::sync_with_stdio(0);     int m, cnt = 0;     cin >> m;     vector<int> vv;     for (int i = 0; i < m; i++) {       string s;       cin >> s;       lwr(s);       if (!who.count(s)) {         who[s] = cnt;         val[cnt] = _rank(s);         cnt++;       }       vv.push_back(who[s]);     }     int n;     cin >> n;     for (int i = 0; i < n; i++) {       string u, v;       cin >> u >> v;       lwr(u);       lwr(v);       if (!who.count(u)) {         who[u] = cnt;         val[cnt] = _rank(u);         cnt++;       }       if (!who.count(v)) {         who[v] = cnt;         val[cnt] = _rank(v);         cnt++;       }       int uu = who[u], vv = who[v];       g[uu].push_back(vv);       gt[vv].push_back(uu);     }     for (int i = 0; i < cnt; i++) {       if (!vis[i]) dfs(i);     }     int comp = 0;     fill(valc, valc + N, pair<int, int>(0x3f3f3f3f, 0x3f3f3f3f));     for (int i = cnt - 1; i >= 0; i--) {       if (vis[ts[i]] != 2) dfst(ts[i], comp++);     }     for (int u = 0; u < cnt; u++) {       for (int v : g[u]) {         if (c[u] != c[v]) gc[c[u]].push_back(c[v]);       }     }     fill(best, best + N, pair<int, int>(0x3f3f3f3f, 0x3f3f3f3f));     pair<long long, long long> ans(0LL, 0LL);     for (int i = 0; i < m; i++) {       pair<int, int> ret = solve(c[vv[i]]);       ans.first += ret.first;       ans.second += ret.second;     }     cout << ans.first <<     << ans.second <<   n ;     return 0;   }
#include <bits/stdc++.h>   int n, m, p, r[605], c[605], f[605], g[605][605], a[605][605], b[605][605];   void tuopu() {     int h = 0, t = 0;     for (int i = 1; i <= n; i++)       if (!r[i]) f[++t] = i, g[i][t] = 1;     m = t;     while (h < t) {       int x = f[++h];       for (int i = 1; i <= n; i++)         if (b[x][i]) {           r[i] -= b[x][i];           if (!r[i]) f[++t] = i;           for (int j = 1; j <= m; j++)             g[i][j] = (g[i][j] + (long long)g[x][j] * b[x][i]) % p;         }     }     int now = 0;     for (int j = 1; j <= n; j++)       if (!c[j]) {         ++now;         for (int i = 1; i <= m; i++) a[i][now] = g[j][i];       }   }   void swap(int &x, int &y) {     int tmp = x;     x = y;     y = tmp;   }   void work() {     int flag = 1;     for (int i = 1; i <= m; i++) {       if (!a[i][i])         for (int j = i + 1; j <= m; j++)           if (a[j][i]) {             for (int k = i; k <= m; k++) swap(a[i][k], a[j][k]);             flag = -flag;             break;           }       for (int j = i + 1; j <= m; j++)         while (a[j][i]) {           long long z;           if (a[i][i])             z = a[j][i] / a[i][i];           else             z = 0;           flag = -flag;           for (int k = i; k <= m; k++)             a[j][k] = (a[j][k] - z * a[i][k]) % p, swap(a[j][k], a[i][k]);         }     }     long long ans = flag;     for (int i = 1; i <= m; i++) ans = ans * a[i][i] % p;     printf( %d n , (ans + p) % p);   }   int main() {     scanf( %d%d%d , &n, &m, &p);     int x, y;     for (int i = 1; i <= m; i++) scanf( %d%d , &x, &y), b[x][y]++, c[x]++, r[y]++;     tuopu();     work();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int t, n, a[100005];   vector<int> v[100005];   int val[100005];   int k[100005];   int main() {     for (int i = 2; i <= 100000; i++) {       v[i].push_back(1);       for (int j = i + i; j <= 100000; j += i) {         v[j].push_back(i);       }     }     scanf( %d , &t);     while (t--) {       memset(k, 0, sizeof(k));       scanf( %d , &n);       for (int i = 1; i <= n; i++) {         scanf( %d , &a[i]);       }       for (int i = n; i >= 1; i--) {         if (k[i] == 0) k[i] = 1;         int p = v[i].size();         for (int j = 0; j < p; j++) {           if (a[i] > a[v[i][j]]) k[v[i][j]] = max(k[v[i][j]], k[i] + 1);         }       }       int mx = 0;       for (int i = 1; i <= n; i++) {         mx = max(mx, k[i]);       }       printf( %d n , mx);     }     return 0;   }
#include <bits/stdc++.h>   int a[500005][9] = {0};   int nnf[500005] = {0};   int pn[200005] = {0};   int val[200005];   int x, in;   void print(int *a, int n) {     int i;     for (i = 0; i < n; i++) printf( %d  , a[i]);     printf(  n );   }   long long int check(int cnt, int val, int d) {     if (in == -1) nnf[val] += in;     long long int q = d * nnf[val], i;     for (i = cnt + 1; i <= a[x][0]; i++) q += check(i, val * a[x][i], -d);     if (in == 1) nnf[val] += in;     return q;   }   int main() {     a[1][0] = 1;     a[1][1] = 1;     int i, j;     for (i = 1; i < 500001; i++) {       if (a[i][0] == 1) {         for (j = i; j < 500001; j += i) {           a[j][0] += 1;           a[j][a[j][0]] = i;         }       }     }     a[1][0] = 1;     int n, q;     long long int ans = 0;     scanf( %d %d , &n, &q);     for (i = 1; i <= n; i++) scanf( %d , &val[i]);     for (i = 0; i < q; i++) {       scanf( %d , &j);       if (pn[j] == 1)         in = -1;       else         in = 1;       pn[j] = pn[j] ^ 1;       x = val[j];       ans += check(1, 1, in);       printf( %lld n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N, K, L;   int pre[1000005];   long long dp[1000005];   int cnt[1000005];   string s;   pair<int, int> chk(long long C) {     fill(dp + 1, dp + 1 + N, 0);     fill(cnt + 1, cnt + 1 + N, 0);     for (int i = 1; i <= N; i++) {       dp[i] = dp[i - 1];       cnt[i] = cnt[i - 1];       if (i >= L) {         long long v = dp[i - L] + pre[i] - pre[i - L] - C;         if ((dp[i] == v && cnt[i - L] + 1 < cnt[i]) || (dp[i] < v)) {           dp[i] = v;           cnt[i] = cnt[i - L] + 1;         }       } else {         long long v = pre[i] - C;         if ((dp[i] < v)) {           dp[i] = v;           cnt[i] = 1;         }       }     }     return {dp[N], cnt[N]};   }   int solve(char lb, char ub) {     for (int i = 1; i <= N; i++) {       pre[i] = (s[i - 1] >= lb && s[i - 1] <= ub);       pre[i] += pre[i - 1];     }     long long l = 0, r = N + 1;     int ret = 0;     while (l <= r) {       long long mid = (l + r) / 2;       auto res = chk(mid);       if (res.second <= K) {         ret = mid;         r = mid - 1;       } else {         l = mid + 1;       }     }     return pre[N] - (chk(ret).first + 1LL * K * ret);   }   int main() {     cin.sync_with_stdio(0);     cin.tie(0);     cin >> N >> K >> L >> s;     int ret = min(solve( a ,  z ), solve( A ,  Z ));     cout << ret << endl;   }
#include <bits/stdc++.h>   const int N = 1010;   int n, k, a[N], a2[N], used[N], m, d, ans;   std::list<int> list;   int t;   void spendTimeUntil(int setSz) {     while (list.size() > setSz) {       d = round(100 * (double)m / (double)n);       for (int x : list) {         if (a2[x] + 1 == d && !used[x]) {           used[x] = 1;           ans++;         }       }       for (auto it = list.begin(); it != list.end();) {         if (++a2[*it] != a[*it])           it++;         else {           it = list.erase(it);           m++;         }       }     }   }   int main() {     scanf( %d%d , &n, &k);     for (int i = 0; i < n; i++) {       scanf( %d , a + i);       if (list.size() < k)         list.push_back(i);       else {         spendTimeUntil(k - 1);         list.push_back(i);       }     }     spendTimeUntil(0);     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void fun() {}   const long long int inf = 1e18;   const long long int md = 1e9 + 7;   const long long int N = 300050;   long long int __gcd(long long int a, long long int b) {     if (b == 0) return a;     return __gcd(b, a % b);   }   long long int poww(long long int a, long long int b, long long int md) {     if (b < 0) return 0;     if (a == 0) return 0;     long long int res = 1;     while (b) {       if (b & 1) {         res = (1ll * res * a) % md;       }       a = (1ll * a * a) % md;       b >>= 1;     }     return res;   }   long long int poww(long long int a, long long int b) {     if (b < 0) return 0;     if (a == 0) return 0;     long long int res = 1;     while (b) {       if (b & 1) {         res = (1ll * res * a);       }       a = (1ll * a * a);       b >>= 1;     }     return res;   }   long long int divide(long long int a, long long int b, long long int md) {     long long int rr = a * (poww(b, md - 2, md));     rr %= md;     return rr;   }   long long int lcm(long long int a, long long int b) {     return (a * b) / __gcd(a, b);   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long int t;     cin >> t;     while (t--) {       long long int l, r;       cin >> l >> r;       if (2 * l > r)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> v[27];   bool vis[27];   vector<pair<int, int> > pr;   int cnt, flag;   void dfs(int nod, int dest) {     int i;     vis[nod] = 1;     if (nod == dest) {       flag = 1;       return;     }     for (i = 0; i < v[nod].size(); i++) {       int curr = v[nod][i];       if (vis[curr] == 0) {         dfs(curr, dest);       }     }     return;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, i;     cin >> n;     string s1, s2;     cin >> s1 >> s2;     for (i = 0; i < n; i++) {       flag = 0;       memset(vis, 0, sizeof(vis));       int nod = s1[i] -  a  + 1;       int dest = s2[i] -  a  + 1;       dfs(nod, dest);       if (flag == 0) {         cnt++;         pr.push_back(make_pair(nod, dest));         v[nod].push_back(dest);         v[dest].push_back(nod);       }     }     cout << cnt << endl;     for (i = 0; i < pr.size(); i++) {       char ch1 = pr[i].first +  a  - 1, ch2 = pr[i].second +  a  - 1;       cout << ch1 <<     << ch2 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     string s;     vector<int> a;     while (t--) {       int x;       cin >> x >> s;       a.resize(x);       int sz = s.size();       for (int i = 0; i < sz && i < x; ++i) {         a[i] = s[i] -  0 ;       }       long long sol = s.size();       for (int i = 1; i <= x; ++i) {         int r = sz;         for (int j = 1; j < a[i - 1] && sz < x; ++j) {           for (int k = i; k < r && sz < x; ++k) {             a[sz] = a[k];             ++sz;           }         }         sol = ((sol - i + MOD) % MOD * a[i - 1] + i) % MOD;       }       cout << sol <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const int N = 1e6 + 7;   long long p[N];   int main() {     int a, b, c, d;     scanf( %d , &a), scanf( %d , &b), scanf( %d , &c), scanf( %d , &d);     for (int i = a; i < (int)b + 1; i++) {       p[i + b] += 1;       p[i + c + 1] -= 1;     }     for (int i = 1; i < (int)N; i++) p[i] += p[i - 1];     for (int i = 1; i < (int)N; i++) p[i] += p[i - 1];     long long val = 0;     for (int i = c; i < (int)d + 1; i++) val += p[N - 1] - p[i];     printf( %lld n , val);   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast ,  unroll-loops ,  no-stack-protector )   using namespace std;   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long test = 1;     while (test--) {       long long x, y;       cin >> x >> y;       long long n;       cin >> n;       long long hash[7];       hash[0] = 0;       hash[1] = x;       hash[2] = y;       hash[3] = (y - x + 1000000007) % 1000000007;       hash[4] = (-1 * x + 1000000007) % 1000000007;       hash[5] = (-1 * y + 1000000007) % 1000000007;       hash[6] = (x - y + 1000000007) % 1000000007;       long long rem = (n) % 6;       if (rem == 0) rem = 6;       long long ans = hash[rem];       cout << (ans + 1000000007) % 1000000007;     }     cerr << endl          <<  Time:   << (clock() * 1000. / CLOCKS_PER_SEC) <<   ms  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, k, i, tt = 1, a, b;     cin >> n >> k;     vector<pair<int, int> > p;     for (i = 0; i < n; i++) {       cin >> a >> b;       p.push_back(make_pair(-a, b));     }     sort(p.begin(), p.end());     for (i = k - 1; i < n - 1; i++) {       if (p[i].first == p[i + 1].first && p[i].second == p[i + 1].second)         tt += 1;       else         break;     }     for (i = k - 1; i > 0; i--) {       if (p[i].first == p[i - 1].first && p[i].second == p[i - 1].second)         tt += 1;       else         break;     }     cout << tt;   }
#include <bits/stdc++.h>   using namespace std;      const int N = (int) 1e7 + 100;      long long s[N];   int d[N];   int ans[N];      int main() {     fill(d, d + N, -1);     d[1] = 1;     for (int i = 2; i * i < N; i++) {       if (d[i] == -1) {         d[i] = i;         for (int j = i * i; j < N; j += i) {           if (d[j] == -1) {             d[j] = i;           }         }       }     }     s[1] = 1;     for (int i = 2; i < N; i++) {       if (d[i] == -1) {         d[i] = i;         s[i] = i + 1;       } else {         int j = i;         s[i] = 1;         while (j % d[i] == 0) {           j /= d[i];           s[i] = s[i] * d[i] + 1;         }         s[i] *= s[j];       }     }     fill(ans, ans + N, -1);     for (int i = N - 1; i > 0; i--) {       if(s[i]<N){  // avoiding overflow.       ans[s[i]] = i;      }                     }     int tests;     cin >> tests;     while (tests-- > 0) {       int c;       cin >> c;       cout << ans[c] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int const N = 2e5 + 5;   vector<vector<int> > adj(N);   long long a[N];   pair<pair<long long, long long>, long long> dfs(int u, int prt = 0) {     if (adj[u].empty()) return {{1, a[u]}, a[u]};     pair<pair<long long, long long>, long long> ret = {{0, 0}, 0};     for (int v : adj[u]) {       if (v == prt) continue;       auto ch = dfs(v, u);       ret.first.first += ch.first.first, ret.first.second += ch.first.second;       ret.second = max(ret.second, ch.second);     }     long long k = ret.second * ret.first.first - ret.first.second;     long long rem = a[u] - min(a[u], k);     ret.second += rem / ret.first.first + (rem % ret.first.first != 0);     ret.first.second += a[u];     return ret;   }   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     int n;     cin >> n;     for (int i = 2; i <= n; i++) {       int p;       cin >> p;       adj[p].push_back(i);     }     for (int i = 1; i <= n; i++) cin >> a[i];     cout << dfs(1).second << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   int n;   char cmd[1000001];   bool sym(int p) {     int rm = 0, cur = 0;     for (int i = 0; i < n - 1; ++i) {       if (cur > p + 1 && cmd[i] ==  L )         cur--;       else if (cmd[i] ==  R )         rm = max(rm, ++cur);     }     return cur + 1 > rm;   }   int main() {     scanf( %s , cmd);     n = strlen(cmd);     if (cmd[n - 1] ==  L )       for (int i = 0; i < n; ++i) cmd[i] = cmd[i] ==  R  ?  L  :  R ;     if (sym(-mod))       puts( 1 );     else {       int a = -mod, b = 0;       while (b - a > 1) {         int m = (a + b) >> 1;         if (sym(m))           b = m;         else           a = m;       }       printf( %d n , -b);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t;     cin >> t;     while (t--) {       long long int n, k;       cin >> n >> k;       vector<long long int> a(n);       for (int i = 0; i < n; i++) cin >> a[i];       vector<long long int> pks;       for (int i = 1; i < n - 1; i++) {         if (a[i] > a[i - 1] && a[i] > a[i + 1]) pks.push_back(i);       }       long long int maxi = 0, l = 0;       for (long long int i = 0; i <= n - k; i++) {         long long int tmp1 = upper_bound(pks.begin(), pks.end(), i) - pks.begin();         long long int tmp2 =             lower_bound(pks.begin(), pks.end(), i + k - 1LL) - pks.begin();         long long int cnt = tmp2 - tmp1;         if (cnt > maxi) {           maxi = cnt;           l = i;         }       }       cout << maxi + 1 <<     << l + 1 << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, x;     scanf( %d %d %d , &a, &b, &x);     if (a != 0 && a >= b) {       a = a - (a / b) * b;     }     a *= 10;     int cont = 0;     vector<int> v;     while (cont <= b && a != 0) {       if (a < b) {         v.push_back(0);       } else {         v.push_back(a / b);         a = a - (a / b) * b;       }       a *= 10;       cont++;     }     if (a == 0) v.push_back(0);     if (find(v.begin(), v.end(), x) != v.end()) {       printf( %d n , (find(v.begin(), v.end(), x) - v.begin()) + 1);     } else       puts( -1 );   }
#include <bits/stdc++.h>   using namespace std;   int ans;   void solve(long long n, long long l1, long long r1, long long l, long long r) {     if (n == 0 || l1 > r || r1 < l) return;     long long mid = (l1 + r1) >> 1;     if (mid >= l && mid <= r) ans += (n % 2);     solve(n / 2, l1, mid - 1, l, r);     solve(n / 2, mid + 1, r1, l, r);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n, l, r;     cin >> n, cin >> l, cin >> r;     long long tmp = n, var = 0;     while (tmp > 0) {       tmp /= 2;       var++;     }     long long num = (1LL << var) - 1;     solve(n, 1, num, l, r);     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int w[110], n, C0, C1, D[110][110][2];   int main() {     int i, j, k, l;     scanf( %d , &n);     for (i = 1; i <= n; i++) {       scanf( %d , &w[i]);       if (i % 2 == 0)         C0++;       else         C1++;     }     for (i = 0; i <= n; i++) {       for (j = 0; j <= n; j++) {         D[i][j][0] = D[i][j][1] = 1e9;       }     }     D[0][0][0] = D[0][0][1] = 0;     for (i = 1; i <= n; i++) {       for (j = 0; j < i; j++) {         for (k = 0; k < 2; k++) {           int t = D[i - 1][j][k];           if (w[i]) {             if (w[i] % 2 == 0) {               D[i][j + 1][0] = min(D[i][j + 1][0], t + (k != 0));             } else {               D[i][j][1] = min(D[i][j][1], t + (k != 1));             }           } else {             for (l = 0; l < 2; l++) {               D[i][j + 1 - l][l] = min(D[i][j + 1 - l][l], t + (k != l));             }           }         }       }     }     printf( %d n , min(D[n][C0][0], D[n][C0][1]));   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   int main() {     long long n, m;     cin >> n >> m;     string s;     cin >> s;     vector<vector<long long>> cost(n + 1, vector<long long>(6));     for (int i = n - 1; i >= 0; i--) {       cost[i][0] = (s[i] ==  a  ? 0 : 1) + cost[i + 1][3];       cost[i][1] = (s[i] ==  a  ? 0 : 1) + cost[i + 1][5];       cost[i][2] = (s[i] ==  b  ? 0 : 1) + cost[i + 1][1];       cost[i][3] = (s[i] ==  b  ? 0 : 1) + cost[i + 1][4];       cost[i][4] = (s[i] ==  c  ? 0 : 1) + cost[i + 1][0];       cost[i][5] = (s[i] ==  c  ? 0 : 1) + cost[i + 1][2];     }     while (m--) {       long long l, r;       cin >> l >> r;       l--, r--;       long long d = (r + 1 - l) % 3;       long long res = n;       res = min(res, cost[l][0] - (d == 0   ? cost[r + 1][0]                                    : d == 1 ? cost[r + 1][3]                                             : cost[r + 1][4]));       res = min(res, cost[l][1] - (d == 0   ? cost[r + 1][1]                                    : d == 1 ? cost[r + 1][5]                                             : cost[r + 1][2]));       res = min(res, cost[l][2] - (d == 0   ? cost[r + 1][2]                                    : d == 1 ? cost[r + 1][1]                                             : cost[r + 1][5]));       res = min(res, cost[l][3] - (d == 0   ? cost[r + 1][3]                                    : d == 1 ? cost[r + 1][4]                                             : cost[r + 1][0]));       res = min(res, cost[l][4] - (d == 0   ? cost[r + 1][4]                                    : d == 1 ? cost[r + 1][0]                                             : cost[r + 1][3]));       res = min(res, cost[l][5] - (d == 0   ? cost[r + 1][5]                                    : d == 1 ? cost[r + 1][2]                                             : cost[r + 1][1]));       cout << res << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     cin >> n;     cout << (n % 4 == 0 ?  YES  :  NO ) <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long arr[300000];   int main() {     long long n, m;     scanf( %lld %lld , &n, &m);     for (long long i = 1; i <= n; i++) {       scanf( %lld , &arr[i]);     }     string s;     cin >> s;     long long len = s.size();     long long ans = 0;     for (long long i = 0; i < len; i++) {       char c = s[i];       priority_queue<long long> q;       long long j = i;       while (s[j] == c && j < len) {         q.push(arr[j + 1]);         i = j;         j++;       }       long long temp = m;       while (temp > 0 && !q.empty()) {         long long keep = q.top();         ans += keep;         q.pop();         temp--;       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int mod(long long int x) {     return (((x) % 1000000007) + 1000000007) % 1000000007;   }   long long int mod1(long long int x, long long int m) {     return (((x) % m) + m) % m;   }   long long int solve() {     long long int n, k;     cin >> n >> k;     long long int s[n + 1];     for (long long int i = 1; i < n + 1; i++) {       long long int p;       cin >> p;       if (p == 0)         s[i] = (k < i - 1 ? k : i - 1) + 1;       else         s[i] = s[p] + (2 * k < i - p - 1 ? 2 * k : i - p - 1) + 1;       cout << s[i] + (k < n - i ? k : n - i) <<   n ;     }     return 0;   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     long long int t;     t = 1;     while (t--) {       solve();     }     return 0;   }