malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     int sizePermute, sizebkp, x, minimum = 100, maximum = 0, maximumIndex,                                  minimumIndex, counter = 0;     cin >> sizePermute;     sizebkp = sizePermute;     vector<int> myvec(sizePermute);     myvec.clear();     while (sizePermute != 0) {       cin >> x;       if (x < minimum) {         minimum = x;         minimumIndex = counter;       }       if (x > maximum) {         maximum = x;         maximumIndex = counter;       }       myvec.push_back(x);       sizePermute--;       counter++;     }     if (maximumIndex == (sizebkp - 1) && minimumIndex == 0) {       cout << sizebkp - 1 << endl;       return 0;     } else if (minimumIndex == (sizebkp - 1) && maximumIndex == 0) {       cout << sizebkp - 1 << endl;       return 0;     } else if (maximumIndex < minimumIndex &&                (((sizebkp - 1) - minimumIndex) > (maximumIndex - 0))) {       cout << sizebkp - 1 - maximumIndex << endl;       return 0;     } else if (maximumIndex < minimumIndex &&                (((sizebkp - 1) - minimumIndex) < (maximumIndex - 0))) {       cout << minimumIndex << endl;       return 0;     } else if (maximumIndex > minimumIndex &&                (((sizebkp - 1) - maximumIndex) > (minimumIndex - 0))) {       cout << sizebkp - 1 - minimumIndex << endl;       return 0;     } else if (maximumIndex > minimumIndex &&                (((sizebkp - 1) - maximumIndex) < (minimumIndex - 0))) {       cout << maximumIndex << endl;       return 0;     } else if (maximumIndex > minimumIndex &&                (((sizebkp - 1) - maximumIndex) == (minimumIndex - 0))) {       cout << sizebkp - 1 - minimumIndex << endl;       return 0;     } else if (maximumIndex < minimumIndex &&                (((sizebkp - 1) - minimumIndex) == (maximumIndex - 0))) {       cout << sizebkp - 1 - maximumIndex << endl;       return 0;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long a, b, c;     cin >> a >> b >> c;     long long power = 0, l = 0, emp = 1, aa = 0;     for (long long i = 0; i > -1; i++) {       if (i != 0) {         for (long long j = 0; j < i; j++) {           emp = emp * c;         }       }       if (emp >= a && emp <= b) {         cout << emp <<    ;         power++;       }       if (emp > b / c) {         break;       }       emp = 1;     }     if (power == 0) {       cout <<  -1  << endl;     }     return 0;   }
#include <bits/stdc++.h>   const long long mod = 1000 * 1000 * 1000 + 7;   const long long mod1 = 998244353;   const long long INF = 1ll * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 + 7;   using namespace std;   long long power(long long x, long long y) {     long long res = 1;     while (y > 0) {       if (y & 1) res = (long long)(res * x);       y = y >> 1;       x = (long long)(x * x);     }     return res;   }   bool vis[3000];   vector<long long> a[3000];   vector<pair<long long, long long> > fin[3000];   map<long long, long long> suc;   long long val[3000];   long long c[3000];   long long cur = 1;   bool dfs(long long parent) {     long long f = 0;     long long s = 0;     for (auto edge : a[parent]) {       f += 1;       if (!vis[edge]) {         vis[edge] = true;         bool x = dfs(edge);         if (x == false) return false;         s += int((fin[edge]).size());         for (int j = 0; j < int((fin[edge]).size()); j++)           fin[parent].push_back(fin[edge][j]);       }     }     if (f == 1 and parent != a[0][0]) {       if (c[parent] > s) return false;       while (suc[cur] != 0) cur += 1;       fin[parent].push_back({cur, parent});       val[parent] = cur;       suc[cur] = 1;     } else {       if (c[parent] > s)         return false;       else {         sort(fin[parent].begin(), fin[parent].end());         if (c[parent] == 0) {           val[parent] = fin[parent][0].first;           suc[val[parent]] = 1;           for (int j = 0; j < int((fin[parent]).size()); j++) {             fin[parent][j].first += 1;             val[fin[parent][j].second] += 1;           }           suc[fin[parent].back().first] = 1;           fin[parent].push_back({val[parent], parent});         } else if (c[parent] == s) {           val[parent] = fin[parent].back().first + 1;           suc[val[parent]] = 1;           fin[parent].push_back({val[parent], parent});         } else {           val[parent] = fin[parent][c[parent]].first;           suc[val[parent]] = 1;           for (int j = c[parent]; j < int((fin[parent]).size()); j++) {             fin[parent][j].first += 1;             val[fin[parent][j].second] += 1;           }           suc[fin[parent].back().first] = 1;           fin[parent].push_back({val[parent], parent});         }       }     }     return true;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     for (int(i) = (0); (i) < (n); ++(i)) {       long long x, y;       cin >> x >> y;       if (x != 0) a[i + 1].push_back(x);       a[x].push_back(i + 1);       c[i + 1] = y;     }     if (n == 1) {       if (c[1] == 0) {         cout <<  YES               <<   n ;         cout << 1;         return 0;       }     }     vis[a[0][0]] = true;     bool ans = dfs(a[0][0]);     if (ans == false) {       cout <<  NO ;     } else {       cout <<  YES             <<   n ;       for (int i = 1; i <= n; i++) cout << val[i] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 10005;   int a[N], sorted[N], n, m, sum[20][N], tree[20][N];   inline void build(int deep, int l, int r) {     int i, mid = (l + r) >> 1, lm = mid - l + 1, lp = l, rp = mid + 1;     for (i = l; i <= mid; i++)       if (sorted[i] > sorted[mid]) lm--;     for (i = l; i <= r; i++) {       if (i == l)         sum[deep][i] = 0;       else         sum[deep][i] = sum[deep][i - 1];       if (tree[deep][i] == sorted[mid]) {         if (lm) {           lm--;           sum[deep][i]++;           tree[deep + 1][lp++] = tree[deep][i];         } else           tree[deep + 1][rp++] = tree[deep][i];       } else if (tree[deep][i] > sorted[mid]) {         sum[deep][i]++;         tree[deep + 1][lp++] = tree[deep][i];       } else         tree[deep + 1][rp++] = tree[deep][i];     }     if (l != r) {       build(deep + 1, l, mid);       build(deep + 1, mid + 1, r);     }   }   int ask(int deep, int l, int r, int ql, int qr, int k) {     int s, ss, mid = (l + r) >> 1;     if (l == r) return tree[deep][l];     if (l == ql) {       s = 0;       ss = sum[deep][qr];     } else {       s = sum[deep][ql - 1];       ss = sum[deep][qr] - s;     }     if (k <= ss)       return ask(deep + 1, l, mid, l + s, l + s + ss - 1, k);     else       return ask(deep + 1, mid + 1, r, mid - l + 1 + ql - s,                  mid - l + 1 + qr - s - ss, k - ss);   }   inline bool cmp(int a, int b) { return a > b; }   inline int read() {     int x = 0;     char ch = getchar();     bool positive = 1;     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) positive = 0;     for (; isdigit(ch); ch = getchar()) x = x * 10 + ch -  0 ;     return positive ? x : -x;   }   inline void write(int a) {     if (a >= 10) write(a / 10);     putchar( 0  + a % 10);   }   int main() {     n = read();     m = read();     for (int i = 1; i <= n; i++) a[i] = tree[0][i] = sorted[i] = read();     sort(sorted + 1, sorted + 1 + n, cmp);     build(0, 1, n);     while (m--) {       int s1 = read(), s2 = read(), s3 = read();       if (ask(0, 1, n, s1, s2, s2 - s3 + 1) == a[s3])         puts( Yes );       else         puts( No );     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 210, INF = 1 * 1000 * 1000 * 1000 + 10, maxm = 150, maxk = 10;   int n, m, k, sar, now, par[maxn], x[maxk], c[maxn], d[maxn], f[maxn][maxn],       dp[maxm][maxn], dx[4] = {-1, 1, 0, 0}, dy[4] = {0, 0, -1, 1}, cur, X, Y,                       save;   vector<int> t[maxm][maxn], path[maxn][maxn];   queue<int> q;   bool mark[maxn];   char ans[maxn][maxn];   inline bool valid(int &a, int &b) { return a >= 0 && a < n && b >= 0 && b < m; }   inline void SPFA() {     while (!q.empty()) {       sar = q.front();       X = sar / m;       Y = sar % m;       q.pop();       mark[sar] = 0;       for (int i = 0; i < 4; i++) {         X += dx[i];         Y += dy[i];         save = X * m + Y;         if (valid(X, Y) && d[save] > d[sar] + c[save]) {           d[save] = d[sar] + c[save];           par[save] = sar;           if (!mark[save]) {             q.push(save);             mark[save] = 1;           }         }         X -= dx[i];         Y -= dy[i];       }     }   }   int main() {     ios::sync_with_stdio(0);     cin >> n >> m >> k;     for (int i = 0; i < n * m; i++) cin >> c[i];     for (int i = 0; i < n * m; i++) {       for (int j = 0; j < n * m; j++) d[j] = INF;       d[i] = 0;       par[i] = -1;       mark[i] = 1;       q.push(i);       SPFA();       for (int j = 0; j < n * m; j++) {         f[i][j] = d[j];         now = j;         while (par[now] != -1) {           path[i][j].push_back(now);           now = par[now];         }       }     }     memset(dp, 63, sizeof dp);     for (int i = 0; i < k; i++) {       cin >> X >> Y;       X--;       Y--;       x[i] = X * m + Y;       for (int j = 0; j < n * m; j++) {         dp[1 << i][j] = f[x[i]][j] + c[x[i]];         t[1 << i][j] = path[x[i]][j];         t[1 << i][j].push_back(x[i]);       }     }     for (int i = 3; i < (1 << k); i++) {       if (__builtin_popcount(i) > 1) {         for (int j = 0; j < n * m; j++) {           for (int sub = i; sub; sub = (sub - 1) & i) {             if (sub == i) continue;             cur = i ^ sub;             for (int p = 0; p < n * m; p++) {               if (dp[sub][p] + dp[cur][p] + f[p][j] - c[p] < dp[i][j]) {                 dp[i][j] = dp[sub][p] + dp[cur][p] + f[p][j] - c[p];                 save = sub;                 X = p;               }             }           }           cur = i ^ save;           t[i][j] = path[X][j];           for (int p = 0; p < ((int(t[save][X].size()))); p++)             t[i][j].push_back(t[save][X][p]);           for (int p = 0; p < ((int(t[cur][X].size()))); p++) {             if (t[cur][X][p] != X) t[i][j].push_back(t[cur][X][p]);           }         }       }     }     cout << dp[(1 << k) - 1][x[0]];     for (int i = 0; i < ((int(t[(1 << k) - 1][x[0]].size()))); i++)       ans[t[(1 << k) - 1][x[0]][i] / m][t[(1 << k) - 1][x[0]][i] % m] =  X ;     for (int i = 0; i < n; i++) {       cout << endl;       for (int j = 0; j < m; j++) {         if (ans[i][j] ==  X )           cout << ans[i][j];         else           cout <<  . ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1 << 21 | 1;   int n, p[N];   long long a[N], b[N], c[N];   char s[N], t[N];   void OR(long long* a) {     int i, j, u, v, l, t;     for (i = 2; i <= n; i <<= 1)       for (j = 0, t = i >> 1; j < n; j += i)         for (u = j, v = l = j + t; u < l; ++u, ++v) a[v] += a[u];   }   void IOR(long long* a) {     int i, j, u, v, l, t;     for (i = 2; i <= n; i <<= 1)       for (j = 0, t = i >> 1; j < n; j += i)         for (u = j, v = l = j + t; u < l; ++u, ++v) a[v] -= a[u];   }   int main() {     int m, i;     scanf( %d%s%s , &m, s, t), n = 1 << m;     for (i = 1; i < n; ++i) p[i] = p[i - (i & -i)] + 2;     for (i = 0; i < n; ++i)       a[i] = (s[i] - 48ll) << p[i], b[i] = (t[i] - 48ll) << p[i];     OR(a), OR(b);     for (i = 0; i < n; ++i) c[i] = a[i] * b[i];     IOR(c);     for (i = 0; i < n; ++i) putchar(c[i] >> p[i] & 3 | 48);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 100;   const double PI = 3.14159;   vector<int> v;   long long n, m, k, t, ans, sum, r, l, b, c, d, a;   bool f;   string s;   set<int> st;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cin >> n >> m;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       sum += x;       ans += sum / m;       sum %= m;       cout << ans <<    ;       ans = 0;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int INF = 1e9 + 5;   const long long INF64 = 1e18;   string to_string(const string &s) { return     + s +    ; }   string to_string(bool b) { return b ?  true  :  false ; }   template <typename A, typename B>   string to_string(pair<A, B> p) {     return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;   }   template <typename T>   string to_string(const vector<T> &v) {     string ret =  < ;     for (auto it : v) ret += to_string(it) +  ,  ;     ret.pop_back();     ret.pop_back();     ret +=  > ;     return ret;   }   void debug_print() { cerr << endl; }   template <typename T, typename... U>   void debug_print(T t, U... u) {     cerr <<     << to_string(t);     debug_print(u...);   }   const int N = 1e5 + 5;   long long mulmod(long long a, long long b) {     a %= MOD;     b %= MOD;     return (a * b) % MOD;   }   long long f(long long n) {     long long r = (n + 1) / 2;     if (n & 1) return mulmod(r, r);     return mulmod(r, r + 1);   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0);     int t;     cin >> t;     while (t--) {       long long n;       cin >> n;       n += 2;       n /= 2;       cout << f(n) <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 7;   bool vis[N];   int n, a[N], go[N];   pair<int, int> v[N];   bool isLucky(int x) {     while (x > 0) {       if (x % 10 != 4 && x % 10 != 7) return false;       x /= 10;     }     return true;   }   void solve() {     bool hasLN = false;     for (int i = (0); i < (n); ++i)       if (isLucky(a[i])) {         hasLN = true;         break;       }     if (!hasLN) {       for (int i = (0); i < (n - 1); ++i)         if (a[i] > a[i + 1]) {           puts( -1 );           return;         }       puts( 0 );       return;     }     for (int i = (0); i < (n); ++i) v[i] = make_pair(a[i], i);     sort(v, v + n);     for (int i = (0); i < (n); ++i) go[v[i].second] = i;     vector<pair<int, int> > ans;     for (int i = (0); i < (n); ++i)       if (!vis[i] && isLucky(a[i])) {         vector<int> vec;         int x = go[i];         while (!vis[x]) {           vec.push_back(x), vis[x] = true;           x = go[x];         }         if (((int)(vec).size()) == 1) continue;         for (int j = (((int)(vec).size()) - 1) - 1; j >= (0); --j) {           ans.push_back(make_pair(vec[j], vec[j + 1]));           swap(a[vec[j]], a[vec[j + 1]]);         }       }     int p;     for (int i = (0); i < (n); ++i)       if (vis[i] && isLucky(a[i])) {         p = i;         break;       }     for (int i = (0); i < (n); ++i)       if (!vis[i]) {         vector<int> vec;         int x = i;         while (!vis[x]) {           vec.push_back(x), vis[x] = true;           x = go[x];         }         if (((int)(vec).size()) == 1) continue;         for (int j = (((int)(vec).size())) - 1; j >= (0); --j) {           ans.push_back(make_pair(p, vec[j]));           swap(p, vec[j]);           swap(a[p], a[vec[j]]);         }         ans.push_back(make_pair(p, vec.back()));         swap(p, vec.back());         swap(a[p], a[vec.back()]);       }     if (((int)(ans).size()) > 2 * n) {       puts( -1 );       return;     }     printf( %d n , ((int)(ans).size()));     for (int i = (0); i < (((int)(ans).size())); ++i) {       int x, y;       tie(x, y) = ans[i];       printf( %d %d n , x + 1, y + 1);     }   }   int main() {     scanf( %d , &n);     for (int i = (0); i < (n); ++i) scanf( %d , a + i);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   namespace IO {   bool REOF = 1;   inline char nc() {     static char buf[100000], *p1 = buf, *p2 = buf;     return p1 == p2 && REOF &&                    (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)                ? (REOF = 0, EOF)                : *p1++;   }   template <class T>   inline bool read(T &x) {     if (!REOF) return false;     char c = nc();     bool f = 0;     x = 0;     while (c <  0  || c >  9 ) c ==  -  && (f = 1), c = nc();     while (c >=  0  && c <=  9 ) x = (x << 3) + (x << 1) + (c ^ 48), c = nc();     if (f) x = -x;     return true;   }   template <typename T, typename... T2>   inline bool read(T &x, T2 &...rest) {     if (!REOF) return false;     read(x);     return read(rest...);   }   inline bool need(char &c) {     return ((c >=  a ) && (c <=  z )) || ((c >=  0 ) && (c <=  9 )) ||            ((c >=  A ) && (c <=  Z ));   }   inline bool read_str(char *a) {     if (!REOF) return false;     while ((*a = nc()) && need(*a) && REOF) ++a;     *a =   0 ;     return true;   }   inline bool read_dbl(double &x) {     if (!REOF) return false;     bool f = 0;     char ch = nc();     x = 0;     while (ch <  0  || ch >  9 ) {       f |= (ch ==  - );       ch = nc();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10.0 + (ch ^ 48);       ch = nc();     }     if (ch ==  . ) {       double tmp = 1;       ch = nc();       while (ch >=  0  && ch <=  9 ) {         tmp = tmp / 10.0;         x = x + tmp * (ch ^ 48);         ch = nc();       }     }     if (f) x = -x;     return true;   }   template <class TH>   void _dbg(const char *sdbg, TH h) {     cerr << sdbg <<  =  << h <<   n ;   }   template <class TH, class... TA>   void _dbg(const char *sdbg, TH h, TA... a) {     while (*sdbg !=  , ) cerr << *sdbg++;     cerr <<  =  << h <<  ,  <<    ;     _dbg(sdbg + 1, a...);   }   template <class T>   ostream &operator<<(ostream &os, vector<T> V) {     os <<  [ ;     for (auto vv : V) os << vv <<  , ;     return os <<  ] ;   }   template <class L, class R>   ostream &operator<<(ostream &os, pair<L, R> P) {     return os <<  (  << P.st <<  ,  << P.nd <<  ) ;   }   }  // namespace IO   using namespace IO;   const int maxn = 2e5 + 5;   const int mod = 998244353;   const int INF = 1e9 + 7;   const double eps = 1e-12;   int dx[4] = {0, 0, 1, -1};   int dy[4] = {1, -1, 0, 0};   int n, x, y;   int best() {     int z = x + y + 1;     return max(z - n, 1);   }   int worst() {     int z = x + y;     return min(z - 1, n);   }   void solve() {     read(n, x, y);     if (x > y) swap(x, y);     if (x == 1 && y == 1) {       printf( 1 1 n );       return;     }     if (x == n && y == n) {       printf( %d %d n , n, n);       return;     }     printf( %d %d n , best(), worst());   }   int main() {     int _T;     read(_T);     for (int _ = 1; _ <= _T; _++) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   unsigned long long int a, b, c, l;   int main() {     ios::sync_with_stdio(false);     cin >> a >> b >> c >> l;     unsigned long long int ans = ((l + 3) * (l + 2) * (l + 1)) / (6);     for (int i = 0; i <= l; i++) {       if (a + i >= b + c) {         unsigned long long int x =             ((a + i - b - c) < (l - i) ? (a + i - b - c) : (l - i));         ans -= ((x + 2) * (x + 1)) / (2);       }     }     for (int i = 0; i <= l; i++) {       if (b + i >= a + c) {         unsigned long long int x =             ((b + i - a - c) < (l - i) ? (b + i - a - c) : (l - i));         ans -= ((x + 2) * (x + 1)) / (2);       }     }     for (int i = 0; i <= l; i++) {       if (c + i >= b + a) {         unsigned long long int x =             ((c + i - a - b) < (l - i) ? (c + i - a - b) : (l - i));         ans -= ((x + 2) * (x + 1)) / (2);       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 1e6 + 5;   string s;   long long a, b;   long long v[N], pre[N], suf[N];   int32_t main() {     cin >> s >> a >> b;     long long n = s.size();     for (long long i = 1; i <= n; i++) v[i] = s[i - 1] -  0 ;     for (long long i = 1; i <= n; i++) {       pre[i] = pre[i - 1] * 10 + v[i];       pre[i] %= a;     }     long long curpow = 1;     for (long long i = n; i >= 1; i--) {       suf[i] = v[i] * curpow + suf[i + 1];       curpow *= 10;       curpow %= b;       suf[i] %= b;     }     long long check = 0, ind;     for (long long i = 1; i < n; i++) {       if (pre[i] == 0 && suf[i + 1] == 0 && v[i + 1] != 0) {         ind = i;         check = 1;       }     }     if (check) {       cout <<  YES             <<   n ;       for (long long i = 1; i <= ind; i++) {         cout << v[i];       }       cout <<   n ;       for (long long i = ind + 1; i <= n; i++) {         cout << v[i];       }     } else       cout <<  NO ;   }
#include <bits/stdc++.h>   using namespace std;   int de(int x) {     if (x == 0) return 0;     if (x & 1) return de(x / 2) + 1;     return de(x / 2);   }   long long val[101000];   int main() {     int n, i, j, a;     while (scanf( %d , &n) != EOF) {       memset(val, 0, sizeof(val));       for (i = 0; i < n; i++) {         scanf( %d , &a);         val[de(a)]++;       }       long long ans = 0;       for (i = 0; i <= 50000; i++) ans += (val[i] * (val[i] - 1)) / 2;       printf( %I64d n , ans);     }   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:16777216 )   using namespace std;   const int M1 = 1000000007;   const int M2 = 1000000087;   int N;   int H1[310000];   int P1[310000];   int H2[310000];   int P2[310000];   int HH1, HH2;   int n, m;   vector<int> g[100007];   string s[100007];   char t[300007];   int ans;   void precalc() {     H1[0] = H2[0] = 0;     P1[0] = P2[0] = 1;     for (int i = 1; i < 300007; i++) {       P1[i] = (P1[i - 1] * 31LL) % M1;       P2[i] = (P2[i - 1] * 37LL) % M2;     }     for (int i = 0, _n = (m); i < _n; ++i) {       char c = t[i] -  a  + 1;       HH1 = (HH1 * 31LL + c) % M1;       HH2 = (HH2 * 37LL + c) % M2;     }   }   void addChar(char c) {     c = c -  a  + 1;     H1[N + 1] = (H1[N] * 31LL + c) % M1;     H2[N + 1] = (H2[N] * 37LL + c) % M2;     N++;   }   bool isTail() {     if (N < m) return false;     int r = N - 1;     int l = r - m + 1;     int CH1 = H1[r + 1] - ((long long)H1[l] * P1[r - l + 1]) % M1;     if (CH1 < 0) CH1 += M1;     int CH2 = H2[r + 1] - ((long long)H2[l] * P2[r - l + 1]) % M2;     if (CH2 < 0) CH2 += M2;     return CH1 == HH1 && CH2 == HH2;   }   void dfs(int v) {     for (int i = 0, _n = ((int)((s[v]).size())); i < _n; ++i) {       addChar(s[v][i]);       ans += isTail();     }     for (int i = 0, _n = ((int)((g[v]).size())); i < _n; ++i) dfs(g[v][i]);     N -= (int)((s[v]).size());   }   void solution() {     scanf( %d n , &n);     for (int i = 0, _n = (n - 1); i < _n; ++i) {       int p;       scanf( %d %s n , &p, t);       s[i + 1] = string(t);       g[p - 1].push_back(i + 1);     }     m = strlen(gets(t));     precalc();     dfs(0);     printf( %d n , ans);   }   int main() {     solution();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       bool usa[n], usb[n];       for (int i = 0; i < n; ++i) {         usa[i] = 1;         usb[i] = 1;       }       for (int i = 0; i < n; ++i) {         int a;         cin >> a;         bool f = 1;         for (int j = 0; j < a; j++) {           int b;           cin >> b;           if (usb[b - 1] && f) {             usb[b - 1] = 0;             usa[i] = 0;             f = 0;           }         }       }       bool c = 0, d = 0;       int x, y;       for (int i = 0; i < n; ++i) {         if (usa[i] && !c) {           x = i + 1;           c = 1;         }         if (usb[i] && !d) {           y = i + 1;           d = 1;         }       }       if (c)         cout <<  IMPROVE  << endl << x <<     << y << endl;       else         cout <<  OPTIMAL  << endl;     }   }