malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long INF = (1e19);   int n, m;   int a[105];   bool cmp(int a, int b) { return a > b; }   bool check(int d) {     int i = 1, k = 0, ans = 0;     while (a[i] - k > 0 && i <= n) {       ans += (a[i] - k);       if (i % d == 0) {         k++;       }       if (ans >= m) {         return true;       }       i++;     }     return false;   }   int main() {     scanf( %d%d , &n, &m);     int ans = 0;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       ans += a[i];     }     if (ans < m) {       printf( -1 );     } else {       sort(a + 1, a + 1 + n, cmp);       int l = 1, r = n, p;       while (l <= r) {         int mid = (l + r) / 2;         if (check(mid)) {           r = mid - 1;           p = mid;         } else {           l = mid + 1;         }       }       printf( %d n , p);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     vector<long long> a(n);     map<long long, long long> mp;     long long ans = 0;     for (long long i = 0; i < n; i++) {       cin >> a[i];       if (mp[a[i]]) {         mp[a[i]] = 0;         mp[i + 1] = 1;       } else {         mp[i + 1] = 1;         ans++;       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using namespace std;   const int MAXN = 1005;   vector<int> child[200000];   int ceng[200000];   void dfs(int v, int ii) {     ceng[ii]++;     for (int i = 0; i < child[v].size(); i++) {       dfs(child[v][i], ii + 1);     }   }   int main() {     int n;     scanf( %d , &n);     int temp;     for (int i = 2; i <= n; i++) {       scanf( %d , &temp);       child[temp].push_back(i);     }     int ans = 0;     dfs(1, 1);     for (int i = 1; i <= n; i++) {       if (ceng[i] % (2) == 0) ceng[i] = 0;       if (ceng[i]) ceng[i] = 1;       ans += ceng[i];     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 309, mod = 1e9 + 7;   inline long long read() {     register long long x = 0, f = 1;     register char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = (x << 3) + (x << 1) + c - 48, c = getchar();     }     return x * f;   }   void pls(long long &x, long long y) {     x += y;     x = (x >= mod ? x - mod : x);   }   long long n, a[N], s[N];   namespace Solution_1 {   long long s[N], f[2][N][N];   void solve() {     long long d = 0;     for (register long long i = (1); i <= (n); i++) {       if (a[i] == a[i - 1])         s[i] = s[i - 1] + 1;       else         s[i] = 0;     }     f[0][0][0] = 1;     for (register long long i = (1); i <= (n); i++) {       if (a[i] != a[i - 1]) {         for (register long long j = (0); j <= (i); j++)           for (register long long k = (1); k <= (s[i - 1]); k++)             pls(f[d ^ 1][j][0], f[d ^ 1][j][k]), f[d ^ 1][j][k] = 0;       }       for (register long long j = (0); j <= (i); j++) {         long long upk = min(s[i], j);         for (register long long k = (0); k <= (upk); k++) {           if (j && k)             pls(f[d][j][k], f[d ^ 1][j - 1][k - 1] * (2 * s[i] - k + 1) % mod);           pls(f[d][j][k], f[d ^ 1][j][k] * (i - 2 * s[i] + 2 * k - j) % mod);           pls(f[d][j][k], f[d ^ 1][j + 1][k] * (j - k + 1) % mod);         }       }       memset(f[d ^ 1], 0, sizeof(f[d ^ 1]));       if (i != n) d ^= 1;     }     printf( %lld n , f[d][0][0]);   }   }  // namespace Solution_1   signed main() {     n = read();     for (register long long i = (1); i <= (n); i++) {       a[i] = read();       for (long long j = 2; j * j <= a[i]; j++)         while (a[i] % (j * j) == 0) a[i] /= j * j;     }     sort(a + 1, a + n + 1);     Solution_1::solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int poww(int a, int b) {     for (int i = 0; i < b; i++) a *= a;     return a;   }   int main() {     int n, t;     cin >> n;     if (n < 10) {       cout << n << endl;       return 0;     }     long long i = 2;     long long sum = 9;     long long x = 10, v[] = {999999999, 99999999, 9999999, 999999, 99999, 9999,                              999,       99,       9,       0,      0};     reverse(v, v + 11);     for (int i = 10; i > 1; i--) {       if (n - v[i] > 0) {         sum += (n - v[i]) * i;         n -= (n - v[i]);       }     }     cout << sum << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 200005;   const int M = 1000000007;   int n, m, i, j, t, k, tot, a[505][505], b[505][505], c[505][505], d[505][505],       q, ans[505][505], u, v, x, y;   char e[505][505];   int s[255][505][505];   int main() {     scanf( %d %d %d , &n, &m, &q);     for (i = 1; i <= n; ++i) scanf( %s , e[i] + 1);     for (i = 1; i <= n; ++i)       for (j = 1; j <= m; ++j) {         a[i][j] = a[i - 1][j] + a[i][j - 1] - a[i - 1][j - 1] + (e[i][j] ==  R );         b[i][j] = b[i - 1][j] + b[i][j - 1] - b[i - 1][j - 1] + (e[i][j] ==  G );         c[i][j] = c[i - 1][j] + c[i][j - 1] - c[i - 1][j - 1] + (e[i][j] ==  Y );         d[i][j] = d[i - 1][j] + d[i][j - 1] - d[i - 1][j - 1] + (e[i][j] ==  B );       }     for (i = 1; i <= n; ++i)       for (j = 1; j <= m; ++j) {         for (k = 1; k <= i && k <= j; ++k) {           if (a[i][j] + a[i - k][j - k] - a[i - k][j] - a[i][j - k] != k * k)             break;           if (b[i][j + k] + b[i - k][j] - b[i - k][j + k] - b[i][j] != k * k)             break;           if (c[i + k][j] + c[i][j - k] - c[i][j] - c[i + k][j - k] != k * k)             break;           if (d[i + k][j + k] + d[i][j] - d[i][j + k] - d[i + k][j] != k * k)             break;         }         ans[i][j] = k - 1;       }     for (i = 1; i <= 250; ++i)       for (j = 1; j <= n; ++j)         for (k = 1; k <= m; ++k)           s[i][j][k] = (ans[j][k] >= i) - s[i][j - 1][k - 1] + s[i][j][k - 1] +                        s[i][j - 1][k];     while (q--) {       scanf( %d %d %d %d , &u, &v, &x, &y);       int l = 1, r = min((x - u + 1) / 2, (y - v + 1) / 2) + 1;       while (l < r) {         int mid = l + r >> 1;         if (s[mid][x - mid][y - mid] - s[mid][u + mid - 2][y - mid] -                 s[mid][x - mid][v + mid - 2] + s[mid][u + mid - 2][v + mid - 2] >             0)           l = mid + 1;         else           r = mid;       }       printf( %d n , 4 * (l - 1) * (l - 1));     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e3 + 5;   char g1[N][N];   int dp1[N][N];   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr), cout.tie(nullptr);     int n = 0, m = 0, ans1 = 0;     cin >> n >> m;     for (int i = 1; i <= n; ++i) cin >> g1[i];     for (int i = 1; i <= n; ++i) {       for (int j = 0; j < m; ++j) {         dp1[i][j] = 1;         if (i > 2 && j > 0 && j < m - 1 && g1[i][j] == g1[i - 1][j] &&             g1[i][j] == g1[i - 2][j] && g1[i][j] == g1[i - 1][j - 1] &&             g1[i][j] == g1[i - 1][j + 1]) {           dp1[i][j] +=               min(min(dp1[i - 1][j - 1], dp1[i - 1][j + 1]), dp1[i - 2][j]);         }         ans1 += dp1[i][j];       }     }     cout << ans1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5e3 + 3;   int sz, mn, o, rt, s[N], s2[N], fa[N], ch[N][2], lf[N], cnt;   bool vis[N];   void findrt(int u) {     if (vis[u]) {       s[u] = 0;       return;     }     int mx;     if (ch[u][0]) {       int x = ch[u][0], y = ch[u][1];       findrt(x), findrt(y);       s[u] = s[x] + s[y] + 1, mx = max(s2[u] = sz - s[u], max(s[x], s[y]));     } else       s[u] = 1, mx = s2[u] = sz - s[u];     if (mx < mn) mn = mx, o = u;   }   void lk(int f, int c, int x) { ch[fa[x] = f][c] = x; }   void solve(int u, int f, int c, int nd) {     vis[u] = true;     char str[5];     int x = ch[u][0], y = ch[u][1];     if (x) {       printf( %d %d %d n , lf[x], lf[y], nd);       fflush(stdout), scanf( %s , str);     }     if (!x || str[0] ==  X ) {       if (!fa[u] || vis[fa[u]]) {         if (!fa[u])           rt = ++cnt;         else           lk(fa[u], c, ++cnt);         lk(cnt, 0, u), lk(cnt, 1, nd), lf[cnt] = lf[nd] = nd;         return;       }       sz = mn = s2[u], findrt(f ? ch[f][c] : rt), solve(o, f, c, nd);     } else {       int t = str[0] ==  Y , x = ch[u][t];       if (vis[x]) {         lk(++cnt, 0, x), lk(cnt, 1, nd), lk(u, t, cnt), lf[cnt] = lf[nd] = nd;         return;       }       sz = mn = s[x], findrt(x), solve(o, u, t, nd);     }   }   int main() {     srand(time(0));     int n;     scanf( %d , &n);     cnt = n;     lk(rt = ++cnt, 0, 1), lk(rt, 1, 2), lf[1] = lf[rt] = 1, lf[2] = 2;     for (int i = 3; i <= n; ++i) {       memset(vis, 0, sizeof(vis));       sz = mn = 2 * (i - 1) - 1, findrt(rt), solve(o, 0, 0, i);     }     puts( -1 );     for (int i = 1; i <= cnt; ++i) printf( %d  , fa[i] ? fa[i] : -1);     fflush(stdout);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       string s;       cin >> s;       long long tot = 0;       long long cont = 0;       for (int i = 0; i < s.size(); i++) {         if (s[i] ==  -  && cont == 0) {           tot += i + 1;         } else if (s[i] ==  + ) {           cont++;         } else if (s[i] ==  - ) {           cont--;         }       }       tot += s.size();       cout << tot <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100500;   int n, m;   char s[N];   int dp[N];   void solve() {     scanf( %d%d%s , &n, &m, s);     long long ans = (m - 1) * n;     for (int i = 0; i < n; i++) {       if (i - 1 >= 0 && s[i] != s[i - 1]) ans += (m - 1) * i;       if (i + 1 < n && s[i] != s[i + 1]) ans += (m - 1) * (n - 1 - i);     }     for (int i = 0; i < n; i++) {       dp[i] = 1;       if (i - 1 >= 0 && s[i - 1] != s[i]) dp[i] = 2;       if (i - 2 >= 0 && s[i - 1] != s[i] && s[i - 2] == s[i])         dp[i] = dp[i - 1] + 1;       ans -= dp[i] - 1;     }     printf( %lld n , ans);   }   int main() {     solve();     0;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long t, n, g, b;     cin >> t;     while (t--) {       cin >> n >> g >> b;       long long val = (n + 1) / 2;       long long total = val / g;       long long sum = total * g;       if (val % g) {         total++;       }       total--;       sum += (b * total);       sum += (val % g);       if (sum <= n)         cout << n << endl;       else         cout << sum << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using namespace std;   using ll = long long;   using ld = long double;   const int MOD = 1e9 + 7, inf = 1e9, N = 2e5 + 1;   const ll INF = 1e18;   ld tic, tac;   void solve() {     string str, ans =   ;     cin >> str;     int cr = 0, cs = 0, cp = 0;     for (int i = 0; i < (str.size()); ++i) {       if (str[i] ==  R )         cr++;       else if (str[i] ==  P )         cp++;       else         cs++;     }     char ch;     if (cr >= cp && cr >= cs)       ch =  P ;     else if (cp >= cs && cp >= cr)       ch =  S ;     else       ch =  R ;     cout << string(str.size(), ch) <<   n ;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t = 1;     cin >> t;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double PI = 3.1415926535;   double cot(double x) { return cos(x) / sin(x); }   int main() {     double r, n;     cin >> n >> r;     cout << fixed << setprecision(9)          << n * r * r * sin(PI / n) / (1 + 2 * cos(PI / n));     return 0;   }
#include <bits/stdc++.h>   const double PI = 3.14159265358979323846;   using namespace std;   int main() {     std::map<int, long long> pairs;     std::set<long long> positive;     int n;     std::cin >> n;     std::vector<int> nums(n);     for (int i = 0; i < n; ++i) {       std::cin >> nums[i];       if (nums[i] > 0) {         positive.insert(nums[i]);       }       pairs[nums[i]]++;     }     long long result = 0;     if (pairs[0]) {       result += pairs[0] * (pairs[0] - 1) / 2;     }     for (std::set<long long>::iterator itr = positive.begin();          itr != positive.end(); ++itr) {       result += pairs[*itr] * pairs[-(*itr)];     }     std::cout << result << std::endl;     return 0;   }
#include <bits/stdc++.h>   #pragma warning(disable : 4244 4267 4018 4996 4800)   using namespace std;   istream& in = std::cin;   ostream& out = std::cout;   int n, m, total;   int xstart = -1, ystart;   vector<vector<char>> p;   int res = -1;   bool ones(int x1, int y1, int x2, int y2) {     for (int i = x1; i <= x2; ++i)       for (int j = y1; j <= y2; ++j)         if (!p[i][j]) return false;     return true;   }   int count(int w, int h) {     int x = ::xstart, y = ::ystart;     int res = 0;     while (x < n && y < m && p[x][y]) {       if (x + h < n && p[x + h][y] && (y + w == m || !p[x][y + w])) {         if (ones(x, y, x, y + w - 1))           res += w;         else           return -1;         ++x;       } else if (y + w < m && p[x][y + w] && (x + h == n || !p[x + h][y])) {         if (ones(x, y, x + h - 1, y))           res += h;         else           return -1;         ++y;       } else         break;     }     if (x < n && y < m && p[x][y]) {       if (ones(x, y, x + h - 1, y + w - 1))         res += w * h;       else         return -1;     }     return res;   }   void trysolve() {     int w = 0, h = 0;     int i;     for (i = ystart; i < m && p[xstart][i]; ++i, ++w)       ;     int prev = -1;     for (i = xstart; i < n && p[i][ystart]; ++i) {       if (ystart + w < m && p[i][ystart + w] && prev == -1) {         prev = i;       }     }     h = prev == -1 ? 1 : i - prev;     if (count(w, h) == total && (res == -1 || w * h < res)) res = w * h;   }   template <class T>   vector<T> transpose(vector<T> const& t) {     vector<T> u(t[0].size(), T(t.size()));     for (unsigned i = 0; i < t.size(); ++i)       for (unsigned j = 0; j < t[i].size(); ++j) u[j][i] = t[i][j];     return u;   }   int main() {     std::ios_base::sync_with_stdio(false);     in >> n >> m;     string s;     p.resize(n, vector<char>(m));     for (auto& row : p) {       in >> s;       for (int i = 0; i < s.size(); ++i) row[i] = s[i] ==  X  ? 1 : 0;     }     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         if (p[i][j]) {           ++total;           if (xstart == -1) {             xstart = i;             ystart = j;           }         }       }     }     trysolve();     p = transpose(p);     swap(xstart, ystart);     swap(n, m);     trysolve();     out << res;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   #define int long long   #define pii pair<int, int>   int32_t mod = 1e9 + 7;      void solveCase()   {       int n = 0, m = 0;       cin >> n >> m;          vector<vector<int>> mp(m, vector<int>(26, 0));       for (int i = 0; i < n; i++)       {           string s;           cin >> s;           for (int i = 0; i < m; i++)               mp[i][s[i] -  a ]++;       }       for (int i = 0; i < n - 1; i++)       {           string s;           cin >> s;           for (int i = 0; i < m; i++)               mp[i][s[i] -  a ]--;       }          for (int i = 0; i < m; i++)           for (int x = 0; x < 26; x++)               if (mp[i][x])                   cout << char( a  + x);       cout <<   n ;   }      int32_t main()   {       ios::sync_with_stdio(false), cin.tie(NULL);       int t = 0;       cin >> t;       while (t--)           solveCase();   }
#include <bits/stdc++.h>   using namespace std;   int32_t main() {     long long int n;     std::cin >> n;     long long int ans[n];     for (long long int i = 0; i < n; i++) {       std::cin >> ans[i];     }     long long int count[n];     memset(count, 0, sizeof(count));     for (long long int i = 0; i < n; i++) {       count[i] += (ans[i] * 15);       for (long long int j = 0; j < ans[i]; j++) {         long long int x;         std::cin >> x;         count[i] += (x * 5);       }     }     long long int min = (*(std::min_element(count, count + n)));     std::cout << min <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 10;   int sz[N];   struct Edge {     long long from, to, val, nex;   } edge[N];   int h[N], idx;   void add(long long u, long long v, long long w) {     Edge E = {u, v, w, h[u]};     edge[idx] = E;     h[u] = idx++;   }   void init() {     memset(h, -1, sizeof(h));     idx = 0;   }   long long ans;   void dfs1(int u, int fa) {     sz[u] = 1;     for (int i = h[u]; ~i; i = edge[i].nex) {       int v = edge[i].to;       if (v == fa) continue;       dfs1(v, u);       sz[u] += sz[v];       if (sz[v] & 1) {         ans += edge[i].val;       }     }   }   int n;   long long ans2;   void dfs2(int u, int fa) {     sz[u] = 1;     for (int i = h[u]; ~i; i = edge[i].nex) {       int v = edge[i].to;       if (v == fa) continue;       dfs2(v, u);       sz[u] += sz[v];       ans2 += min(sz[v], n - sz[v]) * edge[i].val;     }   }   int main() {     int t;     cin >> t;     while (t--) {       cin >> n;       n = n * 2;       init();       ans = ans2 = 0;       for (int i = 1; i < n; i++) {         long long u, v, w;         cin >> u >> v >> w;         add(u, v, w);         add(v, u, w);       }       dfs1(1, -1);       printf( %lld  , ans);       dfs2(1, -1);       printf( %lld  , ans2);       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     int l, i, j, k;     cin >> s;     for (i = 1; i < s.size() - 1; i++) {       if (s[i] ==  A  && ((s[i + 1] ==  B  && s[i - 1] ==  C ) ||                           (s[i - 1] ==  B  && s[i + 1] ==  C ))) {         printf( YES n );         return 0;       } else if (s[i] ==  B  && ((s[i + 1] ==  A  && s[i - 1] ==  C ) ||                                  (s[i - 1] ==  A  && s[i + 1] ==  C ))) {         printf( YES n );         return 0;       } else if (s[i] ==  C  && ((s[i + 1] ==  B  && s[i - 1] ==  A ) ||                                  (s[i - 1] ==  B  && s[i + 1] ==  A ))) {         printf( YES n );         return 0;       }     }     printf( NO n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 10100;   int i, j, k, n, m, ch, c;   int s[N], t[N];   long long ans, f[N];   void R(int &x) {     x = 0;     ch = getchar();     while (ch <  0  ||  9  < ch) ch = getchar();     while ( 0  <= ch && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();   }   void W(long long x) {     if (x >= 10) W(x / 10);     putchar(x % 10 +  0 );   }   long long min(long long x, long long y) {     if (x < y) return x;     return y;   }   int main() {     R(n);     R(c);     for (i = 1; i <= n; i++) R(s[i]);     for (i = 1; i <= n; i++) R(t[i]);     memset(f, 60, sizeof f);     f[0] = 0;     for (i = 1; i <= n; i++)       for (j = i - 1; j >= 0; j--) {         f[j + 1] = min(f[j + 1], f[j] + t[i]);         f[j] = (long long)c * j + f[j] + s[i];       }     ans = 1000000000000000000ll;     for (i = 0; i <= n; i++) ans = min(ans, f[i]);     W(ans);     puts(  );   }
#include <bits/stdc++.h>   using namespace std;   int color[100005];   vector<int> DSK[100005];   int num = 0, block_size;   int S[100005], E[100005], c[100005];   struct query {     int l, r, k, id;   } Q[100005];   void DFS(int u, int pre) {     S[u] = ++num;     c[num] = color[u];     for (int i = 0; i < DSK[u].size(); i++) {       int w = DSK[u][i];       if (w != pre) DFS(w, u);     }     E[u] = num;   }   int cnt[100005], ans[100005], res[100005];   void add(int i) {     cnt[c[i]]++;     ans[cnt[c[i]]]++;   }   void del(int i) {     ans[cnt[c[i]]]--;     cnt[c[i]]--;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n >> m;     for (int i = 1; i <= n; i++) cin >> color[i];     for (int i = 1; i < n; i++) {       int u, v;       cin >> u >> v;       DSK[u].push_back(v);       DSK[v].push_back(u);     }     DFS(1, -1);     for (int i = 1; i <= m; i++) {       int v, k;       cin >> v >> k;       Q[i] = {S[v], E[v], k, i};     }     block_size = sqrt(n);     sort(Q + 1, Q + 1 + m, [](const query &a, const query &b) {       if (a.l / block_size == b.l / block_size) return a.r < b.r;       return a.l / block_size < b.l / block_size;     });     int curL = 1, curR = 0;     for (int i = 1; i <= m; i++) {       int L = Q[i].l, R = Q[i].r;       while (curL > L) {         add(curL - 1);         curL--;       }       while (curR < R) {         add(curR + 1);         curR++;       }       while (curL < L) {         del(curL);         curL++;       }       while (curR > R) {         del(curR);         curR--;       }       res[Q[i].id] = ans[Q[i].k];     }     for (int i = 1; i <= m; i++) cout << res[i] <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   bool can(int x, int y, int a, int b) {     cout <<  ?   << x <<     << y <<     << a <<     << b << endl;     string ans;     cin >> ans;     if (ans ==  BAD ) exit(0);     return ans ==  YES ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     int x = 1, y = 1;     string ord1(n - 1,    ), ord2(n - 1,    );     int i = 0;     while (i < n - 1) {       if (can(x + 1, y, n, n)) {         ++x;         ord1[i] =  D ;       } else {         ord1[i] =  R ;         ++y;       }       ++i;     }     x = n;     y = n;     i = 0;     while (i < n - 1) {       if (can(1, 1, x, y - 1)) {         ord2[i] =  R ;         --y;       } else {         --x;         ord2[i] =  D ;       }       ++i;     }     reverse(ord2.begin(), ord2.end());     cout <<  !   << ord1 << ord2 << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int Maxn = 507;   int n, m;   int E[Maxn][Maxn];   vector<int> V[Maxn];   int ans[Maxn];   bool mark[Maxn];   void dfs(int v) {     mark[v] = true;     for (int i = 0; i < V[v].size(); i++) {       int u = V[v][i];       if (!mark[u])         ans[u] = 2 - ans[v], dfs(u);       else if (ans[u] == ans[v]) {         cout <<  No  << endl;         exit(0);       }     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     for (int i = 0; i < m; i++) {       int u, v;       cin >> u >> v;       E[u][v] = E[v][u] = 1;     }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++)         if (!E[i][j] and i != j) V[i].push_back(j);     for (int i = 1; i <= n; i++) {       if (!V[i].size())         ans[i] = 1, mark[i] = true;       else if (!mark[i])         ans[i] = 2, dfs(i);     }     for (int i = 1; i <= n; i++)       for (int j = 1; j < i; j++) {         if (E[i][j] and abs(ans[i] - ans[j]) == 2) return cout <<  No  << endl, 0;       }     cout <<  Yes  << endl;     for (int i = 1; i <= n; i++) cout << (char)(ans[i] +  a );     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, m;       string s;       cin >> n >> m >> s;       vector<int> pref(n);       for (int i = 0; i < m; ++i) {         int p;         cin >> p;         ++pref[p - 1];       }       for (int i = n - 1; i > 0; --i) {         pref[i - 1] += pref[i];       }       vector<int> ans(26);       for (int i = 0; i < n; ++i) {         ans[s[i] -  a ] += pref[i];         ++ans[s[i] -  a ];       }       for (int i = 0; i < 26; ++i) {         cout << ans[i] <<    ;       }       cout << endl;     }     return 0;   }