malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000 * 100;   int n;   pair<int, int> sora[maxn + 100];   int lpos = 0;   bool seen[maxn + 100];   bool comp(pair<int, int> a, pair<int, int> b) {     if (a.first < b.first)       return true;     else {       if (a.first == b.first)         return a.second < b.second;       else         return false;     }   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       int temp;       scanf( %d , &temp);       sora[i] = make_pair(temp, i);     }     sort(sora, sora + n, comp);     int co = 0;     for (int i = 0; i < n; i++) {       seen[sora[i].second] = true;       while (lpos < n && seen[lpos]) lpos++;       if (lpos > i || lpos == n) {         co++;       }     }     cout << co << endl;   }
#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   double fRand(double fMin, double fMax) {     double f = (double)rand() / RAND_MAX;     return fMin + f * (fMax - fMin);   }   template <class T>   T min(T a, T b, T c) {     return min(a, min(b, c));   }   template <class T>   T max(T a, T b, T c) {     return max(a, max(b, c));   }   struct matrix {     vector<vector<int> > a;     int m, n;     matrix(int _m, int _n) {       m = _m;       n = _n;       a.resize(m);       for (int i = (0); i <= (m - 1); ++i) a[i].resize(n);     }     bool inline operator==(const matrix &o) const {       if (m != o.m || n != o.n) return false;       for (int i = (0); i <= (m - 1); ++i) {         for (int j = (0); j <= (n - 1); ++j) {           if (a[i][j] != o.a[i][j]) return false;         }       }       return true;     }     void inline operator=(const matrix &o) {       m = o.m;       n = o.n;       for (int i = (0); i <= (m - 1); ++i) {         for (int j = (0); j <= (n - 1); ++j) a[i][j] = o.a[i][j];       }     }     matrix inline operator*(const matrix &o) const {       matrix c(m, o.n);       for (int i = (0); i <= (m - 1); ++i) {         for (int j = (0); j <= (o.n - 1); ++j) {           c.a[i][j] = 0;           for (int k = (0); k <= (n - 1); ++k)             c.a[i][j] = (c.a[i][j] + 1LL * a[i][k] * o.a[k][j]) % 1000000007;         }       }       return c;     }     void print() {       for (int i = (0); i <= (m - 1); ++i) {         for (int j = (0); j <= (n - 1); ++j) printf( %d  , a[i][j]);         puts(  );       }       puts(  );     }   };   matrix Identity(int n) {     matrix I(n, n);     for (int i = (0); i <= (n - 1); ++i) I.a[i][i] = 1;     return I;   }   matrix matPow(matrix A, int n) {     if (n == 0) return Identity(A.m);     if (n % 2 == 1) return A * matPow(A, n - 1);     matrix B = matPow(A, n / 2);     return B * B;   }   int n, l, M, c[3][1000005], dpp[105], last[105];   int main() {     scanf( %d%d%d , &n, &l, &M);     for (int i = (0); i <= (2); ++i)       for (int j = (1); j <= (n); ++j) scanf( %d , &c[i][j]);     matrix A(1, M);     for (int i = (1); i <= (n); ++i) ++A.a[0][c[0][i] % M];     for (int i = (1); i <= (n); ++i) ++dpp[c[1][i] % M];     matrix B(M, M);     for (int i = (0); i <= (M - 1); ++i)       for (int j = (0); j <= (M - 1); ++j) B.a[i][j] = dpp[(j - i + M) % M];     matrix C = A * matPow(B, l - 2);     for (int i = (1); i <= (n); ++i) {       ++last[(c[1][i] + c[2][i]) % M];     }     int ans = 0;     for (int i = (0); i <= (M - 1); ++i) {       ans = (ans + 1LL * last[i] * C.a[0][(M - i) % M]) % 1000000007;     }     printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, a[5005], b[5005], ans[5005], s, q[10005], x[10005];   map<int, int> m;   void ask(int x, int y) {     printf( ? %d %d n , x, y);     fflush(stdout);   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) ask(i, 0), scanf( %d , a + i), x[a[i]] = i;     for (int i = 0; i < n; i++) ask(x[0], i), scanf( %d , b + i);     for (int i = 0; i < n; i++) {       memset(q, -1, sizeof(q));       for (int j = 0; j < n; j++) q[a[j] ^ i] = j;       bool ok = 1;       for (int j = 0; j < n; j++)         if (q[j] != (b[j] ^ i)) ok = 0, j = n;       if (ok) ans[++s] = i;     }     printf( ! n );     printf( %d n , s);     s = ans[1];     for (int i = 0; i < n - 1; i++) printf( %d  , a[i] ^ s);     printf( %d n , a[n - 1] ^ s);     fflush(stdout);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int32_t main() {     long long n, k;     cin >> n >> k;     vector<long long> a(n);     vector<long long> b(n);     vector<long long> c(n);     long long sum1 = 0;     for (long long i = 0; i < n; i++) {       cin >> a[i];     }     for (long long i = 0; i < n; i++) {       cin >> b[i];       sum1 += b[i];     }     for (long long i = 0; i < n; i++) {       c[i] = b[i] - a[i];     }     sort(c.begin(), c.end());     reverse(c.begin(), c.end());     long long sum2 = 0;     for (long long i = 0; i < k; i++) {       sum2 += c[i];     }     for (long long i = k; i < n; i++) {       if (c[i] > 0) sum2 += c[i];     }     cout << sum1 - sum2 << endl;   }
#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const long long MOD = (long long)1e9 + 7;   long long add(long long x, long long y) {     x += y;     if (x >= MOD) return x - MOD;     return x;   }   long long sub(long long x, long long y) {     x -= y;     if (x < 0) return x + MOD;     return x;   }   long long mult(long long x, long long y) { return (x * y) % MOD; }   const int N = (int)1e6 + 7;   long long f[N], rf[N];   long long pw1[N], pw2[N];   int n, m;   int main() {     rf[0] = rf[1] = 1;     for (long long x = 2; x < N; x++) rf[x] = sub(0, mult(MOD / x, rf[MOD % x]));     for (int i = 2; i < N; i++) rf[i] = mult(rf[i - 1], rf[i]);     f[0] = 1;     for (int i = 1; i < N; i++) f[i] = mult(f[i - 1], i);     scanf( %d%d , &n, &m);     pw1[0] = pw2[0] = 1;     for (int i = 1; i < N; i++) {       pw1[i] = mult(pw1[i - 1], n);       pw2[i] = mult(pw2[i - 1], m);     }     long long ans = 0;     for (int k = 1; k < n - 1 && k <= m; k++) {       long long cur = k + 1;       cur = mult(cur, pw1[n - k - 2]);       cur = mult(cur, f[n - 2]);       cur = mult(cur, rf[n - k - 1]);       cur = mult(cur, f[m - 1]);       cur = mult(cur, rf[k - 1]);       cur = mult(cur, rf[m - k]);       cur = mult(cur, pw2[n - 1 - k]);       ans = add(ans, cur);     }     if (n - 1 <= m) {       long long cur = f[n - 2];       cur = mult(cur, f[m - 1]);       cur = mult(cur, rf[n - 2]);       cur = mult(cur, rf[m - n + 1]);       ans = add(ans, cur);     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 55;   const int maxm = 2e4 + 5;   int a[maxn][maxm], dp[maxm], nxt[maxm], sum[maxn][maxm];   int pre[maxm], suff[maxm];   int n, m, k;   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cin >> n >> m >> k;     for (int i = 0; i <= n - 1; i++)       for (int j = 0; j <= m - 1; j++) cin >> a[i][j];     for (int i = 0; i <= n - 1; i++)       for (int j = 0; j <= k - 1; j++) sum[i][0] += a[i][j];     for (int i = 0; i <= n - 1; i++)       for (int j = 1; j <= m - k; j++)         sum[i][j] = sum[i][j - 1] + a[i][j + k - 1] - a[i][j - 1];     for (int i = 0; i <= m - k; i++) nxt[i] = sum[0][i] + sum[1][i];     for (int i = 1; i <= n - 1; i++) {       for (int j = 0; j <= m - k; j++) dp[j] = nxt[j], nxt[j] = 0;       pre[0] = dp[0];       for (int i = 1; i <= m - k; i++) pre[i] = max(pre[i - 1], dp[i]);       suff[m - k] = dp[m - k];       for (int i = m - k - 1; i >= 0; i--) suff[i] = max(suff[i + 1], dp[i]);       for (int j = 0; j <= m - k; j++) {         if (j - k >= 0) nxt[j] = max(pre[j - k], nxt[j]);         if (j + k <= m - k) nxt[j] = max(suff[j + k], nxt[j]);       }       int tmp = 0;       deque<pair<int, int> > que;       for (int j = 0; j <= m - k; j++) {         int now = dp[j] - tmp - sum[i][j];         while (que.size() && que.front().first < now) que.pop_front();         que.push_front(pair<int, int>(now, j));         if (j - k >= 0 && que.size() && que.back().second == j - k)           que.pop_back();         nxt[j] = max(nxt[j], que.back().first + tmp);         tmp += a[i][j];       }       tmp = 0;       que.clear();       for (int j = m - k; j >= 0; j--) {         int now = dp[j] - tmp - sum[i][j];         while (que.size() && que.front().first < now) que.pop_front();         que.push_front(pair<int, int>(now, j));         if (j + k <= m - k && que.size() && que.back().second == j + k)           que.pop_back();         nxt[j] = max(nxt[j], que.back().first + tmp);         tmp += a[i][j + k - 1];       }       for (int j = 0; j <= m - k; j++) nxt[j] += sum[i][j] + sum[i + 1][j];     }     int res = 0;     for (int i = 0; i <= m - k; i++) res = max(res, nxt[i]);     cout << res <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   char a[51][51], b[51][51];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int ax, ay, bx, by, xx, yy, s = 0, ans = 0;     cin >> ax >> ay;     for (int i = 1; i <= ax; i++) {       for (int j = 1; j <= ay; j++) cin >> a[i][j];     }     cin >> bx >> by;     for (int i = 1; i <= bx; i++) {       for (int j = 1; j <= by; j++) cin >> b[i][j];     }     for (int x = -50; x <= 50; x++) {       for (int y = -50; y <= 50; y++) {         s = 0;         for (int i = 1; i <= ax; i++) {           for (int j = 1; j <= ay; j++) {             if (((i + x >= 1) && (i + x <= bx)) &&                 ((j + y >= 1) && (j + y <= by))) {               s += (a[i][j] -  0 ) * (b[i + x][j + y] -  0 );             }           }         }         if (s >= ans) {           ans = s;           xx = x;           yy = y;         }       }     }     cout << xx <<     << yy;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int countbit(int a) {     int i = 0;     while (a != 0) {       if (a & 1) i++;       a /= 2;     }     return i;   }   int dp[1100000] = {0};   int main() {     int a[150];     int arr[150], arr1[150] = {0};     int n, m;     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     for (int i = 0; i < n / 2; i++) swap(a[i], a[n - 1 - i]);     cin >> m;     for (int i = m; i > 0; i--) {       char s[50];       int x;       cin >> s >> x;       if (s[0] ==  p ) {         arr1[i] = 1;       }       if (x == 1)         arr[i] = 1;       else         arr[i] = -1;     }     dp[0] = 0;     for (int i = 1; i < (1 << m); i++) {       int z = countbit(i);       if (arr[z] > 0) {         dp[i] = -1 * 0x3f3f3f3f;         for (int j = 0; j < m; j++) {           if (i & (1 << j)) {             dp[i] = max(dp[i], dp[i ^ (1 << j)] + arr1[z] * a[j]);           }         }       } else {         dp[i] = 0x3f3f3f3f;         for (int j = 0; j < m; j++) {           if (i & (1 << j)) {             dp[i] = min(dp[i], dp[i ^ (1 << j)] - arr1[z] * a[j]);           }         }       }     }     cout << dp[(1 << m) - 1];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void sol() {     int n, m, k;     cin >> n >> m >> k;     int a[n + 1][m + 1];     for (int i = 1; i <= n; i++)       for (int ii = 1; ii <= m; ii++) cin >> a[i][ii];     for (int i = 1; i <= k; i++) {       int x, y;       cin >> y;       x = 1;       while (x != n + 1) {         if (a[x][y] == 1)           a[x][y] = 2, y++;         else if (a[x][y] == 2)           x++;         else           a[x][y] = 2, y--;       }       cout << y <<    ;     }     cout <<   n ;   }   int main() {     std::ios_base::sync_with_stdio(0);     std::cin.tie(0);     std::cout.tie(0);     ;     int tc = 1;     while (tc--) sol();     return 0;   }
#include<bits/stdc++.h>   using namespace std;      #define pii             pair<int,int>   #define vi              vector<int>   #define mii             map<int,int>   #define pqs             priority_queue<int,vi,greater<int> >   #define mod             1000000007   #define int             long long   #define pb              push_back   #define inf             1e18   #define sp(x,y)         fixed<<setprecision(y)<<x   #define mk(arr,n,type)  type *arr=new type[n];   #define w(t)            int t; cin>>t; while(t--)   #define mp              make_pair   #define endl              n    #define pqb             priority_queue<int>   #define ceil(a , b)     ((a / b) + (a%b && 1))   #define rep(i,a,b)      for(int i=a;i<(int)b;i++)   #define repr(i,a,b)     for(int i=a;i>=(int)b;i--)   #define fastio          ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);   #define setbits(x)      __builtin_popcountll(x)   #define zrobits(x)      __builtin_ctzll(x)   #define all(v)          v.begin(), v.end()   #define ff              first   #define ss              second   template<typename... T> void pn(T... args) { ((cout << args <<    ), ...); cout<<  n ; }   template<typename... T> void ps(T... args) { ((cout << args <<    ), ...); cout<<  ; }   // void start()   // {   //     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);   // #ifndef ONLINE_JUDGE   //     freopen( input.txt ,  r , stdin);   //     freopen( output.txt ,  w , stdout);   // #endif   // }   int power(int a, int b,int P=mod) {       int res = 1;       for (; b; b >>= 1, a = 1ll * a * a % P)           if (b & 1)               res = 1ll * res * a % P;       return res;   }      void solve()   {       int n;       cin>>n;       int arr[n];       int sum=0;       vector<int>temp;       int ans=n-1;       for(int i=0; i<n; i++)       {           cin>>arr[i];           sum+=arr[i];           temp.pb(sum);       }       for(auto j:temp)       {           int i=0,cnt=0;           sum=0;           while(i<n)           {               sum+=arr[i];               if(sum==j)               {                   cnt++;                   sum=0;               }               else if(sum>j)               {                   break;               }               i++;           }           if(i==n&&sum==0)           {               ans=min(ans,n-cnt);           }       }       cout<<ans<<endl;      }   int32_t main()   {       fastio;       w(t)       {           solve();       }          return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:268435456,268435456 )   using namespace std;   int above[41][41], dp[41][41][41][41];   char s[42];   int main() {     int n, m, q, s1, s2, s3, s4;     scanf( %d %d %d , &n, &m, &q);     for (int i = 1; i <= n; i++) {       scanf( %s , s + 1);       for (int j = 1; j <= m; j++)         if (s[j] ==  0 ) above[i][j] += above[i - 1][j] + 1;     }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         for (int k = i; k <= n; k++)           for (int l = j; l <= m; l++) {             dp[i][j][k][l] =                 dp[i][j][k - 1][l] + dp[i][j][k][l - 1] - dp[i][j][k - 1][l - 1];             int temp = min(above[k][l], k - i + 1);             dp[i][j][k][l] += temp;             for (int z = l - 1; z >= j; z--) {               temp = min(temp, above[k][z]);               if (temp == 0)                 break;               else                 dp[i][j][k][l] += temp;             }           }     for (int i = 0; i < q; i++)       scanf( %d %d %d %d , &s1, &s2, &s3, &s4),           printf( %d n , dp[s1][s2][s3][s4]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   vector<int> vec[300000];   int mn(int x);   int mx(int x) {     if (!vec[x].size()) return 0;     int ret = n;     for (int i = (0); i < (vec[x].size()); i++) ret = min(ret, mn(vec[x][i]));     return ret;   }   int mn(int x) {     if (!vec[x].size()) return 0;     int ret = 0;     for (int i = (0); i < (vec[x].size()); i++) ret += mx(vec[x][i]) + 1;     return ret - 1;   }   int main() {     scanf( %d , &n);     for (int i = (0); i < (n - 1); i++) {       int x, y;       scanf( %d%d , &x, &y);       x--;       y--;       vec[x].push_back(y);     }     int leaf = 0;     for (int i = (0); i < (n); i++)       if (!vec[i].size()) leaf++;     printf( %d %d n , leaf - mx(0), 1 + mn(0));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int T, n, m, sa[40010], sb[40010], ls, du[201], ans;   bool g[201][201];   int getint() {     int w = 0;     bool q = 0;     char c = getchar();     while ((c >  9  || c <  0 ) && c !=  - ) c = getchar();     if (c ==  - ) c = getchar(), q = 1;     while (c >=  0  && c <=  9 ) w = w * 10 + c -  0 , c = getchar();     return q ? -w : w;   }   void dfs(int u) {     while (du[u]) {       for (int i = 1; i <= n; i++)         if (g[u][i]) {           ls++;           sa[ls] = u;           sb[ls] = i;           du[u]--, du[i]--;           g[u][i] = g[i][u] = 0;           u = i;           break;         }     }   }   int main() {     T = getint();     while (T--) {       ans = n = getint();       m = getint();       for (int i = 1, x, y; i <= m; i++) {         x = getint();         y = getint();         g[x][y] = g[y][x] = 1;         du[x]++;         du[y]++;       }       for (int i = 1; i <= n; i++) ans -= du[i] & 1;       printf( %d n , ans);       for (int i = 1; i <= n; i++)         if (du[i] & 1)           while (du[i]) dfs(i);       for (int i = 1; i <= n; i++)         while (du[i]) dfs(i);       for (int i = 1; i <= ls; i++) printf( %d %d n , sa[i], sb[i]);       ls = 0;     }   }
#include <bits/stdc++.h>   using namespace std;   long long cross(pair<long long, long long> a, pair<long long, long long> b,                   pair<long long, long long> c) {     return abs((b.first - a.first) * (c.second - a.second) -                (b.second - a.second) * (c.first - a.first));   }   vector<pair<long long, long long> > P;   int n;   long long s;   int main() {     cin >> n >> s;     for (int i = 1; i <= n; i++) {       pair<long long, long long> p;       cin >> p.first >> p.second;       P.push_back(p);     }     sort(P.begin(), P.end());     pair<long long, long long> a, b, c;     a = P[0], b = P[1], c = P[2];     long long ans = cross(a, b, c);     int flag = 1;     while (flag) {       flag = 0;       for (int i = 0; i < P.size(); i++) {         long long tmp = cross(P[i], b, c);         if (tmp > ans) {           ans = tmp;           a = P[i];           flag = 1;         }       }       for (int i = 0; i < P.size(); i++) {         long long tmp = cross(a, P[i], c);         if (tmp > ans) {           ans = tmp;           b = P[i];           flag = 1;         }       }       for (int i = 0; i < P.size(); i++) {         long long tmp = cross(a, b, P[i]);         if (tmp > ans) {           ans = tmp;           c = P[i];           flag = 1;         }       }     }     cout << a.first + b.first - c.first <<     << a.second + b.second - c.second          << endl;     cout << a.first + c.first - b.first <<     << a.second + c.second - b.second          << endl;     cout << b.first + c.first - a.first <<     << b.second + c.second - a.second          << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     s +=  0 ;     int c = 1;     char sc = s[0];     bool xd = false;     string res =   ;     for (int i = 1; i < s.size(); i++) {       if (sc != s[i]) {         if (c == 1) {           res += sc;           xd = false;         } else if (c >= 2 && xd) {           xd = false;           res += sc;         } else {           xd = true;           res += sc;           res += sc;         }         c = 1;         sc = s[i];       } else         c++;     }     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int64_t mod = 1e9 + 7;   int64_t mod1 = 1e9 + 6;   int64_t power(int64_t a, int64_t b) {     if (b == 0)       return 1;     else if (b % 2 == 0)       return power((((a % mod) * (a % mod)) % mod), b / 2) % mod;     else       return ((a % mod) * (power((((a % mod) * (a % mod)) % mod), b / 2) % mod)) %              mod;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int64_t n;     cin >> n;     int64_t a[n + 1], b[n + 1], c[n + 1], d[n + 1], e[n + 1];     for (int64_t i = 1; i <= n; ++i) cin >> a[i] >> b[i] >> c[i] >> d[i] >> e[i];     if (n <= 2) {       cout << n <<   n ;       for (int64_t i = 1; i <= n; ++i) cout << i <<   n ;       return 0;     }     bool vis[n + 1];     memset(vis, false, sizeof(vis));     for (int64_t i = 1; i <= n; ++i) {       if (vis[i]) continue;       int64_t ch = 0;       for (int64_t j = 1; j <= n; ++j) {         if (i == j) continue;         for (int64_t k = j + 1; k <= n; ++k) {           if (i == k or k == j) continue;           int64_t s =               (a[j] - a[i]) * (a[k] - a[i]) + (b[j] - b[i]) * (b[k] - b[i]) +               (c[j] - c[i]) * (c[k] - c[i]) + (d[j] - d[i]) * (d[k] - d[i]) +               (e[j] - e[i]) * (e[k] - e[i]);           if (s > 0) {             ch = 1;             break;           }         }         if (ch) break;       }       if (ch == 0) {         cout << 1 <<   n ;         cout << i;         return 0;       }     }     cout << 0;   }
#define rep(i,n) for(int i=0;i<(int)(n);i++)   #define ALL(v) v.begin(),v.end()   typedef long long ll;       #include<bits/stdc++.h>   using namespace std;       int main(){     ios::sync_with_stdio(false);     std::cin.tie(nullptr);          int t;     cin>>t;     while(t--){       int xa,ya,xb,yb,xf,yf;       cin>>xa>>ya>>xb>>yb>>xf>>yf;              if(xa==xb && xf==xa && (yf-ya)*(yf-yb)<0) cout<<abs(ya-yb)+2<<endl;       else if(ya==yb && yf==ya && (xf-xa)*(xf-xb)<0) cout<<abs(xa-xb)+2<<endl;       else cout<<abs(xa-xb)+abs(ya-yb)<<endl;                                 }                      return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 400;   int n, m, dp[MAXN + 5][MAXN + 5];   char s[MAXN + 5], t[MAXN + 5];   inline void ckmax(int &x, int y) { x = x > y ? x : y; }   int main() {     int T;     scanf( %d , &T);     while (T--) {       scanf( %s%s , s + 1, t + 1);       n = strlen(s + 1);       m = strlen(t + 1);       bool ok = 0;       for (int i = 1; i <= m; ++i) {         memset(dp, -1, sizeof(dp));         dp[0][0] = 0;         for (int j = 1; j <= n; ++j) {           for (int k = 0; k <= i; ++k) {             if (dp[j - 1][k] != -1) {               ckmax(dp[j][k], dp[j - 1][k] + (i + dp[j - 1][k] + 1 <= m &&                                               s[j] == t[i + dp[j - 1][k] + 1]));             }             if (k >= 1 && s[j] == t[k]) {               ckmax(dp[j][k], dp[j - 1][k - 1]);             }           }         }         if (dp[n][i] == m - i) {           ok = 1;           break;         }       }       if (ok)         puts( YES );       else         puts( NO );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     string s1, s2;     cin >> s1 >> s2;     if (s1.size() > s2.size())       cout << s1.size();     else if (s2.size() > s1.size())       cout << s2.size();     else if (s1 == s2)       cout <<  -1 ;     else       cout << s1.size();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5e5 + 5;   int n, k, par[N];   int64_t f[N], g[N];   vector<pair<int, int> > ke[N];   vector<int64_t> c[N];   void dfs(int u) {     int64_t sum = 0;     for (auto e : ke[u])       if (e.second != par[u]) {         int v = e.second, w = e.first;         par[v] = u;         dfs(v);         sum += f[v];         c[u].push_back(g[v] + w - f[v]);       }     sort(c[u].begin(), c[u].end(), greater<int64_t>());     for (int i = 0; i < k - 1 && i < (int)c[u].size() && c[u][i] > 0; ++i)       sum += c[u][i];     f[u] = g[u] = sum;     if (k <= (int)c[u].size() && c[u][k - 1] > 0) f[u] += c[u][k - 1];   }   int main() {     int T;     scanf( %d , &T);     while (T--) {       scanf( %d%d , &n, &k);       for (int i = 1; i < n; ++i) {         int u, v, w;         scanf( %d%d%d , &u, &v, &w);         ke[u].push_back(make_pair(w, v));         ke[v].push_back(make_pair(w, u));       }       dfs(1);       printf( %I64d n , f[1]);       for (int i = 1; i <= n; ++i) ke[i].clear(), c[i].clear(), par[i] = 0;     }   }