malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 123456;   int n, d[N], h[N];   bool vis[N];   vector<int> G[N];   struct Node {     int u, h;     bool operator<(const Node& rhs) const { return h < rhs.h; }     Node(int u, int h) : u(u), h(h) {}   };   priority_queue<Node> pq;   int bfs() {     memset(d, -1, sizeof(d));     d[1] = 0;     queue<int> q;     q.push(1);     while (!q.empty()) {       int u = q.front();       q.pop();       for (int v : G[u])         if (d[v] == -1) {           d[v] = d[u] + 1;           q.push(v);         }     }     int ans = 1, maxm = 0;     for (int i = 2; i <= n; i++)       if (d[i] > maxm) {         maxm = d[i];         ans = i;       }     return ans;   }   int dfs(int u, int fa) {     for (int v : G[u])       if (v != fa) h[u] = max(h[u], dfs(v, u) + 1);     if (fa) pq.push(Node(u, h[u]));     return h[u];   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n;     for (int i = 0; i < n - 1; i++) {       int u, v;       cin >> u >> v;       G[u].push_back(v);       G[v].push_back(u);     }     int root = bfs();     dfs(root, 0);     cout << 1;     int cnt = 1;     for (int i = 2; i <= n; i++) {       if (cnt == n) {         cout <<     << n;         continue;       }       int cur = 0;       while (!pq.empty()) {         Node u = pq.top();         pq.pop();         if (!vis[u.u]) {           cur = u.u;           break;         }       }       for (;;) {         cnt++;         vis[cur] = true;         if (!h[cur]) break;         for (int v : G[cur])           if (h[v] == h[cur] - 1) {             cur = v;             break;           }       }       cout <<     << cnt;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<int, int> f;   long long fib[100] = {0};   int solve(long long n) {     int what[100] = {0};     int ind = -1;     for (int i = 90; i >= 0; i--) {       if (n >= fib[i]) {         n -= fib[i], what[i] = true;         if (ind == -1) ind = i;       }     }     vector<int> x, y;     x.push_back(1);     y.push_back(0);     int zero = 0, f = 1;     for (int i = 0; i <= ind; i++) {       if (what[i] == 0)         zero++;       else {         int z1 = (zero / 2) * (x.back() + y.back());         if (zero & 1 && !f) z1 += x.back();         int z2 = x.back() + y.back();         x.push_back(z1);         y.push_back(z2);         zero = 0;         f = false;       }     }     return x.back() + y.back();   }   int main() {     fib[0] = 1;     fib[1] = 2;     for (int i = 2; i <= 90; i++) fib[i] = fib[i - 1] + fib[i - 2];     int T;     long long n;     cin >> T;     while (T--) {       cin >> n;       cout << solve(n) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 2e9 + 1e8;   const long long INF = 2e18 + 1e17;   const int mod = 998244353;   const int MOD = 1e9 + 7;   long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); }   bool is_prime(int x) {     if (x <= 1 || (x % 2 == 0 && x > 2)) return false;     for (int i = 3; i * i <= x; i += 2) {       if (!(x % i)) {         return false;       }     }     return true;   }   const int MAXN = 40010;   int N;   string str;   vector<int> arr;   int ans;   int main() {     cin >> N >> str;     arr.resize(N);     int sum = 0;     for (int i = 0; i < str.length(); i++) {       arr[i] = (str[i] ==  )  ? -1 : 1);       sum += arr[i];     }     if (sum != 0) {       cout <<  -1  << endl;       return 0;     }     int cur = 0, last = 0;     bool bad = false;     for (int i = 0; i < N; i++) {       cur += arr[i];       if (!bad && cur < 0) {         bad = true;         last = i;       } else if (cur == 0 && bad) {         ans += (i - last + 1);         bad = false;       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     string s1, s2;     cin >> s1 >> s2;     int n = s1.size();     int m = s2.size();     pair<pair<int, int>, pair<int, char> > parent[n + 1][m + 1][205];     int dp[n + 5][m + 5][205];     for (int i = 0; i <= n; i++) {       for (int j = 0; j <= m; j++) {         for (int bal = 0; bal <= 200; bal++) {           dp[i][j][bal] = 600;         }       }     }     dp[0][0][0] = 0;     for (int i = 0; i <= n; i++) {       for (int j = 0; j <= m; j++) {         for (int bal = 0; bal <= 200; bal++) {           if (dp[i][j][bal] == 600) continue;           int newI = i + (i < n && s1[i] ==  ( );           int newJ = j + (j < m && s2[j] ==  ( );           if (bal + 1 < 205 && dp[newI][newJ][bal + 1] > dp[i][j][bal] + 1) {             dp[newI][newJ][bal + 1] = dp[i][j][bal] + 1;             parent[newI][newJ][bal + 1] =                 make_pair(make_pair(i, j), make_pair(bal,  ( ));           }           newI = i + (i < n && s1[i] ==  ) );           newJ = j + (j < m && s2[j] ==  ) );           if (bal > 0 && dp[newI][newJ][bal - 1] > dp[i][j][bal] + 1) {             dp[newI][newJ][bal - 1] = dp[i][j][bal] + 1;             parent[newI][newJ][bal - 1] =                 make_pair(make_pair(i, j), make_pair(bal,  ) ));           }         }       }     }     int cBal = 0;     for (int bal = 0; bal <= 200; bal++) {       if (dp[n][m][bal] + bal < dp[n][m][cBal] + cBal) {         cBal = bal;       }     }     int ci = n, cj = m;     string res = string(cBal,  ) );     while (ci > 0 || cj > 0 || cBal != 0) {       int nci = parent[ci][cj][cBal].first.first;       int ncj = parent[ci][cj][cBal].first.second;       int ncBal = parent[ci][cj][cBal].second.first;       res += parent[ci][cj][cBal].second.second;       ci = nci;       cj = ncj;       cBal = ncBal;     }     reverse(res.begin(), res.end());     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int DEBUG = 0;   double Min(double a, double b) { return (a < b ? a : b); }   double Max(double a, double b) { return (a > b ? a : b); }   double Abs(double a) { return (a >= 0 ? a : -a); }   void print1d(int *vec, int M, const char *str = NULL) {     if (str != NULL) printf( %s  , str);     for (int i = 0; i < M; i++) {       if (i > 0) printf(   );       printf( %d , vec[i]);     }     printf(  n );   }   struct NODE {     double t, v;   };   int compare_NODE_inc(const void *a_, const void *b_) {     NODE *a = (NODE *)a_;     NODE *b = (NODE *)b_;     if (a->t > b->t)       return 1;     else if (a->t < b->t)       return -1;     else       return 0;   }   int main(int argc, char **argv) {     DEBUG = (argc >= 2) ? atoi(argv[1]) : 0;     int n;     double a, d;     cin >> n >> a >> d;     NODE bus[n];     for (int i = 0; i < n; i++) {       cin >> bus[i].t >> bus[i].v;     }     qsort(bus, n, sizeof(NODE), compare_NODE_inc);     double prevt = 0;     double tim;     for (int i = 0; i < n; i++) {       double t = bus[i].t;       double v = bus[i].v;       if (v * v >= 2.0 * a * d) {         tim = t + sqrt(2.0 * d / a);       } else {         tim = t + (1.0 * d / v + 1.0 * v / 2.0 / a);       }       prevt = Max(tim, prevt);       printf( %.10f n , prevt);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:8000000 )   int main() {     int n;     scanf( %d , &n);     if (n % 2 == 1) {       printf( -1 );       return 0;     }     for (int k = 0; k != n; ++k)       for (int i = 0; i != n; ++i) {         for (int j = 0; j != n; ++j)           if ((j % 4 < 2) ^ (k % 2 == 0) ^ (i % 4 < 2))             printf( b );           else             printf( w );         printf(  n );       }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     double l, v1, v2;     scanf( %d%lf%lf%lf%d , &n, &l, &v1, &v2, &k);     int num = n / k;     if (num * k < n) {       num++;     }     double w = (v1 + v2) * v2 / (2 * v1 * v2 * num + v2 * v2 - v1 * v2) * l;     double t = w / v2 + (l - w) / v1;     printf( %.10lf n , t);   }
#include <bits/stdc++.h>   using namespace std;   void SOLVE(int, int);   int main() {     int A, B;     cin >> A >> B;     SOLVE(A, B);     return 0;   }   void SOLVE(int A, int B) {     int T1 = min(A, B);     int T2 = (A + B) / 2;     cout << T1 <<     << abs(T2 - T1) << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int Hash = 743;   const int Mod = 51123987;   int powh[2000005], N, h1[2000005], h2[2000005], start[2000005], finish[2000005],       a[2000005], b[2000005];   char s[2000005];   int getsub1(int lo, int hi) {     return lo == 0 ? h1[hi] : h1[hi] - h1[lo - 1] * powh[hi - lo + 1];   }   int getsub2(int lo, int hi) {     return hi == N - 1 ? h2[lo] : h2[lo] - h2[hi + 1] * powh[hi - lo + 1];   }   int main(void) {     powh[0] = 1;     for (int i = 1; i < 2000005; ++i) powh[i] = powh[i - 1] * Hash;     scanf( %d %s , &N, s);     int ch = 0;     for (int i = 0; i < N; ++i) {       ch = ch * Hash + s[i];       h1[i] = ch;     }     ch = 0;     for (int i = N - 1; i >= 0; --i) {       ch = ch * Hash + s[i];       h2[i] = ch;     }     long long tot = 0;     for (int i = 0; i < N; ++i) {       int lo = 1, hi = min(i + 1, N - i), mid, ans = 1;       while (lo <= hi) {         mid = (lo + hi) / 2;         int s1 = getsub1(i, i + mid - 1);         int s2 = getsub2(i - mid + 1, i);         if (s1 == s2) {           lo = mid + 1;           ans = mid;         } else           hi = mid - 1;       }       tot += ans;       tot %= Mod;       a[i - ans + 1] += 1;       a[i + 1] -= 1;       b[i] += 1;       b[i + ans] -= 1;     }     for (int i = 0; i + 1 < N; ++i) {       if (s[i] != s[i + 1]) continue;       int lo = 1, hi = min(i + 1, N - (i + 1)), mid, ans = 1;       while (lo <= hi) {         mid = (lo + hi) / 2;         int s1 = getsub1(i + 1, i + mid);         int s2 = getsub2(i - mid + 1, i);         if (s1 == s2) {           lo = mid + 1;           ans = mid;         } else           hi = mid - 1;       }       tot += ans;       tot %= Mod;       a[i - ans + 1] += 1;       a[i + 1] -= 1;       b[i + 1] += 1;       b[i + 1 + ans] -= 1;     }     for (int i = 0; i < N; ++i) {       a[i] %= Mod;       b[i] %= Mod;       a[i] += Mod;       b[i] += Mod;       start[i] = (i == 0) ? a[i] : start[i - 1] + a[i];       finish[i] = (i == 0) ? b[i] : finish[i - 1] + b[i];       start[i] %= Mod;       finish[i] %= Mod;     }     int sf = 0, sol = 0;     for (int i = 0; i < N; ++i) {       sol = (sol + (long long)(start[i]) * (long long)(sf) % Mod) % Mod;       sf = (sf + finish[i]) % Mod;     }     cout << ((long long)(tot) * (tot - 1) / 2 - sol + Mod) % Mod << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<long long> v[100000 + 1];   long long n, m;   long long taken[100000 + 1];   map<int, int> v2;   int check = 0, sum;   void bfs() {     queue<long long> q;     long long j, x, y;     for (int i = 1; i <= n; i++) {       if (taken[i] == 0) {         q.push(i);         check = 0;         while (!q.empty()) {           x = q.front();           q.pop();           v2[x] = 1;           for (j = 0; j < v[x].size(); j++) {             y = v[x][j];             if (taken[y] == 0) {               q.push(y);               taken[y] = 1;             } else if (taken[y] == 1 && v2[y] == 0) {               check = 1;             }           }         }         if (check == 0) {           sum = sum + 1;         }       }     }   }   int main() {     long long i, x, y;     cin >> n >> m;     for (i = 1; i <= m; i++) {       cin >> x >> y;       v[x].push_back(y);       v[y].push_back(x);     }     sum = 0;     bfs();     cout << sum <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int q;     cin >> q;     while (q--) {       int a, b, c, d;       cin >> a >> b >> c;       d = (a + b + c) / 3;       int ans = min(a, b);       ans = min(d, ans);       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline bool chkmin(T &x, T y) {     return y < x ? x = y, 1 : 0;   }   template <class T>   inline bool chkmax(T &x, T y) {     return x < y ? x = y, 1 : 0;   }   inline long long Max(long long x, long long y) { return x > y ? x : y; }   inline long long Min(long long x, long long y) { return x < y ? x : y; }   int n, m;   long long fac[1002], inv[1002];   long long dp[47][1002], ans[1002][47];   void Add(long long &x, long long y) {     x += y;     if (x >= 1000000007) x -= 1000000007;   }   long long C(int n, int m) {     if (n < 0 || m > n) return 0;     return fac[n] * inv[m] % 1000000007 * inv[n - m] % 1000000007;   }   void Init() {     fac[0] = fac[1] = 1;     for (int i = (2), i_end_ = (1002); i < i_end_; i++)       fac[i] = fac[i - 1] * i % 1000000007;     inv[0] = inv[1] = 1;     for (int i = (2), i_end_ = (1002); i < i_end_; i++)       inv[i] = (1000000007 - (1000000007 / i)) * inv[1000000007 % i] % 1000000007;     for (int i = (2), i_end_ = (1002); i < i_end_; i++)       inv[i] = inv[i] * inv[i - 1] % 1000000007;     dp[0][0] = 1;     for (int i = (1), i_end_ = (47); i < i_end_; i++)       for (int j = (i * (i + 1) / 2), j_end_ = (1002); j < j_end_; j++)         Add(dp[i][j] = dp[i][j - i], dp[i - 1][j - i]);     for (int i = (1), i_end_ = (1002); i < i_end_; i++) {       for (int k = (1), k_end_ = (47); k < k_end_; k++) {         for (int j = (k * (k + 1) / 2), j_end_ = (i); j <= j_end_; j++)           Add(ans[i][k], C(i - j + k, k) * dp[k][j] % 1000000007);         ans[i][k] = ans[i][k] * fac[k] % 1000000007;       }     }   }   int main() {     Init();     int cas;     cin >> cas;     while (cas--) {       scanf( %d%d , &n, &m);       printf( %I64d n , m >= 45 ? 0 : ans[n][m]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 100 * 1000 + 19;   const int MASK = 20;   const int inf = 2e9 + 19;   long long n, m, dp[1 << MASK][MASK + 1];   string s[MAX_N];   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> s[i];     for (int i = 0; i < m; i++) {       long long tmp = 0;       for (int j = 0; j < n; j++) tmp += ((1 << j) * (s[j][i] ==  1 ));       dp[tmp][0]++;     }     for (int i = 1; i <= n; i++) {       for (int j = i; j >= 1; j--) {         for (int mask = 0; mask < (1 << n); mask++)           dp[mask][j] += dp[mask ^ (1 << (i - 1))][j - 1];       }     }     long long ans = inf;     for (int mask = 0; mask < (1 << n); mask++) {       long long sum = 0;       for (long long j = 0; j <= n; j++) sum += dp[mask][j] * min(j, n - j);       ans = min(ans, sum);     }     cout << ans;     return (0);   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 100100;   int n, m;   long long h[MAX], t[MAX];   bool can(int cur, int last, int nxt, long long val) {     if (t[last] >= h[cur]) return val >= t[nxt] - h[cur];     if (t[nxt] <= h[cur]) return val >= h[cur] - t[last];     return val >= min((h[cur] - t[last]) + (t[nxt] - t[last]),                       (t[nxt] - h[cur]) + (t[nxt] - t[last]));   }   bool check(long long val) {     int last = 1;     for (int i = 1; i <= n; ++i) {       int j = last;       while (j <= m && can(i, last, j, val)) ++j;       last = j;     }     return last == m + 1;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) scanf( %I64d , h + i);     for (int i = 1; i <= m; ++i) scanf( %I64d , t + i);     long long low = 0, high = 20000000000LL, mid;     while (low <= high) {       mid = (low + high) >> 1;       if (check(mid))         high = mid - 1;       else         low = mid + 1;     }     printf( %I64d n , high + 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   double a[1 << 19];   double ans;   int n, r, w;   int main() {     scanf( %d%d , &n, &r);     w = 1 << n;     for (register int i = 0; i < w; i++) {       scanf( %lf , &a[i]);       ans += a[i];     }     printf( %.6lf n , ans / w);     while (r--) {       int pos;       double x;       scanf( %d%lf , &pos, &x);       ans -= a[pos];       a[pos] = x;       ans += a[pos];       printf( %.6lf n , ans / w);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   void DBG() { cerr <<  ]  << endl; }   template <class H, class... T>   void DBG(H h, T... t) {     cerr << to_string(h);     if (sizeof...(t)) cerr <<  ,  ;     DBG(t...);   }   int main(void) {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     cerr.tie(nullptr);     int n;     cin >> n;     vector<vector<long long>> a(n, vector<long long>(3));     for (int i = 0; i < n; ++i) {       cin >> a[i][0] >> a[i][1] >> a[i][2];     }     vector<bool> vis(n);     for (int i = 0; i < n; ++i) {       long long bonus = 0, cnt = 0;       if (vis[i]) continue;       for (int j = i + 1; j < n; ++j) {         if (vis[j]) continue;         a[j][2] -= max(0LL, (a[i][0] - cnt));         ++cnt;         a[j][2] -= bonus;         if (a[j][2] < 0) {           vis[j] = true;           bonus += a[j][1];         }       }     }     vector<int> ans;     for (int i = 0; i < n; ++i) {       if (!vis[i]) {         ans.push_back(i + 1);       }     }     cout << ((int)(ans).size()) <<   n ;     for (auto &A : ans) cout << A <<    ;   }
#include <bits/stdc++.h>   using namespace std;   struct node {     int t, l, r, m;   } op[5010];   int a[5010], b[5010], n, m;   bool solve() {     int p, i, k;     for (i = 1; i <= n; i++) {       a[i] = 1000000000;     }     memset(b, 0, sizeof(b));     for (p = 1; p <= m; p++) {       if (op[p].t == 1)         for (i = op[p].l; i <= op[p].r; i++) b[i] += op[p].m;       else         for (i = op[p].l; i <= op[p].r; i++) a[i] = min(a[i], op[p].m - b[i]);     }     memset(b, 0, sizeof(b));     for (p = 1; p <= m; p++) {       if (op[p].t == 1)         for (i = op[p].l; i <= op[p].r; i++) b[i] += op[p].m;       else {         k = -1000000007;         for (i = op[p].l; i <= op[p].r; i++) k = max(k, a[i] + b[i]);         if (k != op[p].m) return false;       }     }     return true;   }   int main() {     int i;     scanf( %d%d , &n, &m);     for (i = 1; i <= m; i++) {       scanf( %d%d%d%d , &op[i].t, &op[i].l, &op[i].r, &op[i].m);     }     if (!solve()) {       printf( NO n );     } else {       printf( YES n );       for (i = 1; i <= n; i++) printf( %d  , a[i]);       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct point {     int n;     int value;     vector<int> next;   } p[100010];   queue<struct point> q;   int main() {     int n, m, x, y, flag = 1, t;     scanf( %d%d , &n, &m);     for (int i = 0; i < m; i++) {       scanf( %d %d , &x, &y);       p[x].next.push_back(y);       p[x].n++;       p[y].next.push_back(x);       p[y].n++;     }     for (int i = 1; i <= n; i++) {       if (!flag) break;       if (p[i].n && !p[i].value) {         p[i].value = 1;         q.push(p[i]);         while (!q.empty()) {           for (int j = 0; j < q.front().n; j++) {             if (!p[q.front().next[j]].value) {               p[q.front().next[j]].value = q.front().value % 2 + 1;               q.push(p[q.front().next[j]]);             } else {               if (p[q.front().next[j]].value != q.front().value % 2 + 1) {                 flag = 0;                 break;               }             }           }           q.pop();         }       }     }     if (flag) {       int ans = 0;       for (int i = 1; i <= n; i++) {         if (p[i].value == 1) ans++;       }       printf( %d n , ans);       for (int i = 1; i <= n; i++) {         if (p[i].value == 1) {           printf( %d  , i);         }       }       printf(  n );       ans = 0;       for (int i = 1; i <= n; i++) {         if (p[i].value == 2) ans++;       }       printf( %d n , ans);       for (int i = 1; i <= n; i++) {         if (p[i].value == 2) {           printf( %d  , i);         }       }     } else {       printf( -1 );     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 16, K = 225;   struct HASH {     size_t operator()(const pair<long long, long long> &x) const {       return hash<long long>()((x.first) ^ ((x.second) << 32));     }   };   int dx[4] = {0, 0, -1, 1}, dy[4] = {1, -1, 0, 0};   int n, m;   int len = 0;   long long pw[N];   string str[N];   unordered_map<pair<long long, long long>, int, HASH> dis;   bool good(pair<long long, long long> p, int i, int j) {     int cur = (i * m + j);     for (int k = 0; k < len - 1 - 5; k++)       if (p.first / pw[k] % K == cur) return false;     for (int k = 0; k < min(len - 1, 5); k++)       if (p.second / pw[k] % K == cur) return false;     return true;   }   bool in_bound(int i, int j) {     return i >= 0 && i < n && j >= 0 && j < m && str[i][j] !=  # ;   }   pair<long long, long long> getnxt(pair<long long, long long> p, int i, int j) {     p.first *= K;     p.first += p.second / pw[4];     p.first %= pw[max(len - 5, 0)];     p.second *= K;     p.second += (i * m + j);     p.second %= pw[min(len, 5)];     return p;   }   int main() {     pw[0] = 1;     for (int i = 1; i < 6; i++) pw[i] = pw[i - 1] * K;     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> str[i];     pair<long long, long long> ori;     queue<pair<long long, long long> > que;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         char c = str[i][j];         if (c >=  1  && c <=  9 ) {           int x = c -  0 ;           len = max(len, x);           x--;           if (x >= 5)             ori.first += (i * m + j) * pw[x - 5];           else             ori.second += (i * m + j) * pw[x];         }       }     }     que.push(ori);     dis[ori] = 0;     while (!que.empty()) {       pair<long long, long long> p = que.front();       que.pop();       int curdis = dis[p];       int ci = (int)(p.second % K / m), cj = (int)(p.second % K % m);       for (int d = 0; d < 4; d++) {         int ni = ci + dx[d], nj = cj + dy[d];         if (in_bound(ni, nj) && good(p, ni, nj)) {           if (str[ni][nj] ==  @ ) {             return cout << curdis + 1 << endl, 0;           }           pair<long long, long long> nxt = getnxt(p, ni, nj);           if (!dis.count(nxt)) {             que.push(nxt);             dis[nxt] = curdis + 1;           }         }       }     }     cout <<  -1  << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int N = 5e10 + 5;   int main() {     bool flag = 0;     int n, ans = 0, k;     cin >> n;     int arr[n + 5];     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     sort(arr, arr + n);     k = n / 2;     for (int i = 0; i < n / 2; i++) {       for (int j = k; j < n; j++) {         if (arr[i] * 2 <= arr[j]) {           ans++;           k = j + 1;           break;         }         if (j == n - 1) {           flag = 1;         }       }       if (flag) break;     }     cout << n - ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int val{0};   struct Triplet {     char letter;     int onePosn;     int otherPosn;   };   int findContinuous(string s) {     int j{0};     for (auto i = 0; i < s.length() - 2; i++) {       if (s[i] ==  Q  && s[i + 1] ==  A  && s[i + 2] ==  Q ) {         j++;       }     }     return j;   }   int findLastQ(string s) {     int j{0};     for (auto i = 0; i < s.length() - 1; i++) {       if (s[i] ==  Q  && s[i + 1] ==  A ) {         for (int k = i + 2; k < s.length(); k++) {           if (s[k] ==  Q ) {             j++;           }         }       }     }     return j;   }   int findFirstQ(string s) {     int j{0};     for (auto i = 0; i < s.length() - 1; i++) {       if (s[i] ==  A  && s[i + 1] ==  Q ) {         for (int k = 0; k < i; k++) {           if (s[k] ==  Q ) {             j++;           }         }       }     }     return j;   }   int findDisjoint(string s) {     int j{0};     for (auto i = 0; i < s.length(); i++) {       int before{0};       int after{0};       if (s[i] ==  A ) {         for (int k = 0; k < i; k++) {           if (s[k] ==  Q ) {             before++;           }         }         for (int k = i + 1; k < s.length(); k++) {           if (s[k] ==  Q ) {             after++;           }         }         j += before * after;       }     }     return j;   }   int main() {     string s;     cin >> s;     int n = findDisjoint(s);     cout << n;     return 0;   }