malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int n, m, t;   struct node {     int l, r;   } a[20050];   int cnt[90000], ans[20050];   bool cmp(const node &a, const node &b) { return a.l < b.l; }   int main() {     scanf( %d%d%d , &n, &m, &t);     int x, y, z;     for (int i = (1); i <= (n); i++) {       scanf( %d:%d:%d , &x, &y, &z);       int _ = x * 3600 + y * 60 + z;       a[i] = (node){_, _ + t};       cnt[_]++;       cnt[_ + t]--;     }     int sum = 0, nos = 1;     for (int i = (0); i <= (86400); i++) {       sum += cnt[i];       if (sum >= m) nos = 0;       cnt[i] = 0;     }     if (nos) {       cout <<  No solution  << endl;       return 0;     }     sort(a + 1, a + n + 1, cmp);     for (int i = (1); i <= (n); i++) cnt[a[i].r]--;     sum = 0;     int num = 0, j = 0, la = 0;     for (int i = (0); i <= (86400); i++) {       sum += cnt[i];       while (j + 1 <= n && a[j + 1].l == i) {         j++;         if (sum < m) {           sum++;           ans[la = j] = ++num;         } else {           cnt[a[la].r]++;           ans[la = j] = num;         }       }     }     cout << num << endl;     for (int i = (1); i <= (n); i++) printf( %d n , ans[i]);     return 0;   }
#pragma GCC optimize( O3 , Ofast , no-stack-protector , unroll-loops , omit-frame-pointer , inline ) //Optimization flags   #pragma GCC option( arch=native , tune=native , no-zero-upper ) //Enable AVX   // #pragma GCC target( avx2 ) //Enable AVX      #include <bits/stdc++.h>      #define int long long      using namespace std;      const int MOD = 1e9 + 7;      const int MAXN = 110;      int C[MAXN];      int B[MAXN];      int T[MAXN];      int dp[MAXN][MAXN*MAXN];      int32_t main()   {       ios_base::sync_with_stdio(0);       cin.tie(0);       int N;    cin >> N;       for(int i = 1 ; i <= N ; i++)    {     cin >> C[i];    }           for(int i = 2 ; i <= N ; i++)    {     cin >> B[i];     T[i] = T[i-1]+B[i];    }       for(int i = 1 ; i <= N ; i++)    {     T[i] += T[i-1];    }       int ini = -T[N]/N - 50;    int fin = (100*N-T[N])/N + 50;       map<int,int> mp;       for(int X = ini ; X <= fin ; X++)    {     for(int j = 0 ; j <= 10000 ; j++)     {      dp[0][j] = 1;     }        for(int i = 1 ; i <= N ; i++)     {      for(int j = 0 ; j <= 10000 ; j++)      {       dp[i][j] = 0;       if(j-T[i] >= X*i)       {        int val = 0;        if(j-C[i]-1 >= 0)val = dp[i-1][j-C[i]-1];           dp[i][j] = (dp[i-1][j]+MOD-val);        dp[i][j] %= MOD;       }      }         for(int j = 1 ; j <= 10000 ; j++)      {       dp[i][j] += dp[i][j-1];       dp[i][j] %= MOD;      }     }        mp[X] = dp[N][10000];    }       int Q;    cin >> Q;       for(int i = 1 ; i <= Q ; i++)    {     int X;     cin >> X;        if(X < ini)cout << mp[ini] <<   n ;     else if(X > fin)cout << 0 <<   n ;     else cout << mp[X] <<   n ;    }          return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a, z, k, r;   int v[109];   int ans[1000009];   int w[1000009][2];   int main() {     scanf( %d , &a);     k = 1;     for (int i = 1; i < 1000001; i++) {       z = i;       while (z > 0) {         if (z % 10 != 0 && z % 10 != 1) {           z = -1;           break;         }         z = z / 10;       }       if (z != -1) {         v[k] = i;         k++;         w[i][0] = 1;         w[i][1] = k - 1;       } else         w[i][0] = 9999999;     }     for (int i = 1; i < k; i++)       for (int j = 0; j < 1000001 - v[i]; j++)         if (w[j][0] + 1 < w[j + v[i]][0]) {           w[j + v[i]][0] = w[j][0] + 1;           w[j + v[i]][1] = i;         }     while (a > 0) {       ans[r] = v[w[a][1]];       a = a - v[w[a][1]];       r++;     }     printf( %d n , r);     for (int i = 0; i < r; i++) printf( %d  , ans[i]);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, z;     cin >> n >> m;     z = 0;     int* a = new int[n + 1];     int* s = new int[n + 1];     for (int i = 1; i <= n; i++) cin >> a[i];     s[1] = a[1];     s[0] = 0;     for (int i = 2; i <= n; i++) s[i] = a[i] + s[i - 1];     for (int i = 1; i <= m; i++) {       int l, r;       cin >> l >> r;       int v = s[r] - s[l - 1];       if (v > 0) {         z += v;       }     }     cout << z << endl;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int sum[26];   char str[5002];   char str_list[5002][5002];   int main() {     double ans = 0.0;     scanf( %s , str), n = strlen(str);     for (int i = 0; i < 26; i++) {       int cnt = 0;       int max_total = 0;       for (int j = 0; j < n; j++)         if (str[j] ==  a  + i) {           for (int k = j; k < n; k++) str_list[cnt][k - j] = str[k];           for (int k = 0; k < j; k++) str_list[cnt][k + n - j] = str[k];           cnt++;         }       for (int j = 1; j < n; j++) {         int total = 0;         for (int k = 0; k < 26; k++) sum[k] = 0;         for (int k = 0; k < cnt; k++) sum[(int)(str_list[k][j] -  a )]++;         for (int k = 0; k < 26; k++)           if (sum[k] == 1) total++;         max_total = max(max_total, total);       }       ans += 1.0 * max_total / (1.0 * n);     }     printf( %.10lf n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     ;     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       if (n <= 3)         cout << -1 <<   n ;       else {         if (n & 1) {           for (long long i = 1; i <= n; i++) {             if (i & 1) cout << i <<    ;           }           cout << n - 3 <<     << n - 1 <<    ;           for (long long i = n - 4; i >= 1; i--) {             if ((i & 1) == 0) cout << i <<    ;           }           cout <<   n ;         } else {           for (long long i = 1; i <= n; i++) {             if ((i & 1) == 0) cout << i <<    ;           }           cout << n - 3 <<     << n - 1 <<    ;           for (long long i = n - 4; i >= 1; i--) {             if ((i & 1)) cout << i <<    ;           }           cout <<   n ;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int mx[4] = {1, 0, -1, 0};   int my[4] = {0, 1, 0, -1};   void dfs(int x, int y, vector<vector<char> > &b, vector<vector<int> > &val,            int &c, int &v) {     v++;     val[x][y] = c;     for (int i = 0; i < 4; i++) {       int xt = x + mx[i];       int yt = y + my[i];       if (xt >= 0 && xt < b.size() && yt >= 0 && yt < b[0].size() &&           b[xt][yt] ==  .  && val[xt][yt] == 0) {         dfs(xt, yt, b, val, c, v);       }     }   }   int main() {     int n, m;     while (cin >> n >> m) {       vector<vector<char> > board(n, vector<char>(m,  . ));       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) cin >> board[i][j];       }       vector<vector<int> > values(n, vector<int>(m, 0));       int color = 1;       vector<int> colors(n * m, 0);       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           if (board[i][j] ==  .  && values[i][j] == 0) {             int val = 0;             dfs(i, j, board, values, color, val);             colors[color] = val;             color++;           }         }       }       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           if (board[i][j] ==  . ) {             cout <<  . ;             continue;           } else {             int acu = 0;             set<int> valA;             for (int k = 0; k < 4; k++) {               int xt = i + mx[k];               int yt = j + my[k];               if (xt >= 0 && xt < board.size() && yt >= 0 &&                   yt < board[0].size() && !valA.count(values[xt][yt])) {                 acu += colors[values[xt][yt]];                 valA.insert(values[xt][yt]);               }             }             cout << (acu + 1) % 10;           }         }         cout << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   bool isOk(char c, int v) { return v == (c ==  B  ? -1 : 1); }   int main() {     int n, m;     scanf( %d %d , &n, &m);     string a[n];     int v[n][m];     char ch;     int vx;     int nOp = 0;     for (int i = 0; i < n; i++) {       fill(v[i], v[i] + m, 0);       cin >> a[i];     }     for (int i = n - 1; i >= 0; i--)       for (int j = m - 1; j >= 0; j--) {         if (!isOk(a[i][j], v[i][j])) {           ++nOp;           vx = (a[i][j] ==  W  ? v[i][j] - 1 : v[i][j] + 1);           for (int i1 = 0; i1 <= i; i1++)             for (int j1 = 0; j1 <= j; j1++) v[i1][j1] -= vx;         }       }     printf( %d n , nOp);     return 0;     return 0;   }
#include <bits/stdc++.h>   #include<unordered_map>   //#pragma GCC optimize(2)   #define ll long long   #define sc(n) scanf( %d ,&n)   #define scl(n) scanf( %lld ,&n)   //#define int ll   using namespace std;   inline int rd() { int x = 0, f = 1; char c = getchar(); while (c !=  -  && c < 48)c = getchar(); if (c ==  - )f = -1, c = getchar(); while (c > 47)x = (x << 1) + (x << 3) + (c ^ 48), c = getchar(); return f * x; }   const int maxn = 500001, inf = 2147483647;   const ll mod = 0 ? 998244353 : 1000000007, linf = 9223372036854775807;   const double pi = acos(-1);   inline ll mi(ll a, ll b, ll mm = mod) { a %= mm; ll u = 1; while (b) { if (b & 1)u = u * a % mm; a = a * a % mm, b >>= 1; }return u; }   inline ll gcd(ll a, ll b) { ll c = a % b; while (c)a = b, b = c, c = a % b; return b; }   inline void mem(int* a, int p = 0, int len = maxn) { for (int i = 0; i < len; i++)a[i] = p; }   struct p { int r, c; }e[maxn];   static bool cmp(p i, p j) { return i.r < j.r; };   int t, n, m, a[maxn], b[maxn], c[maxn], x, y, xx, yy, su, q, k, u, l, r;   string s;   int g(int n) {    int x = 1, y = n;    while (y)     x <<= 1, y >>= 1;    x >>= 1;    return x;   }   signed main() {    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);//sf和cin混用会出错    cin >> t;    while (t--) {     cin >> n >> m;     map<int, int>ma;     for (int i = 0; i < n; i++)      cin >> a[i], ma[a[i]]++;     su = 0;     while (n) {      su++;      y = m, x = g(m);      while (x) {       while (ma[x] && y >= x)        y -= x, n--, ma[x]--;       x >>= 1;      }     }     cout << su << endl;    }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int i, j;     long long n, a, b, ans;     long long arr[50];     arr[0] = 1;     for (i = 1; i < 40; i++) arr[i] = arr[i - 1] * 3;     scanf( %I64d , &n);     for (i = 0; i < 40; i++) {       if (n == arr[i]) {         printf( 1 n );         break;       } else if (n % arr[i] != 0) {         b = arr[i];         a = (n / arr[i]) + 1;         printf( %I64d n , a);         break;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int ans, n;   string str;   char ch[101000];   int a[101000];   void init() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> ch[i];     }     for (int i = 1; i <= n; i++) {       cin >> a[i];     }   }   void work() {     int ti = 0;     for (int i = 1; ti <= n; ti++) {       if (ch[i] ==  > )         i += a[i];       else if (ch[i] ==  < ) {         i -= a[i];       }       if (i < 1 || i > n) {         cout <<  FINITE  << endl;         return;       }     }     cout <<  INFINITE  << endl;   }   int main() {     init();     work();     return 0;   }
#include <bits/stdc++.h>   #include <iostream>   using namespace std;   const int MAX_N = 1e5 + 5;   const int MAX_L = 20; // ~ Log N   const long long MOD = 1e9 + 7;   const long long INF = 1e9 + 7;   typedef long long ll;      const int mx = 5e6 + 23;   const ll mod = 1e9 + 7;      int a[mx], team[mx], org[mx];   int n, m;   ll s[2];      int seed, base;   int rnd(){     int ret = seed;     seed = (1ll * seed * base + 233) % mod;     return ret;   }      void solve() {     cin>>n>>m;     int lastp = 0;     for(int i=1,p,k,b,w;i<=m;i++){       cin>>p>>k>>b>>w;       seed = b;       base = w;       for(int j=lastp;j<p;j++){         team[j] = rnd() % 2;         s[team[j]] += (org[j] = a[j] = rnd() % k + 1);       }       lastp = p;     }     int st = 0;     if(s[team[0]] > s[!team[0]]){       s[team[0]]--;       a[0]--;       while(team[0] == team[st] && st < n)         st++;     }     int cur = st;     ll sum = 0;     if(st != n)       while(s[team[st]]){         if(team[cur] == team[st]){           sum += a[cur];           a[cur] = 0;         }         else{           ll d = min(1ll * a[cur], sum);           s[team[st]] -= d;           sum -= d;           a[cur] -= d;         }         cur = (cur + 1 == n ? 0 : cur + 1);       }       ll ans = 1;       for(int i=0;i<n;i++){         ll qwq = (((org[i] - a[i]) ^ (1ll * (i + 1) * (i + 1))) + 1) % mod;         ans = ans * qwq % mod;       }       cout<<ans;   }   int main()    {       ios_base::sync_with_stdio(false);cin.tie(NULL);             #ifndef ONLINE_JUDGE       freopen( input.txt ,  r , stdin);       freopen( error.txt ,  w , stderr);       freopen( output.txt ,  w , stdout);       #endif             int t=1;     // cin>>t;       while(t--)       {          solve();         // cout<<  n ;       }             cerr<< time taken :  <<(float)clock()/CLOCKS_PER_SEC<<  secs <<endl;       return 0;    }
#include <bits/stdc++.h>   using namespace std;   int n;   string s;   set<string> st;   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> s;       sort(s.begin(), s.end());       s.erase(unique(s.begin(), s.end()), s.end());       st.insert(s);     }     cout << st.size();   }
#include <bits/stdc++.h>   using namespace std;   string s;   int main() {     long long ans = 0;     string in;     string un =  ><+-.,[] ;     cin >> in;     for (int i = 0; i < in.size(); i++) {       ans = (16 * ans + (un.find(in[i]) + 8)) % 1000003;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int a[50];   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> a[i];       a[i] %= m;     }     sort(a, a + n);     set<int> S1, S2;     for (int i = 0; i < n; i++) {       set<int> s = i < n / 2 ? S1 : S2;       s.insert(a[i]);       for (auto b : i < n / 2 ? S1 : S2) {         s.insert((a[i] + b) % m);       }       if (i < n / 2)         S1 = s;       else         S2 = s;     }     S1.insert(0);     S2.insert(0);     int best = 0;     for (auto b : S1) {       best = max(best, b + *(--S2.lower_bound(m - b)));     }     cout << best;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000 * 100 + 10;   const int MOD = 1000 * 1000 * 1000 + 7;   long double n, m;   long double Pow(long double a, int b) {     if (b == 0) return 1;     long double x = Pow(a, b / 2);     x *= x;     if (b % 2) x *= a;     return x;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0), cout.tie(0);     cout << fixed << setprecision(10);     cin >> m >> n;     long double ans = 0;     for (long double i = 1; i < m; i++) {       ans += Pow(i / m, n);     }     cout << m - ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x, y;     cin >> n;     long long sumX = 0;     long long sumY = 0;     long long sum = 0;     for (int i = n; i > 0; i--) {       cin >> x;       cin >> y;       sumX += x;       sum += x * x;       sumY += y;       sum += y * y;     }     printf( %I64d , (n * sum) - (sumX * sumX) - (sumY * sumY));     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 2005;   bool a[MAX][MAX], row[MAX], col[MAX];   int main() {     ios::sync_with_stdio(false);     int n;     cin >> n;     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) {         char c;         cin >> c;         a[i][j] = (c ==  1 );       }     int ans = 0;     for (int i = 0; i < n; i++)       for (int j = n - 1; j > i; j--)         if (a[i][j] ^ row[i] ^ col[j]) {           a[i][j] = false;           row[i] = !row[i];           col[j] = !col[j];           ans++;         }     for (int i = 0; i < n; i++) {       a[i][i] ^= row[i] ^ col[i];       row[i] = col[i] = false;     }     for (int j = 0; j < n; j++)       for (int i = n - 1; i > j; i--)         if (a[i][j] ^ row[i] ^ col[j]) {           a[i][j] = false;           row[i] = !row[i];           col[j] = !col[j];           ans++;         }     for (int i = 0; i < n; i++) ans += (a[i][i] ^ row[i] ^ col[i]);     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> digs;     while (n % 10 != 0) {       digs.push_back(n % 10);       n /= 10;     }     reverse(digs.begin(), digs.end());     int ans = 1;     for (int i = 0; i < digs.size(); i++) {       ans *= 2;       if (digs[i] == 7) {         ans++;       }     }     cout << ans - 1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 505, M = 10;   int ST[N][N][M][M], a[N][N], lg[N];   void build(int n, int m) {     for (int i = 2; i <= max(n, m); i++) {       lg[i] = lg[i / 2] + 1;     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         ST[i][j][0][0] = a[i][j];       }     }     for (int i = 1; i <= n; i++) {       for (int k = 1; (1 << k) <= m; k++) {         for (int j = 1; j + (1 << k) - 1 <= m; j++) {           ST[i][j][0][k] =               max(ST[i][j][0][k - 1], ST[i][j + (1 << (k - 1))][0][k - 1]);         }       }     }     for (int k1 = 1; (1 << k1) <= n; k1++) {       for (int i = 1; i + (1 << k1) - 1 <= n; i++) {         for (int k2 = 0; (1 << k2) <= m; k2++) {           for (int j = 1; j + (1 << k2) - 1 <= m; j++) {             ST[i][j][k1][k2] =                 max(ST[i][j][k1 - 1][k2], ST[i + (1 << (k1 - 1))][j][k1 - 1][k2]);           }         }       }     }   }   int query(int x1, int y1, int x2, int y2) {     if (x2 < x1 || y2 < y1) return 0;     const int k1 = lg[x2 - x1 + 1], k2 = lg[y2 - y1 + 1];     x2 = x2 - (1 << k1) + 1;     y2 = y2 - (1 << k2) + 1;     return max({ST[x1][y1][k1][k2], ST[x1][y2][k1][k2], ST[x2][y1][k1][k2],                 ST[x2][y2][k1][k2]});   }   int dp[N][N][4];   char s[N][N];   int main() {     ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);     int n, m, q;     cin >> n >> m >> q;     for (int i = 1; i <= n; i++) {       cin >> (s[i] + 1);     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (s[i][j] ==  R ) {           dp[i][j][0] =               min({dp[i][j - 1][0], dp[i - 1][j][0], dp[i - 1][j - 1][0]}) + 1;         }       }     }     for (int i = 1; i <= n; i++) {       for (int j = m; j >= 1; j--) {         if (s[i][j] ==  G ) {           dp[i][j][1] =               min({dp[i][j + 1][1], dp[i - 1][j][1], dp[i - 1][j + 1][1]}) + 1;         }       }     }     for (int i = n; i >= 1; i--) {       for (int j = 1; j <= m; j++) {         if (s[i][j] ==  Y ) {           dp[i][j][2] =               min({dp[i][j - 1][2], dp[i + 1][j][2], dp[i + 1][j - 1][2]}) + 1;         }       }     }     for (int i = n; i >= 1; i--) {       for (int j = m; j >= 1; j--) {         if (s[i][j] ==  B ) {           dp[i][j][3] =               min({dp[i][j + 1][3], dp[i + 1][j][3], dp[i + 1][j + 1][3]}) + 1;         }       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         a[i][j] = min(             {dp[i][j][0], dp[i][j + 1][1], dp[i + 1][j][2], dp[i + 1][j + 1][3]});       }     }     build(n, m);     while (q--) {       int r1, r2, c1, c2;       cin >> r1 >> c1 >> r2 >> c2;       int left = 0, right = min(c2 - c1 + 1, r2 - r1 + 1) / 2;       int ans = 0;       while (left <= right) {         int mid = (left + right) >> 1;         if (query(r1 + mid - 1, c1 + mid - 1, r2 - mid, c2 - mid) >= mid) {           left = mid + 1;           ans = mid;         } else {           right = mid - 1;         }       }       cout << (ans * ans * 4) <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 105;   const int M = 2005;   pair<pair<int, int>, pair<int, int> > adj[N];   int dp[M];   vector<int> way[M];   bool cmp(pair<pair<int, int>, pair<int, int> > a,            pair<pair<int, int>, pair<int, int> > b) {     return a.second.second < b.second.second;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       int t, d, p;       cin >> t >> d >> p;       adj[i] = make_pair(make_pair(t, i), make_pair(p, d));     }     sort(adj + 1, adj + 1 + n, cmp);     for (int i = 1; i <= n; i++) {       for (int j = adj[i].second.second - 1; j >= adj[i].first.first; j--) {         if (dp[j] < dp[j - adj[i].first.first] + adj[i].second.first) {           dp[j] = dp[j - adj[i].first.first] + adj[i].second.first;           way[j] = way[j - adj[i].first.first];           way[j].emplace_back(adj[i].first.second);         }       }     }     int ans1 = 0;     vector<int> ans2;     for (int i = 0; i <= M - 1; i++) {       if (dp[i] > ans1) {         ans1 = dp[i];         ans2 = way[i];       }     }     cout << ans1 <<   n  << ans2.size() <<   n ;     for (auto op : ans2) {       cout << op <<    ;     }   }
#include <bits/stdc++.h>   const double eps = 1e-9;   using namespace std;   double f[2050], p[2050], q[2050];   int fa[2050], fb[2050];   int n, a, b;   void calc(double w1, double w2) {     for (int i = 1; i <= n; i++) {       f[i] = f[i - 1];       fa[i] = fa[i - 1];       fb[i] = fb[i - 1];       if (f[i - 1] + p[i] - w1 > f[i]) {         f[i] = f[i - 1] + p[i] - w1;         fa[i] = fa[i - 1] + 1;         fb[i] = fb[i - 1];       }       if (f[i - 1] + q[i] - w2 > f[i]) {         f[i] = f[i - 1] + q[i] - w2;         fa[i] = fa[i - 1];         fb[i] = fb[i - 1] + 1;       }       if (f[i - 1] + p[i] + q[i] - p[i] * q[i] - w1 - w2 > f[i]) {         f[i] = f[i - 1] + p[i] + q[i] - p[i] * q[i] - w1 - w2;         fa[i] = fa[i - 1] + 1;         fb[i] = fb[i - 1] + 1;       }     }   }   int main() {     scanf( %d%d%d , &n, &a, &b);     for (int i = 1; i <= n; i++) scanf( %lf , &p[i]);     for (int i = 1; i <= n; i++) scanf( %lf , &q[i]);     double l1 = 0, r1 = 1, l2, r2;     while (l1 + eps < r1) {       double mid1 = (l1 + r1) / 2;       l2 = 0, r2 = 1;       while (l2 + eps < r2) {         double mid2 = (l2 + r2) / 2;         calc(mid1, mid2);         if (fb[n] > b)           l2 = mid2;         else           r2 = mid2;       }       calc(mid1, r2);       if (fa[n] > a)         l1 = mid1;       else         r1 = mid1;     }     calc(r1, r2);     printf( %.10lf n , f[n] + a * r1 + b * r2);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100 + 10;   int n, m;   int main() {     cin >> n >> m;     cout << n + m - 1 << endl;     cout <<  1 1  << endl;     for (int i = 2; i <= n; ++i) cout << i <<   1  << endl;     for (int i = 2; i <= m; ++i) cout <<  1   << i << endl;     fclose(stdin);     fclose(stdout);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 200005;   int n, ans, root;   int f[N], fa[N];   inline int read() {     int a = 0, f = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       a = a * 10 + c -  0 ;       c = getchar();     }     return a * f;   }   int find(int i) { return f[i] == i ? i : f[i] = find(f[i]); }   int main() {     n = read();     for (int i = 1; i <= n; i++) f[i] = i;     for (int i = 1; i <= n; i++) {       fa[i] = read();       if (fa[i] == i) root = i;     }     for (int i = 1; i <= n; i++) {       if (i != root) {         int p = find(i), q = find(fa[i]);         if (p == q) {           ans++;           if (!root) root = i;           fa[i] = root;         } else           f[p] = q;       }     }     printf( %d n , ans);     for (int i = 1; i <= n; i++) printf( %d%c , fa[i], i == n ?   n  :    );     return 0;   }
#include <bits/stdc++.h>   int n, m;   int a[2000];   int b[2000];   int can[2000];   using namespace std;   int main() {     int c = 0;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i] >> b[i];     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (i != j && !can[j] && b[i] == a[j]) {           can[j] = 1;           c++;         }       }     }     cout << n - c << endl;   }