malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <iostream>   #include <vector>   #include <algorithm>   #include <string>    #include <set>   #include <cmath>   #include <bitset>   #include <iomanip>   #include <queue>   #include <stack>   #include <map>   #include <unordered_map>   #include <unordered_set>   #include <chrono>   #include <random>   #include <complex>   using namespace std;      mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());      inline void boostIO() {    ios_base::sync_with_stdio(0);    cin.tie(0);    cout.tie(0);    cout << fixed << setprecision(10);   }      bool isPrime(int x) {    if (x <= 4 || x % 2 == 0 || x % 3 == 0) return x == 2 || x == 3;    for (int i = 5; i * i <= x; i += 6) if (x % i == 0 || x % (i + 2) == 0) return 0; return 1;   }      typedef long long int ll;   typedef long double ld;   typedef unsigned long long ull;      typedef vector<int> vi;   typedef vector<ll> vll;   typedef pair<int, int> pii;      #define fori(n) for(int i = 0; i < (n); ++i)   #define forj(n) for(int j = 0; j < (n); ++j)   #define fork(n) for(int k = 0; k < (n); ++k)   #define forx(n) for(int x = 0; x < (n); ++x)      #define all(x) (x).begin(), (x).end()   #define rall(x) (x).rbegin(), (x).rend()   #define ff first   #define ss second   #define debug(x) cerr << #x <<   =   << x << endl;   #define debug_p(x) cerr << #x <<     << x.ff <<     << x.ss << endl;   #define debug_v(x) cerr << #x <<    ; for (auto ii : x) cout << i <<    ; cout << endl;   #define debug_vp(x) cerr << #x <<    ; for (auto ii : x) cout <<  [  << ii.ff <<     << ii.ss <<  ] ; cout << endl;   #define mp make_pair   #define rand kjsdflsdfsdlsjdlkfsdjflsjdfl       #define Return cerr<<endl<< RUNTIME:  <<1.0*clock()/CLOCKS_PER_SEC <<   s  <<endl; return 0;      #define PI 3.14159265      ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }   ll lcm(ll a, ll b) { return a * b / gcd(a, b); }      /////////////////////   #define int long long   int Mod = 1e9 + 7;   #define endl   n    /////////////////////      int inf = 1e18;      vector<int> A;   int dp[2000][2000] = {};   int seen[2000][2000] = {};      int rec(int l, int r) {    if (l == r) {     return 0;    }    if (seen[l][r]) {     return dp[l][r];    }    seen[l][r] = 1;    //here    int ans = inf;    ans = min(rec(l+1, r), rec(l, r-1)) + A[r] - A[l];    dp[l][r] = ans;    return dp[l][r];      }      int32_t main() {    boostIO();    int n; cin >> n;    A.assign(n, 0);    fori(n) {     cin >> A[i];    }     sort(all(A));    cout << rec(0, n - 1);   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const int MOD = 1e9 + 7;   int n, m;   vector<int> a;   int main() {     ios_base::sync_with_stdio(0), cin.tie(0);     cin >> n >> m;     a.resize(n);     for (int i = 0; i < n; i++) cin >> a[i];     sort(a.begin(), a.end());     int cnt = 0;     for (int i = n - 1; i >= 0; i--) {       if (m <= 0) break;       m -= a[i], cnt++;     }     cout << cnt <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 20;   int n, k;   int dp[1 << N][2][2];   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i < (1 << n); ++i)       dp[i][0][0] = dp[i][0][1] = dp[i][1][0] = dp[i][1][1] = -1e9;     for (int i = 1; i <= k; ++i) {       int a;       scanf( %d , &a);       dp[(1 << n) - 1 + a][0][1] = 1;     }     for (int i = (1 << n) - 1; i >= (1 << (n - 1)); --i) {       int tot = dp[i << 1][0][1] + dp[i << 1 | 1][0][1];       if (tot == 0) dp[i][0][0] = 0;       if (tot == 1) dp[i][0][1] = dp[i][1][0] = 1;       if (tot == 2) dp[i][1][1] = 1;     }     for (int i = (1 << (n - 1)) - 1; i; --i) {       for (int x1 = 0; x1 <= 1; ++x1)         for (int x2 = 0; x2 <= 1; ++x2)           for (int y1 = 0; y1 <= 1; ++y1)             for (int y2 = 0; y2 <= 1; ++y2) {               if (y1 | y2)                 dp[i][x1 | x2 | (y1 + y2 == 2)][1] =                     max(dp[i][x1 | x2 | (y1 + y2 == 2)][1],                         dp[i << 1][x1][y1] + dp[i << 1 | 1][x2][y2] + 1 +                             (x1 | x2 | (y1 + y2 == 2)) * 2);               if ((y1 & y2) == 0)                 dp[i][x1 | x2 | (y1 + y2 >= 1)][0] =                     max(dp[i][x1 | x2 | (y1 + y2 >= 1)][0],                         dp[i << 1][x1][y1] + dp[i << 1 | 1][x2][y2] +                             (x1 | x2 | (y1 + y2 >= 1)) * 2);             }     }     printf( %d n ,            max(max(0, dp[1][0][1] + 1), max(dp[1][1][1] + 1, dp[1][1][0] + 1)));   }
#include <bits/stdc++.h>   using namespace std;   bool compare(string &s1, string &s2) { return s1.size() < s2.size(); }   bool sortmahstyle(const pair<int, int> &a, const pair<int, int> &b) {     if (a.first < b.first) return true;     return false;   }   void solve() {     long long int n, op;     cin >> n >> op;     string s;     cin >> s;     for (int i = 0; i < n - 2 && op > 0; i++) {       if (s[i] !=  4  && s[i + 1] ==  4  && s[i + 2] ==  7 ) {         if (i % 2)           s[i + 2] =  4 , op--;         else           s[i + 1] =  7 , op--;       } else if (s[i] ==  4  && s[i + 1] ==  7  && s[i + 2] !=  7 ) {         if (i % 2 == 0)           s[i + 1] =  4 , op--;         else           s[i] =  7 , op--;       } else if (s[i] ==  4  && s[i + 1] ==  7  && s[i + 2] ==  7 ) {         if (i % 2 == 0) {           if (op % 2) {             s[i + 1] =  4 ;             break;           } else {             break;           }         } else           s[i] =  7 , op--;       } else if (s[i] ==  4  && s[i + 1] ==  4  && s[i + 2] ==  7 ) {         if (i % 2 == 0) {           if (op % 2) {             s[i + 1] =  7 ;             break;           } else {             break;           }         } else           s[i + 2] =  4 , op--;       }     }     cout << s <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t = 1;     while (t-- > 0) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool isPrime(long long n) {     if (n == 1) return false;     if (n == 2) return true;     for (long long i = 2; i * i <= n; i++) {       if (n % i == 0) return false;     }     return true;   }   long long powm(long long a, long long b) {     long long res = 1;     while (b) {       if (b & 1) res = res * 1ll * a % 1000000007;       a = a * 1ll * a % 1000000007;       b >>= 1;     }     return res;   }   long long mul(long long x, long long y) { return (x * 1ll * y) % 1000000007; }   void solve() {     long long i = 0, j = 0, k = 0, n = 0, m = 0, rb, cb, rd, cd;     cin >> n >> m >> rb >> cb >> rd >> cd;     if (rd >= rb && cd >= cb) {       {         cout << min((rd - rb), (cd - cb)) <<   n ;         return;       };     }     if (cd >= cb) {       cout << min((n - rb) * 2 + abs(rb - rd), (cd - cb)) <<   n ;       return;     };     if (rd >= rb) {       cout << min((m - cb) * 2 + abs(cb - cd), (rd - rb)) <<   n ;       return;     };     {       cout << min((((n - rb) * 2) + abs(rb - rd)), ((m - cb) * 2 + abs(cb - cd)))            <<   n ;       return;     }   }   signed main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cout << setprecision(15);     long long t = 1;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 10001;   int st, en;   const int limit = -5000000;   const int maxlongint = 1 << 20;   struct edges {     int v, flow, rev;     int cost;   } make;   vector<edges> g[maxn];   int dist[maxn];   bool vis[maxn];   int tot;   bool ans[maxn];   int i, j, m, n, l, o, p, x, y, z;   int k;   struct pairs {     int x, y;   } pre[maxn];   struct tris {     int s, t, fee;   } sp[maxn];   inline bool spfa() {     for (int i = 0; i <= st; i++) dist[i] = maxlongint;     dist[st] = 0;     queue<int> q;     q.push(st);     while (!q.empty()) {       int x = q.front();       vis[x] = false;       q.pop();       for (int i = 0; i < g[x].size(); i++)         if (g[x][i].flow && dist[g[x][i].v] > dist[x] + g[x][i].cost) {           dist[g[x][i].v] = dist[x] + g[x][i].cost;           pre[g[x][i].v].x = x;           pre[g[x][i].v].y = i;           if (!vis[g[x][i].v]) {             q.push(g[x][i].v);             vis[g[x][i].v] = true;           }         }     }     return dist[en] < maxlongint;   }   inline void addedge(int x, int y, int flow, int cost) {     int v1 = g[x].size();     int v2 = g[y].size();     make.v = y;     make.flow = flow;     make.cost = cost;     make.rev = v2;     g[x].push_back(make);     make.v = x;     make.flow = 0;     make.rev = v1;     make.cost = -cost;     g[y].push_back(make);   }   int mincut(int x, int fw) {     if (x == st) return fw;     int f = mincut(pre[x].x, min(fw, g[pre[x].x][pre[x].y].flow));     g[pre[x].x][pre[x].y].flow -= f;     g[x][g[pre[x].x][pre[x].y].rev].flow += f;     return f;   }   int main() {     scanf( %d%d , &n, &k);     en = 2 * n + 1;     st = en + 1;     addedge(st, 0, k, 0);     for (int i = 1; i <= n; i++) {       scanf( %d%d%d , &sp[i].s, &sp[i].t, &sp[i].fee);       addedge(0, i * 2 - 1, 1, 0);       addedge(i * 2 - 1, i * 2, 1, -sp[i].fee);       addedge(i * 2, en, 1, 0);     }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++)         if (sp[i].s + sp[i].t <= sp[j].s) addedge(i * 2, j * 2 - 1, 1, 0);     while (spfa()) mincut(en, maxlongint);     for (int i = 1; i <= n; i++)       for (j = 0; j < g[i * 2 - 1].size(); j++)         if (g[i * 2 - 1][j].v == i * 2 && g[i * 2 - 1][j].flow == 0)           ans[i] = true;     for (int i = 1; i <= n; i++) printf( %d  , ans[i]);     cout << endl;     fclose(stdin);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   namespace FFT {   const int N = 1 << 21;   struct Complex {     double r, i;   };   inline Complex operator+(const Complex &a, const Complex &b) {     return {a.r + b.r, a.i + b.i};   }   inline Complex operator-(const Complex &a, const Complex &b) {     return {a.r - b.r, a.i - b.i};   }   inline Complex operator*(const Complex &a, const Complex &b) {     return {a.r * b.r - a.i * b.i, a.i * b.r + a.r * b.i};   }   int rev[N];   const double PI = acos(-1);   void FFT(Complex a[], int n, int fl) {     for (int i = 0; i < n; i++)       if (i < rev[i]) swap(a[i], a[rev[i]]);     for (int s = 1; s < n; s <<= 1) {       Complex wn = {cos(PI / s), sin(PI / s) * fl};       for (int i = 0; i < n; i += s << 1) {         Complex w = {1, 0};         for (int j = 0; j < s; j++, w = w * wn) {           Complex x = a[i + j], y = w * a[i + s + j];           a[i + j] = x + y;           a[i + s + j] = x - y;         }       }     }     if (fl == -1)       for (int i = 0; i < n; i++) a[i].r /= n, a[i].i /= n;   }   Complex f[N], g[N];   int n, m;   void solve() {     int lim = 1, d = 0;     while (lim <= n + m) ++d, lim <<= 1;     for (int i = 0; i < lim; i++)       rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (d - 1));     for (int i = n + 1; i < lim; i++) f[i] = {0, 0};     for (int i = m + 1; i < lim; i++) g[i] = {0, 0};     FFT(f, lim, 1);     FFT(g, lim, 1);     for (int i = 0; i < lim; i++) f[i] = f[i] * g[i];     FFT(f, lim, -1);   }   }  // namespace FFT   const int N = 55, M = 105, K = 20005;   const double INF = 1e18;   int n, m, t, x, a[M], b[M];   double dis[N][N], c[M], p[M][K * 2], f[N][K * 2], g[M][K];   void solve(int l, int r) {     if (l == t) return;     if (l == r) {       for (int i = 1; i < n; i++) f[i][l] = INF;       for (int i = 1; i <= m; i++)         if (a[i] != n) f[a[i]][l] = min(f[a[i]][l], g[i][l] + c[i]);       return;     }     int mid = (l + r) >> 1;     solve(mid + 1, r);     FFT::n = r - l - 1;     FFT::m = r - mid - 1;     for (int i = 1; i <= m; i++)       if (a[i] != n) {         for (int j = 0; j <= FFT::n; j++) FFT::f[j] = {p[i][j + 1], 0};         for (int j = 0; j <= FFT::m; j++) FFT::g[j] = {f[b[i]][r - j], 0};         FFT::solve();         for (int j = l; j <= mid; j++) g[i][j] += FFT::f[r - j - 1].r;       }     solve(l, mid);   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> m >> t >> x;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++)         if (i != j) dis[i][j] = INF;     int t1;     for (int i = 1; i <= m; i++) {       cin >> a[i] >> b[i] >> t1;       c[i] = dis[a[i]][b[i]] = t1;       for (int j = 1; j <= t; j++) cin >> t1, p[i][j] = t1 / 1e5;     }     for (int k = 1; k <= n; k++)       for (int i = 1; i <= n; i++)         for (int j = 1; j <= n; j++)           dis[i][j] = min(dis[i][k] + dis[k][j], dis[i][j]);     for (int i = 0; i < t * 2; i++) f[n][i] = i <= t ? 0 : x;     for (int i = 1; i < n; i++)       for (int j = t; j < t * 2; j++) f[i][j] = dis[i][n] + x;     solve(0, t * 2 - 1);     printf( %.10lf n , f[1][0]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline void write(long long a) {     if (a >= 10) write(a / 10);     putchar( 0  + a % 10);   }   inline void writeln(int a) {     write(a);     puts(  );   }   inline int read() {     int x = 0;     char ch = getchar();     bool positive = 1;     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) positive = 0;     for (; isdigit(ch); ch = getchar()) x = x * 10 + ch -  0 ;     return positive ? x : -x;   }   const int N = 200005, oo = 2000000005;   struct data {     int l, r, cost;   } a[N], b[N];   int n, m, ans, tong[N], j;   inline bool cmp1(data a, data b) { return a.r < b.r; }   inline bool cmp2(data a, data b) { return a.l < b.l; }   int main() {     n = read();     m = read();     for (int i = 1; i <= n; i++) {       a[i].l = read();       a[i].r = read();       a[i].cost = read();       b[i] = a[i];     }     sort(&a[1], &a[n + 1], cmp1);     ans = oo;     sort(&b[1], &b[n + 1], cmp2);     j = 1;     for (int i = 1; i <= n; i++) {       for (; a[j].r < b[i].l; j++)         if (!tong[a[j].r - a[j].l + 1])           tong[a[j].r - a[j].l + 1] = a[j].cost;         else           tong[a[j].r - a[j].l + 1] = min(tong[a[j].r - a[j].l + 1], a[j].cost);       if (m >= b[i].r - b[i].l + 1 && tong[m - (b[i].r - b[i].l + 1)])         ans = min(ans, b[i].cost + tong[m - (b[i].r - b[i].l + 1)]);     }     if (ans < oo)       writeln(ans);     else       puts( -1 );   }
#include <bits/stdc++.h>   using namespace std;   int const INF = numeric_limits<int>::max();   long long const LLINF = numeric_limits<long long>::max();   long double const EPS = 1e-9;   int n, m, k, q;   int const N = 505;   int a[N][N];   struct qu {     int x, y, t;   };   bool operator<(const qu& a, const qu& b) { return a.t < b.t; }   qu qq[N * N];   bool check() {     int ans = 0;     vector<int> d(m, -1), d1(m), d2(m);     stack<int> st;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j)         if (a[i][j] == 0) d[j] = i;       while (!st.empty()) st.pop();       for (int j = 0; j < m; ++j) {         while (!st.empty() && d[st.top()] <= d[j]) st.pop();         d1[j] = st.empty() ? -1 : st.top();         st.push(j);       }       while (!st.empty()) st.pop();       for (int j = m - 1; j >= 0; --j) {         while (!st.empty() && d[st.top()] <= d[j]) st.pop();         d2[j] = st.empty() ? m : st.top();         st.push(j);       }       for (int j = 0; j < m; ++j)         ans = max(ans, min((i - d[j]), (d2[j] - d1[j] - 1)));     }     return ans >= k;   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> m >> k >> q;     for (int i = 0; i < q; i++) {       cin >> qq[i].x >> qq[i].y >> qq[i].t;       qq[i].x--;       qq[i].y--;       a[qq[i].x][qq[i].y] = 1;     }     if (!check()) {       cout << -1 << endl;       return 0;     }     sort(qq, qq + q);     int l = 0, r = q - 1;     while (r - l > 1) {       int mid = (l + r) / 2;       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           a[i][j] = 0;         }       }       for (int i = 0; i <= mid; i++) {         a[qq[i].x][qq[i].y] = 1;       }       if (check()) {         r = mid;       } else {         l = mid;       }     }     while (r >= l) {       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           a[i][j] = 0;         }       }       for (int i = 0; i <= l; i++) {         a[qq[i].x][qq[i].y] = 1;       }       if (check()) {         break;       } else {         l++;       }     }     cout << qq[l].t << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct node {     int x, y;   };   int main() {     int n;     while (scanf( %d , &n) != EOF) {       int i, j, cnt = 0;       node a[110];       for (i = 0; i < n; i++) {         scanf( %d%d , &a[i].x, &a[i].y);       }       bool u[110] = {0};       queue<int> q;       for (i = 0; i < n; i++) {         if (u[i]) continue;         u[i] = 1;         q.push(i);         while (!q.empty()) {           node t = a[q.front()];           q.pop();           for (j = 0; j < n; j++) {             if (u[j] == 0 && (t.x == a[j].x || t.y == a[j].y)) {               u[j] = 1;               q.push(j);             }           }         }         cnt += 1;       }       printf( %d n , cnt - 1);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long t;     cin >> t;     while (t--) {       long long a, b;       cin >> a >> b;       long long xx = fabs(a - b);       long long d = xx / 2;       if ((a + b) % 2) {         long long yy = a + b - 2 * d + 1;         cout << yy <<   n ;         for (long long i = d; i <= a + b - d; i++) {           cout << i <<    ;         }         cout <<   n ;       } else {         long long yy = (a + b - 2 * d) / 2 + 1;         cout << yy <<   n ;         for (long long i = d; i <= a + b - d; i += 2) {           cout << i <<    ;         }         cout <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const long long N = 2e5 + 5, M = N;   long long mx, n;   vector<long long> a;   long long dp[N];   void solve() {     long long i, j, m;     cin >> n;     a.resize(n);     map<long long, long long> mapp;     for (i = 0; i < n; i++) {       cin >> a[i];       mapp[a[i] - i] += a[i];     }     for (auto it : mapp) {       mx = max(it.second, mx);     }     cout << mx;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int power(int a, int b, int c) {     long long x = 1, y = a;     while (b > 0) {       if (b % 2 == 1) {         x = (x * y) % c;       }       y = (y * y) % c;       b /= 2;     }     return x % c;   }   long long int gcd(long long int a, long long int b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   int dp[26][1 << 21];   int main() {     long long int n, m;     string str1, str2;     memset(dp, 0, sizeof(dp));     long long int ans = 0, i;     cin >> n >> m;     cin >> str1 >> str2;     long long int g = gcd(int((str1).size()), int((str2).size()));     for (i = 0; i < int((str1).size()); i++) {       dp[str1[i] -  a ][i % g]++;     }     for (i = 0; i < int((str2).size()); i++) {       ans += dp[str2[i] -  a ][i % g];     }     ans = int((str2).size()) * m - ans * gcd(n, m);     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e+5 + 10;   const int INF = 0x7fffffff;   struct edge {     int v, n;   } e[maxn * 2];   struct node {     int mx, mi, i, c;     bool operator<(const node &sec) const { return mx > sec.mx; }   } a[maxn];   int n, m, k;   int head[maxn], rd[maxn];   void read() {     int i, u, v;     scanf( %d%d%d , &n, &m, &k);     for (i = 1; i <= n; i++) {       scanf( %d , &a[i].c);       a[i].i = i;       if (a[i].c)         a[i].mx = a[i].mi = a[i].c;       else         a[i].mx = k, a[i].mi = 1;     }     memset(head, -1, sizeof(head));     for (i = 0; i < m; i++) {       scanf( %d%d , &u, &v);       e[i << 1].v = v;       e[i << 1].n = head[u];       head[u] = i << 1;       e[i << 1 | 1].v = u;       e[i << 1 | 1].n = head[v];       head[v] = i << 1 | 1;     }   }   void tuopu(int d) {     int i, u, v;     queue<int> q;     memset(rd, 0, sizeof(rd));     for (i = 0; i < m; i++) rd[e[i << 1 | d].v]++;     for (i = 1; i <= n; i++)       if (!rd[i]) q.push(i);     while (!q.empty()) {       u = q.front();       q.pop();       for (i = head[u]; i != -1; i = e[i].n)         if ((i & 1) == d) {           v = e[i].v;           rd[v]--;           if (!rd[v]) q.push(v);           if (d)             a[v].mi = max(a[v].mi, a[u].mi + 1);           else             a[v].mx = min(a[v].mx, a[u].mx - 1);         }     }     for (i = 1; i <= n; i++)       if (rd[i]) {         printf( -1 n );         exit(0);       }   }   bool cmpa(node aa, node bb) { return aa.mi < bb.mi; }   bool cmpi(node aa, node bb) { return aa.i < bb.i; }   void check() {     for (int i = 1; i <= n; i++)       if (a[i].mx < a[i].mi) {         printf( -1 n );         exit(0);       }   }   void solve() {     int i, j = 1;     priority_queue<node> q;     bool del;     for (i = 1; i <= k; i++) {       del = false;       for (; j <= n && a[j].mi == i; j++) {         node tmp = a[j];         tmp.i = j;         q.push(tmp);       }       while (!q.empty() && q.top().mx == i) {         node tmp = q.top();         q.pop();         a[tmp.i].c = i;         del = true;       }       if (!del) {         if (q.empty()) {           printf( -1 n );           exit(0);         }         node tmp = q.top();         q.pop();         a[tmp.i].c = i;       }     }   }   void print() {     for (int i = 1; i <= n; i++) printf( %d  , a[i].c);   }   int main() {     read();     tuopu(0);     tuopu(1);     sort(a + 1, a + n + 1, cmpa);     check();     solve();     sort(a + 1, a + n + 1, cmpi);     print();     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:1024000000,1024000000 )   using namespace std;   int pre[1005], c[1005];   vector<int> a[1005];   int find(int x) { return pre[x] = (x == pre[x] ? x : find(pre[x])); }   void Union(int a, int b) {     if (a != b) pre[a] = b;   }   int main() {     int n, m, cnt = 0;     cin >> n >> m;     for (int i = 1; i <= n; i++) pre[i] = i;     for (int i = 1; i <= n; i++) {       int k, b;       cin >> c[i];       k = c[i];       if (k == 0) cnt++;       while (k--) {         cin >> b;         a[b].push_back(i);       }     }     for (int i = 1; i <= m; i++) {       for (int j = 1; j < a[i].size(); j++) {         Union(find(a[i][0]), find(a[i][j]));       }     }     int ans = 0;     for (int i = 1; i <= n; i++)       if (pre[i] == i && c[i]) ans++;     cout << max(0, ans - 1) + cnt << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7, N = 2e2 + 10;   long long c[8];   int main() {     int t;     cin >> t;     while (t--) {       long long x, y;       scanf( %lld%lld , &x, &y);       for (int i = 1; i <= 6; i++) {         scanf( %lld , &c[i]);       }       for (int i = 1; i <= 6; i++) {         c[2] = min(c[2], c[1] + c[3]);         c[6] = min(c[6], c[1] + c[5]);         c[3] = min(c[3], c[2] + c[4]);         c[1] = min(c[1], c[2] + c[6]);         c[4] = min(c[4], c[3] + c[5]);         c[5] = min(c[5], c[4] + c[6]);       }       long long ans;       if (x >= 0 && y >= 0) {         if (x > y) {           ans = y * c[1] + (x - y) * c[6];         } else {           ans = x * c[1] + (y - x) * c[2];         }       } else if (x >= 0 && y < 0) {         ans = -y * c[5] + c[6] * x;       } else if (x < 0 && y >= 0) {         ans = -x * c[3] + y * c[2];       } else {         if (x >= y)           ans = c[4] * -x + (x - y) * c[5];         else           ans = c[4] * -y + c[3] * (y - x);       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   double calcC(int N, int M) {     if (M > N) return 0;     M = min(N - M, M);     double res = 1;     for (int i = 1; i <= M; ++i) res *= N - M + i, res /= i;     return res;   }   int main() {     int N, M;     while (cin >> N >> M) {       double result = 0;       for (int k = 1; k <= N; ++k) {         double tmp = 1;         tmp = calcC(M, k) * calcC(N * M - M, N - k) * k * k;         tmp /= calcC(N * M, N) * N * N;         result += tmp;       }       result *= N;       cout << setprecision(10) << result << endl;     }   }