malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   const int N = 100005;   long long f[N];   long long inverse(long long x) {     if (x >= mod) return inverse(x % mod);     assert(x != 0);     if (x == 1) return 1;     return inverse(mod % x) * (mod - mod / x) % mod;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     vector<long long> a(n);     long long sum = 0;     for (auto &x : a) {       cin >> x;       sum += x;     }     f[0] = 0;     f[1] = ((sum - 1) * (sum - 1) % mod) * inverse(sum) % mod;     for (int m = 2; m < N && m < sum; m++) {       f[m] = 2 * f[m - 1] - f[m - 2] - ((sum - 1) * inverse(sum - m + 1) % mod);       f[m] %= mod;       if (f[m] < 0) f[m] += mod;     }     long long ans = 0;     for (auto x : a) {       ans += f[x];     }     ans %= mod;     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int fastMax(int x, int y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ y; }   int fastMin(int x, int y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ x; }   const long long int MAXN = 1e6 + 10;   long long int n, ans = 1;   long long int a[MAXN], dp[MAXN];   void solve() {     cin >> n;     for (int i = (1); i <= (n); ++i) {       cin >> a[i];       dp[a[i]]++;     }     for (int i = (MAXN - 1); i >= (1); --i) {       if (!dp[i]) continue;       for (long long int j = 2 * i; j <= MAXN - 1; j += i) {         dp[i] = max(dp[i], 1 + dp[j]);         ans = max(ans, dp[i]);       }     }     cout << ans << endl;   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long int t;     t = 1;     for (int i = (1); i <= (t); ++i) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   static const int INF = 500000000;   template <class T>   void debug(T a, T b) {     for (; a != b; ++a) cerr << *a <<    ;     cerr << endl;   }   int h, w, q;   char buf[505][505];   int ans[1000005];   struct query_ {     int y1, x1, y2, x2;     int id;   };   bitset<505> able[2][505][505];   void rec(int l, int r, vector<query_>& query) {     vector<query_> left, right;     int md = (l + r) >> 1;     for (int i = 0; i < h; ++i)       for (int j = l; j < r; ++j) able[0][i][j].reset(), able[1][i][j].reset();     for (int i = 0; i < h; ++i)       if (buf[i][md] ==  . ) able[0][i][md].set(i), able[1][i][md].set(i);     for (int i = h - 1; i >= 0; --i)       for (int j = md; j >= l; --j)         if (buf[i][j] ==  . ) {           able[0][i][j] |= able[0][i + 1][j];           if (j < md) able[0][i][j] |= able[0][i][j + 1];         }     for (int i = 0; i < h; ++i)       for (int j = md; j < r; ++j)         if (buf[i][j] ==  . ) {           if (buf[i][j + 1] ==  . ) able[1][i][j + 1] |= able[1][i][j];           if (buf[i + 1][j] ==  . ) able[1][i + 1][j] |= able[1][i][j];         }     for (int i = 0; i < query.size(); ++i) {       if (query[i].x1 <= md && md <= query[i].x2) {         if ((able[0][query[i].y1][query[i].x1] &              able[1][query[i].y2][query[i].x2])                 .any()) {           ans[query[i].id] = 1;         }       } else if (query[i].x2 < md)         left.push_back(query[i]);       else         right.push_back(query[i]);     }     if (!left.empty()) rec(l, md, left);     if (!right.empty()) rec(md, r, right);     query.clear();   }   int main() {     for (int i = 0; i < h; ++i)       for (int j = 0; j < w; ++j) buf[i][j] =  # ;     scanf( %d%d , &h, &w);     for (int i = 0; i < h; ++i) scanf( %s , buf[i]);     scanf( %d , &q);     vector<query_> query;     for (int i = 0; i < q; ++i) {       int a, b, c, d;       scanf( %d%d%d%d , &a, &b, &c, &d);       --a;       --b;       --c;       --d;       if (a > c || b > d) continue;       query.push_back((query_){a, b, c, d, i});     }     rec(0, w, query);     for (int i = 0; i < q; ++i) {       if (ans[i])         puts( Yes );       else         puts( No );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t = 1;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<int> v(n);       for (int i = 0; i < n; i++) cin >> v[i];       vector<int> ans(n);       for (int i = 0; i < n / 2; i++) {         ans[i] = v[n - 1 - i];         ans[n - 1 - i] = -1 * v[i];       }       for (int ele : ans) cout << ele <<    ;       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using cd = complex<double>;   const int Inf = 1000000007;   const long long mod = 1000000007;   const double Pi = acos(-1);   void Fastio() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);   }   int n, t, ans = 0;   long long res = 0;   int Co[4], Color[100005], a[100005];   vector<int> Adj[100005];   map<int, long long> C;   int main() {     Fastio();     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     for (int j = 2; j <= n; j++) {       int temp;       cin >> temp;       Adj[temp].emplace_back(j);       Adj[j].emplace_back(temp);     }     queue<int> BFS;     BFS.push(1);     Co[1] = 1;     Color[1] = 1;     while (BFS.empty() == false) {       int node = BFS.front();       for (auto x : Adj[node]) {         if (!Color[x]) {           Color[x] = 3 - Color[node];           Co[Color[x]]++;           BFS.push(x);         }       }       BFS.pop();     }     for (int i = 1; i <= n; i++) {       if (Adj[i].size() == 1 and i != 1) {         t = Color[i];         break;       }     }     t = 3 - t;     for (int i = 1; i <= n; i++) {       if (Color[i] == 3 - t) {         ans ^= a[i];         C[a[i]]++;       }     }     if (ans == 0) {       res += 1ll * Co[3 - t] * (Co[3 - t] - 1) / 2;       res += 1ll * Co[t] * (Co[t] - 1) / 2;     }     for (int i = 1; i <= n; i++) {       if (Color[i] == t) {         res += C[a[i] ^ ans];       }     }     cout << res;   }
#include <bits/stdc++.h>   using namespace std;   void no(int ex = -1) { cout << ex <<   n ; }   void bl(bool win) {     if (win)       cout <<  YES ;     else       cout <<  NO ;     cout <<   n ;   }   const int N = 2 * 10e5;   const int mod = 998244353;   vector<bool> pr;   void prime() {     int EDGE = 1000;     pr = vector<bool>(EDGE);     for (int i = 0; i < EDGE; i++) pr[i] = true;     pr[0] = false;     pr[1] = false;     for (int i = 2; i < EDGE; i++) {       if (pr[i]) {         if (i * i < EDGE) {           for (int j = i * i; j < EDGE; j += i) pr[j] = false;         }       }     }   }   long long nod(long long a1, long long b1) {     if (b1 == 0)       return a1;     else       return nod(b1, a1 % b1);   }   long long T;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, k;     cin >> n >> k;     vector<int> mn(n);     for (int i = 0; i < int(n); i++) {       cin >> mn[i];     }     vector<int> res(k);     for (int i = 0; i < int(k); i++) {       cin >> res[i];     }     vector<int> ab = {0, 0, 0, 1};     vector<int>::iterator hig;     hig = lower_bound(ab.begin(), ab.end(), 1);     vector<vector<int>> ans(n, {0});     sort(mn.begin(), mn.end());     vector<int> us(n, 0);     int cnt = 0;     for (int z = n - 1; z >= 0; z--) {       vector<int>::iterator low;       low = lower_bound(us.begin(), us.end(), res[mn[z] - 1]);       int y = low - us.begin();       y = min(n - 1, y);       if (us[y] == res[mn[z] - 1]) y--;       ans[n - y - 1][0]++;       us[y]++;       ans[n - y - 1].push_back(mn[z]);     }     int cur = 0;     while (cur < n && ans[cur][0] != 0) {       cur++;     }     cout << cur <<   n ;     for (int i = 0; i < cur; i++) {       for (int j = 0; j <= ans[i][0]; j++) cout << ans[i][j] <<    ;       cout <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int n, ans = 1e5, freq[125];   bool exst[125];   string s;   int main() {     scanf( %d , &n);     cin >> s;     for (int i = 0; i < n; i++) {       exst[s[i]] = true;     }     freq[s[0]] = 1;     for (int i = 0, j = 0; j < n;) {       bool valid = 1;       for (int k = 0; k <=  z ; k++) {         if (exst[k] && !freq[k]) {           j++;           freq[s[j]]++;           valid = 0;           break;         }       }       if (valid) {         ans = min(ans, j - i + 1);         freq[s[i]]--;         i++;       }     }     printf( %d , ans);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long int n, x, y, i, j;     long double sum1 = 0, sum2 = 0, mini, maxi, p, z;     cin >> n >> x >> y;     long int a[n];     for (i = 0; i < n; i++) {       cin >> a[i];     }     sort(a, a + n);     mini = min(x, y);     maxi = max(x, y);     p = mini;     j = 0;     while (mini--) {       sum1 = sum1 + a[n - 1 - j];       j++;     }     z = maxi;     while (maxi--) {       sum2 = sum2 + a[n - 1 - j];       j++;     }     cout << fixed << setprecision(12) << sum1 / p + sum2 / z;   }
#include <bits/stdc++.h>   long long int oddsum[100020], evensum[100020];   int main() {     memset(oddsum, 0, sizeof(oddsum));     memset(evensum, 0, sizeof(evensum));     int n, i;     long long int x, ans = 0, sum;     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %lld , &x);       if (i & 1)         oddsum[(i >> 1) + 1] = oddsum[i >> 1] + x;       else         evensum[(i >> 1) + 1] = evensum[i >> 1] + x;     }     for (i = 0; i < n; i++) {       if (i & 1)         sum =             oddsum[(i >> 1) + 1] + evensum[(n >> 1) + 1] - evensum[(i >> 1) + 1];       else         sum = evensum[(i >> 1) + 1] + oddsum[n >> 1] - oddsum[i >> 1];       if (ans < sum) ans = sum;     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string s[222], str;   int res[1000000] = {0};   bool hh(int n, int x) {     for (int i = 0; i < (1 << x); i++) {       str =   ;       for (int k = 0; k < x; k++) (i & (1 << k)) ? str +=  1  : str +=  0 ;       if (s[n].find(str) == -1) return false;     }     return true;   }   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> s[i];       int ii = 0, jj = 10;       while (ii < jj && hh(i, ii + 1)) ii++;       res[i] = ii;     }     int t, m;     cin >> t;     while (t--) {       int i, j, mid, ii, jj;       cin >> i >> j;       ii = i;       jj = j;       n++;       s[n] = s[i] + s[j];       if (s[n].size() > 1000)         s[n] = s[n].substr(0, 500) + s[n].substr(s[n].size() - 500, 500);       i = 0;       j = 10;       while (i < j && hh(n, i + 1)) i++;       res[n] = max(i, max(res[ii], res[jj]));       cout << res[n] <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     static int f[10000];     int n, ok = false;     scanf( %d , &n);     for (register int i = 1; i <= n; ++i) scanf( %d , f + i);     for (int i = 1; i <= n; ++i)       if (f[f[f[i]]] == i) ok = true;     puts(ok ?  YES  :  NO );   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 10;   const long long mod = 1e9 + 7;   inline long long gcd(long long a, long long b) {     return !b ? a : gcd(b, a % b);   }   inline long long q_pow(long long a, long long x) {     long long ans = 1, tmp = a;     while (x) {       if (x & 1) (ans *= tmp) %= mod;       (tmp *= tmp) %= mod;       x >>= 1;     }     return ans;   }   template <typename T>   inline void re(T &N) {     int f = 1;     char c;     while ((c = getchar()) <  0  || c >  9 )       if (c ==  - ) f = -1;     N = c -  0 ;     while ((c = getchar()) >=  0  && c <=  9 ) N = N * 10 + c -  0 ;     N *= f;   }   int m, n, t = 1, st, en;   struct Trie {     struct node {       int a[2];       int ans, len;       int ma, mi;       node() {         a[0] = a[1] = 0;         ans = 1e9;         len = 1;         ma = -1e9;         mi = 1e9;       }       node(int x) {         a[0] = a[1] = 0;         ans = 1e9;         len = 1;         ma = mi = 0;       }     } nul;     vector<node> v;     Trie() { v.assign(1, nul); }     inline void push_up(int p) {       v[p].mi = min(v[(v[p].a[0])].mi, v[(v[p].a[1])].mi + v[(v[p].a[0])].len);       v[p].ma = max(v[(v[p].a[0])].ma, v[(v[p].a[1])].ma + v[(v[p].a[0])].len);       v[p].ans =           min({v[(v[p].a[0])].ans, v[(v[p].a[1])].ans,                v[(v[p].a[1])].mi - v[(v[p].a[0])].ma + v[(v[p].a[0])].len});       v[p].len = v[(v[p].a[0])].len + v[(v[p].a[1])].len;     }     int build(int p, int l, int r) {       if (!p) v.push_back(nul), p = (int)v.size() - 1;       if (l == r) return p;       int mid = (l + r) >> 1;       (v[p].a[0]) = build((v[p].a[0]), l, mid);       (v[p].a[1]) = build((v[p].a[1]), mid + 1, r);       push_up(p);       return p;     }     void insert(int p, int dep, int val) {       if (!(~dep)) return v[p] = node(1), void();       insert(v[p].a[val >> dep & 1], dep - 1, val);       push_up(p);     }     void rotate(int p, int dep, int lim) {       if (dep == lim) {         swap((v[p].a[0]), (v[p].a[1]));         push_up(p);         return;       }       rotate((v[p].a[0]), dep - 1, lim);       rotate((v[p].a[1]), dep - 1, lim);       push_up(p);     }   } tr;   int main() {     ios::sync_with_stdio(0);     int n, k;     cin >> n >> k;     vector<int> a(n);     for (int i = 0; i < n; i++) cin >> a[i];     tr.build(0, 0, (1 << k) - 1);     for (int i = 0; i < n; i++) tr.insert(1, k - 1, a[i]);     vector<int> ans(1 << k), gray(1 << k);     for (int i = 0; i < 1 << k; i++) {       gray[i] = (i >> 1) ^ i;       vector<int> tmp;       for (int j = 0; j < k; j++, gray[i] >>= 1) tmp.push_back(gray[i] & 1);       for (int j = 0; j < k; j++) gray[i] = gray[i] << 1 | tmp[j];     }     for (int i = 0; i < 1 << k; i++) {       ans[gray[i]] = tr.v[1].ans;       if ((i + 1) < 1 << k) {         int pos = 31 - __builtin_clz(gray[i] ^ gray[i + 1]);         tr.rotate(1, k - 1, pos);       }     }     for (int i = 0; i < 1 << k; i++) cout << ans[i] <<    n [i + 1 == 1 << k];   }
#include <bits/stdc++.h>   using namespace std;   vector<int> adj[100010], ans;   bool vis[100010];   bool c[100010];   void find(int v) {     vis[v] = true;     bool del = true;     for (int u : adj[v]) {       del &= c[u];       if (!vis[u]) find(u);     }     if (c[v] && del) ans.push_back(v);   }   int main() {     int n;     cin >> n;     int root;     for (int i = 1; i <= n; i++) {       int p;       cin >> p >> c[i];       if (p != -1)         adj[p].push_back(i);       else         root = i;     }     find(root);     sort(ans.begin(), ans.end());     if (ans.empty()) cout <<  -1 ;     for (int v : ans) cout << v <<    ;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string s, s1, s2, q =  rock , w =  paper , e =  scissors ;   int main() {     cin >> s >> s1 >> s2;     if (s != s1 && s1 == s2 && s == q && s1 == e ||         s != s1 && s1 == s2 && s == w && s1 == q ||         s != s1 && s1 == s2 && s == e && s1 == w)       cout <<  F ;     else if (s1 != s && s == s2 && s1 == q && s == e ||              s1 != s && s == s2 && s1 == w && s == q ||              s1 != s && s == s2 && s1 == e && s == w)       cout <<  M ;     else if (s2 != s && s == s1 && s2 == q && s == e ||              s2 != s && s == s1 && s2 == w && s == q ||              s2 != s && s == s1 && s2 == e && s == w)       cout <<  S ;     else       cout <<  ? ;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 111;   int N;   long long A[maxn];   map<long long, long long> f;   void rl(long long &x) {     char ch = (getchar());     x = 0;     while ((ch <  0  || ch >  9 )) ch = (getchar());     while (!(ch <  0  || ch >  9 )) x = x * 10 + ch -  0 , ch = (getchar());   }   int main() {     scanf( %d , &N);     for (int i = 1; i <= N; ++i) rl(A[i]);     f[A[1] - 1] = 0;     for (int i = 2; i <= N; ++i)       for (map<long long, long long>::iterator j = f.lower_bound(A[i]);            j != f.end(); f.erase(j++)) {         long long x = j->first, y = j->second;         f[x % A[i]] = max(f[x % A[i]], y + 1ll * (i - 1) * (x - x % A[i]));         f[A[i] - 1] =             max(f[A[i] - 1], y + 1ll * (i - 1) * A[i] * ((x - A[i] + 1) / A[i]));       }     long long ans = 0;     for (map<long long, long long>::iterator i = f.begin(); i != f.end(); ++i)       ans = max(ans, i->first * N + i->second);     cout << ans;     return 0;   }
#include <bits/stdc++.h>   const int MN = 1e5 + 4, INF = 0x3f3f3f3f;   int N, R, M, ans, D, A[MN], depth[MN], ord[MN], ecnt, ein[MN], eout[MN], st[MN];   std::vector<int> adj[MN];   struct nd {     int l, r, val;     nd *ch[2];     nd() : l(0), r(0), val(INF), ch{0} {}   } * sgt[MN];   void dfs(int src, int p, int d) {     depth[src] = d;     ein[src] = ++ecnt;     for (int i : adj[src]) {       if (i == p) continue;       dfs(i, src, d + 1);     }     eout[src] = ecnt;   }   inline void upd(nd *n) { n->val = std::min(n->ch[0]->val, n->ch[1]->val); }   void build(nd *&n, int l, int r) {     n = new nd();     n->l = l, n->r = r;     if (l == r) return;     int mid = l + r >> 1;     build(n->ch[0], l, mid);     build(n->ch[1], mid + 1, r);   }   void mod(nd *&n, nd *o, int p, int v) {     n = new nd();     n->l = o->l, n->r = o->r;     if (n->l == n->r) {       n->val = v;       return;     }     int mid = n->l + n->r >> 1;     bool b = p > mid;     n->ch[!b] = o->ch[!b];     mod(n->ch[b], o->ch[b], p, v);     upd(n);   }   int qry(nd *n, int l, int r) {     if (l > n->r || r < n->l) return INF;     if (l <= n->l && n->r <= r) return n->val;     return std::min(qry(n->ch[0], l, r), qry(n->ch[1], l, r));   }   int main() {     scanf( %d%d , &N, &R);     for (int i = 1; i <= N; scanf( %d , A + i++))       ;     for (int i = 1, a, b; i < N; ++i) {       scanf( %d%d , &a, &b);       adj[a].emplace_back(b);       adj[b].emplace_back(a);     }     dfs(R, -1, 1);     for (int i = 0; i < N; ++i) ord[i] = i + 1;     std::stable_sort(ord, ord + N, [=](const int &a, const int &b) {       return depth[a] < depth[b];     });     build(sgt[0], 1, N);     for (int i = 0; i < N; ++i) {       if (depth[ord[i]] != D) st[D++] = i;       mod(sgt[i + 1], sgt[i], ein[ord[i]], A[ord[i]]);     }     st[D] = N;     scanf( %d , &M);     for (int i = 0, a, b; i < M; ++i) {       scanf( %d%d , &a, &b);       a = ((a + ans) % N) + 1, b = (b + ans) % N;       printf( %d n ,              ans = qry(sgt[st[std::min(depth[a] + b, D)]], ein[a], eout[a]));     }   }
#include <bits/stdc++.h>   using namespace std;   const int L = 0, R = 1, U = 2, D = 3;   const int maxn = 5005;   class Node {    public:     int dir, l, r, u, d;   } a[maxn], b[maxn];   int n, m;   char s[maxn];   inline int id(int x, int y) { return x * m + y; }   inline void build(int x, int y) {     Node &u = a[id(x, y)];     int nx, ny;     for (nx = x, ny = y - 1; ny >= 0 && s[id(nx, ny)] ==  . ; --ny)       ;     if (ny < 0)       u.l = -1;     else       u.l = id(nx, ny);     for (nx = x, ny = y + 1; ny < m && s[id(nx, ny)] ==  . ; ++ny)       ;     if (ny >= m)       u.r = -1;     else       u.r = id(nx, ny);     for (nx = x - 1, ny = y; nx >= 0 && s[id(nx, ny)] ==  . ; --nx)       ;     if (nx < 0)       u.u = -1;     else       u.u = id(nx, ny);     for (nx = x + 1, ny = y; nx < n && s[id(nx, ny)] ==  . ; ++nx)       ;     if (nx >= n)       u.d = -1;     else       u.d = id(nx, ny);     return;   }   inline void connectX(int u, int v) {     if (~u) b[u].r = v;     if (~v) b[v].l = u;   }   inline void connectY(int u, int v) {     if (~u) b[u].d = v;     if (~v) b[v].u = u;     return;   }   inline void erase(int u) {     connectX(b[u].l, b[u].r);     connectY(b[u].u, b[u].d);     return;   }   inline void dfs(int x, int &res) {     Node &u = b[x];     ++res;     if (u.dir == L) {       if (!~u.l) return;       erase(x);       dfs(u.l, res);     } else if (u.dir == R) {       if (!~u.r) return;       erase(x);       dfs(u.r, res);     } else if (u.dir == U) {       if (!~u.u) return;       erase(x);       dfs(u.u, res);     } else {       if (!~u.d) return;       erase(x);       dfs(u.d, res);     }     return;   }   int main() {     cin >> n >> m;     for (int i = (0); i < (n); ++i) {       string buf;       cin >> buf;       for (int j = (0); j < (m); ++j) {         s[id(i, j)] = buf[j];         if (buf[j] ==  L )           a[id(i, j)].dir = L;         else if (buf[j] ==  R )           a[id(i, j)].dir = R;         else if (buf[j] ==  U )           a[id(i, j)].dir = U;         else if (buf[j] ==  D )           a[id(i, j)].dir = D;       }     }     for (int x = (0); x < (n); ++x)       for (int y = (0); y < (m); ++y)         a[id(x, y)].l = a[id(x, y)].r = a[id(x, y)].u = a[id(x, y)].d = -1;     for (int x = (0); x < (n); ++x)       for (int y = (0); y < (m); ++y) build(x, y);     int ans = 0, cnt = 0;     for (int i = (0); i < (n); ++i)       for (int j = (0); j < (m); ++j)         if (s[id(i, j)] !=  . ) {           for (int x = (0); x < (n); ++x)             for (int y = (0); y < (m); ++y) b[id(x, y)] = a[id(x, y)];           int res = 0;           dfs(id(i, j), res);           if (res > ans)             ans = res, cnt = 1;           else if (res == ans)             ++cnt;         }     printf( %d %d n , ans, cnt);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char s[500010];   int num[500010];   int cnt;   long long t, mid;   int n;   int skip[500010];   long long minn(long long a, long long b) { return a < b ? a : b; }   stack<int> sta;   int ok(long long k) {     int i, j, end = -1, last, type = -1, cnt = 0;     long long time = 0, min;     for (i = 0; i < n; ++i) {       ++time;       if (s[i] ==  H ) {         if (k) {           --k;           last = i;           type = 0;           continue;         }         type = 1;         if (skip[i] == -1) {           return 0;         }         time += (skip[i] - i) * 3;         if (end != -1) {           num[cnt++] = i - end;         }         num[cnt++] = skip[i] - i;         end = skip[i];         last = skip[i];         i = skip[i];       } else if (s[i] ==  S ) {         ++k;       }     }     if (type == 0 && end != -1) {       num[cnt++] = last - end;     }     time -= (n - 1 - last);     min = time;     for (i = cnt - 1; i >= 0; --i) {       if (i & 1) {         time += num[i];       } else {         time -= num[i];         min = minn(min, time);       }     }     return min <= t;   }   int main() {     long long left, right;     int i;     cin >> n >> t >> s;     memset(skip, -1, sizeof(skip));     for (i = 0; i < n; ++i) {       if (s[i] ==  H ) {         sta.push(i);       } else if (s[i] ==  S ) {         if (!sta.empty()) {           skip[sta.top()] = i;           sta.pop();         }       }     }     left = 0;     right = n + 1;     while (left < right) {       mid = (left + right) >> 1;       if (ok(mid))         right = mid;       else {         left = mid + 1;       }     }     if (right == n + 1)       printf( -1 n );     else       cout << left << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, flag = 1, num = 0;     cin >> n;     string st;     cin >> st;     for (int i = 0; i < n && flag; i++) {       if (i < n - 1) {         if (st[i] == st[i + 1]) {           if (st[i] !=  ? ) {             flag = 0;           } else {             num = 1;           }         }       }       if (st[i] ==  ? ) {         if (i == 0 || i == n - 1)           num += 1;         else {           if (st[i - 1] == st[i + 1]) num += 1;         }       }     }     if (flag == 0)       cout <<  No ;     else {       if (num >= 1)         cout <<  Yes ;       else         cout <<  No ;     }   }