malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int s[200005];   struct pp {     int lev;     int loc;   } s1[200005], s2[200005];   bool cmp(pp &a, pp &b) { return a.lev < b.lev; }   int main() {     int t;     cin >> t;     for (int i = 0; i < t; i++) {       int s1h = 0, s2h = 0;       string test;       int n;       cin >> n;       for (int j = 0; j < n; j++) {         cin >> s[j];       }       cin >> test;       for (int p = 0; p < test.length(); p++) {         if (test[p] ==  0 )           s1[s1h].lev = s[p], s1[s1h++].loc = p;         else           s2[s2h].lev = s[p], s2[s2h++].loc = p;       }       sort(s1, s1 + s1h, cmp);       sort(s2, s2 + s2h, cmp);       for (int j = 0; j < s1h; j++) {         s[s1[j].loc] = j + 1;       }       for (int j = 0; j < s2h; j++) {         s[s2[j].loc] = j + s1h + 1;       }       for (int j = 0; j < n; j++) cout << s[j] <<    ;       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1e9 + 7;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int T = clock();     long long int a, ta, b, tb;     cin >> a >> ta >> b >> tb;     string s;     cin >> s;     long long int i = 5 * 60, lim = 23 * 60 + 59;     long long int st = stoi(s.substr(0, 2)) * 60 + stoi(s.substr(3));     long long int ed = st + ta;     long long int ans = 0;     while (i < ed && i <= lim) {       if (i + tb > st) ans++;       i += b;     }     cout << ans;     cerr <<   n nTIME:   << (long double)(clock() - T) / CLOCKS_PER_SEC          <<   sec n ;     T = clock();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, a2 = 0, b2 = 0, a3 = 0, b3 = 0, a5 = 0, b5 = 0;     cin >> a >> b;     while (a % 2 == 0) {       a2++;       a /= 2;     }     while (a % 3 == 0) {       a3++;       a /= 3;     }     while (a % 5 == 0) {       a5++;       a /= 5;     }     while (b % 2 == 0) {       b2++;       b /= 2;     }     while (b % 3 == 0) {       b3++;       b /= 3;     }     while (b % 5 == 0) {       b5++;       b /= 5;     }     if (a == b) {       cout << abs(a2 - b2) + abs(a3 - b3) + abs(a5 - b5) << endl;     } else {       cout << -1 << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 200514;   vector<int> a3[N], a4[N], mn, mx;   set<int> s;   int p3[N], p4[N];   int n, m, M, a[N], ct[N], l1 = 1, l2 = 1;   int j, p1, p2, k1, k2;   int main() {     scanf( %d%d , &n, &m);     p3[n + 1] = p4[n + 1] = n + 1;     for (int i = (1); i <= (n); i++) scanf( %d , &a[i]);     for (int i = (n); i >= (1); i--) {       j = i - 1;       p3[i] = p4[i] = n + 1;       while (j >= 1 && a[i] == a[j]) j--;       while (mn.size() && a[i] < a[mn.back()]) {         if (!(--ct[mn.back()])) s.insert(mn.back());         l1 = 0;         mn.pop_back();       }       while (mx.size() && a[i] > a[mx.back()]) {         if (!(--ct[mx.back()])) s.insert(mx.back());         l2 = 0;         mx.pop_back();       }       p1 = lower_bound(mn.begin(), mn.end(), i,                        [&](int x, int y) { return a[x] < a[y]; }) -            mn.begin() - 1;       p2 = lower_bound(mx.begin(), mx.end(), i,                        [&](int x, int y) { return a[x] > a[y]; }) -            mx.begin() - 1;       p3[i] = i + 1 + max(l1, l2);       a3[i] = {i, p3[i] - 1, p3[i]};       if (~p1 && ~p2) {         auto it = s.lower_bound(max(mn[p1], mx[p2]));         if (it != s.end()) {           p4[i] = *it;           k1 = upper_bound(mn.begin(), mn.end(), p4[i], greater<int>()) -                mn.begin();           k2 = upper_bound(mx.begin(), mx.end(), p4[i], greater<int>()) -                mx.begin();           a4[i] = {i, min(mn[k1], mx[k2]), max(mn[k1], mx[k2]), p4[i]};         }       }       if (p3[i] > p3[i + 1]) a3[i] = a3[i + 1], p3[i] = p3[i + 1];       if (p4[i] > p4[i + 1]) a4[i] = a4[i + 1], p4[i] = p4[i + 1];       for (int k = (j + 1); k <= (i); k++) {         l1++, l2++;         mn.push_back(k), mx.push_back(k);         ct[k] = 2;         p3[k] = p3[i], p4[k] = p4[i], a3[k] = a3[i], a4[k] = a4[i];       }       i = j + 1;     }     int x, y;     for (int i = (1); i <= (m); i++) {       scanf( %d%d , &x, &y);       if (p4[x] <= y) {         puts( 4 );         for (int l : a4[x]) printf( %d  , l);         puts(  );       } else if (p3[x] <= y) {         puts( 3 );         for (int l : a3[x]) printf( %d  , l);         puts(  );       } else         puts( 0 );     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     vector<vector<int> > g;     vector<int> buf;     g.clear();     buf.clear();     for (int i = 0; i < k; i++) g.push_back(buf);     vector<int> num;     num.clear();     int j;     for (j = 0; j < n * k; j++) num.push_back(0);     for (int i = 0; i < k; i++) {       int c;       cin >> c;       g[i].push_back(c);       num[c - 1] = 1;     }     int l = 0;     for (j = 0; j < n * k; j++)       if (num[j] == 0) {         g[l].push_back(j + 1);         l++;         if (l == k) l = 0;       }     for (int i = 0; i < k; i++) {       for (int j = 0; j < n; j++) cout << g[i][j] <<    ;       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = (1ll << 45);   long long bit[1000006];   void update(long long from, long long val) {     for (long long i = from; i < 1000006; i += i & -i) bit[i] += val;   }   long long query(long long from) {     if (from == 0) return 0;     long long cnt = 0;     for (long long i = from; i > 0; i -= i & -i) cnt += bit[i];     return cnt;   }   long long query(long long l, long long r) { return query(r) - query(l - 1); }   struct Node {     Node *lc, *rc;     long long mx, tag;     Node() : lc(NULL), rc(NULL), mx(-INF), tag(0) {}     void pull() { mx = max(lc->mx, rc->mx); }   };   const long long N = 1000002;   Node* Build(long long L, long long R) {     Node* node = new Node();     if (L == R) {       node->mx = -N + L;       return node;     }     long long mid = (L + R) >> 1;     node->lc = Build(L, mid);     node->rc = Build(mid + 1, R);     node->pull();     return node;   }   void push(Node* node, long long L, long long R) {     if (L == R) node->tag = 0;     if (node->tag == 0) return;     node->lc->mx += node->tag;     node->rc->mx += node->tag;     node->lc->tag += node->tag;     node->rc->tag += node->tag;     node->tag = 0;     return;   }   void modify(Node* node, long long L, long long R, long long l, long long r,               long long val) {     if (l > R || L > r)       return;     else if (l <= L && R <= r) {       node->mx += val;       node->tag += val;       return;     }     push(node, L, R);     long long mid = (L + R) >> 1;     modify(node->lc, L, mid, l, r, val);     modify(node->rc, mid + 1, R, l, r, val);     node->pull();     return;   }   long long query(Node* node, long long L, long long R, long long l,                   long long r) {     if (l > R || L > r)       return -INF;     else if (l <= L && R <= r)       return node->mx;     push(node, L, R);     long long mid = (L + R) >> 1;     return max(query(node->lc, L, mid, l, r), query(node->rc, mid + 1, R, l, r));   }   long long n, x[N][2];   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n;     Node* root = Build(1, N);     string in;     long long v1, v2;     for (long long i = 1; i < n + 1; ++i) {       cin >> in;       if (in ==  ? ) {         cin >> v1;         cout << query(root, 1, N, 1, v1) + (N - v1) - query(v1 + 1, 1000006 - 1)              <<   n ;       } else if (in ==  + ) {         cin >> v1 >> v2;         x[i][0] = v1;         x[i][1] = v2;         modify(root, 1, N, 1, x[i][0], x[i][1]);         update(v1, v2);       } else if (in ==  - ) {         cin >> v1;         modify(root, 1, N, 1, x[v1][0], -x[v1][1]);         update(x[v1][0], -x[v1][1]);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1 << 28;   const long long LINF = 1ll << 61;   inline long long getnum() {     register long long r = 0;     register bool ng = 0;     register char c;     c = getchar();     while (c !=  -  && (c <  0  || c >  9 )) c = getchar();     if (c ==  - ) ng = 1, c = getchar();     while (c !=     && c !=   n ) r = r * 10 + c -  0 , c = getchar();     if (ng) r = -r;     return r;   }   template <class T>   inline void putnum(T x) {     if (x < 0) putchar( - ), x = -x;     register short a[20] = {}, sz = 0;     while (x > 0) a[sz++] = x % 10, x /= 10;     if (sz == 0) putchar( 0 );     for (int i = sz - 1; i >= 0; i--) putchar( 0  + a[i]);   }   inline void putsp() { putchar(   ); }   inline void putendl() { putchar(  n ); }   int n, a[200111], p[200111], cnt[200111], mx = 1, ans[200111];   bool f[200111];   map<int, vector<int> > mp;   int gf(int x) { return x == p[x] ? x : p[x] = gf(p[x]); }   void un(int x, int y) {     x = gf(x), y = gf(y);     if (x == y) return;     p[y] = x;     cnt[x] += cnt[y];     mx = max(mx, cnt[x]);   }   int main() {     n = getnum();     for (int i = 1; i <= n; i++) {       p[i] = i;       a[i] = getnum();       mp[a[i]].push_back(i);       cnt[i] = 1;     }     for (map<int, vector<int> >::iterator it = --mp.end();; it--) {       vector<int> &v = it->second;       for (int i = 0; i < v.size(); i++) {         f[v[i]] = 1;         if (f[v[i] - 1]) un(v[i] - 1, v[i]);         if (f[v[i] + 1]) un(v[i] + 1, v[i]);         ans[mx] = max(ans[mx], it->first);       }       if (it == mp.begin()) break;     }     int res = ans[n];     for (int i = n; i >= 1; i--) {       if (ans[i] != 0) res = ans[i];       ans[i] = res;     }     for (int i = 1; i <= n; i++) putnum(ans[i]), putsp();     return 0;   }
#include <bits/stdc++.h>   int vi[60], ho[60];   int main() {     int n, k, i;     int x, y;     scanf( %d , &n);     for (k = 1; k <= n * n; k++) {       scanf( %d%d , &x, &y);       if (vi[x] || ho[y]) continue;       vi[x] = 1;       ho[y] = 1;       printf( %d  , k);     }   }
#include<bits/stdc++.h>      #define y1 dmytxdy   #define pb push_back   #define fi first   #define se second   #define mp make_pair      using namespace std;      typedef long long ll;   typedef unsigned long long ull;   typedef pair<int,int> pii;   typedef pair<ll,ll> pll;   typedef long double ld;      template <typename T> bool chkmin(T &x,T y){return x>y?x=y,1:0;}   template <typename T> bool chkmax(T &x,T y){return x<y?x=y,1:0;}      int readint(){    int x=0,f=1; char ch=getchar();    while(ch< 0 ||ch> 9 ){if(ch== - )f=-1;ch=getchar();}    while(ch>= 0 &&ch<= 9 ){x=x*10+ch- 0 ;ch=getchar();}    return x*f;   }      struct node{    int x,y,id;    node(int x=0,int y=0,int id=0):x(x),y(y),id(id){}   }p[2005];      int n,m;   int x[2005],y[2005],a[2005];   bool vis[2005];      ll operator*(pii x,pii y){return 1ll*x.fi*y.se-1ll*x.se*y.fi;}      int main(){    n=readint();    for(int i=1;i<=n;i++) x[i]=readint(),y[i]=readint(),a[i]=readint();    int pl=0,mina=1<<30;    for(int i=1;i<=n;i++) if(a[i]!=i&&chkmin(mina,x[i])) pl=i;    if(!pl){     printf( 0 n );     return 0;    }    for(int i=1;i<=n;i++) if(i!=pl&&a[i]!=i) p[++m]=node(x[i],y[i],i);    for(int i=1;i<=m;i++) for(int j=i+1;j<=m;j++) if(mp(p[i].x-x[pl],p[i].y-y[pl])*mp(p[j].x-x[pl],p[j].y-y[pl])<0) swap(p[i],p[j]);    vector<pii> ans(0);    for(int i=1;i<m;i++){     for(int j=p[i].id,k=1;k<=n;j=a[j],k++) vis[j]=1;     bool fl=vis[p[i+1].id];     for(int j=p[i].id,k=1;k<=n;j=a[j],k++) vis[j]=0;     if(!fl) ans.pb(mp(p[i].id,p[i+1].id)),swap(a[p[i].id],a[p[i+1].id]);    }    for(int j=a[pl];j!=pl;j=a[j]) ans.pb(mp(pl,j));    printf( %d n ,ans.size());    for(auto r:ans) printf( %d %d n ,r.fi,r.se);    return 0;   }
#include<bits/stdc++.h>   using namespace std;   int main()   {       int tst,i,m,n;       cin>>tst;       while(tst--)       {           int ar[4];           cin>>ar[0]>>ar[1]>>ar[2]>>ar[3];           n=max(ar[2],ar[3]);m=max(ar[0],ar[1]);           sort(ar,ar+4);           ((n==ar[3]||n==ar[2])&&(m==ar[3] || m==ar[2]))?cout<< YES n :cout<< NO n ;       }   }
#include <bits/stdc++.h>   using namespace std;   constexpr int maxn = 1010;   int n;   bool e[maxn][maxn];   pair<int, int> flip(int a, int b, bool inv) {     int x = -1, y;     for (int i = 0; i < n; i++)       if (e[a][i] && e[b][i])         if (x == -1)           x = i;         else {           y = i;           break;         }     e[a][b] = e[b][a] = false;     e[x][y] = e[y][x] = true;     return inv ? make_pair(x, y) : make_pair(a, b);   }   vector<pair<int, int> > solve(bool inv) {     memset(e, 0, sizeof(e));     for (int i = 0; i < n; i++) e[i][(i + 1) % n] = e[(i + 1) % n][i] = true;     for (int i = 0, a, b; i < n - 3; i++) {       cin >> a >> b;       a--;       b--;       e[a][b] = e[b][a] = true;     }     vector<pair<int, int> > res;     for (int i = 1; i < n;) {       if (e[0][i]) {         i++;         continue;       }       int j;       for (j = i + 1; e[0][j] == 0; j++)         ;       res.push_back(flip(i - 1, j, inv));     }     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin >> n;     vector<pair<int, int> > a = solve(false), b = solve(true);     cout << a.size() + b.size() << endl;     for (int i = 0; i < (int)a.size(); i++)       cout << a[i].first + 1 <<     << a[i].second + 1 << endl;     for (int i = b.size() - 1; i >= 0; i--)       cout << b[i].first + 1 <<     << b[i].second + 1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   std::ostream& operator<<(std::ostream& os, const std::vector<T>& input) {     for (auto const& i : input) {       os << i <<    ;     }     return os;   }   template <class T1, class T2>   std::ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& input) {     os <<  (  << input.first <<  ,   << input.second <<  ) ;     return os;   }   const int maxn = 1000;   int d[maxn], f[maxn];   vector<int> E[maxn], node[maxn];   void dfs(int u, int fa) {     node[d[u]].push_back(u + 1);     for (int v : E[u])       if (v != fa) {         d[v] = d[u] + 1;         f[v] = u;         dfs(v, u);       }   }   void solve() {     int n, x, y;     cin >> n;     for (int i = 0; i < int(n); ++i) {       node[i].clear();       E[i].clear();     }     for (int i = 0; i < int(n - 1); ++i) {       cin >> x >> y;       x--, y--;       E[x].push_back(y);       E[y].push_back(x);     }     cout <<  ?   << n;     for (int i = 0; i < int(n); ++i) cout <<     << i + 1;     cout << endl;     int root, dist;     cin >> root >> dist;     root--;     d[root] = 0;     dfs(root, -1);     int l = 0, r = 0;     for (int i = 0; i < int(n); ++i) r = max(r, d[i]);     r++;     int node_u, node_v;     while (r - l > 1) {       int m = (l + r) >> 1;       cout <<  ?   << (node[m]).size() <<     << node[m] << endl;       cin >> x >> y;       x--;       if (y == dist) {         node_u = x + 1;         l = m;       } else {         r = m;       }     }     int lv = dist - l;     if (lv == 0) {       node_v = root + 1;     } else {       int w = node_u - 1;       for (int i = 0; i < int(l - lv); ++i) {         w = f[w];       }       vector<int> tmp(0);       for (int x : node[lv])         if (x != w + 1) tmp.push_back(x);       cout <<  ?   << (tmp).size() <<     << tmp << endl;       cin >> node_v >> y;       assert(y == dist);     }     cout <<  !   << node_u <<     << node_v << endl;     string ret;     cin >> ret;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int cas = 1;     cin >> cas;     for (int ca = 0; ca < int(cas); ++ca) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct point {     int x, y;   };   int dist(const point &a, const point &b) {     return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);   }   int main(int argc, char *argv[]) {     point p[8];     int a[8] = {0, 1, 2, 3, 4, 5, 6, 7};     for (int i = 0; i < 8; i++) scanf( %d %d , &p[i].x, &p[i].y);     bool found = false;     do {       int d = dist(p[a[0]], p[a[1]]);       if (d != dist(p[a[0]], p[a[2]]) || d != dist(p[a[1]], p[a[3]]) ||           d != dist(p[a[2]], p[a[3]]))         continue;       if (2 * d != dist(p[a[0]], p[a[3]]) || 2 * d != dist(p[a[1]], p[a[2]]))         continue;       int d1 = dist(p[a[4]], p[a[5]]);       int d2 = dist(p[a[4]], p[a[6]]);       if (d1 != dist(p[a[6]], p[a[7]]) || d2 != dist(p[a[5]], p[a[7]])) continue;       if (d1 + d2 != dist(p[a[5]], p[a[6]]) || d1 + d2 != dist(p[a[4]], p[a[7]]))         continue;       found = true;       break;     } while (next_permutation(a, a + 8));     if (found) {       printf( YES n );       for (int i = 0; i < 4; i++) printf( %s%d , i > 0 ?     :   , a[i] + 1);       printf(  n );       for (int i = 4; i < 8; i++) printf( %s%d , i > 4 ?     :   , a[i] + 1);       printf(  n );     } else {       printf( NO n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 59;   int t[N];   inline int read() {     int s = 1, a = 0;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) s = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       a = a * 10 + ch -  0 ;       ch = getchar();     }     return s * a;   }   int main() {     int n = read(), k = read(), m = read(), s = 0;     for (int i = 1; i <= k; i++) t[i] = read(), s += t[i];     sort(t + 1, t + k + 1);     long long res = 0;     for (int i = 0; i <= n; i++) {       long long tim = i * s, cur = i * (k + 1);       if (tim > m) break;       for (int j = 1; j <= k; j++) {         if (tim + (n - i) * t[j] <= m)           tim += (n - i) * t[j], cur += (n - i);         else {           while (tim + t[j] <= m) tim += t[j], cur++;           break;         }       }       res = max(res, cur);     }     return 0 * printf( %d n , res);   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 7;   const int M = 23;   const int inf = 1e9 + 7;   const long long base = 1e18;   const double pi = acos(-1);   const double ep = 1e-9;   map<int, int> st;   int pre[1 << M];   int cur[1 << M];   int n;   int a[N];   int main() {     cin >> n;     for (int i = 1; i < n + 1; i++) {       cin >> a[i];       st[a[i]] = i - 1;     }     for (int mask = 0; mask < 1 << M; mask++) cur[mask] = inf;     cur[1] = 1;     for (int i = 2; i < n + 1; i++) {       for (int mask = 0; mask < 1 << (i - 1); mask++) {         pre[mask] = cur[mask];         cur[mask] = inf;       }       for (int mask = 0; mask < 1 << (i - 1); mask++) {         if (pre[mask] >= inf) continue;         bool check = false;         for (int j = 0; j + 1 < i; j++) {           if ((mask & (1 << j)) && st.count(a[i] - a[j + 1]) &&               (mask & (1 << st[a[i] - a[j + 1]]))) {             check = true;             break;           }         }         if (!check) continue;         for (int j = 0; j + 1 < i; j++)           if (mask & (1 << (j))) {             int nxt = mask ^ (1 << j) ^ (1 << (i - 1));             cur[nxt] = min(cur[nxt], pre[mask]);           }         int nxt = mask ^ (1 << (i - 1));         cur[nxt] =             min(cur[nxt], pre[mask] + (pre[mask] == __builtin_popcount(mask)));       }     }     int ans = inf;     for (int mask = 0; mask < 1 << n; mask++) ans = min(ans, cur[mask]);     if (ans == inf) ans = -1;     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int n, r;   vector<pair<int, int> > pos, L, R;   vector<int> ans;   map<pair<int, int>, int> vis;   bool cmp(pair<int, int> a, pair<int, int> b) {     return a.first + a.second < b.first + b.second;   }   int main() {     cin >> n >> r;     for (int i = 0; i < n; i++) {       int x, y;       cin >> x >> y;       vis[{x, y}]++;       if (y >= 0)         pos.push_back({x, y});       else         R.push_back({y, x}), L.push_back({x, y});     }     sort(pos.begin(), pos.end());     sort(L.rbegin(), L.rend(), cmp);     vector<pair<int, int> > aux;     for (pair<int, int> x : pos) {       while (aux.size() && r >= aux.back().first) {         r += aux.back().second;         aux.pop_back();       }       if (r < x.first) {         aux.push_back(x);       } else {         r += x.second;       }     }     if (aux.size()) {       cout <<  NO  << endl;       return 0;     }     for (pair<int, int> x : L) {       if (r < x.first) {         cout <<  NO  << endl;         return 0;       }       r += x.second;     }     if (r < 0)       cout <<  NO  << endl;     else       cout <<  YES  << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main(int argc, char* argv[]) {     ios_base::sync_with_stdio(false);     long long int N, M;     cin >> N >> M;     long long int max_n1;     for (max_n1 = 1; (max_n1 * (max_n1 - 1)) / 2 + 1 <= N; max_n1 += 2)       ;     max_n1 -= 2;     long long int max_n2;     for (max_n2 = 0; (max_n2 * (max_n2 - 1)) / 2 + max_n2 / 2 <= N; max_n2 += 2)       ;     max_n2 -= 2;     long long int max_n = max(max_n1, max_n2);     vector<long long int> qs(M, 0);     vector<long long int> ws(M, 0);     for (int m = 0; m < M; ++m) cin >> qs[m] >> ws[m];     sort(ws.begin(), ws.end(), greater<long long int>());     max_n = min(max_n, (long long int)ws.size());     long long int res = 0;     for (int i = 0; i < max_n; ++i) res += ws[i];     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 111111;   int N;   char s[MAX];   int f[MAX];   int sum[MAX];   bool match(int i, int j) {     if (i < 1 || j < 1) return 0;     if (s[i - 1] ==  ) )       return s[j - 1] ==  ( ;     else       return s[j - 1] ==  [ ;   }   int get(int i) { return f[i - 1] < N ? f[i - 1] : i; }   int main() {     int i, j, k;     while (cin >> s) {       N = strlen(s);       sum[0] = 0;       for (i = 1; i <= N; ++i) sum[i] = sum[i - 1] + (s[i - 1] ==  ] );       memset(f, 127, sizeof f);       for (i = 2; i <= N; ++i) {         if (s[i - 1] ==  (  || s[i - 1] ==  [ ) continue;         if (match(i, i - 1)) f[i] = get(i - 1);         if (f[i - 1] < N && match(i, f[i - 1] - 1))           f[i] = min(f[i], get(f[i - 1] - 1));       }       int ans = 0, ansi;       for (i = 1; i <= N; ++i)         if (f[i] < N && sum[i] - sum[f[i] - 1] > ans) {           ans = sum[i] - sum[f[i] - 1];           ansi = i;         }       printf( %d n , ans, ansi);       if (ans > 0) {         for (i = f[ansi] - 1; i < ansi; ++i) putchar(s[i]);       }       puts(  );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct node {     int num;     double w;   } point[1005];   bool cmp(node a, node b) {     if (fabs(a.w - b.w) < 0.0001) return a.num < b.num;     return a.w > b.w;   }   int main() {     int i, n, t1, t2, k, a, b;     scanf( %d%d%d%d , &n, &t1, &t2, &k);     for (i = 1; i <= n; i++) {       scanf( %d%d , &a, &b);       point[i].num = i;       point[i].w = t1 * a * (1 - k * 0.01) + t2 * b;       if (t1 * b * (1 - k * 0.01) + t2 * a > point[i].w)         point[i].w = t1 * b * (1 - k * 0.01) + t2 * a;     }     sort(point + 1, point + 1 + n, cmp);     for (i = 1; i <= n; i++) printf( %d %.2lf n , point[i].num, point[i].w);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<pair<int, int> > v;     for (int i = 0; i < n; i++) {       int a, b;       cin >> a >> b;       v.push_back(make_pair(a, b));     }     int k;     cin >> k;     int i;     for (i = 0; i < n; i++) {       if (k >= v[i].first and k <= v[i].second) break;     }     cout << n - i << endl;   }