malteklaes/cpp-code-code_search_net-style huggingface dataset:
// #pragma GCC optimize( Ofast,unroll-loops )   // #pragma GCC target( avx,avx2,fma )      #include <bits/stdc++.h>   using namespace std;      #define ll long long   #define ull unsigned long long   #define dd double   #define ld long double   #define sl(n) scanf( %lld , &n)   #define si(n) scanf( %d , &n)   #define sd(n) scanf( %lf , &n)   #define pll pair <ll, ll>   #define pii pair <int, int>   #define mp make_pair   #define pb push_back   #define all(v) v.begin(), v.end()   #define inf (1LL << 61)   #define loop(i, start, stop, inc) for(ll i = start; i <= stop; i += inc)   #define for1(i, stop) for(ll i = 1; i <= stop; ++i)   #define for0(i, stop) for(ll i = 0; i < stop; ++i)   #define rep1(i, start) for(ll i = start; i >= 1; --i)   #define rep0(i, start) for(ll i = (start-1); i >= 0; --i)   #define ms(n, i) memset(n, i, sizeof(n))   #define casep(n) printf( Case %lld: , ++n)   #define pn printf(  n )   #define pf printf   #define EL   n    #define fastio std::ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);      // === Debug macro starts here ===   #ifndef ONLINE_JUDGE   #define DEBUG   #define SYS_COL system( COLOR )   #endif      int recur_depth = 0;   #ifdef DEBUG   #define dbg(x) {++recur_depth; auto x_=x; --recur_depth; SYS_COL;                    cerr<<string(recur_depth,   t )<<  [91m <<__func__<< :                     <<__LINE__<<  t <<#x<<  =  <<x_<<  [39m <<endl;}      template<typename Ostream, typename Cont>   typename enable_if<is_same<Ostream,ostream>::value,               Ostream&>::type operator<<(Ostream& os,  const Cont& v) {    os<< [ ;    for(auto& x:v){os<<x<< ,  ;}    return os<< ] ;   }   template<typename Ostream, typename ...Ts>   Ostream& operator<<(Ostream& os,  const pair<Ts...>& p){    return os<< { <<p.first<< ,  <<p.second<< } ;   }   #else   #define dbg(x)   #endif   // === Debug macro ends here ===      #define ff first   #define ss second      const ll sz = 1e5 + 10, mod = 1e9 + 7;   ll fact[sz], inv[sz];      ll fastPow(ll x, ll n, ll MOD)   {       ll ret = 1;       while (n)       {           if (n & 1) ret = (ret * x) % MOD;           x = (x * x) % MOD;           n >>= 1;       }       return ret % MOD;   }      inline ll ncr(ll n, ll r)   {       if(n < r) return 0;       ll den = (inv[r] * inv[n-r]) % mod;       return (fact[n] * den) % mod;   }      int main()   {       fact[0] = 1;       for1(i, sz-1) fact[i] = (fact[i-1] * i) % mod;          inv[sz-1] = fastPow(fact[sz-1], mod-2, mod);       rep0(i, sz-1) inv[i] = (inv[i+1] * (i+1)) % mod;          ll t;       cin >> t;          while(t--) {           ll n, k;           sl(n), sl(k);              ll ans = 0;              for1(p, n) {               ll posCell = n - (k-1)*(p-1);               if(posCell <= 0) break;                  ll prob = (fact[p] * inv[n]) % mod;               prob = (prob * fact[n-p]) % mod;                  ans += (ncr(posCell, p) * prob) % mod;               if(ans >= mod) ans -= mod;           }           pf( %lld n , (ans+1)%mod);       }          return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 10;   int a[N], n, l, r, ans;   bool check(int k) {     for (int i = 1; i <= n; ++i) {       if (1LL * k * (i - 1) > a[i]) return false;       if (1LL * k * (n - i) > a[i]) return false;     }     return true;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d , &a[i]);     l = 0, r = 1e9, ans = 0;     while (l <= r) {       int mid = l + r >> 1;       if (check(mid)) {         ans = mid;         l = mid + 1;       } else         r = mid - 1;     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5 + 5;   long long v[N], mn[N];   int main() {     long long n;     long long ans = 0;     cin >> n;     for (long long i = 0; i < n; i++) cin >> v[i];     for (long long i = 0; i < n; i++) mn[i] = v[i] + 1;     for (long long i = 1; i < n; i++) mn[i] = max(mn[i - 1], mn[i]);     for (long long i = n - 2; i >= 0; i--) mn[i] = max(mn[i], mn[i + 1] - 1);     for (long long i = 0; i < n; i++) ans += mn[i] - v[i] - 1;     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int P = 1e9 + 7;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long qpow(long long a, long long n) {     long long r = 1 % P;     for (a %= P; n; a = a * a % P, n >>= 1)       if (n & 1) r = r * a % P;     return r;   }   long long inv(long long x) { return x <= 1 ? 1 : inv(P % x) * (P - P / x) % P; }   const int N = 2e5 + 10;   int a[N], h[N], f[N], n, m, k, p;   struct _ {     long long day, id;     bool operator<(const _& rhs) const { return day > rhs.day; }   };   priority_queue<_> q;   bool check(long long x) {     memset(f, 0, sizeof f);     while (!q.empty()) q.pop();     for (int i = 1; i <= n; ++i)       if (x - (long long)a[i] * m < h[i]) q.push({x / a[i], i});     for (int i = 1; i <= m; ++i)       for (int j = 1; j <= k; ++j) {         if (q.empty()) return 1;         _ u = q.top();         q.pop();         if (u.day < i) return 0;         if (x + (long long)p * ++f[u.id] - (long long)m * a[u.id] < h[u.id]) {           q.push({(x + (long long)p * f[u.id]) / a[u.id], u.id});         }       }     return q.empty();   }   int main() {     scanf( %d%d%d%d , &n, &m, &k, &p);     for (int i = 1; i <= n; ++i) scanf( %d%d , h + i, a + i);     long long l = 0, r = 1e15, ans;     while (l <= r)       check((l + r >> 1))                        ? ans = (l + r >> 1),                             r = (l + r >> 1) - 1 : l = (l + r >> 1) + 1;     cout << ans << endl;   }
#include <bits/stdc++.h>   const long long int m = 1000000007;   using namespace std;   int main() {     int tc;     cin >> tc;     while (tc--) {       int x1, y1, x2, y2;       cin >> x1 >> y1 >> x2 >> y2;       if (x1 == x2 || y1 == y2)         cout << abs(x1 - x2) + abs(y2 - y1) <<   n ;       else         cout << abs(x2 - x1) + abs(y2 - y1) + 2 <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int n, q;     cin >> n >> q;     long long int arr[n];     long long int aftern[n];     long long int maxi[n];     for (long long int i = 0; i < n; i++) {       cin >> arr[i];       if (i == 0)         maxi[i] = i;       else {         if (arr[i] > arr[maxi[i - 1]])           maxi[i] = i;         else           maxi[i] = maxi[i - 1];       }     }     long long int i = n - 1;     long long int e = n - 1;     while (i >= 0) {       long long int maxin = maxi[i];       for (long long int j = maxin; j < e; j++) {         aftern[j] = arr[j + 1];       }       aftern[e] = arr[maxin];       i = maxin - 1;       e = i;     }     long long int max_in = maxi[n - 1];     for (long long int i = 0; i < q; i++) {       long long int x;       cin >> x;       if (x > (n - 1)) {         long long int t = x % (n - 1);         if (t != 0)           cout << arr[max_in] <<     << aftern[t - 1] <<   n ;         else           cout << arr[max_in] <<     << aftern[n - 2] <<   n ;       } else {         cout << arr[maxi[x - 1]] <<     << arr[x] <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long x[5003], a[5003], b[5003], c[5003], d[5003];   vector<int> path;   long long weight[5003][5003];   long long edge(int i, int j) {     long long ans = abs(x[i] - x[j]);     if (j < i) ans += (c[i] + b[j]);     if (i < j) ans += (d[i] + a[j]);     return ans;   }   int main() {     int n, s, e;     cin >> n >> s >> e;     for (int i = 1; i <= n; i++) cin >> x[i];     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n; i++) cin >> b[i];     for (int i = 1; i <= n; i++) cin >> c[i];     for (int i = 1; i <= n; i++) cin >> d[i];     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) weight[i][j] = edge(i, j);     long long ans = weight[s][e];     path.push_back(s);     path.push_back(e);     for (int i = 1; i <= n; i++) {       if (i == s || i == e) continue;       int insert_at = 0;       long long best = 1e12;       for (int j = 0; j < path.size() - 1; j++) {         long long temp = weight[path[j]][i] + weight[i][path[j + 1]] -                          weight[path[j]][path[j + 1]];         if (temp < best) {           best = temp;           insert_at = j;         }       }       ans += best;       vector<int>::iterator ins = find(path.begin(), path.end(), path[insert_at]);       ins++;       path.insert(ins, i);     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline T abs(T t) {     return t < 0 ? -t : t;   }   const long long modn = 1000000007;   inline long long mod(long long x) { return x % modn; }   int main() {     long long d1, d2, d3;     cin >> d1 >> d2 >> d3;     long long ans = min(d1 + d2 + d3, d1 * 2 + d2 * 2);     ans = min(ans, min(d1 * 2 + d3 * 2, d2 * 2 + d3 * 2));     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000000;   int a[300005], b[300005];   class SegmentTree {    public:     SegmentTree* left = nullptr;     SegmentTree* right = nullptr;     int start, end, val = 0, lazyadd = 0;     SegmentTree(int s, int e) {       start = s;       end = e;       if (start != end) {         left = new SegmentTree(start, (start + end) / 2);         right = new SegmentTree((start + end) / 2 + 1, end);       }     }     void propogate() {       if (lazyadd) {         left->val += lazyadd;         right->val += lazyadd;         left->lazyadd += lazyadd;         right->lazyadd += lazyadd;         lazyadd = 0;       }     }     void update(int l, int r, int v) {       if (l > end || r < start) {         return;       }       if (l <= start && end <= r) {         val += v;         lazyadd += v;         return;       }       propogate();       left->update(l, r, v);       right->update(l, r, v);       val = min(left->val, right->val);     }     int traverse() {       if (val >= 0) {         return -1;       }       if (start == end) {         return start;       }       propogate();       if (right->val < 0) {         return right->traverse();       }       return left->traverse();     }   };   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(0);     int n, m, q, input;     int index, x;     cin >> n >> m;     SegmentTree myTree(1, 1000000);     for (int i = 1; i <= n; i++) {       cin >> a[i];       myTree.update(1, a[i], -1);     }     for (int j = 1; j <= m; j++) {       cin >> b[j];       myTree.update(1, b[j], 1);     }     cin >> q;     for (int w = 0; w < q; w++) {       cin >> input >> index >> x;       if (input == 1) {         myTree.update(1, a[index], 1);         a[index] = x;         myTree.update(1, a[index], -1);       } else {         myTree.update(1, b[index], -1);         b[index] = x;         myTree.update(1, b[index], 1);       }       cout << myTree.traverse() << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, x, len, dir, t, y;   bool fin;   pair<int, int> a[210000];   int loc[210000];   int binary_right(int x, int t) {     int l = x, r = n, mid;     while (l < r) {       mid = (l + r + 1) / 2;       if (a[mid].first <= t)         l = mid;       else         r = mid - 1;     }     return l;   }   int binary_left(int x, int t) {     int l = 1, r = x, mid;     while (l < r) {       mid = (l + r) / 2;       if (a[mid].first >= t)         r = mid;       else         l = mid + 1;     }     return l;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i].first);       a[i].second = i;     }     sort(a + 1, a + n + 1);     for (int i = 1; i <= n; i++) loc[a[i].second] = i;     for (int i = 1; i <= m; i++) {       scanf( %d%d , &x, &len);       x = loc[x];       dir = 1;       fin = 0;       while (!fin) {         t = a[x].first + dir * len;         if (dir == 1) {           y = binary_right(x, t);           if (binary_left(y, a[y].first - (len - a[y].first + a[x].first)) == x) {             if (y == x)               fin = 1;             else               len %= 2 * (a[y].first - a[x].first);           } else {             dir = -1;             len -= (a[y].first - a[x].first);             x = y;           }         } else {           y = binary_left(x, t);           if (binary_right(y, a[y].first + (len - a[x].first + a[y].first)) ==               x) {             if (y == x)               fin = 1;             else               len %= 2 * (a[x].first - a[y].first);           } else {             dir = 1;             len -= (a[x].first - a[y].first);             x = y;           }         }       }       printf( %d n , a[x].second);     }   }
#include <bits/stdc++.h>   using namespace std;   int n, k;   int main() {     while (scanf( %d%d , &n, &k) != EOF) {       if (k > n || k > 26 || (n > 1 && k == 1))         printf( -1 n );       else {         for (int i = 0; i < n - max(0, (k - 2)); i++)           if (i % 2 == 0)             printf( a );           else             printf( b );         for (int i = (2); i <= (k - 1); ++i) printf( %c ,  a  + i);         printf(  n );       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int a[5000006];   int S;   void go(int lf, int rg) {     if (lf < 0) return;     S = max(S, (rg - lf) / 2);     if (a[lf] == a[rg]) {       for (int i = lf; i < rg; ++i) a[i] = a[lf];     } else {       for (int i = lf, j = rg; i < j; ++i, --j) {         a[i] = a[lf];         a[j] = a[rg];       }     }   }   void solve() {     cin >> n;     for (int i = 0; i < (n); ++i) scanf( %d , a + i);     int lst = 0;     S = 0;     for (int i = 1; i <= (n - 2); ++i) {       if (a[i] == a[i - 1] || a[i] == a[i + 1]) {         if (i - lst > 1) go(lst, i);         lst = i;       }     }     if (n - 1 - lst > 1) go(lst, n - 1);     cout << S << endl;     for (int i = 0; i < (n); ++i) printf( %d  , a[i]);   }   int main() {     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[30];   int main() {     int n, k, i, j, m;     string s;     cin >> s;     cin >> k;     map<char, int> mp;     map<char, int>::iterator it;     n = s.size();     for (i = 0; i < n; i++) {       ++mp[s[i]];     }     multimap<int, char> mp2;     multimap<int, char>::iterator it2;     for (it = mp.begin(); it != mp.end(); it++) {       mp2.insert(pair<int, char>(it->second, it->first));     }     map<char, int> mp3;     for (it2 = mp2.begin(); it2 != mp2.end(); it2++) {       if (k - it2->first >= 0) {         mp3[it2->second] = 1;         k -= it2->first;       }     }     string s2 =   ;     for (i = 0; i < n; i++) {       if (mp3[s[i]] == 0) {         s2 += s[i];       }     }     mp3.clear();     n = s2.size();     for (i = 0; i < n; i++) {       ++mp3[s2[i]];     }     cout << mp3.size() << endl;     cout << s2 << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 7;   int n, m, q[N], a[N];   int main() {     scanf( %d , &m);     for (int i = (0); i < (m); ++i) scanf( %d , &q[i]);     int mn = *min_element(q, q + m);     scanf( %d , &n);     for (int i = (0); i < (n); ++i) scanf( %d , &a[i]);     sort(a, a + n);     int ans = 0;     for (int i = n - 1, c = 0; i >= 0; --i) {       ans += a[i], ++c;       if (c >= mn) c = 0, i -= 2;     }     printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       if (n <= 30) {         cout <<  NO n ;       } else if (n == 36) {         cout <<  YES n ;         cout <<  5 6 10 15               <<   n ;       } else if (n == 40) {         cout <<  YES n ;         cout <<  9 6 10 15               <<   n ;       } else if (n == 44) {         cout <<  YES n ;         cout <<  6 7 10 21               <<   n ;       } else {         cout <<  YES n ;         cout <<  6 10 14   << n - 30 <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6;   int d[2 * N], c[2 * N], n, k, l, p, a = N, q, w, u;   string s;   int main() {     cin >> n >> k >> l >> s;     q = 0;     w = N;     while (q < w) {       p = (q + w) >> 1;       for (int i = n - 1; i >= 0; i--) {         d[i] = d[i + 1] + (s[i] > 96);         c[i] = c[i + 1];         if (d[i + l] + p < d[i]) d[i] = d[i + l] + p, c[i] = c[i + l] + 1;       }       if (c[0] > k)         q = p + 1;       else         w = p, u = d[0] - p * k;     }     a = min(a, u);     for (auto &p : s) p = (p + 32) % 125;     q = 0;     w = N;     while (q < w) {       p = (q + w) >> 1;       for (int i = n - 1; i >= 0; i--) {         d[i] = d[i + 1] + (s[i] > 96);         c[i] = c[i + 1];         if (d[i + l] + p < d[i]) d[i] = d[i + l] + p, c[i] = c[i + l] + 1;       }       if (c[0] > k)         q = p + 1;       else         w = p, u = d[0] - p * k;     }     a = min(a, u);     printf( %i n , a);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       unsigned long long a, b;       cin >> a >> b;       if (max(a, b) % min(a, b)) {         cout << -1 << endl;         continue;       }       int dem = 0;       long long p = max(a, b) / min(a, b);       while (p != 1) {         if (p % 8 == 0) {           dem++;           p /= 8;         } else if (p % 4 == 0) {           dem++;           p /= 4;         } else if (p % 2 == 0) {           dem++;           p /= 2;         } else {           dem = -1;           break;         }       }       cout << dem << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = (int)5e5 + 9;   const int maxm = (int)1e6 + 9;   const long long mod = (long long)1e9 + 7;   const double pi = acos(-1);   const double eps = 1e-15;   vector<pair<int, int> > to[maxn];   int fa[maxn];   int tobig[maxn];   int n, m;   int e[maxn];   int e2[maxn];   int f[maxn];   int fe[maxn];   void init() {     scanf( %d%d , &n, &m);     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       to[a].emplace_back(i, b);       to[b].emplace_back(i, a);       e[i] = a;       e2[i] = b;     }     memset(tobig, -1, sizeof(tobig));   }   int vis[maxn];   void dfs(int u, int ft) {     vis[u] = -1;     for (int i = 0; i < to[u].size(); i++) {       int v = to[u][i].second;       if (ft == v) continue;       fa[u] = i;       if (vis[v] == 0) {         dfs(v, u);       } else if (vis[v] == -1) {         int mn = maxn;         int mx = -1;         int tmp = v;         vector<int> tot;         do {           int d = to[tmp][fa[tmp]].first;           tot.push_back(d);           mn = min(mn, d);           mx = max(mx, d);           tmp = to[tmp][fa[tmp]].second;         } while (tmp != v);         tobig[mn] = mx;         int mxp, mnp;         int len = tot.size();         for (int x = 0; x < len; x++) {           if (mx == tot[x]) mxp = x;           if (mn == tot[x]) mnp = x;         }         int fl = 0;         for (int x = mxp; x != mnp; x = (x + 1) % len) {           if (tot[x] < tot[(x + 1) % len]) {             fl = 1;             break;           }         }         for (int x = mxp; x != mnp; x = (x + len - 1) % len) {           if (tot[x] < tot[(x + len - 1) % len]) {             fl = 1;             break;           }         }         if (fl) {           tobig[mn] = -1;         }       }     }     vis[u] = 1;   }   int bcj[maxn];   int fd(int x) { return bcj[x] = bcj[x] == x ? x : fd(bcj[x]); }   int main() {     init();     dfs(1, -1);     for (int i = 1; i <= n; i++) {       bcj[i] = i;       f[i] = 1;     }     for (int i = m - 1; i >= 0; i--) {       int fu = fd(e[i]);       int fv = fd(e2[i]);       int tt = f[e[i]] + f[e2[i]];       if (fu == fv) {         if (tobig[i] != -1) {           tt -= fe[tobig[i]];         }       } else {         bcj[fu] = fv;       }       fe[i] = f[e[i]] = f[e2[i]] = tt;     }     for (int i = 1; i <= n; i++) {       cout << f[i] - 1 <<    ;     }     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   int n, q;   int tim[10000];   int main() {     while (~scanf( %d%d , &n, &q)) {       memset(tim, -1, sizeof(tim));       while (q--) {         int ti, ni, di;         scanf( %d%d%d , &ti, &ni, &di);         int cnt = 0;         for (int i = 1; i <= n; i++) {           if (tim[i] <= ti) tim[i] = -1;         }         for (int i = 1; i <= n; i++) {           if (tim[i] == -1) cnt++;         }         if (cnt >= ni) {           int sum = 0;           for (int i = 1; i <= n; i++) {             if (tim[i] == -1) {               if (ni > 0) {                 tim[i] = ti + di;                 sum += i;                 ni--;               }             }           }           printf( %d n , sum);         } else {           printf( -1 n );         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2000500;   int P[N];   int D[N];   multiset<int> S[N];   inline bool recalc(int x) {     if (x == 1) {       D[x] = *S[x].rbegin() + 1;       return false;     } else {       int nd;       if (S[x].size() == 1)         nd = *S[x].rbegin();       else         nd = max(*S[x].rbegin(), *(++S[x].rbegin()) + 1);       if (nd != D[x]) {         S[P[x]].erase(S[P[x]].find(D[x]));         D[x] = nd;         S[P[x]].insert(nd);         return true;       } else         return false;     }   }   int main() {     int n;     scanf( %d , &n);     P[1] = -1;     D[0] = 1;     for (int i = 2; i < n + 2; i++) {       scanf( %d , &P[i]);       S[P[i]].insert(0);       for (int x = P[i]; recalc(x); x = P[x])         ;       printf( %d  , D[1]);     }     printf(  n );   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n + 1];     for (int i = 1; i <= n; i++) cin >> a[i];     sort(a + 1, a + n + 1);     if (n % 2)       cout << a[n / 2 + 1] << endl;     else       cout << a[n / 2] << endl;   }
#include <bits/stdc++.h>   using namespace std;   int n, k, ans;   int a[500101], b[500101], fl[500101];   int q[500101], qn;   void solve() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= k; i++) {       scanf( %d , &b[i]);       fl[b[i]] = 1;     }     int fl2 = 0;     for (int i = 2; i <= k; i++)       if (a[b[i]] <= a[b[i - 1]] || a[b[i]] - a[b[i - 1]] < b[i] - b[i - 1]) {         fl2 = 1;         break;       }     if (fl2) {       printf( -1 n );       return;     }     for (int i = 1; i <= n; i++) a[i] -= i;     q[0] = -1000000007;     int last = 0;     for (int i = 1; i <= n; i++) {       if (a[i] >= q[qn]) {         q[++qn] = a[i];         if (fl[i]) last = qn;       } else {         int p = upper_bound(q + 1, q + 1 + qn, a[i]) - q;         if (p > last) {           q[p] = a[i];           if (fl[i]) last = qn = p;         }       }     }     printf( %d n , n - qn);   }   int main() {     int T = 1;     while (T--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 6;   int n, m;   int a[200];   bool check() {     if (*max_element(a, a + n) != 0) {       return false;     }     return true;   }   void solve() {     int k;     cin >> n >> k;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     if (k == 1) {       if ((count(a, a + n, *max_element(a, a + n))) != n) {         cout << -1 <<   n ;         return;       } else {         cout << 1 <<   n ;         return;       }     }     m = 0;     while (!check()) {       int tmp = k;       m++;       std::vector<int> b(n);       for (int i = 0; i < n; i++) {         if (i == 0) {           tmp--;         } else {           if (a[i] != a[i - 1]) {             if (tmp == 0)               break;             else {               tmp--;             }           }         }         b.push_back(i);       }       for (auto j : b) {         a[j] = 0;       }     }     cout << m <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     int T;     cin >> T;     while (T--) {       solve();     }     return 0;   }