malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000005;   int n, k;   struct edge {     int v;     edge *nxt;   } g[maxn << 1], *he[maxn];   int cnt;   void add_edge(int a, int b) {     edge *e = g + (++cnt);     e->v = b, e->nxt = he[a];     he[a] = e;   }   bool in[maxn];   int mxs[maxn], dep[maxn], fa[maxn];   int f[maxn][25];   void dfs(int p, int ffa) {     dep[p] = dep[ffa] + 1;     f[p][0] = ffa;     fa[p] = ffa;     for (int i = 1; i <= 20; ++i) f[p][i] = f[f[p][i - 1]][i - 1];     for (edge *e = he[p]; e; e = e->nxt) {       int to = e->v;       if (to == ffa) continue;       dfs(to, p);     }   }   int main() {     scanf( %d%d , &n, &k);     k = n - k;     int a, b;     for (int i = 1; i < n; ++i) {       scanf( %d%d , &a, &b);       add_edge(a, b);       add_edge(b, a);     }     dep[n] = -1;     dfs(n, 0);     k--;     in[n] = true;     int now = n;     for (int i = n - 1; i; --i) {       if (k == 0) break;       int p = i;       for (int j = 20; ~j; --j)         if (!in[f[p][j]] && f[p][j] != 0) {           p = f[p][j];         }       int lc = f[p][0];       if (dep[i] - dep[lc] <= k) {         p = i;         while (!in[p] && p != lc) {           in[p] = true;           p = fa[p];           k--;         }       }     }     vector<int> ans;     for (int i = 1; i <= n; ++i) {       if (!in[i]) ans.push_back(i);     }     for (int i = 0; i < ans.size(); ++i) printf( %d  , ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6;   int t, tot, type[N];   long long r, f[N];   vector<int> son[N];   template <class T>   inline void read(T &x) {     x = 0;     char ch = getchar(), w = 0;     while (!isdigit(ch)) w = ch ==  - , ch = getchar();     while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();     x = w ? -x : x;     return;   }   inline char getch() {     char c = getchar();     while (c ==    ) c = getchar();     return c;   }   int solve(int fa) {     char c = getch();     int now = ++tot;     type[now] = 0, son[now].clear();     if (c ==  * ) return f[now] = 1, now;     son[now].push_back(solve(now));     while (1) {       c = getch();       if (c ==  S )         type[now] = 1;       else if (c ==  P )         type[now] = 2;       else         break;       son[now].push_back(solve(now));     }     if (type[now] == 1) {       f[now] = 1e18;       for (auto &v : son[now]) f[now] = min(f[v], f[now]);     } else {       f[now] = 0;       for (auto &v : son[now]) f[now] += f[v];     }     return now;   }   void resolve(int now, long long r) {     if (type[now] == 0) {       printf( %lld  , r);       return;     }     if (type[now] == 1) {       int pos = 0;       long long minV = 1e18;       for (auto &k : son[now])         if (f[k] < minV) minV = f[k], pos = k;       for (auto &k : son[now]) resolve(k, pos == k ? r : 0);       return;     }     for (auto &k : son[now]) resolve(k, r);     return;   }   int main() {     read(t);     while (t--) {       read(r), tot = 0;       int root = solve(0);       printf( REVOLTING  );       resolve(root, r * f[root]);       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct node {     int a, b;     bool operator<(const node& r) const { return r.b < b; }   } e[105];   int dp[10005][105];   int main() {     int n, sum = 0, num = 0, sum2 = 0;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &e[i].a);       sum += e[i].a;     }     for (int i = 0; i < n; i++) {       scanf( %d , &e[i].b);       sum2 += e[i].b;     }     sort(e, e + n);     for (int i = 0; i < n; i++) {       num += e[i].b;       if (num >= sum) {         num = i + 1;         break;       }     }     for (int i = sum2; i >= 0; i--) {       for (int k = num; k >= 0; k--) {         dp[i][k] = -234723846;       }     }     dp[0][0] = 0;     for (int i = 0; i < n; i++) {       for (int k = sum2; k >= e[i].b; k--) {         for (int j = num; j >= 1; j--) {           dp[k][j] = max(dp[k][j], dp[k - e[i].b][j - 1] + e[i].a);         }       }     }     int ans = 0;     for (int i = sum; i <= sum2; i++) {       ans = max(ans, dp[i][num]);     }     printf( %d %d n , num, sum - ans);   }
#include <bits/stdc++.h>   using ll = long long;   using namespace std;   int main() {     cin.tie(nullptr);     ios::sync_with_stdio(false);     cout << fixed << setprecision(15);     int t;     cin >> t;     for (ll _ = 0, _Len = (t); _ < _Len; ++_) {       ll n;       cin >> n;       vector<ll> a(n);       vector<pair<ll, ll>> sorted;       for (ll i = 0, iLen = (n); i < iLen; ++i) {         cin >> a[i];         sorted.emplace_back(a[i], i);       }       sort(sorted.begin(), sorted.end());       int comp_n = -1, prev_n = -1;       vector<int> num_cnt;       for (auto &[num, index] : sorted) {         if (prev_n < num) {           prev_n = num;           comp_n++;           num_cnt.emplace_back(0);         }         a[index] = comp_n;         num_cnt.back()++;       }       map<int, int> mp;       vector<int> current_cnt(num_cnt.size());       vector<vector<int>> dp(n + 1, vector<int>(3, 1));       int ans = 0;       for (ll i = 0, iLen = (n); i < iLen; ++i) {         current_cnt[a[i]]++;         auto itr1 = mp.find(a[i]), itr2 = mp.find(a[i] - 1);         if (itr1 != mp.end()) {           int j = itr1->second;           dp[i][0] = dp[j][0] + 1;           dp[i][1] = dp[j][1] + 1;           dp[i][2] = dp[j][2] + 1;         }         if (itr2 != mp.end()) {           int j = itr2->second;           dp[i][2] = max(dp[i][2], dp[j][0] + 1);           if (current_cnt[a[i]] == 1) {             dp[i][1] = max(dp[i][1], dp[j][0] + 1);           }           if (num_cnt[a[i] - 1] == current_cnt[a[i] - 1]) {             dp[i][2] = max(dp[i][2], dp[j][1] + 1);           }           if (itr1 == mp.end() && num_cnt[a[i] - 1] == current_cnt[a[i] - 1]) {             dp[i][1] = max(dp[i][1], dp[j][1] + 1);           }         }         ans = max({ans, dp[i][0], dp[i][1], dp[i][2]});         mp[a[i]] = i;       }       cout << n - ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   T gcd(T first, T second) {     while (second > 0) {       first %= second;       swap(first, second);     }     return first;   }   template <class T>   T lcm(T a, T b) {     return a / gcd(a, b) * b;   }   template <class _T>   inline _T sqr(const _T &first) {     return first * first;   }   template <class _T>   inline string tostr(const _T &a) {     ostringstream os(  );     os << a;     return os.str();   }   const long double PI = 3.1415926535897932384626433832795L;   template <typename T>   inline void input(T &a) {     static int ed;     a = 0;     while (!isdigit(ed = getchar()) && ed !=  - ) {     }     char neg = 0;     if (ed ==  - ) {       neg = 1;       ed = getchar();     }     while (isdigit(ed)) {       a = 10 * a + ed -  0 ;       ed = getchar();     }     if (neg) a = -a;   }   template <typename T = int>   inline T nxt() {     T res;     input(res);     return res;   }   mt19937 generator;   bool check(int v) {     if (v < 2) return false;     for (int i = 2; i * i <= v; ++i) {       if (v % i == 0) {         return false;       }     }     return true;   }   long long pw(long long a, long long n, long long m) {     long long res = 1;     while (n) {       if (n & 1ll) {         res = res * a % m;       }       a = a * a % m;       n >>= 1;     }     return res;   }   long long bin[5][5];   void pre() {     for (int i = 0; i < 5; ++i) {       bin[i][0] = 1;       for (int j = 1; j <= i; ++j) {         bin[i][j] = bin[i - 1][j] + bin[i - 1][j - 1];       }     }   }   void read() {}   void test() {}   long long mod = 1000000007;   vector<int> g[1 << 20];   int dp[1 << 20];   int solve(int v) {     int &res = dp[v];     if (res != -1) {       return res;     }     res = 1;     for (int to : g[v]) {       if (to < v) {         res = max(res, solve(to) + 1);       }     }     return res;   }   void solve() {     int n = nxt();     int m = nxt();     for (int i = 0; i < m; ++i) {       int u = nxt() - 1;       int v = nxt() - 1;       g[u].push_back(v);       g[v].push_back(u);     }     memset(dp, 255, sizeof(dp));     long long ans = 0;     for (int i = 0; i < n; ++i) {       ans = max(ans, 1ll * solve(i) * (int)g[i].size());     }     cout << ans << endl;   }   void solve2() {}   int main() {     int t = 1;     pre();     while (t--) {       read();       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inv = 1000000000;   const int minv = -inv;   const int max_n = 100010;   const int max_m = 100010;   const int max_k = 110;   const int modref = 1000000007;   int n, m;   int a[max_n];   int b[max_n][max_k + 1] = {0};   int c[max_k + 1] = {0};   int bin[max_n + max_k + 1][max_k + 1];   int main() {     for (int i = 0; i <= max_n + max_k; ++i) {       bin[i][0] = 1;       if (i <= max_k) bin[i][i] = 1;       for (int j = 1; j <= min(i - 1, max_k); ++j) {         bin[i][j] = bin[i - 1][j - 1] + bin[i - 1][j];         bin[i][j] %= modref;       }     }     scanf( %d , &n);     scanf( %d , &m);     for (int i = 0; i < n; ++i) scanf( %d , &a[i]);     for (int i = 0; i < m; ++i) {       int l, r, k;       scanf( %d , &l);       scanf( %d , &r);       scanf( %d , &k);       --l;       --r;       ++b[l][k];       b[l][k] %= modref;       if (r + 1 < n)         for (int j = 0; j <= k; ++j) {           b[r + 1][j] += (modref - bin[r + 1 - l - 1 + k - j][k - j]);           b[r + 1][j] %= modref;         }     }     for (int i = 0; i < n; ++i) {       int res = a[i];       for (int j = 99; j >= 0; --j) {         c[j] = c[j + 1] + c[j];         c[j] %= modref;       }       for (int j = 100; j >= 0; --j) {         c[j] += b[i][j];         c[j] %= modref;         res += c[j];         res %= modref;       }       printf( %d  , res);     }     printf(  n );     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast,inline,unroll-loops,fast-math )   using namespace std;   int f[5020][5020];   inline int Mod(int x) { return x + ((x >> 31) & 998244353); }   int Power(int x, int y) {     int o;     for (o = 1; y; y >>= 1) {       if (y & 1) o = (long long)o * x % 998244353;       x = (long long)x * x % 998244353;     }     return o;   }   int P(int n, int m) {     int i, o;     if (m < 0 || m > n) return 0;     for (i = o = 1; i <= m; i++) o = (long long)o * (n - i + 1) % 998244353;     return o;   }   int main(void) {     int n, m, k;     int i, j, o;     cin >> n >> m >> k;     for (i = f[0][0] = 1; i <= k; i++)       for (j = 1; j <= i; j++)         f[i][j] = Mod(f[i - 1][j - 1] + (long long)f[i - 1][j] * j % 998244353 -                       998244353);     m = Power(m, 998244353 - 2);     for (i = o = 0; i <= k; i++)       o = Mod(o +               (long long)f[k][i] * P(n, i) % 998244353 * Power(m, i) % 998244353 -               998244353);     cout << o << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long INF = 1000 * 1000 * 1000;   const long long int mod = 1000000007;   int dp[100050];   int main() {     std::ios::sync_with_stdio(false);     int t;     cin >> t;     while (t--) {       long double d;       cin >> d;       long double a, b, x, y;       x = d * d - 4 * d;       if (x < 0) {         cout <<  N  <<   n ;         continue;       }       x = sqrt(x);       if (d - x < 0) {         cout <<  N  <<   n ;         continue;       }       a = (d + x) / 2.0;       b = (d - x) / 2.0;       cout <<  Y             <<    ;       cout << setprecision(12) << fixed << a <<    ;       cout << setprecision(12) << fixed << b <<    ;       cout <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int m[120], n, k = 0;   int main() {     cin >> n;     char a, b;     getchar();     for (int i = 1; i < n; i++) {       a = getchar();       b = getchar();       m[a -  a ]++;       if (m[b -  A ] > 0) {         m[b -  A ]--;       } else {         k++;       }     }     cout << k << endl;     return 0;   }
#define _CRT_SECURE_NO_WARNINGS   #include <vector>   #include <string>   #include <map>   #include <queue>   #include <unordered_map>   #include <unordered_set>   #include <cassert>   #include <complex>   #include <cstdio>   #include <iostream>   #include <iomanip>   #include <cmath>   #include <functional>   #include <algorithm>   #include <stack>   #include <numeric>   #include <set>   #include <chrono>   #include <random>      #define all(X) (X).begin(), (X).end()   #define int long long   #define m_p make_pair   #define endl   n    using namespace std;   mt19937_64 rnd(std::chrono::system_clock::now().time_since_epoch().count());      const int MAXN = 1e6 + 100, mod = 1e9 + 7;      int gcd(int a, int b) {    if (b == 0)     return a;    else     return gcd(b, a % b);   }      void extgcd(int a, int b, int &x, int &y) {    if (b == 0) {     x = 1; y = 0;     return;    }    else {     extgcd(b, a % b, x, y);     int temp = y;     y = x - (a / b) * y;     x = temp;    }   }      int inv(int a, int mod) {    int x, y;    extgcd(a, mod, x, y);    x = (x % mod + mod) % mod;    return x;   }      int f[MAXN];      int c(int n, int k) {    if (n < 0 || n < 0 || n - k < 0)     return 0;    return (f[n] * inv(f[n - k] * f[k], mod)) % mod;   }      signed main() {    ios::sync_with_stdio(0);    cin.tie(0);   #ifndef ONLINE_JUDGE    freopen( input.txt ,  r , stdin);   #endif       int n; cin >> n;    f[0] = 1;    for (int i = 1; i <= n; i++)     f[i] = (f[i - 1] * i) % mod;       int ans = 0;    for (int k = 0; k <= n; k++) {     if ((n - k) % 2)      continue;     ans += (f[n - k] * ((2 * c(n - k - 1, k) + 4 * c(n - k - 1, k - 1)) % mod)) % mod;     ans %= mod;    }    cout << ans;    return 0;   }
#include <bits/stdc++.h>   const long long N = 5e5 + 5;   const int MOD = 1e9 + 7;   using namespace std;   int n;   int a[N];   long long b[N], c[N];   multiset<long long> s;   void xuly() {     cin >> n;     for (int i = (1); i <= (n); ++i) cin >> a[i];     sort(a + 1, a + 1 + n);     cout << (n - 1) / 2 <<   n ;     int top2 = n, top1 = 1;     for (int i = (1); i <= (n); ++i) {       if (i & 1)         cout << a[top2--] <<    ;       else         cout << a[top1++] <<    ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     xuly();   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   struct gg {     int a, b, num;   } g[maxn], out[maxn];   bool cmp(gg g1, gg g2) { return g1.a < g2.a || (g1.a == g2.a && g1.b > g2.b); }   int main() {     int n, m;     cin >> n >> m;     for (int i = 0; i < m; ++i) {       cin >> g[i].a >> g[i].b;       g[i].num = i;     }     sort(g, g + m, cmp);     int node = 1;     int flag = 0;     int a = 2, b = 3;     for (int i = 0; i < m; ++i) {       if (g[i].b) {         node++;         out[g[i].num].a = node;         out[g[i].num].b = 1;       } else {         if (1ll * node * (node - 1) / 2ll < i + 1) {           flag = 1;           break;         }         out[g[i].num].a = a;         out[g[i].num].b = b;         if (a == b - 1) {           b++;           a = 2;         } else {           a++;         }       }     }     if (flag) {       cout <<  -1 n ;     } else {       for (int i = 0; i < m; ++i) {         cout << out[i].a <<     << out[i].b << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   void printArray(T arr, int l) {     for (int i = 0; i < l; i++) cout << arr[i] <<    ;     cout << endl;   }   int main(void) {     int n, k;     cin >> n >> k;     vector<int> floors;     for (int i = 0; i < n; i++) {       int temp;       cin >> temp;       floors.push_back(temp);     }     sort(floors.begin(), floors.end(), greater<int>());     int done = 0;     long long int cost = 0;     while (done < n) {       cost += 2 * (floors[done] - 1);       done += k;     }     cout << cost << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[105];   int t, n, m;   bool check() {     int flag = 1;     for (int i = 1; i < n; i++) {       if (a[i] > a[i + 1]) return 0;     }     return 1;   }   int main() {     cin >> t;     while (t--) {       cin >> n >> m;       for (int i = 1; i <= n; i++) cin >> a[i];       set<int> s;       int x;       for (int i = 1; i <= m; i++) {         cin >> x;         s.insert(x);       }       int flag = 1;       while (1) {         if (check()) break;         for (int i = 1; i < n; i++) {           if (a[i] > a[i + 1]) {             set<int>::iterator it = s.lower_bound(i);             if (*it != i) {               flag = 0;               break;             }             swap(a[i], a[i + 1]);           }         }         if (flag == 0) break;       }       if (flag)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   void rd(T& x) {     int f = 0, c;     while (!isdigit(c = getchar())) f ^= !(c ^ 45);     x = (c & 15);     while (isdigit(c = getchar())) x = x * 10 + (c & 15);     if (f) x = -x;   }   template <typename T>   void pt(T x, int c = -1) {     if (x < 0) putchar( - ), x = -x;     if (x > 9) pt(x / 10);     putchar(x % 10 + 48);     if (c != -1) putchar(c);   }   const int N = 1000005;   const long long INFLL = 0X3F3F3F3F3F3F3F3FLL;   int n, m, p, a[N];   long long sum[N * 4];   vector<long long> v[N * 4];   void upd(int k1, int sz) {     sum[k1] = sum[k1 * 2] + sum[k1 * 2 + 1];     int lsz = (sz + 1) >> 1;     int rsz = sz >> 1;     v[k1].assign(sz + 2, INFLL);     int j = 0;     for (int i = (0); i <= (lsz); ++i) {       if (j > rsz) --j;       for (; j <= rsz; ++j) {         long long tem = v[k1 * 2 + 1][j] + 1LL * i * p - sum[k1 * 2];         long long w = v[k1 * 2][i + 1] - 1 - 1LL * i * p + sum[k1 * 2];         if (w < v[k1 * 2 + 1][j]) {           if (j) --j;           break;         }         v[k1][i + j] = min(v[k1][i + j], max(v[k1 * 2][i], tem));       }     }   }   void bud(int k1, int k2, int k3) {     ((void)0);     if (k2 == k3) {       v[k1].push_back(~INFLL);       v[k1].push_back(p - a[k2]);       v[k1].push_back(INFLL);       sum[k1] = a[k2];       return;     }     int mid = (k2 + k3) >> 1;     bud(k1 * 2, k2, mid), bud(k1 * 2 + 1, mid + 1, k3);     upd(k1, k3 - k2 + 1);   }   long long qry(int k1, int k2, int k3, int k4, int k5, long long k6) {     ((void)0);     if (k2 > k5 || k3 < k4) return k6;     if (k4 <= k2 && k3 <= k5) {       long long pos =           upper_bound(v[k1].begin(), v[k1].end(), k6) - v[k1].begin() - 1;       return k6 - p * pos + sum[k1];     }     int mid = (k2 + k3) >> 1;     return qry(k1 * 2 + 1, mid + 1, k3, k4, k5, qry(k1 * 2, k2, mid, k4, k5, k6));   }   signed main() {     rd(n), rd(m), rd(p);     for (int i = (1); i <= (n); ++i) rd(a[i]);     bud(1, 1, n);     for (int i = (1); i <= (m); ++i) {       int l, r;       rd(l), rd(r);       pt(qry(1, 1, n, l, r, 0),   n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int ans[6];     cout <<  ? 1 2  <<   n ;     cout.flush();     double a;     cin >> a;     cout <<  ? 2 3  <<   n ;     cout.flush();     double b;     cin >> b;     map<double, bool> have;     have[4] = 1;     have[8] = 1;     have[15] = 1;     have[16] = 1;     have[23] = 1;     have[42] = 1;     double arr[6] = {4, 8, 15, 16, 23, 42};     for (int i = 0; i < 6; i++) {       if ((have[a / arr[i]] && a / arr[i] != arr[i]) &&           (have[b / arr[i]] && b / arr[i] != arr[i])) {         ans[1] = arr[i];         ans[0] = a / arr[i];         ans[2] = b / arr[i];         break;       }     }     cout <<  ? 4 5  <<   n ;     cout.flush();     double c;     cin >> c;     cout <<  ? 5 6  <<   n ;     cout.flush();     double d;     cin >> d;     for (int i = 0; i < 6; i++) {       if ((have[c / arr[i]] && c / arr[i] != arr[i]) &&           (have[d / arr[i]] && d / arr[i] != arr[i])) {         ans[4] = arr[i];         ans[3] = c / arr[i];         ans[5] = d / arr[i];         break;       }     }     cout <<  !  ;     for (int i = 0; i < 6; i++) {       cout << ans[i] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long dp[3505][305];   int a[305], b[305];   const int mod = 1e9 + 7;   int main() {     int n, l;     cin >> n >> l;     for (int i = 0; i < n; i++) {       scanf( %d%d , &a[i], &b[i]);       dp[a[i]][i]++;       if (a[i] != b[i]) {         a[i + n] = b[i];         b[i + n] = a[i];         dp[a[i + n]][i + n]++;       }     }     for (int i = 1; i <= l; i++) {       for (int j = 0; j < n * 2; j++) {         if (dp[i][j] == 0) continue;         for (int k = 0; k < 2 * n; k++) {           if (k % n != j % n && a[k] == b[j]) {             dp[i + a[k]][k] = (dp[i + a[k]][k] + dp[i][j]) % mod;           }         }       }     }     long long ans = 0;     for (int i = 0; i < n * 2; i++) {       ans = (ans + dp[l][i]) % mod;     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   typedef long long ll;   using mseti = multiset<int>;   using mmapii = multimap<int, int>;   inline int int_max() { return numeric_limits<int>::max(); }   inline int int_min() { return numeric_limits<int>::min(); }   inline ll ll_max() { return numeric_limits<ll>::max(); }   inline ll ll_min() { return numeric_limits<ll>::min(); }   inline void fastIO() {     cin.tie(nullptr);     cout.tie(nullptr);     ios_base::sync_with_stdio(0);   }   template <class T>   inline ostream& operator<<(ostream& p, deque<T>& o) {     for (auto& e : o) p << e <<    ;     p <<   n ;     return p;   }   template <class T>   inline istream& operator>>(istream& p, vector<T>& o) {     for (auto& e : o) p >> e;     return p;   }   const int M = 1e9;   const int N = 1e2;   void solve() {     int n, m;     cin >> n >> m;     for (int i = 1; i <= 2 * n; i++) {       if (2 * n + i <= m) cout << 2 * n + i <<    ;       if (i <= m) cout << i <<    ;     }     cout <<   n ;   }   int main() {     fastIO();     int T = 1;     while (T--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int a[300007];   int main() {     int n, k;     scanf( %d%d , &n, &k);     string s;     cin >> s;     int sum = 1;     a[0] = 1;     for (int i = (1); i <= (n - 1); ++i) {       if (sum && s[i] ==  . ) a[i] = 1;       sum += a[i];       if (i >= k) sum -= a[i - k];     }     if (a[n - 1])       puts( YES );     else       puts( NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int l, n, a[55], b[55], c[55], d[55];   int main() {     cin >> n >> l;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) cin >> b[i];     for (int i = 1; i < n; i++) c[i] = a[i] - a[i - 1];     c[0] = a[0] + l - a[n - 1];     for (int i = 1; i < n; i++) d[i] = b[i] - b[i - 1];     d[0] = b[0] + l - b[n - 1];     for (int i = 0; i < n; i++) {       bool f = 1;       for (int j = i; j < n; j++) {         if (c[j - i] != d[j]) f = 0;       }       for (int j = 0; j < i; j++) {         if (c[j + n - i] != d[j]) f = 0;       }       if (f) {         cout <<  YES n ;         return 0;       }     }     cout <<  NO n ;   }
#include <bits/stdc++.h>   using namespace std;   int dx[] = {0, 1, 0, -1, -1, -1, 1, 1};   int dy[] = {1, 0, -1, 0, 1, -1, 1, -1};   int main() {     ios::sync_with_stdio(false);     long long n, k;     cin >> n >> k;     if (n == 1)       cout << 0;     else if (n <= k)       cout << 1;     else {       n--;       long long mx = k * (k - 1) / 2;       if (n > mx) {         cout << -1;         return 0;       }       long long l = 1, r = k - 1, mid, res;       while (l <= r) {         mid = (l + r) >> 1;         long long sum = mx - mid * (mid - 1) / 2;         if (sum > n)           l = mid + 1;         else           res = mid, r = mid - 1;       }       long long sum = mx - res * (res - 1) / 2;       res = k - res;       if (sum < n) res++;       cout << res << endl;     }     return 0;   }