malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const long long maxS = 2e5 + 5;   long long N, M;   long long A[201], B[201];   long long DP[201][515];   long long go(long long pos, long long prev) {     if (pos == N + 1) return 0;     if (DP[pos][prev] != -1) return DP[pos][prev];     long long ans = INT_MAX;     for (long long i = 1; i <= M; i++)       ans = min(ans,                 (prev | (A[pos] & B[i]) | go(pos + 1, (prev | (A[pos] & B[i])))));     return DP[pos][prev] = ans;   }   void code_idhr_h() {     cin >> N >> M;     for (long long i = 1; i <= N; i++) cin >> A[i];     for (long long i = 1; i <= M; i++) cin >> B[i];     memset(DP, -1, sizeof DP);     cout << go(1, 0) <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long T = 1;     for (long long t = 1; t <= T; t++) {       code_idhr_h();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 5000000 + 10;   const int mod = 51123987;   int n;   long long p[maxn], sum;   char s1[maxn], s[maxn];   long long min(int a, int b) { return a < b ? a : b; }   inline void init() {     s[0] =  $ ;     for (int i = 1; i <= n; ++i) s[2 * i] = s1[i], s[2 * i - 1] =  # ;     s[2 * n + 1] =  # ;     n = 2 * n + 1;   }   inline void manacher() {     init();     p[0] = 0;     for (int i = 1, id = 0, mx = 0; i <= n; ++i) {       if (mx > i)         p[i] = min(mx - i + 1, p[2 * id - i]);       else         p[i] = 0;       while (s[i - p[i]] == s[i + p[i]]) ++p[i];       if (i + p[i] - 1 > mx) id = i, mx = i + p[i] - 1;       sum += (p[i] - 1) / 2;       if (i % 2 == 0) ++sum;     }   }   long long f[maxn], g[maxn];   inline void solve() {     sum %= mod;     sum = sum * (sum - 1) / 2;     sum %= mod;     for (int i = 2; i <= n; i += 2) {       ++f[i - p[i] + 2];       --f[i + 2];       ++g[i];       --g[i + p[i]];     }     for (int i = 1; i <= n; i += 2) {       ++f[i - p[i] + 2];       --f[i + 1];       ++g[i + 1];       --g[i + p[i]];     }     for (int i = 2; i <= n; i += 2) {       f[i] += f[i - 2];       f[i] %= mod;       g[i] += g[i - 2];       g[i] %= mod;     }     f[n + 1] = 0;     for (int i = n - 1; i >= 1; i -= 2) f[i] += f[i + 2];     for (int i = 2; i <= n; i += 2) {       sum = sum - (g[i] * f[i + 2]) % mod;       sum = (sum + mod) % mod;     }     sum = (sum + mod) % mod;     printf( %I64d n , sum);   }   int main() {     scanf( %d%s , &n, s1 + 1);     manacher();     solve();     return 0;   }
#include <bits/stdc++.h>   char ar[10][10];   int q[10 * 10 * 10 * 10][3];   bool forb[10][10][10 * 10];   bool used[10][10][10 * 10];   int dir[9][2] = {{1, 1},  {1, 0},  {1, -1}, {0, 1},  {0, 0},                    {0, -1}, {-1, 1}, {-1, 0}, {-1, -1}};   void BFS(void) {     int x = 8, y = 1;     q[1][0] = x;     q[1][1] = y;     q[1][2] = 1;     used[x][y][1] = 1;     for (int al = 1, at = 1; al <= at; al++) {       x = q[al][0];       y = q[al][1];       if (x == 1 && y == 8) {         printf( WIN n );         return;       }       for (int i = 0; i < 9; i++) {         int cx = x + dir[i][0];         int cy = y + dir[i][1];         if (cx > 0 && cx <= 8 && cy > 0 && cy <= 8)           if (!used[cx][cy][q[al][2] + 1])             if (!forb[cx][cy][q[al][2]] && !forb[cx][cy][q[al][2] + 1]) {               q[++at][0] = cx;               q[at][1] = cy;               q[at][2] = q[al][2] + 1;               used[cx][cy][q[al][2] + 1] = 1;             }       }     }     printf( LOSE n );   }   int main() {     for (int i = 1; i <= 8; i++)       for (int j = 1; j <= 8; j++) {         scanf(  %c , &ar[i][j]);         if (ar[i][j] ==  S )           for (int k = i; k <= 8; k++) forb[k][j][k - i + 1] = 1;       }     BFS();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using pii = pair<int, int>;   using vi = vector<int>;   constexpr int MOD = 998244353;   int sum(int a, int b, int mod = MOD) {     int c = a + b;     if (c >= mod) {       c -= mod;     }     return c;   }   inline int prod(int a, int b, int mod = MOD) { return (1LL * a * b) % mod; }   int modpow(int base, ll exp, int mod = MOD) {     int res = 1;     int cur = base;     for (ll p = 1LL; p <= exp; p <<= 1LL) {       if (p & exp) {         res = prod(res, cur, mod);       }       cur = prod(cur, cur, mod);     }     return res;   }   inline int inv(int x, int mod = MOD) { return modpow(x, mod - 2, mod); }   constexpr int MAXN = 1e6 + 6;   int fact[MAXN], tcaf[MAXN];   void gen_fact() {     fact[0] = 1;     for (int i = 1; i < MAXN; ++i) {       fact[i] = prod(fact[i - 1], i);     }     tcaf[MAXN - 1] = inv(fact[MAXN - 1]);     for (int i = MAXN - 2; i >= 0; --i) {       tcaf[i] = prod(tcaf[i + 1], i + 1);     }   }   int choose(int n, int k) {     assert(n >= 0);     assert(0 <= k and k <= n);     return prod(fact[n], prod(tcaf[k], tcaf[n - k]));   }   int solve(ll n) {     int ans = modpow(3, 1LL * n * n);     for (int i = 1; i <= n; ++i) {       int x = prod(choose(n, i), modpow(3, 1LL * (n * (n - i)) + i));       int v = prod(2, x);       if (i % 2 == 0) {         ans = sum(ans, v);       } else {         ans = sum(ans, MOD - v);       }     }     for (int i = 1; i < n; ++i) {       int v = prod(6, choose(n, i));       if ((i + n) % 2 == 0) {         ans = sum(ans, v);       } else {         ans = sum(ans, MOD - v);       }     }     ans = sum(ans, 3);     int square_sum = 0;     for (int i = 1; i < n; ++i) {       int row_sum = modpow(1 + MOD - modpow(3, i), n);       row_sum = sum(row_sum, MOD - 1);       row_sum = sum(row_sum, MOD - modpow(MOD - modpow(3, i), n));       square_sum =           sum(square_sum, prod(modpow(MOD - 1, i), prod(choose(n, i), row_sum)));     }     ans = sum(ans, prod(3, square_sum));     return sum(modpow(3, 1LL * n * n), MOD - ans);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     gen_fact();     int n;     cin >> n;     cout << solve(n);     return 0;   }
#include <bits/stdc++.h>   #pragma warning(disable : 4996)   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     string s;     cin >> s;     long long l = -1, r = -1;     for (long long i = 0; i < s.length(); i++) {       if (s[i] ==  [ ) {         l = i;         break;       }     }     for (long long i = s.length(); i >= 0; i--) {       if (s[i] ==  ] ) {         r = i;         break;       }     }     if (l == -1 || r == -1 || r < l)       cout <<  -1             <<   n ,           exit(0);     s = s.substr(l, r - l + 1);     l = -1;     r = -1;     for (long long i = 1; i < s.length() - 1; i++) {       if (s[i] ==  : ) {         l = i;         break;       }     }     for (long long i = s.length() - 2; i >= 1; i--) {       if (s[i] ==  : ) {         r = i;         break;       }     }     if (l == r || l == -1) cout <<  -1 n , exit(0);     string v = s.substr(l, r - l + 1);     long long ct = 0;     for (auto it : v) {       if (it ==  | ) ct++;     }     cout << ct + 4 <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, car[101][101];     bool t[101] = {0};     vector<int> ans;     ans.clear();     scanf( %d , &n);     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         scanf( %d , &car[i][j]);         if (car[i][j] == 2) {           t[j] = true;         } else if (car[i][j] == 1) {           t[i] = true;         } else if (car[i][j] == 3) {           t[i] = true;           t[j] = true;         }       }     }     for (int i = 0; i < n; i++) {       if (t[i] == false) ans.push_back(i + 1);     }     printf( %d n , ans.size());     for (int i = 0; i < ans.size(); i++) {       printf( %d , ans[i]);       if (i < ans.size() - 1) printf(   );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 4003;   int t[N][N];   int a;   string s;   map<long long, long long> mp;   long long acc[N];   int main() {     cin >> a >> s;     int n = s.size();     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) t[i][j] = (s[i] -  0 ) * (s[j] -  0 );     for (int i = 0; i < n; i++) {       long long sum = 0;       for (int j = 0; j <= i; j++) sum += (s[j] -  0 );       acc[i] = sum;     }     acc[-1] = 0;     for (int i = 0; i < n; i++)       for (int j = 0; j <= i; j++) {         long long sum = acc[i] - acc[j - 1];         mp[sum]++;       }     long long ans = 0;     for (int i = 0; i < n; i++) {       long long sum = 0;       for (int j = 0; j <= i; j++) {         sum = acc[i] - acc[j - 1];         if (sum)           if (a % sum == 0) {             ans += mp[a / sum];           }         if (!sum && !a) ans += n * (n + 1) / 2;       }     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   T sqr(T X) {     return X * X;   }   const int maxn = 110;   const double zero = 1e-8;   int n, K;   double omiga;   struct COO {     double x, y;   } ob[maxn], nuclear;   double p[maxn], f[maxn][maxn];   double numb;   double ans;   void init() {     scanf( %d , &n);     scanf( %d%lf , &K, &omiga);     omiga = 1.0 - omiga / 1000;     scanf( %lf%lf , &nuclear.x, &nuclear.y);     for (int i = 1; i <= n; i++) scanf( %lf%lf , &ob[i].x, &ob[i].y);   }   int ZO(double comX, double comY) {     if (abs(comY - comX) <= zero) return 0;     if (comX < comY)       return -1;     else       return 1;   }   void work1(double R) {     for (int i = 1; i <= n; i++) {       double Di = sqr(nuclear.x - ob[i].x) + sqr(nuclear.y - ob[i].y);       if (ZO(Di, sqr(R)) <= 0)         p[i] = 1.0;       else         p[i] = exp(1 - Di / sqr(R));     }   }   void dp() {     for (int i = 0; i <= n; i++)       for (int j = 0; j <= n; j++) f[i][j] = 0.0;     f[0][0] = 1.0;     for (int i = 1; i <= n; i++) f[i][0] = f[i - 1][0] * (1 - p[i]);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= i; j++)         f[i][j] = f[i - 1][j - 1] * p[i] + f[i - 1][j] * (1.0 - p[i]);     numb = 0.0;     for (int j = K; j <= n; j++) numb += f[n][j];   }   void solve() {     double Lx = 0, Rx = 4000.0;     while (ZO(Lx, Rx) < 0) {       double mid = (Lx + Rx) / 2;       work1(mid);       dp();       if (numb >= omiga)         Rx = mid;       else         Lx = mid;     }     ans = Lx;   }   void print() { printf( %.10lf n , ans); }   int main() {     init();     solve();     print();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e18;   const int nax = 1e3 + 20;   const int mod = 1e9 + 7;   int fact[nax];   int binpow(int a, int e) {     int ans = 1;     while (e > 1) {       if (e & 1) {         ans = (1LL * ans * a) % mod;         --e;       }       a = (1LL * a * a) % mod;       e >>= 1;     }     ans = (1LL * ans * a) % mod;     return ans;   }   int C(int n, int k) {     if (k > n) return 0;     return (1LL * fact[n] *             (1LL * binpow(fact[n - k], mod - 2) * binpow(fact[k], mod - 2) %              mod)) %            mod;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cout << setprecision(20) << fixed;     fact[0] = 1;     for (int i = 1; i <= (int)nax - 1; ++i) {       fact[i] = (1LL * fact[i - 1] * i) % mod;     }     int n, m, k;     cin >> n >> m >> k;     cout << (1LL * C(n - 1, 2 * k) * C(m - 1, 2 * k)) % mod <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   template <class X, class Y>   void amax(X& x, const Y& y) {     if (x < y) x = y;   }   template <class X, class Y>   void amin(X& x, const Y& y) {     if (x > y) x = y;   }   const int INF = 1e9 + 10;   const long long INFL = (long long)1e18 + 10;   const int MAX = 2e5 + 10;   int n;   long long l[MAX], r[MAX];   map<long long, long long> cnt, inc, ddec;   void process() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> l[i] >> r[i];     long long maxr = 0, minl = INFL;     for (int i = 1; i <= n; i++) {       inc[l[i]] = ddec[l[i]] = 0;       inc[r[i]] = ddec[r[i]] = 0;       amax(maxr, r[i]);       amin(minl, l[i]);     }     ddec[maxr + 1] = 0;     for (int i = 1; i <= n; i++) {       inc[l[i]]++;       auto p2 = ddec.find(r[i]);       p2 = next(p2);       p2->second++;     }     long long ppost = minl - 1;     int psum = 0;     for (auto p : inc) {       psum -= ddec[p.first];       cnt[psum] += p.first - ppost - 1;       psum += p.second;       cnt[psum]++;       ppost = p.first;     }     for (int i = 1; i <= n; i++) cout << cnt[i] <<    ;   }   int main() {     ios_base::sync_with_stdio(false);     process();   }
#include <bits/stdc++.h>   int main() {     long long int m, n, a;     scanf( %lld %lld %lld , &m, &n, &a);     if (m % a == 0 && n % a == 0) {       printf( %lld , m * n / a / a);     }     if (m % a != 0 && n % a == 0) {       printf( %lld , ((m + a) / a) * (n / a));     }     if (m % a != 0 && n % a != 0) {       printf( %lld , ((m + a) / a) * ((n + a) / a));     }     if (m % a == 0 && n % a != 0) {       printf( %lld , m / a * ((n + a) / a));     }   }
#include <bits/stdc++.h>   using namespace std;   vector<int> e[200000 + 5];   int main() {     int T, n;     int m, p;     scanf( %d , &T);     for (int t = 1; t <= T; ++t) {       scanf( %d , &n);       for (int i = 0; i <= n; ++i) e[i].clear();       for (int i = 1; i <= n; ++i) {         scanf( %d%d , &m, &p);         e[m].push_back(p);       }       priority_queue<int, vector<int>, greater<int> > que;       long long ans = 0;       for (int i = n; i >= 0; --i) {         int len = e[i].size();         for (int j = 0; j < len; ++j) que.push(e[i][j]);         while (que.size() > n - i) {           ans += que.top();           que.pop();         }       }       printf( %lld n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> v[200009];   set<int> ss;   pair<int, int> help[200009];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       int a, b;       scanf( %d %d , &a, &b);       v[a].push_back(b);     }     for (int i = 1; i <= n; i++) sort(v[i].begin(), v[i].end());     help[0] = pair<int, int>(0, 0);     for (int i = 1; i <= n; i++)       if (v[i].size() != 0)         help[i] = pair<int, int>(v[i][v[i].size() - 1], i);       else         help[i] = pair<int, int>(0, 0);     sort(help, help + n + 1);     int q;     cin >> q;     for (int i = 0; i < q; i++) {       ss.clear();       int k;       cin >> k;       for (int i = 0; i < k; i++) {         int a;         scanf( %d , &a);         ss.insert(a);       }       int A, B;       A = B = -1;       for (int j = n; j >= 1; j--) {         if (help[j].first == 0) break;         if (A != -1 && B != -1) break;         if (A == -1) {           if (ss.find(help[j].second) == ss.end() && help[j].second != 0)             A = help[j].second;         } else {           if (ss.find(help[j].second) == ss.end() && help[j].second != 0)             B = help[j].second;         }       }       if (B == -1 && A == -1)         printf( 0 0 n );       else if (B == -1)         printf( %d %d n , A, v[A][0]);       else {         int x = v[B][v[B].size() - 1];         int y = *lower_bound(v[A].begin(), v[A].end(), x);         printf( %d %d n , A, y);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char a[100010];   int c[100010];   const int mod = 1000000007;   long long Pow(long long a, long long b, long long c) {     long long ans = 1;     while (b) {       if (b & 1) ans = ans * a % c;       b >>= 1;       a = a * a % c;     }     return ans;   }   int main() {     scanf( %s , a);     int n = strlen(a), k;     int cnt0 = count(a, a + n,  0 );     int cnt5 = count(a, a + n,  5 );     int cnt = 0;     for (int i = 0; i <= n - 1; i++) {       if (a[i] ==  0  || a[i] ==  5 ) {         c[cnt++] = i;       }     }     scanf( %d , &k);     long long tmp1 = Pow(2, (long long)n * k, mod);     tmp1 -= 1;     if (tmp1 < 0) tmp1 += mod;     long long tmp2 = Pow(2, n, mod);     tmp2 -= 1;     if (tmp2 < mod) tmp2 += mod;     tmp2 = Pow(tmp2, mod - 2, mod);     long long ans = 0;     for (int i = 0; i <= cnt - 1; i++) {       ans += Pow(2, c[i], mod) * tmp1 % mod * tmp2 % mod;       if (ans >= mod) ans -= mod;     }     printf( %I64d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, ans = 0, xs, ys, xe, ye;     char q[105][105];     cin >> n >> m;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         cin >> q[i][j];         if (q[i][j] ==  S ) {           xs = i;           ys = j;         }         if (q[i][j] ==  E ) {           xe = i;           ye = j;         }       }     }     string line;     cin >> line;     int x, y;     for (int w = 0; w <= 3; ++w) {       for (int l = 0; l <= 3; ++l) {         for (int s = 0; s <= 3; ++s) {           for (int r = 0; r <= 3; ++r) {             if (w == l || w == s || w == r) {               continue;             }             if (l == s || l == r) {               continue;             }             if (s == r) {               continue;             }             x = xs;             y = ys;             for (int i = 0; i < line.size(); ++i) {               int p = line[i] -  0 ;               if (p == w) {                 x++;                 if (x >= n) {                   break;                 }               }               if (p == l) {                 y--;                 if (y < 0) {                   break;                 }               }               if (p == s) {                 x--;                 if (x < 0) {                   break;                 }               }               if (p == r) {                 y++;                 if (y >= m) {                   break;                 }               }               if (x == xe && y == ye) {                 break;               }               if (q[x][y] ==  # ) {                 break;               }             }             if (x == xe && y == ye) {               ans++;             }           }         }       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double TOLL = 1e-9;   int N, L, K;   int a[210];   double p[210];   const int maxn = 400;   double dp[201][401][maxn + 2];   double rec(int ind, int l, int cap) {     if (cap < -202) cap = -200;     if (cap > 202) cap = 200;     if (ind == N) {       if (l <= 0 && cap >= 0) return 1;       return 0;     }     if (dp[ind][l + 200][cap + 200] > -.5) return dp[ind][l + 200][cap + 200];     double rv = p[ind] * rec(ind + 1, l - 1, cap + a[ind]) +                 (1 - p[ind]) * rec(ind + 1, l, cap);     return dp[ind][l + 200][cap + 200] = rv;   }   int main() {     while (cin >> N >> L >> K) {       for (int i = 0; i < N; i++) {         cin >> p[i];         p[i] /= 100;       }       for (int i = 0; i < N; i++) cin >> a[i];       memset(dp, -1, sizeof dp);       printf( %.12lf n , rec(0, L, K));     }   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops,fast-math )   using namespace std;   const int N = 2e5 + 100, sq = 1002, nsq = 200;   int cnt[nsq][N], b[nsq][N / 2];   int a[N];   map<int, int> mp, nmp;   vector<pair<int, pair<int, int> > > q;   void add(int id, int val) {     while (id < nsq) {       cnt[id][val]++;       b[id][cnt[id][val]]++;       id++;     }   }   void rem(int id, int val) {     while (id < nsq) {       b[id][cnt[id][val]]--;       cnt[id][val]--;       id++;     }   }   int get1(int id) {     int val = a[id];     int pid = id / sq;     int ans = cnt[pid][val];     int x = pid * sq;     for (int i = x; i <= id; i++) {       if (a[i] == val) ans++;     }     return ans;   }   int get2(int id) {     int val = a[id];     int pid = id / sq;     int w = cnt[pid][val];     int x = pid * sq;     for (int i = x; i <= id; i++) {       if (a[i] == val) w++;     }     int ans = b[pid][w];     for (int i = x; i <= id; i++) {       cnt[pid][a[i]]++;       if (cnt[pid][a[i]] == w) ans++;     }     for (int i = x; i <= id; i++) {       cnt[pid][a[i]]--;     }     return ans;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     vector<int> mol;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       mol.push_back(a[i]);     }     int q1;     cin >> q1;     for (int i = 0; i < q1; i++) {       int t, u, v;       cin >> t >> u >> v;       if (t == 1) mol.push_back(u);       q.push_back({t, {u, v - 1}});     }     sort(mol.begin(), mol.end());     mol.resize(unique(mol.begin(), mol.end()) - mol.begin());     for (int i = 0; i < mol.size(); i++) {       mp[mol[i]] = i + 1;       nmp[i + 1] = mol[i];     }     for (int i = 0; i < n; i++) a[i] = mp[a[i]];     for (int i = 0; i < q1; i++)       if (q[i].first == 1) q[i].second.first = mp[q[i].second.first];     int id = 0;     while (id < n) {       for (int i = 0; i < id; i++) {         cnt[id / sq][a[i]]++;       }       for (int i = 0; i < N; i++) {         b[id / sq][cnt[id / sq][i]]++;       }       for (int i = N - 1; i; i--) {         b[id / sq][i] += b[id / sq][i + 1];       }       id += sq;     }     for (int i = 0; i < q1; i++) {       if (q[i].first == 1) {         int v = q[i].second.first, p = q[i].second.second;         int z = a[p];         add(p / sq + 1, v);         rem(p / sq + 1, a[p]);         a[p] = v;       } else {         int x = q[i].second.first, y = q[i].second.second;         if (x == 1)           cout << nmp[a[y]] <<   n ;         else if (x % 2 == 0) {           int ans = get1(y);           cout << ans <<   n ;         } else {           int ans = get2(y);           cout << ans <<   n ;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   T getint() {     T x = 0, p = 1;     char ch;     do {       ch = getchar();     } while (ch <=    );     if (ch ==  - ) p = -1, ch = getchar();     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     return x * p;   }   template <typename T1, typename T2>   bool umin(T1 &x, const T2 &y) {     if (x > y) return x = y, true;     return false;   }   template <typename T1, typename T2>   bool umax(T1 &x, const T2 &y) {     if (x < y) return x = y, true;     return false;   }   const int maxn = (int)6e5 + 10;   const int inf = (int)1e9 + 5;   const int mod = (int)1e9 + 7;   const long long llinf = (long long)1e18 - 1;   const long double pi = acos(-1.0);   int nxt[maxn][26];   bool leaf[maxn];   int diff[maxn];   int c[maxn];   char s[maxn];   int n;   vector<int> g[maxn];   int sz[maxn];   int root[maxn];   int T = 1;   int calc(int v) {     int ret = leaf[v];     for (int i = (0); i < (26); i++)       if (nxt[v][i]) ret += calc(nxt[v][i]);     return ret;   }   void addTrie(int globroot, int root, int v) {     for (int c = (0); c < (26); c++) {       if (nxt[v][c] == 0) continue;       if (nxt[root][c] == 0) {         diff[globroot] += calc(nxt[v][c]);         nxt[root][c] = nxt[v][c];         continue;       }       diff[globroot] += leaf[nxt[v][c]] - leaf[nxt[root][c]];       leaf[nxt[root][c]] |= leaf[nxt[v][c]];       addTrie(globroot, nxt[root][c], nxt[v][c]);     }   }   void dfs(int v, int par = -1) {     sz[v] = 1;     int chi = -1;     for (int x : g[v]) {       if (x == par) continue;       dfs(x, v);       sz[v] += sz[x];       if (chi == -1 || sz[x] > sz[chi]) {         chi = x;       }     }     int &rt = root[v];     rt = T++;     int &link = nxt[rt][s[v] -  a ];     if (chi != -1) {       link = root[chi];       diff[rt] += diff[link];       for (int x : g[v]) {         if (x == par || x == chi) continue;         addTrie(rt, link, root[x]);       }     } else {       link = T++;     }     leaf[link] = true;     diff[rt]++;     c[v] += diff[rt];   }   int main() {     scanf( %d , &n);     for (int i = (0); i < (n); i++) scanf( %d , c + i);     gets(s);     gets(s);     for (int i = (0); i < (n - 1); i++) {       int x, y;       scanf( %d%d , &x, &y);       --x;       --y;       g[x].push_back(y), g[y].push_back(x);     }     dfs(0, -1);     int mx = c[0] + diff[0], cnt = 1;     for (int i = (1); i < (n); i++) {       int val = c[i];       if (val > mx) mx = val, cnt = 0;       if (val == mx) cnt++;     }     printf( %d n%d n , mx, cnt);     return 0;   }