#include <bits/stdc++.h> n using namespace std; n const double PI = 3.141592653589793238; n long long powmod(long long a, long long b) { n   long long res = 1; n   a %= 1000000007; n   for (; b; b >>= 1) { n     if (b & 1) res = res * a % 1000000007; n     a = a * a % 1000000007; n   } n   return res; n } n long long fac[1000005]; n void factorial(int mx) { n   fac[0] = 1ll; n   for (int i = 1; i <= mx; i++) { n     fac[i] = fac[i - 1] * (long long)i; n     fac[i] %= 1000000007; n   } n } n int main() { n   factorial(1000005 - 5); n   int n, m, vol, type; n   long long ans, cnt = 1ll; n   scanf( %d , &n); n   scanf( %d , &m); n   vector<vector<int> > vec(m); n   for (int i = 0; i < n; i++) { n     scanf( %d , &vol); n     while (vol--) { n       scanf( %d , &type); n       vec[type - 1].push_back(i); n     } n   } n   for (int i = 0; i < m; i++) sort(vec[i].begin(), vec[i].end()); n   sort(vec.begin(), vec.end()); n   ans = 1ll; n   for (int i = 1; i <= m - 1; i++) { n     if (vec[i] == vec[i - 1]) n       ans *= ++cnt; n     else n       cnt = 1; n     ans %= 1000000007; n   } n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   for (int ti = 0; ti < t; ti++) { n     int n, k; n     cin >> n >> k; n     vector<int> arr(n); n     for (int i = 0; i < n; i++) cin >> arr[i]; n     sort(arr.begin(), arr.end()); n     vector<int> weights(k); n     for (int i = 0; i < k; i++) cin >> weights[i]; n     sort(weights.begin(), weights.end()); n     long long total = 0; n     for (int i = n - 1; i >= n - k; i--) { n       total += arr[i]; n     } n     int w = 0; n     for (int i = k - 1; i >= 0; i--) { n       if (weights[i] <= 1) break; n       total += arr[w]; n       w += weights[i] - 1; n     } n     for (int i = 0; i < k; i++) { n       if (weights[i] > 1) break; n       total += arr[n - 1 - i]; n     } n     cout << total << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n long long ago; n using namespace std; n template <class T = long long int> n T nxt() { n   T x; n   cin >> x; n   return x; n } n long long int pw(long long int a, long long int b, long long int mod) { n   if (!b) return 1; n   if (b & 1) return a * pw(a * a % mod, b / 2, mod) % mod; n   return pw(a * a % mod, b / 2, mod) % mod; n } n const long long int N = 1000 + 10; n const long long int INF = 8e18; n const long long int MOD = 1e9 + 7; n long long int n, m, mark[N]; n double dist[N], S[N], Z[N]; n vector<pair<long long int, double>> adj[N]; n priority_queue<pair<double, long long int>, vector<pair<double, long long int>>, n                greater<pair<double, long long int>>> n     pq; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   cout << setprecision(15) << fixed; n   cin >> n; n   for (long long int i = 1; i <= n; i++) { n     for (long long int j = 1; j <= n; j++) { n       long long int p = nxt(); n       if (i == j || p == 0) continue; n       adj[j].emplace_back(i, double(p) / 100); n     } n   } n   fill(Z, Z + N, 1.0); n   fill(dist, dist + N, INF); n   dist[n] = 0; n   pq.push({0, n}); n   while (!pq.empty()) { n     long long int u = pq.top().second; n     pq.pop(); n     if (mark[u]) continue; n     mark[u] = 1; n     for (auto [v, p] : adj[u]) { n       if (mark[v]) continue; n       S[v] += Z[v] * p * (dist[u] + 1); n       Z[v] *= (1 - p); n       dist[v] = (S[v] + Z[v]) / (1 - Z[v]); n       pq.push({dist[v], v}); n     } n   } n   cout << dist[1] <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   int n; n   cin >> n >> s; n   vector<int> vec; n   for (int i = 0; i < s.length(); ++i) { n     if (s[i] ==  B ) { n       int res = 0; n       while (i < s.length() && s[i] ==  B ) { n         ++res; n         ++i; n       } n       vec.push_back(res); n       continue; n     } n   } n   cout << vec.size() <<   n ; n   for (int i = 0; i < (int)vec.size(); ++i) { n     cout << vec[i] <<    ; n   } n   cout <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const int MaxN = 1e5; n struct NOOD { n   int flag; n   int l; n   int r; n   int v; n } num[MaxN + 5]; n int ans[MaxN + 5], p[MaxN + 5]; n bool ok[MaxN + 5], flag; n int Max; n int n, m; n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= m; i++) { n     scanf( %d%d%d%d , &num[i].flag, &num[i].l, &num[i].r, &num[i].v); n   } n   for (int i = 1; i <= n; i++) ans[i] = -100000000; n   for (int i = m; i >= 1; i--) { n     if (num[i].flag == 1) { n       for (int j = num[i].l; j <= num[i].r; j++) ans[j] -= num[i].v; n     } else { n       for (int j = num[i].l; j <= num[i].r; j++) { n         if (ok[j] && ans[j] < num[i].v) continue; n         ans[j] = num[i].v; n         ok[j] = 1; n       } n     } n   } n   for (int i = 1; i <= n; i++) p[i] = ans[i]; n   for (int i = 1; i <= m; i++) { n     if (num[i].flag == 1) { n       for (int j = num[i].l; j <= num[i].r; j++) p[j] += num[i].v; n     } else { n       Max = -100000000; n       for (int j = num[i].l; j <= num[i].r; j++) Max = max(Max, p[j]); n       if (Max != num[i].v) flag = 1; n     } n   } n   if (flag) n     printf( NO n ); n   else { n     printf( YES n ); n     for (int i = 1; i <= n; i++) printf( %d  , ans[i]); n     printf(  n ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long solve() { n   long long n, i, j, k; n   cin >> n >> k; n   long long arr[n]; n   for (i = 0; i < n; i++) cin >> arr[i]; n   sort(arr, arr + n); n   j = 0; n   for (i = 0; i < n && arr[i] < 0; i += k) j += 2 * abs(arr[i]); n   for (i = n - 1; i >= 0 && arr[i] > 0; i -= k) j += 2 * arr[i]; n   j -= max(abs(arr[0]), abs(arr[n - 1])); n   return j; n } n int main() { n   long long t; n   cin >> t; n   while (t--) cout << solve() << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   string a, b, tem; n   scanf( %d , &n); n   a =  <3 ; n   for (int i = 0, j = 0; i < n; ++i) { n     cin >> tem; n     a += tem; n     a +=  <3 ; n   } n   cin >> b; n   int len1 = a.length(), po1 = 0, po2 = 0; n   int len2 = b.length(); n   while (1) { n     if (po1 == len1) { n       printf( yes n ); n       return 0; n     } n     if (po2 == len2) { n       printf( no n ); n       return 0; n     } n     if (a[po1] == b[po2]) po1++; n     po2++; n   } n } n