malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   const int N = 120000;   using namespace std;   vector<string> fig;   int n, m;   vector<vector<string> > figs;   int ans;   vector<pair<pair<int, int>, int> > avec;   int board[200][200];   bool bad(int a, int b) {     return (a < 0 || a >= n || b < 0 || b >= m || board[a][b] == 1);   }   vector<string> rotate(vector<string> cur) {     char temp[10][10];     for (int i = 0; i < 3; i++) {       for (int j = 0; j < 3; j++) {         temp[i][j] = cur[i][j];       }     }     for (int i = 0; i < 3; i++) {       for (int j = 0; j < 3; j++) {         cur[i][j] = temp[j][2 - i];       }     }     return cur;   }   vector<pair<pair<int, int>, int> > cur;   bool can_put(int x, int y, int id) {     for (int i = 0; i < 3; i++) {       for (int j = 0; j < 3; j++) {         if (figs[id][i][j] ==  # ) {           if (bad(i + x, j + y)) return false;         }       }     }     return true;   }   void do_put(int x, int y, int id) {     for (int i = 0; i < 3; i++) {       for (int j = 0; j < 3; j++) {         if (figs[id][i][j] ==  # ) {           board[x + i][y + j] = 1;         }       }     }     cur.push_back(make_pair(make_pair(x, y), id));   }   void unroll(int x, int y, int id) {     for (int i = 0; i < 3; i++) {       for (int j = 0; j < 3; j++) {         if (figs[id][i][j] ==  # ) {           board[x + i][y + j] = 0;         }       }     }     cur.pop_back();   }   int flag, iters;   void dfs(int a, int b) {     int rem_area = n * m - (a * m + b);     if (cur.size() + rem_area / 5 <= avec.size()) return;     ++iters;     if (iters % 1024 == 0) {       double R = clock() * 1.0 / CLOCKS_PER_SEC;       if (R > 1.4) flag = 1;     }     if (flag) return;     if (cur.size() > avec.size()) {       avec = cur;     }     if (a >= n - 2) {       return;     }     for (int i = 0; i < 4; i++) {       if (can_put(a, b, i)) {         do_put(a, b, i);         if (b + 1 == m)           dfs(a + 1, 0);         else           dfs(a, b + 1);         unroll(a, b, i);       }     }     if (b + 1 == m)       dfs(a + 1, 0);     else       dfs(a, b + 1);   }   int main() {     ios_base::sync_with_stdio(0);     fig.push_back( ### );     fig.push_back( .#. );     fig.push_back( .#. );     figs.push_back(fig);     for (int i = 0; i < 3; i++) {       figs.push_back(rotate(figs.back()));     }     cin >> n >> m;     dfs(0, 0);     cout << avec.size() << endl;     for (int i = 0; i < avec.size(); i++) {       int qi, qj;       qi = avec[i].first.first;       qj = avec[i].first.second;       for (int a = 0; a < 3; a++) {         for (int b = 0; b < 3; b++) {           if (figs[avec[i].second][a][b] ==  # ) {             board[qi + a][qj + b] = i + 1;           }         }       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (board[i][j] == 0)           cout <<  . ;         else           cout << char( A  + board[i][j] - 1);       }       cout << endl;     }     cin.get();     cin.get();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long LLINF = 9223372036854775807LL;   const int INF = 2147483647;   const int MOD = 1000000007;   const double eps = 1e-7;   const double PI = acos(-1.0);   int dr[] = {1, 0, -1, 0, -1, 1, 1, -1};   int dc[] = {0, -1, 0, 1, 1, 1, -1, -1};   int m;   pair<int, int> arr[100005];   vector<int> v;   bool done[100005];   bool cf(pair<int, int> a, pair<int, int> b) { return a.first > b.first; }   int main() {     scanf( %d , &m);     for (int(i) = (1); (i) <= (m); (i)++)       scanf( %d , &arr[i].first), arr[i].second = i;     sort(arr + 1, arr + 1 + m);     int cur = arr[1].first;     done[arr[1].second] = true;     v.push_back(cur);     for (int(i) = (2); (i) <= (m); (i)++) {       if (arr[i].first > cur) {         cur = arr[i].first;         done[arr[i].second] = true;         v.push_back(cur);       }     }     sort(arr + 1, arr + 1 + m, cf);     for (int(i) = (1); (i) <= (m); (i)++) {       if (arr[i].first < cur && !done[arr[i].second]) {         cur = arr[i].first;         v.push_back(cur);       }     }     cout << (int)(v.size()) << endl;     for (int(i) = (0); (i) < ((int)(v.size())); (i)++) printf( %d  , v[i]);     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const double eps = 1e-6;   const int INF = 1e12;   const int maxnnn = 2e8 + 30;   const long long zero = 0;   long long gcd(long long a, long long b) {     if (a < b) swap(a, b);     if (a % b == 0)       return b;     else       gcd(b, a % b);   }   string ntos(long long a) {     string str;     stringstream ss;     ss << a;     ss >> str;     return str;   }   long long ston(string a) {     long long x;     stringstream ss;     ss << a;     ss >> x;     return x;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     bool flag;     long long zimu[26];     long long n, m, a, b, t, y, fans, c, x, z, sw;     string s, s1, s2;     cin >> m >> n;     vector<long long> py(m + 1);     sw = 0;     py.clear();     for (long long i = 0; i < n; ++i) {       cin >> a >> b;       py[min(a, b)]++;       if (py[min(a, b)] == 1) sw++;     }     cin >> c;     while (c--) {       cin >> x;       if (x == 3) {         cout << m - sw << endl;       } else if (x == 1) {         cin >> y >> z;         py[min(y, z)]++;         if (py[min(y, z)] == 1) sw++;       } else {         cin >> y >> z;         py[min(y, z)]--;         if (py[min(y, z)] == 0) sw--;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int q;     cin >> q;     long long int x = 0;     vector<long long int> sum = {};     vector<long long int> val = {};     for (int i = 0; i < (int)q; i++) {       int op;       cin >> op;       if (op == 1) {         cin >> x;         sum.push_back(((sum.size()) ? sum.back() : 0) + x);         long long int v[2];         v[0] = sum.size() * sum.back();         v[1] = (sum.size() >= 2) ? ((sum.size() + 1) * sum[sum.size() - 2]) : 0;         val.push_back(v[0] - v[1]);       } else {         auto itr = upper_bound(val.begin(), val.end(), x);         itr--;         long long int v = sum[distance(val.begin(), itr)];         cout << setprecision(16)              << x - (double)(x + v) / (double)(distance(val.begin(), itr) + 2)              << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100000 + 10;   const long long INF = numeric_limits<long long>::max();   enum { EVEN, ODD };   int A[MAXN];   long long dp[2][MAXN];   int main() {     int N;     cin >> N;     for (int i = 1; i <= N; ++i) cin >> A[i];     dp[ODD][1] = dp[EVEN][1] = dp[ODD][2] = -INF;     dp[EVEN][2] = abs(A[2] - A[1]);     long long ans = dp[EVEN][2];     for (int i = 3; i <= N; ++i) {       dp[ODD][i] = dp[EVEN][i - 1] - abs(A[i] - A[i - 1]);       dp[EVEN][i] =           max(dp[ODD][i - 1] + abs(A[i] - A[i - 1]), abs(A[i] - A[i - 1]) * 1ll);       ans = max(ans, max(dp[ODD][i], dp[EVEN][i]));     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = INT_MAX, df = 8e5 + 7;   int i, j, k = 1, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, le[df], rig[df],             c[df][26], ma[df << 1], head[df], pos[df << 1], tot, ans[df],             fail[df], cnt, yet[df][26];   struct node {     int sum, id;   };   vector<node> vec[df];   struct edge {     int to, nxt;   } e[df << 1];   void add(int u, int v) {     e[++o] = (edge){v, head[u]}, head[u] = o;     return;   }   char ch[df], st[df];   void upd(int x, int y) {     if (!x) return;     for (int i = x; i <= 800000; i += (i & -i)) ma[i] += y;     return;   }   int qry(int x) {     int as = 0;     for (int i = x; i; i -= (i & -i)) as += ma[i];     return as;   }   void insert1(int now, int v, int id) {     if (!c[now][v]) c[now][v] = ++tot;     pos[id] = c[now][v];     return;   }   void insert2(char *s, int id) {     int len = strlen(s), now = 0;     for (int i = (0); i <= (len - 1); ++i) {       int v = s[i] -  a ;       if (!c[now][v]) c[now][v] = ++tot;       now = c[now][v];     }     pos[id + n] = now;     return;   }   void init() {     scanf( %d , &n);     for (int i = (1); i <= (n); ++i) {       int op, x;       scanf( %d , &op);       if (op == 1) {         scanf( %s , ch), insert1(0, ch[0] -  a , i);       }       if (op == 2) {         scanf( %d , &x);         scanf( %s , ch);         insert1(pos[x], ch[0] -  a , i);       }     }     scanf( %d , &t);     for (int i = (1); i <= (t); ++i) {       int x;       scanf( %d , &x), scanf( %s , st);       insert2(st, i);       vec[pos[x]].push_back((node){pos[i + n], i});     }     return;   }   void build() {     queue<int> que;     for (int i = (0); i <= (25); ++i)       if (c[0][i]) fail[c[0][i]] = 0, que.push(c[0][i]), yet[0][i] = 1;     while (!que.empty()) {       int u = que.front();       que.pop();       for (int i = (0); i <= (25); ++i) {         if (c[u][i])           fail[c[u][i]] = c[fail[u]][i], yet[u][i] = 1, que.push(c[u][i]);         else           c[u][i] = c[fail[u]][i];       }     }     return;   }   void dfs1(int u) {     le[u] = ++cnt;     for (int i = head[u]; i; i = e[i].nxt) dfs1(e[i].to);     rig[u] = cnt;     return;   }   void dfs2(int u) {     upd(le[u], 1);     int siz = vec[u].size() - 1;     for (int i = (0); i <= (siz); ++i) {       int l = le[vec[u][i].sum], r = rig[vec[u][i].sum];       ans[vec[u][i].id] = qry(r) - qry(l - 1);     }     for (int i = (0); i <= (25); ++i)       if (yet[u][i]) dfs2(c[u][i]);     upd(le[u], -1);     return;   }   int main() {     init();     build();     for (int i = (1); i <= (tot); ++i) add(fail[i], i);     dfs1(0);     dfs2(0);     for (int i = (1); i <= (t); ++i) printf( %d n , ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int size_c = 26;   const int Maxn = 500010 << 1;   string s[100020];   int w[100020];   int n;   struct Suffix_Automaton {     int ch[Maxn][size_c];     int f[Maxn];     int ml[Maxn];     int sz, head, tail;     long long val[Maxn];     int cnt[Maxn], id[Maxn];     inline int getidx(char c) { return c -  a ; }     int node() {       sz++;       f[sz] = ml[sz] = 0;       memset(ch[sz], 0, sizeof(ch[sz]));       return sz;     }     void init() {       head = tail = 1;       sz = 0;       node();     }     void insert(int idx) {       head = tail = 1;       for (int i = 0; i < s[idx].size(); i++) add(getidx(s[idx][i]));     }     void add(int c) {       int p = tail;       if (ch[p][c]) {         int q = ch[p][c];         if (ml[q] == ml[p] + 1) {           tail = ch[p][c];         } else {           int nq = node();           memcpy(ch[nq], ch[q], sizeof(ch[q]));           f[nq] = f[q];           f[q] = nq;           ml[nq] = ml[p] + 1;           for (; p && ch[p][c] == q; p = f[p]) ch[p][c] = nq;           tail = nq;         }         return;       }       int np = node();       ml[np] = ml[p] + 1;       tail = np;       for (; p && !ch[p][c]; p = f[p]) ch[p][c] = np;       if (!p)         f[np] = head;       else if (ml[ch[p][c]] == ml[p] + 1)         f[np] = ch[p][c];       else {         int q = ch[p][c];         int nq = node();         memcpy(ch[nq], ch[q], sizeof(ch[q]));         f[nq] = f[q];         f[q] = f[np] = nq;         ml[nq] = ml[p] + 1;         for (; p && ch[p][c] == q; p = f[p]) ch[p][c] = nq;       }     }     void solve() {       init();       cin >> n;       for (int i = 1; i <= n; i++) cin >> s[i];       for (int i = 1; i <= n; i++) scanf( %d , w + i);       for (int i = 1; i <= n; i++) insert(i);       memset(cnt, 0, sizeof(cnt));       for (int i = 1; i <= sz; i++) cnt[ml[i]]++;       for (int i = 1; i <= sz; i++) cnt[i] += cnt[i - 1];       for (int i = 1; i <= sz; i++) id[cnt[ml[i]]--] = i;       memset(cnt, 0, sizeof(cnt));       for (int idx = 1; idx <= n; idx++) {         int rt = 1;         for (int i = 0; i < s[idx].size(); i++) {           rt = ch[rt][getidx(s[idx][i])];           val[rt] += w[idx];         }       }       for (int i = sz; i >= 1; i--) {         int cur = id[i];         val[f[cur]] += val[cur];       }       long long ans = 0;       for (int i = 1; i <= sz; i++) ans = max(ans, 1LL * ml[i] * val[i]);       cout << ans << endl;     }   } suf;   int main() { suf.solve(); }
#include <bits/stdc++.h>   using namespace std;   void time() {     ios_base ::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   int main() {     time();     int a, s, d, f;     cin >> a >> s >> d >> f;     if (a == s || s > a) {       cout <<  Second  << endl;     } else {       cout <<  First  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1000000007;   int main() {     string s;     cin >> s;     int n = s.length();     vector<int> dist(n);     for (int i = 0; i < n; i++)       if (s[i] ==  0 ) dist[i] = (i ? dist[i - 1] : 0) + 1;     vector<int> dp(n + 2), nxt(n + 2, n);     auto get = [&](int i) { return nxt[i] < n ? dp[nxt[i]] : 0; };     for (int i = n - 1; i >= 0; i--) {       dp[i] = ((dist[i] <= dist.back()) + get(0) + get(dist[i] + 1)) % mod;       nxt[dist[i]] = i;     }     int ans = n;     if (nxt[0] < n) ans = ((long long)get(0) * (nxt[0] + 1)) % mod;     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using std::cin;   using std::string;   string x;   int a, b, c;   int main() {     cin >> x;     switch (x[0]) {       case  r :         a = 0;         break;       case  s :         a = 2;         break;       case  p :         a = 5;         break;     }     cin >> x;     switch (x[0]) {       case  r :         b = 0;         break;       case  s :         b = 2;         break;       case  p :         b = 5;         break;     }     cin >> x;     switch (x[0]) {       case  r :         c = 0;         break;       case  s :         c = 2;         break;       case  p :         c = 5;         break;     }     if (a == b &&         ((c == 0 && a == 2) || (c == 2 && a == 5) || (c == 5 && a == 0)))       printf( S );     else if (b == c &&              ((a == 0 && b == 2) || (a == 2 && b == 5) || (a == 5 && b == 0)))       printf( F );     else if (a == c &&              ((b == 0 && a == 2) || (b == 2 && a == 5) || (b == 5 && a == 0)))       printf( M );     else       printf( ? );   }
#include <bits/stdc++.h>   using namespace std;   bool isPrime(long long int n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     long long int p = sqrt(n);     for (int i = 5; i <= p; i += 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   long long int b2d(string n) {     string num = n;     long long int dec_value = 0;     long long int base = 1;     long long int len = num.length();     for (int i = len - 1; i >= 0; i--) {       if (num[i] ==  1 ) dec_value += base;       base = base * 2;     }     return dec_value;   }   int f, f1, f2;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t = 1;     cin >> t;     while (t--) {       int n;       cin >> n;       f = 0;       int a[n];       int cnt = 0, sum = 0;       int m1 = 0, m2 = INT_MAX;       for (long long i = 0; i < n; i++) {         cin >> a[i];         if (a[i] != -1) f = 1;       }       for (long long i = 0; i < n; i++) {         if (a[i] != -1) {           if ((i > 0 && a[i - 1] == -1) || (i < n - 1 && a[i + 1] == -1)) {             m1 = max(m1, a[i]);             m2 = min(m2, a[i]);           }         }       }       if (!f) {         cout <<  0 1 n ;         continue;       }       int avg1 = (m1 + m2) / 2;       for (long long i = 0; i < n; i++) {         if (a[i] == -1) {           a[i] = avg1;         }       }       int ma1 = 0;       for (long long i = 0; i < n - 1; i++) {         ma1 = max(ma1, abs(a[i + 1] - a[i]));       }       cout << ma1 <<     << avg1 << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, j, k, p, s;     cin >> n;     int a[5][5];     for (i = 1; i <= 4; i++) {       for (j = 1; j <= 4; j++) {         cin >> a[i][j];       }     }     s = 0;     for (i = 1; i <= 4; i++) {       k = min(a[i][1], a[i][2]);       p = min(a[i][3], a[i][4]);       if (k + p <= n) {         cout << i <<     << k <<     << n - k << endl;         s++;         i = n;       }     }     if (s == 0) cout <<  -1  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using uint = unsigned int;   struct Cup {     uint cap;     uint ix;     uint cur;   };   int main() {     uint n;     uint total;     cin >> n >> total;     vector<Cup> cups(n);     for (uint i = 0, wi; i < n; ++i) {       cin >> wi;       cups[i] = {wi, i, 0};     }     sort(cups.begin(), cups.end(),          [](const Cup& left, const Cup& right) { return left.cap < right.cap; });     uint cur = 0;     bool done = true;     for (Cup& cup : cups) {       cur = cup.cap / 2 + (cup.cap & 1);       if (cur > total) {         done = false;         break;       }       cup.cur = cur;       total -= cup.cur;     }     uint diff;     for (int i = n - 1; i > -1; --i) {       diff = min(total, cups[i].cap - cups[i].cur);       total -= diff;       cups[i].cur += diff;     }     if (total > 0) {       done = false;     }     if (!done) {       cout <<  -1 n ;     } else {       sort(cups.begin(), cups.end(),            [](const Cup& left, const Cup& right) { return left.ix < right.ix; });       for (Cup& c : cups) {         cout << c.cur <<    ;       }       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, A[405][405], B[405][405], a[405][405];   char s[405][405];   void Solve() {     cin >> n >> m;     for (int i = 1; i <= n; ++i) {       cin >> (s[i] + 1);       for (int j = 1; j <= m; ++j) {         a[i][j] = s[i][j] -  0 ;       }     }     for (int j = 1; j <= m; ++j) {       for (int i = 1; i <= n; ++i) {         B[i][j] = B[i - 1][j] + a[i][j];         A[i][j] = A[i - 1][j] + !a[i][j];       }     }     int ans = n * m;     for (int i = 2; i < n; ++i) {       for (int j = i + 2; j < n; ++j) {         static int s[405], pre[405];         pre[0] = n * m;         for (int k = 1; k <= m; ++k) {           int w = B[j][k] - B[i - 1][k] + !a[j + 1][k] + !a[i - 1][k];           s[k] = s[k - 1] + w;           pre[k] = min(pre[k - 1], A[j][k] - A[i - 1][k] - s[k]);         }         for (int k = 4; k <= m; ++k) {           ans = min(ans, pre[k - 3] + s[k - 1] + A[j][k] - A[i - 1][k]);         }       }     }     cout << ans <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int T;     cin >> T;     while (T--) Solve();     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:256000000 )   using namespace std;   int n[2], k[2];   string s[] = { First ,  Second };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n[0] >> n[1] >> k[0] >> k[1];     int cur = 0;     while (1) {       if (n[cur] == 0) break;       n[cur]--;       cur ^= 1;     }     cout << s[cur ^ 1];     return 0;   }
#include <bits/stdc++.h>   inline int getint() {     register char ch;     while (!isdigit(ch = getchar()))       ;     register int x = ch ^  0 ;     while (isdigit(ch = getchar())) x = (((x << 2) + x) << 1) + (ch ^  0 );     return x;   }   const int N = 101, K = 41, mod = 1e9 + 7;   int k, f[N][K], tmp[K];   std::forward_list<int> e[N];   inline void add_edge(const int &u, const int &v) {     e[u].push_front(v);     e[v].push_front(u);   }   void dfs(const int &x, const int &par) {     f[x][0] = f[x][k + 1] = 1;     for (int &y : e[x]) {       if (y == par) continue;       dfs(y, x);       std::fill(&tmp[0], &tmp[k * 2] + 1, 0);       for (register int i = 0; i <= k * 2; i++) {         for (register int j = 0; j <= k * 2; j++) {           (tmp[i + j <= k * 2 ? std::min(i, j + 1) : std::max(i, j + 1)] +=            (long long)f[x][i] * f[y][j] % mod) %= mod;         }       }       std::copy(&tmp[0], &tmp[k * 2] + 1, f[x]);     }   }   int main() {     const int n = getint();     k = getint();     for (register int i = 1; i < n; i++) {       add_edge(getint(), getint());     }     dfs(1, 0);     int ans = 0;     for (register int i = 0; i <= k; i++) {       (ans += f[1][i]) %= mod;     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n;     cin >> n;     vector<long long> p(n + 1);     for (long long i = 1; i < n + 1; i++) {       long long x;       cin >> x;       p[x] = i;     }     multiset<pair<long long, long long> > k;     vector<long long> ct(n + 1, 1);     for (long long i = 1; i < n + 1; i++) k.insert({1, i});     for (long long i = 1; i < n + 1; i++) {       long long pos = p[i];       if (ct[pos] != k.rbegin()->first) {         cout <<  No  <<   n ;         return;       }       k.erase({ct[pos], pos});       auto it = k.upper_bound({ct[pos], pos});       if (it == k.end()) continue;       long long newpos = it->second;       k.erase(it);       ct[newpos] += ct[pos];       k.insert({ct[newpos], newpos});     }     cout <<  Yes  <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long TESTS = 1;     cin >> TESTS;     while (TESTS--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   int d, n, m;   int deq[200100];   int qs, qe;   struct stt {     int x, p;     bool operator<(const stt& r) const { return x < r.x; }   };   stt a[200100];   int main() {     int i, j;     long long int ans;     scanf( %d%d%d , &d, &n, &m);     for (i = 0; i < m; i++) {       scanf( %d%d , &a[i].x, &a[i].p);     }     a[m].x = 0;     a[m].p = 0;     m++;     a[m].x = d;     a[m].p = 0;     m++;     std::sort(a, a + m);     for (i = 1; i < m; i++) {       if (a[i].x > a[i - 1].x + n) {         printf( -1 );         return 0;       }     }     qs = 0;     qe = 0;     j = 0;     ans = 0;     for (i = 0; i < m; i++) {       while (qs < qe && a[deq[qs]].x + n < a[i].x) {         ans += ((long long int)a[deq[qs]].x + n - j) * a[deq[qs]].p;         j = a[deq[qs]].x + n;         qs++;       }       ans += ((long long int)a[i].x - j) * a[deq[qs]].p;       j = a[i].x;       while (qs < qe && a[deq[qe - 1]].p > a[i].p) {         qe--;       }       deq[qe] = i;       qe++;     }     printf( %I64d , ans);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     bool size = false, small = false, cap = false, digit = false;     if (s.size() >= 5) {       size = true;       for (int i = 0; i < s.size(); i++) {         if (s[i] ==  !  || s[i] ==  _  || s[i] ==  ;  || s[i] ==  ,  ||             s[i] ==  . )           continue;         else if (s[i] >=  a  && s[i] <=  z )           small = true;         else if (s[i] >=  A  && s[i] <=  Z )           cap = true;         else if (s[i] >= 48 && s[i] <= 57)           digit = true;       }       if (size && small && cap && digit) {         cout <<  Correct  << endl;         return 0;       } else {         cout <<  Too weak  << endl;         return 0;       }     } else {       cout <<  Too weak  << endl;       return 0;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string q;   string d;   int b;   void f(string s, int p) {     char a = 0;     int c = 0;     if (s.size() <= p) return;     for (int i = p; i < s.size(); i++) {       if (s[i] > a) {         a = s[i];         b = i;         c = 1;       } else if (s[i] == a) {         b = i;         c++;       }     }     for (int i = 0; i < c; i++) cout << a;     f(s, b + 1);   }   int main() {     cin >> q;     f(q, 0);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   vector<vector<int> > G;   double dfs(int u, int p = -1) {     double res = 0;     int cnt = 0;     for (int i = 0; i < G[u].size(); ++i) {       int v = G[u][i];       if (v == p) continue;       cnt++;       res += dfs(v, u);     }     return (cnt ? res / cnt + 1 : 0);   }   int main() {     cin >> n;     m = n - 1;     G.resize(n + 1);     for (int i = 0; i < m; ++i) {       int u, v;       cin >> u >> v;       G[u].push_back(v);       G[v].push_back(u);     }     cout << setprecision(7) << fixed << dfs(1);     return 0;   }