malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const double PI = 3.141592653589793238460;   using namespace std;   const int N = 200200;   vector<int> g[N];   int w[N], vis[N], done[N];   int can_back[N];   int n, m, s;   long long maximum = 0;   void dfs(int u, int par) {     vis[u] = 1;     for (auto v : g[u]) {       if (v == par) continue;       if (vis[v])         can_back[v] = 1;       else         dfs(v, u);       if (can_back[v] == 1) can_back[u] = 1;     }   }   void findmax(int u, long long sum) {     done[u] = 1;     if (g[u].size() == 1 and u != s) {       sum += w[u];       maximum = max(maximum, sum);       return;     }     if (can_back[u] == 0) sum += w[u];     for (auto v : g[u]) {       if (!done[v]) findmax(v, sum);     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     for (int i = 1; i <= n; i++) {       cin >> w[i];     }     for (int i = 1; i <= m; i++) {       int u, v;       cin >> u >> v;       g[u].push_back(v);       g[v].push_back(u);     }     cin >> s;     can_back[s] = 1;     dfs(s, 0);     long long ans = 0;     for (int i = 1; i <= n; i++) {       if (can_back[i] == 1) ans += w[i];     }     findmax(s, 0);     ans += maximum;     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int N;     cin >> N;     vector<int> adjL(N, -1);     for (int n = 0; n < N; n++) {       cin >> adjL[n];       adjL[n]--;     }     bool c = false;     for (int i = 0; i < N; i++) {       int node = i;       for (int x = 0; x < 3; x++) {         if (adjL[node] != -1) {           node = adjL[node];         }       }       if (node == i) {         cout <<  YES ;         c = true;         break;       }     }     if (!c) cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e6 + 5;   int n, ri[N];   char s[N];   struct node {     int ch[26], par, val;   } t[N];   int sz = 1, root = 1, last = 1;   void extend(int c) {     int p = last, np = ++sz;     t[np].val = t[p].val + 1;     ri[np]++;     for (; p && !t[p].ch[c]; p = t[p].par) t[p].ch[c] = np;     if (!p)       t[np].par = root;     else {       int q = t[p].ch[c];       if (t[q].val == t[p].val + 1)         t[np].par = q;       else {         int nq = ++sz;         t[nq] = t[q];         t[nq].val = t[p].val + 1;         t[q].par = t[np].par = nq;         for (; p && t[p].ch[c] == q; p = t[p].par) t[p].ch[c] = nq;       }     }     last = np;   }   int vis[N];   void walk(int id) {     int u = root, len = n + n - 1, ans = 0, nowLen = 0;     for (int i = 1; i <= len; i++) {       int c = s[i] -  a ;       if (t[u].ch[c])         u = t[u].ch[c], nowLen++;       else {         while (u && !t[u].ch[c]) u = t[u].par;         if (!u)           u = root, nowLen = 0;         else           nowLen = t[u].val + 1, u = t[u].ch[c];       }       if (vis[u] != id && nowLen >= n) vis[u] = id, ans += ri[u];       if (n != 1)         while (t[t[u].par].val + 1 >= n) u = t[u].par, nowLen = t[u].val;     }     printf( %d n , ans);   }   int c[N], a[N];   void RadixSort() {     for (int i = 1; i <= sz; i++) c[t[i].val]++;     for (int i = 1; i <= n; i++) c[i] += c[i - 1];     for (int i = sz; i >= 1; i--) a[c[t[i].val]--] = i;   }   void solve() {     RadixSort();     int u;     for (int i = sz; i >= 1; i--) u = a[i], ri[t[u].par] += ri[u];     int m;     scanf( %d , &m);     for (int i = 1; i <= m; i++) {       scanf( %s , s + 1);       n = strlen(s + 1);       for (int i = 1; i < n; i++) s[i + n] = s[i];       walk(i);     }   }   int main() {     scanf( %s , s + 1);     n = strlen(s + 1);     for (int i = 1; i <= n; i++) extend(s[i] -  a );     solve();   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     int64_t n, m;     cin >> n >> m;     if (n <= m) {       cout << n << endl;     } else {       n -= m;       int64_t l = 0, r = 2e9;       while (l < r) {         int64_t m = (l + r) / 2;         int64_t val = m * (m + 1) / 2;         if (val >= n) {           r = m;         } else {           l = m + 1;         }       }       cout << l + m << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 3;   const int INF = 1e9;   const int MOD = 1e9 + 7;   int n;   int a[MAXN];   long long seg[12][4 * MAXN];   void add(int j, int l, int r, long long val, int b = 0, int e = n, int k = 0) {     if (l <= b && e <= r) {       seg[j][k] += val;       return;     }     if (r <= b || e <= l) return;     int mid = (b + e) / 2;     add(j, l, r, val, b, mid, k * 2 + 1);     add(j, l, r, val, mid, e, k * 2 + 2);   }   long long get(int j, int i, int b = 0, int e = n, int k = 0) {     if (i < b || i >= e) return 0;     if (b + 1 == e) return seg[j][k];     int mid = (b + e) / 2;     return seg[j][k] + get(j, i, b, mid, k * 2 + 1) +            get(j, i, mid, e, k * 2 + 2);   }   int main() {     cin >> n;     int k;     cin >> k;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       x--;       a[x] = i;     }     for (int i = 0; i < n; i++) {       if (a[i] == 0) {         add(1, a[i], n, 1);       } else {         for (int j = 2; j <= k + 1; j++) {           long long x = get(j - 1, a[i] - 1);           add(j, a[i], n, x);         }         add(1, a[i], n, 1);       }     }     cout << get(k + 1, n - 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1LL << 60;   int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }   int lcm(int a, int b) { return a * b / gcd(a, b); }   const int N = 2e5 + 5;   int v[N], in[N];   vector<int> e[N];   bool cmp(int a, int b) { return in[a] < in[b]; }   void solve() {     int n;     cin >> n;     for (auto &li : e) li.clear();     for (int i = (0); i < (n - 1); ++i) {       int x, y;       cin >> x >> y;       x--, y--;       e[x].push_back(y);       e[y].push_back(x);     }     vector<int> ch, gen;     for (int i = (0); i < (n); ++i) {       v[i] = 0;       int z;       cin >> z;       in[--z] = i;       ch.push_back(z);     }     for (int i = (0); i < (n); ++i) sort((e[i]).begin(), (e[i]).end(), cmp);     queue<int> q;     q.push(0);     v[0] = 1;     while (!q.empty()) {       int t = q.front();       q.pop();       gen.push_back(t);       for (auto to : e[t]) {         if (v[to]) continue;         v[to] = 1;         q.push(to);       }     }     for (int i = (0); i < (n); ++i)       if (gen[i] != ch[i]) {         puts( No );         return;       }     puts( Yes );   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     solve();     return 0;   }
#include <bits/stdc++.h>   int cnt[111], ans, b, d, pr[111], v[111];   int main() {     scanf( %d%d , &b, &d);     int k = b;     for (int i = 2; k > 1; i++) {       if (k % i) continue;       while (k % i == 0) cnt[i]++, k /= i;     }     bool flag = true;     k = d;     for (int i = 2; k > 1; i++) {       if (k % i) continue;       int x = 1;       while (k % i == 0) pr[i]++, k /= i, x *= i;       v[x] = -i;       if (cnt[i] == 0) {         flag = false;         continue;       }       int p = (pr[i] - 1) / cnt[i] + 1;       if (p > ans) ans = p;     }     if (flag)       printf( 2-type n%d n , ans);     else {       if (b % d == 1)         printf( 3-type n );       else if ((b + 1) % d == 0)         printf( 11-type n );       else {         flag = true;         for (int i = 2; i <= d; i++) {           if (v[i] >= 0 || cnt[-v[i]] || b % i == 1 || (b + 1) % i == 0) continue;           flag = false;           break;         }         if (flag)           printf( 6-type n );         else           printf( 7-type n );       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     bool res = false;     for (int i = 0; i < s.size() - 1; ++i) {       if (s[i] ==  A  && s[i + 1] ==  B ) {         for (int j = i + 2; j < s.size() - 1; ++j) {           if (s[j] ==  B  && s[j + 1] ==  A ) {             cout <<  YES n ;             return 0;           }         }         break;       }     }     for (int i = 0; i < s.size() - 1; ++i) {       if (s[i] ==  B  && s[i + 1] ==  A ) {         for (int j = i + 2; j < s.size() - 1; ++j) {           if (s[j] ==  A  && s[j + 1] ==  B ) {             cout <<  YES n ;             return 0;           }         }         break;       }     }     cout <<  NO n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N, M;   string grid[1000];   vector<vector<pair<int, char>>> startAdj;   vector<bool> visited;   vector<int> merged;   vector<vector<pair<int, char>>> adj;   vector<int> value;   vector<int> greaterCount;   void flood(int start, int pos) {     if (visited[pos]) return;     visited[pos] = true;     merged[pos] = start;     for (int i = 0; i < startAdj[pos].size(); i++) {       if (startAdj[pos][i].second !=  = ) {         adj[start].push_back(startAdj[pos][i]);       }     }     for (int i = 0; i < startAdj[pos].size(); i++) {       if (startAdj[pos][i].second ==  = ) {         flood(start, startAdj[pos][i].first);       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin >> N >> M;     for (int i = 0; i < N; i++) cin >> grid[i];     startAdj.assign(N + M + 1, vector<pair<int, char>>());     for (int i = 0; i < N; i++)       for (int j = 0; j < M; j++)         startAdj[i + 1].push_back({j + 1 + N, grid[i][j]});     for (int j = 0; j < M; j++) {       for (int i = 0; i < N; i++) {         char c = grid[i][j];         if (c ==  > )           c =  < ;         else if (c ==  < )           c =  > ;         startAdj[j + 1 + N].push_back({i + 1, c});       }     }     visited.assign(N + M + 1, false);     merged.assign(N + M + 1, 0);     adj.assign(N + M + 1, vector<pair<int, char>>());     value.assign(N + M + 1, 0);     greaterCount.assign(N + M + 1, 0);     for (int i = 1; i <= N + M; i++) {       if (!visited[i]) {         flood(i, i);       }     }     bool works = true;     for (int i = 1; i <= N + M; i++) {       for (int j = 0; j < adj[i].size(); j++) {         if (adj[i][j].second ==  > ) greaterCount[i]++;         if (merged[adj[i][j].first] == i) works = false;       }     }     if (works) {       vector<int> curr;       for (int i = 1; i <= N + M; i++)         if (merged[i] == i && greaterCount[i] == 0) curr.push_back(i);       vector<int> next;       int v = 1;       while (curr.size() != 0) {         for (int i = 0; i < curr.size(); i++) {           value[curr[i]] = v;           for (int j = 0; j < adj[curr[i]].size(); j++) {             if (adj[curr[i]][j].second ==  < ) {               greaterCount[merged[adj[curr[i]][j].first]]--;               if (greaterCount[merged[adj[curr[i]][j].first]] == 0) {                 next.push_back(merged[adj[curr[i]][j].first]);               }             }           }         }         curr = next;         next.clear();         v++;       }       for (int i = 1; i <= N + M; i++) {         if (!value[i] && merged[i] == i) works = false;       }     }     if (works) {       cout <<  Yes n ;       for (int i = 0; i < N; i++) {         if (i) cout <<    ;         cout << value[merged[i + 1]];       }       cout <<   n ;       for (int i = 0; i < M; i++) {         if (i) cout <<    ;         cout << value[merged[i + 1 + N]];       }       cout <<   n ;     } else {       cout <<  No n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long n, k;     cin >> n >> k;     vector<long long> arr(n);     for (long long i = 0; i < n; i++) cin >> arr[i];     long long c = 0;     for (long long i = 1; i < n; i++) {       if (arr[i] + arr[i - 1] < k) {         c += k - arr[i] - arr[i - 1];         arr[i] = k - arr[i - 1];       }     }     cout << c <<   n ;     for (auto i : arr) cout << i <<    ;     ;     cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int MAXN = 1000000005;   long long meta;   bool ok = 0;   map<long long, long long> visite;   void bfs(long long padre) {     queue<long long> cola;     cola.push(padre);     while (!cola.empty()) {       long long hijo = cola.front();       cola.pop();       long long hijo1 = hijo * 2;       long long hijo2 = hijo * 10 + 1;       if (hijo1 == meta) {         ok = 1;         visite[hijo1] = hijo;         break;       }       if (hijo2 == meta) {         ok = 1;         visite[hijo2] = hijo;         break;       }       if (hijo1 < MAXN) {         visite[hijo1] = hijo;         cola.push(hijo1);       }       if (hijo2 < MAXN) {         visite[hijo2] = hijo;         cola.push(hijo2);       }     }   }   int main() {     ios::sync_with_stdio(false);     long long padre;     cin >> padre >> meta;     bfs(padre);     if (ok == false) {       cout <<  NO  << endl;       return 0;     }     cout <<  YES  << endl;     vector<long long> ans;     long long hijo = visite[meta];     ans.push_back(meta);     while (hijo != padre) {       ans.push_back(hijo);       hijo = visite[hijo];     }     ans.push_back(padre);     cout << ans.size() << endl;     for (int i = ans.size() - 1; i >= 0; i--) {       cout << ans[i] <<    ;     }   }
#include <bits/stdc++.h>   int CH, NEG;   template <typename TP>   inline void read(TP& ret) {     ret = NEG = 0;     while (CH = getchar(), CH <  ! )       ;     if (CH ==  - ) NEG = true, CH = getchar();     while (ret = ret * 10 + CH -  0 , CH = getchar(), CH >  ! )       ;     if (NEG) ret = -ret;   }   using namespace std;   int n, K;   struct node {     int sz;     int L[11LL], R[11LL];     bool operator<(const node& B) const {       int i;       for (i = (1); i <= (K); i++)         if (R[i] > B.L[i]) break;       return i > K;     }     bool operator>(const node& B) const {       int i;       for (i = (1); i <= (K); i++)         if (L[i] < B.R[i]) break;       return i > K;     }   } tmp;   int tot = 0;   set<node> S;   set<node>::iterator it1, it2;   void merge(node& A, const node& B) {     A.sz += B.sz;     int i;     for (i = (1); i <= (K); i++)       A.L[i] = std::min(A.L[i], B.L[i]), A.R[i] = std::max(A.R[i], B.R[i]);   }   int Add() {     int i;     tmp.sz = 1;     for (i = (1); i <= (K); i++) read(tmp.L[i]), tmp.R[i] = tmp.L[i];     if (S.empty()) {       S.insert(tmp);       return 1;     }     it1 = S.lower_bound(tmp);     while (true) {       if (it1 == S.end()) break;       if (*it1 > tmp) break;       it2 = it1;       it1++;       merge(tmp, *it2);       S.erase(it2);     }     S.insert(tmp);     it1 = S.end();     it1--;     return it1->sz;   }   int main() {     S.clear();     int i;     read(n), read(K);     for (i = (1); i <= (n); i++) {       printf( %d n , Add());     }   END:     getchar(), getchar();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e4 + 10;   const int N = 5e5 + 10;   const int INF = 0x3f3f3f3f;   const long long mod = 1e9 + 7, G = 3;   const int base = 30000;   int t;   int n, m, k;   int dp[35][35][55];   int dfs(int n, int m, int k) {     if (k == 0 || n * m == k) return 0;     if (dp[n][m][k] != -1) return dp[n][m][k];     int ret = INF;     for (int i = 1; i < n; ++i)       for (int j = 0; j <= k; ++j)         ret = min(ret, dfs(i, m, j) + dfs(n - i, m, k - j) + m * m);     for (int i = 1; i < m; ++i)       for (int j = 0; j <= k; ++j)         ret = min(ret, dfs(n, i, j) + dfs(n, m - i, k - j) + n * n);     if (dp[n][m][k] == -1) dp[n][m][k] = ret;     return ret;   }   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> t;     memset(dp, -1, sizeof(dp));     while (t--) {       cin >> n >> m >> k;       cout << dfs(n, m, k) <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     map<char, int> mapdown, mapup, mapleft, mapright;     char keys[10] = { 0 ,  1 ,  2 ,  3 ,  4 ,  5 ,  6 ,  7 ,  8 ,  9 };     int n, count1 = 0, count2 = 0, count3 = 0, count4 = 0;     char str[15];     mapdown.clear();     mapup.clear();     mapleft.clear();     mapright.clear();     scanf( %d , &n);     scanf( %s , str);     for (int i = 0; i < 10; i++) {       char c = keys[i];       if (keys[i] ==  7  || keys[i] ==  0  || keys[i] ==  9 ) {         mapdown.insert(make_pair(c, 0));       } else {         mapdown.insert(make_pair(c, 1));       }     }     for (int i = 0; i < 10; i++) {       if (keys[i] ==  1  || keys[i] ==  2  || keys[i] ==  3 )         mapup.insert(make_pair(keys[i], 0));       else         mapup.insert(make_pair(keys[i], 1));     }     for (int i = 0; i < 10; i++) {       if (keys[i] ==  3  || keys[i] ==  6  || keys[i] ==  9  || keys[i] ==  0 )         mapright.insert(make_pair(keys[i], 0));       else         mapright.insert(make_pair(keys[i], 1));     }     for (int i = 0; i < 10; i++) {       if (keys[i] ==  1  || keys[i] ==  4  || keys[i] ==  7  || keys[i] ==  0 )         mapleft.insert(make_pair(keys[i], 0));       else         mapleft.insert(make_pair(keys[i], 1));     }     for (int i = 0; i < n; i++) {       if (mapdown[str[i]] != 0) count1++;     }     for (int i = 0; i < n; i++) {       if (mapup[str[i]] != 0) count2++;     }     for (int i = 0; i < n; i++) {       if (mapleft[str[i]] != 0) count3++;     }     for (int i = 0; i < n; i++) {       if (mapright[str[i]] != 0) count4++;     }     if (count1 == n || count2 == n || count3 == n || count4 == n)       printf( NO );     else       printf( YES );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool isSolveabe(int *a, int n, int m) {     int i = m;     int j = n - 1;     int min = INT_MIN;     while (i < j) {       if (a[i] < a[j]) {         if (a[i] < min) {           return false;         }         min = a[i];         ++i;       } else {         if (a[j] < min) {           return false;         }         min = a[j];         --j;       }     }     return true;   }   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int *a = new int[n];       for (int i = 0; i < n; i++) {         cin >> a[i];       }       int s = 0;       int e = n - 1;       int ans = 0;       while (s <= e) {         int m = (s + e) / 2;         if (isSolveabe(a, n, m)) {           ans = m;           e = m - 1;         } else {           s = m + 1;         }       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long GCD(long long a, long long b) { return b ? GCD(b, a % b) : a; }   const long long N = 2e5 + 7;   const long long inf = 1e6 + 1;   const long long mod = 998244353;   int t, n, m, a[N];   struct node {     int def, s;     bool operator<(const node& a) const { return def < a.def; }   } b[N];   bool cmp(const node& a, int x) { return a.def < x; }   int main() {     cin >> t;     while (t--) {       cin >> n;       for (int i = 1; i <= n; i++) cin >> a[i];       cin >> m;       for (int i = 1; i <= m; i++) cin >> b[i].def >> b[i].s;       sort(b + 1, b + 1 + m);       for (int i = m - 1; i >= 1; i--) {         b[i].s = max(b[i].s, b[i + 1].s);       }       bool ok = true;       int minn = 2 * n, ans = 0, last = 0;       for (int i = 1; i <= n; i++) {         int q = lower_bound(b + 1, b + 1 + m, a[i], cmp) - b;         if (q > m) {           ok = false;           break;         }         minn = min(minn, b[q].s);         if (last + minn < i) {           ans++;           last = i - 1;           minn = b[q].s;         }       }       if (ok == false)         cout <<  -1 n ;       else         cout << ans + 1 <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename Elem>   int quick_power(int a, Elem b, int Mod) {     int ans = 1;     while (b) {       if (b & 1) {         ans = 1ll * ans * a % Mod;       }       b >>= 1;       a = 1ll * a * a % Mod;     }     return ans;   }   const int Maxn = 100000;   const int Mod = 998244353;   const int G = 3;   int p[Maxn + 5];   int n;   long long m;   int frac[Maxn + 5], inv_f[Maxn + 5], inv[Maxn + 5];   void init() {     frac[0] = 1;     for (int i = 1; i <= Maxn + 1; i++) {       frac[i] = 1ll * frac[i - 1] * i % Mod;     }     inv_f[Maxn + 1] = quick_power(frac[Maxn + 1], Mod - 2, Mod);     for (int i = Maxn; i >= 0; i--) {       inv_f[i] = 1ll * inv_f[i + 1] * (i + 1) % Mod;     }     inv[1] = 1;     for (int i = 2; i <= Maxn + 1; i++) {       inv[i] = 1ll * (Mod - Mod / i) * inv[Mod % i] % Mod;     }   }   void NTT(int *a, int flag, int n) {     static int R[Maxn << 2 | 5], last_len;     int len = 1, L = 0;     while (len < n) {       len <<= 1;       L++;     }     if (len != last_len) {       for (int i = 0; i < len; i++) {         R[i] = (R[i >> 1] >> 1) | ((i & 1) << (L - 1));       }       last_len = len;     }     for (int i = 0; i < len; i++) {       if (i < R[i]) {         swap(a[i], a[R[i]]);       }     }     for (int j = 1; j < len; j <<= 1) {       int T = quick_power(G, (Mod - 1) / (j << 1), Mod);       for (int k = 0; k < len; k += (j << 1)) {         for (int l = 0, t = 1; l < j; l++, t = 1ll * t * T % Mod) {           int Nx = a[k + l], Ny = 1ll * t * a[j + k + l] % Mod;           a[k + l] = (Nx + Ny) % Mod;           a[j + k + l] = (Nx - Ny + Mod) % Mod;         }       }     }     if (flag == -1) {       reverse(a + 1, a + len);       for (int i = 0, t = quick_power(len, Mod - 2, Mod); i < len; i++) {         a[i] = 1ll * a[i] * t % Mod;       }     }   }   int a[Maxn << 2 | 5], b[Maxn << 2 | 5], f[Maxn << 2 | 5], g[Maxn << 2 | 5];   int main() {     init();     scanf( %d%lld , &n, &m);     for (int i = 0; i <= n; i++) {       scanf( %d , &p[i]);     }     for (int i = 0; i <= n; i++) {       a[i] = inv_f[i];       b[i] = 1ll * frac[n - i] * p[n - i] % Mod;     }     int len = 1;     while (len <= (n << 1)) {       len <<= 1;     }     NTT(a, 1, len);     NTT(b, 1, len);     for (int i = 0; i < len; i++) {       a[i] = 1ll * a[i] * b[i] % Mod;     }     NTT(a, -1, len);     for (int i = 0; i <= n; i++) {       g[i] = 1ll * a[n - i] * inv_f[i] % Mod;       g[i] = 1ll * g[i] * quick_power(inv[i + 1], m, Mod) % Mod;     }     for (int i = 0; i < len; i++) {       a[i] = b[i] = 0;     }     for (int i = 0; i <= n; i++) {       if (i & 1) {         a[i] = Mod - inv_f[i];       } else {         a[i] = inv_f[i];       }       b[i] = 1ll * frac[n - i] * g[n - i] % Mod;     }     NTT(a, 1, len);     NTT(b, 1, len);     for (int i = 0; i < len; i++) {       a[i] = 1ll * a[i] * b[i] % Mod;     }     NTT(a, -1, len);     for (int i = 0; i <= n; i++) {       f[i] = 1ll * a[n - i] * inv_f[i] % Mod;     }     for (int i = 0; i <= n; i++) {       printf( %d  , f[i]);     }     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int n = s.size();     bool p1 = (n >= 5);     bool p2 = 0, p3 = 0, p4 = 0;     for (int i = 0; i < n; i++) {       p2 |= (s[i] >=  a  && s[i] <=  z );       p3 |= (s[i] >=  A  && s[i] <=  Z );       p4 |= (s[i] >=  0  && s[i] <=  9 );     }     if (p1 && p2 && p3 && p4)       printf( Correct );     else       printf( Too weak );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9;   int n;   map<string, int> was;   void read() {     cin >> n;     while (n--) {       int c;       string s;       cin >> c >> s;       sort(s.begin(), s.end());       if (was.count(s) == 0) {         was[s] = c;       } else {         was[s] = min(was[s], c);       }     }   }   int getC(string a, string b) {     if (!was.count(a) || !was.count(b)) {       return INF;     }     return was[a] + was[b];   }   void solve() {     int ans = INF;     if (was.count( A ) && was.count( B ) && was.count( C )) {       ans = was[ A ] + was[ B ] + was[ C ];     }     if (was.count( ABC )) {       ans = min(ans, was[ ABC ]);     }     ans = min(ans, getC( A ,  BC ));     ans = min(ans, getC( AB ,  C ));     ans = min(ans, getC( AC ,  B ));     ans = min(ans, getC( AB ,  BC ));     ans = min(ans, getC( AC ,  BC ));     ans = min(ans, getC( AB ,  AC ));     if (ans == INF) {       ans = -1;     }     cout << ans << endl;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     read();     solve();     return 0;   }