malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using ll = long long int;   using namespace std;   template <class c>   struct rge {     c b, e;   };   template <class c>   rge<c> range(c i, c j) {     return rge<c>{i, j};   }   template <class c>   auto dud(c *x) -> decltype(cerr << *x, 0);   template <class c>   char dud(...);   struct debug {     template <class c>     debug &operator<<(const c &) {       return *this;     }   };   template <typename T>   void ara_read(T &v, ll n) {     ll temp;     for (ll i = 0; i < n; i++) {       scanf( %lld , &temp);       v.emplace_back(temp);     }   }   template <typename T>   void ara_print(T &v) {     for (ll x : v) printf( %lld  , x);     puts(  );   }   const int INF = 1e9 + 99;   using Pair = pair<int, int>;   using vec = vector<ll>;   void bruteforce(int l, int r, vec &v) {     return;     set<ll> myset;     for (ll x : v) {       for (ll i = l; i <= r; i++) myset.insert(i + x);     }     printf( BruteForce : %d n , (int)myset.size());   }   void improved(vec &v, vec &pref, int n) {     ll l, r;     scanf( %lld%lld , &l, &r);     ll w = r - l + 1;     ll ind = lower_bound(v.begin(), --v.end(), w) - v.begin();     ll ans = (n - ind) * w + pref[ind];     printf( %lld  , ans);   }   int main() {     int n;     scanf( %d , &n);     vec v(n);     for (ll &x : v) scanf( %lld , &x);     sort(v.begin(), v.end());     for (int i = 0; i < n - 1; i++) v[i] = v[i + 1] - v[i];     sort(v.begin(), --v.end());     int q;     scanf( %d , &q);     vec pref(n);     for (int i = 1; i < n; i++) pref[i] = pref[i - 1] + v[i - 1];     for (int i = 0; i < q; i++) improved(v, pref, n);     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = (int)1e9 + 7;   const double EPS = 1e-9;   const int INF = INT_MAX;   const long long INFLL = (long long)1e18;   const double PI = acos(-1.0);   template <class T>   T gcd(T a, T b) {     return b ? gcd(b, a % b) : a;   }   template <class T>   T lcm(T a, T b) {     return a / gcd(a, b) * b;   }   const int N = (int)1e5 + 5;   const int P = 1 << 18;   int n, m;   int a[N];   pair<int, int> g[N];   int use[N];   int main() {     ios::sync_with_stdio(false);     cout.setf(ios::fixed | ios::showpoint);     cout.precision(8);     cin >> n >> m;     if (n == 1) return !printf( NO n );     for (int i = 0; i < m; i++) {       int x, y;       cin >> x >> y;       a[x]++;       a[y]++;       g[i] = make_pair(x, y);     }     int flag = 0;     for (int i = 1; i <= n; i++) {       if (a[i] < n - 1) {         flag = 1;         for (int j = 0; j < m; j++) {           if (g[j].first == i) {             use[g[j].second] = 1;           }           if (g[j].second == i) {             use[g[j].first] = 1;           }         }         int cur;         for (int j = 1; j <= n; j++) {           if (!use[j] && j != i) {             cur = j;             break;           }         }         cout <<  YES n ;         int st = 3;         for (int j = 1; j <= n; j++) {           if (j == i) {             cout <<  1  ;             continue;           }           if (j == cur) {             cout <<  2  ;             continue;           }           cout << st <<    ;           st++;         }         cout <<   n ;         st = 3;         for (int j = 1; j <= n; j++) {           if (j == i || j == cur) {             cout <<  1  ;             continue;           }           cout << st <<    ;           st++;         }         return 0;       }     }     if (!flag) return !printf( NO n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> mp[105];   int vis[105];   struct node {     int fa;     int kid;     node(int fa, int b) {       this->fa = fa;       kid = b;     }   };   bool bfs(int rt, int n) {     queue<node> q;     q.push(node(-1, rt));     vis[rt] = 1;     while (!q.empty()) {       int now = q.front().kid;       int fa = q.front().fa;       q.pop();       for (int i = 0; i < mp[now].size(); i++) {         int v = mp[now][i];         if (vis[v] && v != fa) {           vis[v]++;           continue;         }         if (vis[v] || v == fa) continue;         vis[v] = 1;         q.push(node(now, v));       }     }     int f = 0;     for (int i = 1; i <= n; i++) {       if (vis[i] > 2) return false;       if (vis[i] == 2) f = 1;     }     if (f) return true;     return false;   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 0; i < m; i++) {       int u, v;       scanf( %d%d , &u, &v);       mp[u].push_back(v);       mp[v].push_back(u);     }     int yes = 0;     int no = 0;     for (int i = 1; i <= n; i++) {       if (vis[i] == 0) {         if (bfs(i, n)) {           yes++;         } else {           no = 1;         }       }     }     if (yes == 1 && no == 0)       puts( FHTAGN! );     else       puts( NO );   }
#include <bits/stdc++.h>   using namespace std;   int maxrob(int p, int f, int cnt_s, int cnt_w, int s, int w) {     if (p > f) {       swap(p, f);     }     if (s > w) {       swap(cnt_s, cnt_w);       swap(s, w);     }     long long s_total = (long long)cnt_s * s;     if ((p + f) <= s_total) {       return (p / s) + (f / s);     }     int w_cnt_max = min(((p + f) - s_total) / w, (long long)cnt_w);     int answer = 0;     for (int k = 0; k <= w_cnt_max; ++k) {       if ((long long)w * k > p) break;       int res = 0;       int s_cnt_p = min((p - w * k) / s, cnt_s);       int s_cnt_f = cnt_s - s_cnt_p;       res += s_cnt_p;       if ((long long)s * s_cnt_f > f) {         s_cnt_f = (f / s);       }       res += s_cnt_f;       res += min((p - s * s_cnt_p) / w + (f - s * s_cnt_f) / w, cnt_w);       if (answer < res) answer = res;     }     return answer;   }   int main() {     int T;     cin >> T;     while (T-- != 0) {       int p, f;       cin >> p >> f;       int cnt_s, cnt_w;       cin >> cnt_s >> cnt_w;       int s, w;       cin >> s >> w;       cout << maxrob(p, f, cnt_s, cnt_w, s, w) << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t = 1, n, k, fact, a, b;     cin >> t;     while (t--) {       cin >> a >> b;       if (a == 1)         cout <<  0 n ;       else if (a == 2)         cout << b <<   n ;       else         cout << 2 * b <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int res[100010], k = 0;   struct edge {     int id, v, w, next;   } e[100010];   int head[100010], cnt = 0;   void adde(int u, int v, int w, int id) {     e[cnt].id = id;     e[cnt].v = v;     e[cnt].w = w;     e[cnt].next = head[u];     head[u] = cnt++;   }   int ind[100010];   queue<int> q;   int lev[100010];   int tl;   bool check(int lim) {     memset(ind, 0, sizeof ind);     memset(lev, 0, sizeof lev);     tl = 0;     while (!q.empty()) q.pop();     for (int i = 0; i < cnt; ++i)       if (e[i].w > lim) ++ind[e[i].v];     for (int i = 1; i <= n; ++i)       if (ind[i] == 0) q.push(i);     while (!q.empty()) {       int u = q.front();       q.pop();       lev[u] = tl++;       for (int i = head[u], v, w; ~i; i = e[i].next) {         v = e[i].v;         w = e[i].w;         if (w <= lim) continue;         --ind[v];         if (ind[v] == 0) {           q.push(v);         }       }     }     for (int i = 1; i <= n; ++i)       if (ind[i]) return false;     return true;   }   int main() {     memset(head, -1, sizeof head);     scanf( %d%d , &n, &m);     int L = 0, R = 0, mid, ans;     for (int i = 1, u, v, w; i <= m; ++i) {       scanf( %d%d%d , &u, &v, &w);       adde(u, v, w, i);       R = max(R, w);     }     ++R;     while (L < R) {       mid = (L + R) >> 1;       if (check(mid)) {         ans = R = mid;       } else {         L = mid + 1;       }     }     check(ans);     for (int u = 1; u <= n; ++u) {       for (int i = head[u], v, w; ~i; i = e[i].next) {         v = e[i].v;         w = e[i].w;         if (w > ans) continue;         if (lev[u] > lev[v]) res[++k] = e[i].id;       }     }     printf( %d %d n , ans, k);     for (int i = 1; i <= k; ++i) printf( %d%c , res[i], (i == k ?   n  :    ));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);     long long int t;     cin >> t;     while (t--) {       string s;       cin >> s;       if (s.size() == 1) {         cout << 0 << endl;         continue;       }       map<char, int> m;       int i;       int count = 0;       for (i = 0; i < s.size(); i++) {         m[s[i]]++;       }       for (auto it : m) {         if (it.second > 1) {           count += 2;         } else if (it.second == 1) {           count += 1;         }       }       cout << count / 2 << endl;     }   }
#include <bits/stdc++.h>   char s[1111111];   int f[1111111];   int c[1111111];   int d[1111111];   int main() {     int i, j, n, m, l;     scanf( %d%d%s , &n, &m, s);     if (m == 0) {       j = 1;       for (i = 0; i < n; i++) j = 26LL * j % 1000000007;       printf( %d , j);       return 0;     }     f[0] = -1;     for (i = 1; s[i]; i++) {       for (j = f[i - 1];; j = f[j]) {         if (s[j + 1] == s[i]) break;         if (j == -1) break;       }       if (s[j + 1] == s[i])         f[i] = j + 1;       else         f[i] = -1;     }     l = i;     for (j = f[l - 1]; j >= 0; j = f[j]) c[l - j - 1] = 1;     scanf( %d , &i);     d[i - 1] = l;     while (--m) {       scanf( %d , &j);       if (j - i < l && !c[j - i]) {         puts( 0 );         return 0;       }       d[j - 1] = l;       i = j;     }     j = 1;     for (i = 0; i < n; i++) {       if (i) d[i] = std::max(d[i - 1] - 1, d[i]);       if (d[i] == 0) j = 26LL * j % 1000000007;     }     printf( %d , j);   }
#include <bits/stdc++.h>   using namespace std;   uniform_int_distribution<long long> d(156, 99657);   mt19937 rnd;   int n, s, x, mn = -100, q, w;   void solve() {     scanf( %d%d%d , &n, &s, &x);     if (n >= 2000) {       for (int i = 1; i <= 1000; i++) {         printf( ? %d n , (d(rnd) * d(rnd)) % n + 1);         fflush(stdout);         scanf( %d%d , &q, &w);         if (q < x && q > mn) {           mn = q;           s = w;         }       }     }     while (1) {       printf( ? %d n , s);       fflush(stdout);       scanf( %d%d , &q, &w);       if (q >= x) {         printf( ! %d n , q);         fflush(stdout);         return;       }       if (w == -1) {         printf( ! -1 n );         fflush(stdout);         return;       }       s = w;     }   }   int main() {     rnd.seed(time(NULL));     int tt = 1;     for (int i = 1; i <= tt; i++) solve();   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 1 << 30;   const int N = 1003, mod = 1000000007;   int n, q;   char a[N];   int k;   int p[N];   int calc(int x) {     if (x == 1) return 0;     if (p[x] != -1) return p[x];     int cnt = 0, ret = 0;     while (x) {       cnt += (x % 2);       x /= 2;     }     return ret = calc(cnt) + 1;   }   void pre() {     memset(p, -1, sizeof p);     for (int i = 1; i <= 1000; i++) {       p[i] = calc(i);     }   }   int mem[N][N][2];   int dp(int i, int kk, int f) {     if (i == n) {       return (k == p[kk] + 1 && kk != 0);     }     int &ret = mem[i][kk][f];     if (ret != -1) return ret;     ret = 0;     if (f) {       ret += dp(i + 1, kk + 1, f) % mod;       ret %= mod;       ret += dp(i + 1, kk, f) % mod;       ret %= mod;     } else {       if (a[i] ==  0 ) {         ret += dp(i + 1, kk, f) % mod;         ret %= mod;       } else {         ret += dp(i + 1, kk + 1, f) % mod;         ret %= mod;         ret += dp(i + 1, kk, 1) % mod;         ret %= mod;       }     }     return ret;   }   int main() {     pre();     scanf( %s , a);     scanf( %d , &k);     n = strlen(a);     if (k == 0) {       printf( 1 );       return 0;     }     memset(mem, -1, sizeof mem);     printf( %d , (dp(0, 0, 0) % mod + (k == 1 ? -1 : 0)));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     string s;     int i, n;     cin >> s;     n = s.length();     cout <<  Mike  <<   n ;     int mi = s[0] -  a ;     for (i = 1; i < n; i++) {       int x;       x = s[i] -  a ;       if (mi < x) {         cout <<  Ann  <<   n ;       } else {         cout <<  Mike  <<   n ;         mi = x;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, r;   int v[100], cnt, diff;   const int inf = 0x3fffffff;   int calc(int x, int y) {     cnt = 0;     int sum = 0;     while (x) {       if (y % x == 0) {         if (y == 1)           v[++cnt] = y / x;         else if (x == 1)           v[++cnt] = y / x - 1;         else           return inf;       } else         v[++cnt] = y / x;       sum += v[cnt];       int t = y - v[cnt] * x;       y = x;       x = t;     }     if (sum != n) return inf;     diff = 0;     for (int i = 1; i <= cnt; i++)       if (v[i] != 1) diff += v[i] - 1;     return diff;   }   int ans[100], ansc;   int main() {     while (scanf( %d %d , &n, &r) != EOF) {       if (r == 0) {         if (n == 1)           printf( 0 nT n );         else           puts( IMPOSSIBLE );         continue;       }       int ret = inf;       for (int i = 1; i <= r; i++) {         int now = calc(i, r);         if (ret > now) {           ret = now;           ansc = cnt;           for (int j = 1; j <= cnt; j++) ans[j] = v[j];         }       }       if (ret == inf)         puts( IMPOSSIBLE );       else {         printf( %d n , ret);         char c =  T ;         for (int i = ansc; i >= 1; i--) {           while (ans[i]--) putchar(c);           if (c ==  T )             c =  B ;           else             c =  T ;         }         puts(  );       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-8;   const int inf = 0x3f3f3f3f;   const int maxn = 2000 + 10;   long long MOD = 1e9 + 7;   long long fac[200010];   void getFac() {     fac[0] = 1;     for (int i = 1; i < 200010; i++) {       fac[i] = fac[i - 1] * i % MOD;     }   }   long long powerMod(long long x, long long n) {     long long ans = 1;     x %= MOD;     while (n > 0) {       if (n & 1) {         ans = (ans * x) % MOD;       }       x = (x * x) % MOD;       n >>= 1;     }     return ans;   }   long long C(long long n, long long m) {     if (m > n) {       return 0;     } else {       return fac[n] * powerMod(fac[m] * fac[n - m], MOD - 2) % MOD;     }   }   long long Lucas(long long n, long long m) {     if (m == 0) {       return 1;     } else {       return C(n % MOD, m % MOD) * Lucas(n / MOD, m / MOD) % MOD;     }   }   struct Point {     int r, c;     Point(int a = 0, int b = 0) {       r = a;       c = b;     }   };   bool operator<(const Point& a, const Point& b) {     return a.r < b.r || (a.r == b.r && a.c < b.c);   }   int h, w, n;   Point point[maxn];   vector<int> G[maxn];   long long dp[maxn];   long long dfs(int u) {     if (dp[u] >= 0) {       return dp[u];     }     long long ret = Lucas(h - point[u].r + w - point[u].c, h - point[u].r);     int glen = G[u].size();     for (int i = 0; i < glen; i++) {       int v = G[u][i];       ret = (ret - Lucas(point[v].r - point[u].r + point[v].c - point[u].c,                          point[v].r - point[u].r) *                        dfs(v)) %             MOD;     }     return dp[u] = (ret + MOD) % MOD;   }   int main() {     getFac();     scanf( %d%d%d , &h, &w, &n);     for (int i = 0; i < n; i++) {       scanf( %d%d , &point[i].r, &point[i].c);     }     point[n++] = Point(1, 1);     point[n++] = Point(h, w);     sort(point, point + n);     for (int i = 0; i < n - 1; i++) {       for (int j = i + 1; j < n; j++) {         { G[i].push_back(j); }       }     }     for (int i = 0; i < n; i++) {       dp[i] = -1;     }     dp[n - 1] = 0;     long long ans = dfs(0);     printf( %I64d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct Edge {     int v, next;   } edge[100010];   int head[10];   int pos;   void insert(int x, int y) {     edge[pos].v = y;     edge[pos].next = head[x];     head[x] = pos++;   }   int du[10];   int pp[100010];   int qq;   int fa[10];   int find(int x) {     if (fa[x] != x) fa[x] = find(fa[x]);     return fa[x];   }   void uunion(int x, int y) {     int fx = find(x);     int fy = find(y);     fa[fx] = fy;   }   bool vis[100010];   void dfs(int now) {     for (int i = head[now]; i != -1; i = edge[i].next) {       if (vis[i / 2]) continue;       vis[i / 2] = true;       dfs(edge[i].v);       pp[qq++] = i ^ 1;     }   }   int main() {     int n;     scanf( %d , &n);     memset(head, -1, sizeof(head));     pos = 0;     for (int i = 0; i <= 6; i++) fa[i] = i;     for (int i = 0; i < n; i++) {       int x, y;       scanf( %d %d , &x, &y);       insert(x, y);       insert(y, x);       du[x]++;       du[y]++;       uunion(x, y);     }     bool flag = true;     for (int i = 0; i <= 6; i++)       for (int j = 0; j <= 6; j++)         if (du[i] > 0 && du[j] > 0 && find(i) != find(j)) flag = false;     if (!flag) {       printf( No solution n );       return 0;     }     qq = 0;     for (int i = 0; i <= 6; i++)       if (du[i] & 1) pp[qq++] = i;     if (qq > 2) {       printf( No solution n );       return 0;     }     for (int i = 0; i <= 6; i++)       if (du[i] != 0) pp[qq++] = i;     int begin = pp[0];     qq = 0;     memset(vis, false, sizeof(vis));     dfs(begin);     for (int i = 0; i < qq; i++) {       printf( %d  , pp[i] / 2 + 1);       if (pp[i] & 1)         printf( - );       else         printf( + );       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int x[100010], y[100010], vis[100010];   int main() {     int n, ans, i;     scanf( %d , &n);     memset(vis, 0, sizeof(vis));     for (i = 1; i <= n; i++) {       scanf( %d%d , &x[i], &y[i]);       vis[x[i]]++;     }     for (i = 1; i <= n; i++) {       ans = n - 1;       ans = ans + vis[y[i]];       printf( %d %d n , ans, 2 * (n - 1) - ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, t, i, j, k;     cin >> n >> t;     string a;     cin >> a;     for (i = 1; i <= t; ++i) {       for (j = 0; j < n - 1; ++j) {         if (a[j] ==  B  && a[j + 1] ==  G ) {           a[j + 1] =  B ;           a[j] =  G ;           ++j;         }       }     }     cout << a << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, x = -1, y, xx, yy, k;   bool a[510][510];   char h;   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> h;         if (h ==  X ) {           a[i][j] = true;           if (x == -1) {             x = i;             y = j;           }           xx = i;           yy = j;           k++;         }       }     }     for (int i = x; i <= xx; i++) {       for (int j = y; j <= yy; j++) {         if (!a[i][j]) {           cout <<  NO ;           return 0;         }         k--;       }     }     if (k > 0)       cout <<  NO ;     else       cout <<  YES ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> vec;   int main() {     int k;     cin >> k;     string arr;     while (k--) {       cin >> arr;       int n = arr.length();       int maxLen = 0;       for (int i = 0; i < n; i++) {         int len = 0;         while (arr[i] ==  L ) {           len++;           i++;           if (i == n) break;         }         maxLen = max(maxLen, len);       }       cout << maxLen + 1 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long max(long long a, long long b) { return a > b ? a : b; }   long long a[100005];   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       for (int i = 1; i <= n; i++) {         cin >> a[i];       }       sort(a + 1, a + 1 + n);       long long ans = a[n] * a[n - 1] * a[n - 2] * a[n - 3] * a[n - 4];       long long ans1 = a[n] * a[n - 1] * a[n - 2] * a[1] * a[2];       long long ans2 = a[n] * a[1] * a[2] * a[3] * a[4];       cout << max(max(ans, ans1), ans2) << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     vector<long long> bs(n);     for (auto &x : bs) cin >> x;     if (count(bs.begin(), bs.end(), 0) == n) {       cout <<  YES  << endl;       for (int _ = 0; _ < (n); ++_) cout << 1 <<    ;       cout << endl;       return 0;     }     auto prv = [&](int i) { return (i + n - 1) % n; };     bs.push_back(bs[0]);     for (int i = 0; i < (n); ++i)       if (bs[i] > bs[prv(i)]) {         vector<long long> a(n);         a[i] = bs[i];         for (int k = prv(i); k != i; k = prv(k)) {           int j = prv(k), l = (k + 1) % n;           long long x;           long long dif = bs[j] - bs[k];           if (dif < 0)             x = 0;           else {             x = 1 + dif / a[l];           }           a[k] = bs[k] + x * a[l];         }         cout <<  YES  << endl;         for (auto &x : a) cout << x <<    ;         cout << endl;         return 0;       }     cout <<  NO  << endl;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, a[1111];   int main() {     scanf( %d%d , &n, &m);     for (int i = (0); i < (n); i++) scanf( %d , &a[i]);     int ans = 0;     for (int i = (0); i < (m); i++) {       int x, y;       scanf( %d%d , &x, &y);       x--;       y--;       ans += min(a[x], a[y]);     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[10010];   int main() {     int n, m;     while (scanf( %d%d , &n, &m) == 2) {       for (int i = 1; i < n; i++) a[i] = 1;       a[n] = 0;       int maxx = 1;       for (int ii = 0; ii < m; ii++) {         for (int i = 1; i <= n; i++) {           if (a[i] + maxx <= n - i) {             printf( %d  , n - maxx);             a[i] += maxx;           } else {             printf( %d  , i + a[i]);             a[i] = n - i;           }         }         puts(  );         maxx *= 2;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void read(T& x) {     bool fu = 0;     char c;     for (c = getchar(); c <= 32; c = getchar())       ;     if (c ==  - ) fu = 1, c = getchar();     for (x = 0; c > 32; c = getchar()) x = x * 10 + c -  0 ;     if (fu) x = -x;   };   template <class T>   inline void read(T& x, T& y) {     read(x);     read(y);   }   template <class T>   inline void read(T& x, T& y, T& z) {     read(x);     read(y);     read(z);   }   template <class T>   inline void read(T& x, T& y, T& z, T& q) {     read(x);     read(y);     read(z);     read(q);   }   inline char getc() {     char c;     for (c = getchar(); c <= 32; c = getchar())       ;     return c;   }   int n, T, i, j, k, l, p;   long double ans1, ans2;   double xx;   long double f[1110][5000], g[1110][5000];   struct node {     long long t0, t1, s0, s1;     long double f;   } a[1010];   long double get(node a, node b) {     return (a.t1 + b.t1) * (1 - b.f) + a.t1 * b.f * (1 - a.f);   }   bool cmp(node a, node b) { return get(a, b) < get(b, a); }   bool upmaxs(long double& x, long double y) { return y > x ? x = y, 1 : 0; }   void upd(long double& x, long double& x0, long double y, long double y0) {     if (make_pair(y, -y0) > make_pair(x, -x0)) x = y, x0 = y0;   }   int main() {     read(n, T);     for (i = 1; i <= n; i++)       read(a[i].s0, a[i].s1, a[i].t0, a[i].t1), scanf( %lf , &xx), a[i].f = xx;     sort(a + 1, a + 1 + n, cmp);     for (i = 1; i <= n; i++)       for (j = 0; j <= T; j++) {         upd(f[i + 1][j], g[i + 1][j], f[i][j], g[i][j]);         upd(f[i + 1][j + a[i].t0], g[i + 1][j + a[i].t0], f[i][j] + a[i].s0,             g[i][j] + a[i].t0);         upd(f[i + 1][j + a[i].t0 + a[i].t1], g[i + 1][j + a[i].t0 + a[i].t1],             f[i][j] + a[i].s0 + a[i].s1 * (1 - a[i].f),             a[i].t0 + g[i][j] * a[i].f + (j + a[i].t1) * (1 - a[i].f));       }     for (j = 0; j <= T; j++) upd(ans1, ans2, f[n + 1][j], g[n + 1][j]);     cout << fixed << setprecision(20) << ans1 <<     << ans2 << endl;     scanf(  n );     return 0;   }