malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   const long long inf = 1e18 + 10;   long long dis[N], sid[N], mark[N], h[N], dp[N], c[N];   pair<pair<long long, long long>, long long> E[N];   vector<pair<long long, long long> > adj[N], jda[N], g[N];   priority_queue<pair<long long, long long>, vector<pair<long long, long long> >,                  greater<pair<long long, long long> > >       pq;   void dfs(long long v, long long id) {     mark[v] = 1;     dp[v] = inf;     for (pair<long long, long long> e : g[v]) {       long long u = e.first, ind = e.second;       if (ind == id) continue;       if (mark[u]) {         dp[v] = min(dp[v], h[u]);       } else {         h[u] = h[v] + 1;         dfs(u, ind);         dp[v] = min(dp[v], dp[u]);         if (h[v] < dp[u]) c[ind] = 1;       }     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, m, s, t;     cin >> n >> m >> s >> t;     for (int i = 0; i < m; i++) {       long long u, v, w;       cin >> u >> v >> w;       adj[u].push_back({v, w});       jda[v].push_back({u, w});       E[i] = {{u, v}, w};     }     fill(dis, dis + N, inf);     dis[s] = 0;     pq.push({0, s});     while (!pq.empty()) {       long long d = pq.top().first, v = pq.top().second;       pq.pop();       if (d != dis[v]) continue;       for (pair<long long, long long> e : adj[v]) {         long long u = e.first, w = e.second;         if (d + w < dis[u]) {           dis[u] = d + w;           pq.push({d + w, u});         }       }     }     fill(sid, sid + N, inf);     sid[t] = 0;     pq.push({0, t});     while (!pq.empty()) {       long long d = pq.top().first, v = pq.top().second;       pq.pop();       if (d != sid[v]) continue;       for (pair<long long, long long> e : jda[v]) {         long long u = e.first, w = e.second;         if (d + w < sid[u]) {           sid[u] = d + w;           pq.push({d + w, u});         }       }     }     for (int i = 0; i < m; i++) {       long long u = E[i].first.first, v = E[i].first.second, w = E[i].second;       if (dis[u] + w + sid[v] == dis[t]) {         g[u].push_back({v, i});         g[v].push_back({u, i});       }     }     dfs(s, -1);     for (int i = 0; i < m; i++) {       long long u = E[i].first.first, v = E[i].first.second, w = E[i].second;       if (dis[u] + w + sid[v] == dis[t]) {         if (c[i])           cout <<  YES n ;         else if (1 < w)           cout <<  CAN  <<     << 1 <<   n ;         else           cout <<  NO n ;       } else {         long long cst = dis[u] + w + sid[v];         long long dif = cst - dis[t] + 1;         if (dif < w)           cout <<  CAN  <<     << dif <<   n ;         else           cout <<  NO n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int p[2 * 100001], rnk[2 * 100001];   int cnt[2 * 100001];   long long pref[2 * 100001 + 5];   long long ans[2 * 100001 + 5];   vector<pair<int, int> > q;   struct Edge {     int a, b;     int w;     Edge(int a, int b, int w) : a(a), b(b), w(w) {}   };   vector<Edge> e;   bool comp(const Edge &one, const Edge &two) { return one.w < two.w; }   void init() {     pref[0] = 0;     for (int i = 1; i <= 2 * 100001; ++i) pref[i] = pref[i - 1] + (i - 1);   }   void dsu_init() {     for (int i = 0; i < 2 * 100001; ++i) {       p[i] = i;       rnk[i] = 0;       cnt[i] = 1;     }   }   int dsu_find(int v) {     if (p[v] == v) return v;     return p[v] = dsu_find(p[v]);   }   int dsu_meld(int a, int b, int &prev) {     a = dsu_find(a), b = dsu_find(b);     if (a == b) return 0;     if (rnk[a] < rnk[b]) swap(a, b);     p[b] = a;     cnt[a] += cnt[b];     prev = cnt[b];     if (rnk[a] == rnk[b]) ++rnk[a];     return cnt[a];   }   int main() {     cin.sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     init();     dsu_init();     cin >> n >> m;     int a, b, w;     for (int i = 0; i < n - 1; ++i) {       cin >> a >> b >> w;       --a, --b;       e.emplace_back(a, b, w);     }     sort(e.begin(), e.end(), comp);     for (int i = 0; i < m; ++i) {       cin >> a;       q.push_back({a, i});     }     sort(q.begin(), q.end());     long long sum = 0;     int bnd = 0;     int prev, now;     for (int i = 0; i < q.size(); ++i) {       for (int j = bnd; j < e.size(); ++j) {         if (e[j].w > q[i].first) break;         now = dsu_meld(e[j].a, e[j].b, prev);         sum -= pref[prev];         sum += (pref[now] - pref[now - prev]);         ++bnd;       }       ans[q[i].second] = sum;     }     for (int i = 0; i < m; ++i) cout << ans[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T gcd(T a, T b) {     return (b) == 0 ? (a) : gcd((b), ((a) % (b)));   }   template <class T>   inline T lcm(T a, T b) {     return ((a) / gcd((a), (b)) * (b));   }   template <class T>   inline T BigMod(T Base, T power, T M = 1000000007) {     if (power == 0) return 1;     if (power & 1)       return ((Base % M) * (BigMod(Base, power - 1, M) % M)) % M;     else {       T y = BigMod(Base, power / 2, M) % M;       return (y * y) % M;     }   }   template <class T>   inline T ModInv(T A, T M = 1000000007) {     return BigMod(A, M - 2, M);   }   int fx[] = {-1, +0, +1, +0, +1, +1, -1, -1, +0};   int fy[] = {+0, -1, +0, +1, +1, -1, +1, -1, +0};   int day[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};   double arr[111];   double dp[111];   double pre[111];   int main() {     int n, i, j;     double answer = 0;     cin >> n;     for (i = 1; i <= n; i++) cin >> arr[i];     sort(arr + 1, arr + n + 1);     dp[n] = arr[n];     pre[n] = (1 - arr[n]);     for (i = n - 1; i >= 1; i--) {       pre[i] = (1 - arr[i]) * pre[i + 1];       dp[i] = arr[i] * pre[i + 1] + dp[i + 1] * (1 - arr[i]);     }     for (i = 1; i <= n; i++) answer = max(answer, dp[i]);     printf( %.10f , answer);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<int, int> mp;   int a[100010];   int main() {     int i = 0, j = 0;     int n, m;     while (scanf( %d%d , &n, &m) != EOF) {       mp.clear();       int f;       for (i = 1; i <= n; ++i) {         scanf( %d , &f);         if (mp.find(f) != mp.end()) {           mp[f] = -2;         } else {           mp[f] = i;         }       }       int b;       bool flag1 = false;       bool flag2 = false;       for (i = 1; i <= m; ++i) {         scanf( %d , &b);         if (!flag1) {           if (mp.find(b) == mp.end()) {             flag1 = true;           } else if (-2 == mp[b]) {             flag2 = true;           } else {             a[i] = mp[b];           }         }       }       if (flag1) {         printf( Impossible n );       } else if (flag2) {         printf( Ambiguity n );       } else {         printf( Possible n );         for (int i = 1; i <= m; ++i) {           printf( %d  , a[i]);         }         printf(  n );       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int vis[1500000 + 5], a[1000006], marked[1500000], pt = 2;   vector<int> v[1500000 + 5];   bool broken;   bool hoyKina(int x) {     for (int i = 0; i < v[x].size(); i++) {       if (marked[v[x][i]]) return false;     }     for (int i = 0; i < v[x].size(); i++) {       marked[v[x][i]] = 1;     }     return true;   }   int cal(int x) {     if (broken) {       while (1) {         if (hoyKina(pt)) return pt;         pt++;       }     }     while (1) {       if (hoyKina(x)) return x;       broken = true;       x++;     }   }   int main() {     for (int i = 2; i <= 1500000; i++) {       if (vis[i]) continue;       for (int j = i; j <= 1500000; j += i) {         vis[j] = 1;         v[j].push_back(i);       }     }     int n, x;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> x;       printf( %d  , cal(x));     }     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const bool debug = true;   const int MAXN = 100010;   int dp[MAXN], t[MAXN];   const int inf = 2000000010;   int n;   int first_lower(int x) {     if (x < 0) return 0;     return upper_bound(t + 1, t + n + 1, x) - t - 1;   }   struct node {     int mx;     int lazy;     node() {}     node(int _mx, int _lazy) {       mx = _mx;       lazy = _lazy;     }     node operator+(const node &a) const { return *(new node(max(mx, a.mx), 0)); }   } st[4 * MAXN];   int value[MAXN];   void propagate(int idx, int left, int right) {     if (st[idx].lazy == 0) return;     st[idx].mx += st[idx].lazy;     if (left != right) {       st[2 * idx].lazy += st[idx].lazy;       st[2 * idx + 1].lazy += st[idx].lazy;     }     st[idx].lazy = 0;   }   void update(int idx, int left, int right, int l, int r, int val) {     if (l <= left && right <= r) {       st[idx].lazy += val;       return;     }     propagate(idx, left, right);     if (r > (left + right) / 2)       update(2 * idx + 1, (left + right) / 2 + 1, right, l, r, val);     if (l <= (left + right) / 2)       update(2 * idx, left, (left + right) / 2, l, r, val);     propagate(2 * idx, left, (left + right) / 2);     propagate(2 * idx + 1, (left + right) / 2 + 1, right);     st[idx] = st[2 * idx] + st[2 * idx + 1];   }   int get(int idx, int left, int right) {     propagate(idx, left, right);     if (left != right) {       propagate(2 * idx, left, (left + right) / 2);       propagate(2 * idx + 1, (left + right) / 2 + 1, right);     }     if (left == right)       if (st[idx].mx > 0)         return value[left];       else         return -1;     if (st[2 * idx + 1].mx > 0)       return get(2 * idx + 1, (left + right) / 2 + 1, right);     else if (st[2 * idx].mx > 0)       return get(2 * idx, left, (left + right) / 2);     else       return -1;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       int p, type;       scanf( %d %d , &p, &type);       if (type == 1) {         int val;         scanf( %d , &val);         value[p] = val;         update(1, 1, n, 1, p, 1);       } else         update(1, 1, n, 1, p, -1);       printf( %d n , get(1, 1, n));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     string s;     cin >> s;     if (n == 1 && k == 1) {       cout <<  0  << endl;       return 0;     }     if (s[0] !=  1  && k) {       k--;       s[0] =  1 ;     }     for (int i = 1; i < n && k; i++) {       if (s[i] !=  0 ) {         s[i] =  0 ;         k--;       }     }     cout << s << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int getint() {     unsigned int c;     int x = 0;     while (((c = getchar()) -  0 ) >= 10) {       if (c ==  - ) return -getint();       if (!~c) exit(0);     }     do {       x = (x << 3) + (x << 1) + (c -  0 );     } while (((c = getchar()) -  0 ) < 10);     return x;   }   int getc_str(char str[]) {     unsigned int c, n = 0;     while ((c = getchar()) <=    )       ;     if (!~c) exit(0);     do {       str[n++] = c;     } while ((c = getchar()) >    );     str[n] =   0 ;     return n;   }   const long long MOD = 1000000007;   long long dp[123][2789];   int n;   char in[123];   int main() {     int i, j, k, tcc, tc = getint();     dp[0][0] = 1;     for (i = 0; i < 111; i++) {       for (j = 0; j <= 2600; j++) {         for (k = 0; k < 26; k++) {           (dp[i + 1][j + k] += dp[i][j]) %= MOD;         }       }     }     for (tcc = 0; tcc < tc; tcc++) {       n = getc_str(in);       int sum = 0;       for (i = 0; i < n; i++) sum += in[i] -  a ;       int res = (dp[n][sum] - 1 + MOD) % MOD;       printf( %d n , res);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct Edge {     int x;     int y;     int w;   };   const int N = 200 + 7;   const int INF = (int)1e9;   int n;   int m;   int d[N][N];   struct T {     int f;     int s;   };   bool operator<(T a, T b) { return a.s - a.f < b.s - b.f; }   int solve(int x, int y, int w) {     vector<T> pts;     for (int i = 1; i <= n; i++) {       pts.push_back({d[x][i], d[y][i] + w});     }     sort(pts.begin(), pts.end());     vector<int> pre(n), suf(n);     pre[0] = pts[0].s;     for (int i = 1; i < n; i++) {       pre[i] = max(pre[i - 1], pts[i].s);     }     suf[n - 1] = pts[n - 1].f;     for (int i = n - 2; i >= 0; i--) {       suf[i] = max(suf[i + 1], pts[i].f);     }     vector<int> tt(n);     for (int i = 0; i < n; i++) {       tt[i] = (pts[i].s - pts[i].f) / 2;     }     int ret = INF;     for (int last = -1; last < n; last++) {       if (last == -1) {         int m_suf = suf[last + 1];         int t = tt[last + 1];         ret = min(ret, m_suf + t);         continue;       }       if (last == n - 1) {         int m_pre = pre[last];         int t = tt[last];         ret = min(ret, m_pre - t);         continue;       }       int t1 = tt[last];       int t2 = tt[last + 1];       int m_pre = pre[last];       int m_suf = suf[last + 1];       ret = min(ret, max(m_suf + t1, m_pre - t1));       ret = min(ret, max(m_suf + t2, m_pre - t2));       int t = (m_pre - m_suf) / 2;       if (t1 <= t && t <= t2) {         ret = min(ret, max(m_suf + t, m_pre - t));       }     }     return ret;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         d[i][j] = INF;       }       d[i][i] = 0;     }     vector<Edge> e(m);     for (int i = 0; i < m; i++) {       cin >> e[i].x >> e[i].y >> e[i].w;       e[i].w *= 2;       d[e[i].x][e[i].y] = d[e[i].y][e[i].x] = e[i].w;     }     for (int k = 1; k <= n; k++) {       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= n; j++) {           d[i][j] = min(d[i][j], d[i][k] + d[k][j]);         }       }     }     solve(e[0].x, e[0].y, e[0].w);     int ret = INF;     for (auto &it : e) {       ret = min(ret, solve(it.x, it.y, it.w));     }     if (ret % 2 == 0) {       cout << ret / 2 <<  .0 n ;     } else {       cout << ret / 2 <<  .5 n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100005;   string a, b;   int n;   int x[MAXN], y[MAXN];   void pre() {     int cnt = 0, len = b.size();     for (int i = 0; i < n; i++) {       if (cnt == len) continue;       if (b[cnt] == a[i]) {         x[cnt] = i;         cnt++;       }     }     cnt = len - 1;     for (int i = n - 1; i >= 0; i--) {       if (cnt < 0) continue;       if (b[cnt] == a[i]) {         y[cnt] = n - 1 - i;         cnt--;       }     }   }   int bs(int val, int in) {     int s = 0, e = in, mid;     while (s <= e) {       mid = (s + e) / 2;       if (x[mid] < val)         s = mid + 1;       else if (x[mid] > val)         e = mid - 1;       else         return mid;     }     return e;   }   int main() {     ios::sync_with_stdio(NULL);     cin.tie(0);     cin >> a;     cin >> b;     n = a.size();     std::fill(x, x + b.size(), MAXN);     std::fill(y, y + b.size(), MAXN);     pre();     int ani = MAXN, len = b.size();     pair<int, int> ans = make_pair(-1, len);     for (int i = len - 1; i >= 0; i--) {       int an = bs(n - 1 - y[i], i - 1);       if (ani > i - an - 1) {         if (an == -1 && y[i] >= n) continue;         if (an != -1 && x[an] + y[i] + 1 >= n) continue;         ani = i - an - 1;         ans = make_pair(an, i);       }     }     for (int i = 0; i < len; i++)       if (x[i] < n && len - i - 1 < ani) {         ani = len - i - 1;         ans = make_pair(i, len);       }     if (ans.first == -1 && ans.second == len)       cout <<  - n ;     else {       if (ans.first != -1) cout << b.substr(0, ans.first + 1);       if (ans.second != len) cout << b.substr(ans.second, len - ans.second);       cout <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   struct segtree {     int n;     vector<pair<int, int>> st;     segtree(int _n) {       n = _n;       st.assign(4 * n + 5, make_pair(0, 0));     }     pair<int, int> merge(pair<int, int> a, pair<int, int> b) {       pair<int, int> res = make_pair(min(a.first, b.first), 0);       if (a.first == res.first) res.second += a.second;       if (b.first == res.first) res.second += b.second;       if (res.second >= mod) res.second -= mod;       return res;     }     void update(int id, int l, int r, int pos, int val, int num) {       if (l > pos || r < pos) return;       if (l == r) {         st[id] = make_pair(val, num);         return;       }       int mid = (l + r) >> 1;       update(id << 1, l, mid, pos, val, num);       update(id << 1 | 1, mid + 1, r, pos, val, num);       st[id] = merge(st[id << 1], st[id << 1 | 1]);     }     pair<int, int> get(int id, int l, int r, int u, int v) {       if (l > v || r < u) return make_pair((int)2e9, 0);       if (l >= u && r <= v) return st[id];       int mid = (l + r) >> 1;       pair<int, int> lnode = get(id << 1, l, mid, u, v);       pair<int, int> rnode = get(id << 1 | 1, mid + 1, r, u, v);       return merge(lnode, rnode);     }     void update(int pos, int val, int num) { update(1, 1, n, pos, val, num); }     pair<int, int> get(int l, int r) { return get(1, 1, n, l, r); }   };   const int N = 2e5 + 5;   pair<int, int> a[N];   pair<int, int> dp[N];   int n;   int maxpre[N];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i].first >> a[i].second;     }     sort(a + 1, a + n + 1);     segtree st(n);     for (int i = 1; i <= n; i++) {       swap(a[i].first, a[i].second);       int lo = 0;       int hi = i;       while (hi - lo > 1) {         int mid = (lo + hi) >> 1;         if (a[mid].second <= a[i].first)           lo = mid;         else           hi = mid;       }       if (!lo)         dp[i] = make_pair(a[i].first, 1);       else {         dp[i] = st.get(1, lo);         dp[i].first += a[i].first;       }       st.update(i, dp[i].first - a[i].second, dp[i].second);     }     pair<int, int> ans = make_pair((int)2e9, 0);     int mx = 0;     for (int i = n; i >= 1; i--)       if (a[i].second > mx) {         if (ans.first == dp[i].first) {           ans.second += dp[i].second;           if (ans.second >= mod) ans.second -= mod;         } else if (ans.first > dp[i].first)           ans = dp[i];         mx = max(mx, a[i].first);       }     cout << ans.second;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a[200005], dp1[200005], dp2[200005];   int main() {     long long n, k, x;     int xx;     cin >> n >> k >> x;     for (int i = 1; i <= n; i++) {       scanf( %d , &xx);       a[i] = xx;     }     sort(a + 1, a + n + 1);     for (int i = 1; i <= n; i++) {       if (i != 1) {         dp1[i] = dp1[i - 1] | a[i - 1];       }     }     for (int i = n; i >= 1; i--) {       dp2[i] = dp2[i + 1] | a[i + 1];     }     long long mx = 0;     long long pw = 1;     for (int i = 1; i <= k; i++) {       pw *= x;     }     for (int i = n; i >= 1; i--) {       mx = max(mx, ((pw * a[i]) | dp1[i] | dp2[i]));     }     cout << mx;   }
#include <bits/stdc++.h>   using namespace std;   int fun(int x, int y, int z) {     return x * x + y * y + z * z + x * y + y * z + z * x;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t, n;     cin >> t;     while (t--) {       cin >> n;       int a[n];       int f = true;       for (int i = 0; i < n; i++) cin >> a[i];       for (int i = 1; i < n - 1; i++) {         if (a[i] > a[i - 1] && a[i] > a[i + 1]) {           cout <<  YES  << endl;           f = false;           cout << i <<     << i + 1 <<     << i + 2 << endl;           break;         }       }       if (f) cout <<  NO  << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int a[300010];   struct _ {     int val, rpos;   };   vector<_> min_, max_;   int vmin[1200010], cmin[1200010], add[1200010];   void pushup(int rt) {     if (vmin[rt << 1] == vmin[rt << 1 | 1]) {       vmin[rt] = vmin[rt << 1];       cmin[rt] = cmin[rt << 1] + cmin[rt << 1 | 1];     } else {       if (vmin[rt << 1] < vmin[rt << 1 | 1]) {         vmin[rt] = vmin[rt << 1];         cmin[rt] = cmin[rt << 1];       } else {         vmin[rt] = vmin[rt << 1 | 1];         cmin[rt] = cmin[rt << 1 | 1];       }     }   }   void build(int l, int r, int rt) {     if (l == r) {       cmin[rt] = 1;       return;     }     int m = l + r >> 1;     build(l, m, rt << 1);     build(m + 1, r, rt << 1 | 1);     pushup(rt);   }   void pushdown(int rt) {     if (add[rt]) {       add[rt << 1] += add[rt];       vmin[rt << 1] += add[rt];       add[rt << 1 | 1] += add[rt];       vmin[rt << 1 | 1] += add[rt];       add[rt] = 0;       return;     }   }   void update(int L, int R, int c, int l, int r, int rt) {     if (L <= l && r <= R) {       add[rt] += c;       vmin[rt] += c;       return;     }     int m = l + r >> 1;     pushdown(rt);     if (m >= L) update(L, R, c, l, m, rt << 1);     if (m < R) update(L, R, c, m + 1, r, rt << 1 | 1);     pushup(rt);   }   struct __ {     int v, c;     __ operator+(const __ &ob) const {       __ rv;       if (v == ob.v) {         rv.v = v;         rv.c = c + ob.c;       } else {         if (v < ob.v) {           rv.v = v;           rv.c = c;         } else {           rv.v = ob.v;           rv.c = ob.c;         }       }       return rv;     }   };   __ query(int L, int R, int l, int r, int rt) {     if (L <= l && r <= R) return (__){vmin[rt], cmin[rt]};     int m = l + r >> 1;     pushdown(rt);     __ ans;     ans.v = 998244353;     if (m >= L) ans = ans + query(L, R, l, m, rt << 1);     if (m < R) ans = ans + query(L, R, m + 1, r, rt << 1 | 1);     return ans;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     build(1, n, 1);     int i;     int x, y;     for (i = 1; i <= n; ++i) {       cin >> x >> y;       a[x] = y;     }     min_.push_back((_){-1, 0});     max_.push_back((_){n + 1, 0});     long long ans = 0;     for (i = 1; i <= n; ++i) {       while (min_.back().val >= a[i]) {         update(min_[min_.size() - 2].rpos + 1, min_.back().rpos, min_.back().val,                1, n, 1);         min_.pop_back();       }       update(min_.back().rpos + 1, i, -a[i], 1, n, 1);       min_.push_back((_){a[i], i});       while (max_.back().val <= a[i]) {         update(max_[max_.size() - 2].rpos + 1, max_.back().rpos, -max_.back().val,                1, n, 1);         max_.pop_back();       }       update(max_.back().rpos + 1, i, a[i], 1, n, 1);       max_.push_back((_){a[i], i});       update(1, i, -1, 1, n, 1);       ans += query(1, i, 1, n, 1).c;     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     int q;     cin >> q;     while (q--) {       int n;       cin >> n;       string s, t;       cin >> s >> t;       string ss = s;       string tt = t;       sort(ss.begin(), ss.end());       sort(tt.begin(), tt.end());       int ans;       if (ss != tt)         ans = -1;       else {         ans = INT_MAX;         for (int i = 0; i < n; i++) {           int k = i;           for (int j = 0; j < n; j++) {             if (k < n and s[j] == t[k]) k++;           }           ans = min(ans, n - k + i);         }       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     long long p, q, i, t, i1 = 0, i2 = 0, mx;     char c;     cin >> t;     long long a[368], b[368];     for (i = 0; i < 368; i++) {       a[i] = 0;       b[i] = 0;     }     for (i = 0; i < t; i++) {       cin >> c >> p >> q;       if (c ==  F ) {         b[p]++;         b[q + 1]--;       } else {         a[p]++;         a[q + 1]--;       }     }     mx = 0;     for (i = 1; i < 367; i++) {       a[i] += a[i - 1];       b[i] += b[i - 1];       mx = max(mx, (min(a[i], b[i]) * 2));     }     cout << mx << endl;     return 0;   }