malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   template <class T>   void print(const T niz[], const int siz) {     for (int i = 0; i < siz; i++) cout << niz[i] <<    ;     cout << endl;   }   const long long p = 103;   long long add(long long x, long long y) { return (x + y) % 1000000007; }   long long mul(long long x, long long y) { return (x * y) % 1000000007; }   long long power(long long x, long long y) {     if (y == 0) return 1;     long long pola = power(x, y / 2);     pola = mul(pola, pola);     if (y % 2 == 1) pola = mul(pola, x);     return pola;   }   long long inverz[1000005];   int n;   string x;   long long hes[1000005][2];   long long get(long long l, long long r, long long idx) {     if (idx == 0) {       long long sta = hes[r][0] - hes[l - 1][0];       sta %= 1000000007;       sta += 1000000007;       sta %= 1000000007;       sta = mul(sta, inverz[l - 1]);       return sta;     } else {       long long sta = hes[l][1] - hes[r + 1][1];       sta %= 1000000007;       sta += 1000000007;       sta %= 1000000007;       sta = mul(sta, inverz[n - r]);       return sta;     }   }   bool checkpal(int l, int r) {     l = max(l, 0);     r = min(r, n);     if (l == r) return 1;     if (l > r) return 0;     long long sta1 = get(l, r, 0);     long long sta2 = get(l, r, 1);     return (sta1 == sta2);   }   int maksn = 0;   void solve() {     cin >> x;     n = x.length();     maksn = max(maksn, n);     for (int(i) = (0); (i) <= (maksn + 1); ++(i)) {       hes[i][0] = hes[i][1] = 0;     }     long long st = 1;     long long tr = 0;     for (int(i) = (0); (i) <= (n - 1); ++(i)) {       tr = add(tr, mul(st, x[i] -  a  + 1));       hes[i + 1][0] = tr;       st = mul(st, p);     }     tr = 0;     st = 1;     for (int(i) = (n - 1); (i) >= (0); --(i)) {       tr = add(tr, mul(st, x[i] -  a  + 1));       hes[i + 1][1] = tr;       st = mul(st, p);     }     int l = 1;     int r = n;     if (checkpal(1, n)) {       cout << x << endl;       return;     }     int necul = 0;     int necur = 0;     while (l < r) {       if (x[l - 1] != x[r - 1]) {         for (int(i) = (l); (i) <= (r); ++(i)) {           if (checkpal(l, i)) {             necul = i + 1;             necur = r;           }         }         for (int(i) = (r); (i) >= (l); --(i)) {           if (checkpal(i, r)) {             if ((i - 1 - l) < (necur - necul)) {               necur = i - 1;               necul = l;             }           }         }         break;       } else {         l++;         r--;       }     }     for (int(i) = (1); (i) <= (n); ++(i)) {       if (i >= necul && i <= necur) continue;       cout << x[i - 1];     }     cout << endl;   }   int main() {     ios_base::sync_with_stdio(false);     inverz[1000001] = power(power(p, 1000001), 1000000007 - 2);     for (int(i) = (1000000); (i) >= (0); --(i)) inverz[i] = mul(inverz[i + 1], p);     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, k, i;     cin >> n >> k;     long long int a[n + 1], b[n + 1];     pair<long long int, long long int> d[n + 1];     for (i = 0; i < n; i++) cin >> a[i];     for (i = 0; i < n; i++) cin >> b[i];     for (i = 0; i < n; i++) d[i] = make_pair(a[i] - b[i], i);     sort(d, d + n);     long long int s = 0;     for (i = 0; i < k; i++) s += a[d[i].second];     for (i = k; i < n; i++) {       s += min(a[d[i].second], b[d[i].second]);     }     cout << s << endl;     return 0;   }
#include <bits/stdc++.h>   int arr[400][400];   void f(int x, int y) {     if (arr[x][y] < 4) return;     arr[x][y + 1] += arr[x][y] / 4;     arr[x][y - 1] += arr[x][y] / 4;     arr[x + 1][y] += arr[x][y] / 4;     arr[x - 1][y] += arr[x][y] / 4;     arr[x][y] %= 4;     f(x, y + 1);     f(x, y - 1);     f(x + 1, y);     f(x - 1, y);   }   int main() {     int n, t, i;     scanf( %d %d , &n, &t);     arr[200][200] = n;     f(200, 200);     for (i = 0; i < t; i++) {       int x, y;       scanf( %d %d , &x, &y);       if (x + 200 > 400 || y + 200 > 400 || x + 200 < 0 || y + 200 < 0)         printf( 0 n );       else         printf( %d n , arr[x + 200][y + 200]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int k, w;     long long n;     cin >> k >> n >> w;     int l{};     for (int i = 1; i <= w; i++) {       l = l + i;     }     int s = (l * k) - n;     if (s > 0)       cout << s;     else       cout << 0;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long dev[5000005];   long long S[5000005];   long long pri[5000005];   void sieve() {     memset(dev, -1, sizeof dev);     int p = 0;     for (int i = 2; i <= 5000005; i++) {       if (dev[i] != -1) continue;       pri[p++] = i;       for (long long j = 1; j < 5000005; j++) {         if (i * j >= 5000005) break;         dev[i * j] = i;       }     }   }   int main() {     sieve();     for (int i = 1; i < 5000005; i++) {       int x = i;       while (x > 1) {         int d = dev[x];         S[i]++;         x /= d;       }     }     for (int i = 2; i <= 5000005; i++) {       S[i] += S[i - 1];     }     int t;     cin >> t;     while (t--) {       int a, b;       scanf( %d%d , &a, &b);       printf( %I64d n , S[a] - S[b]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int N = 1e5 + 5;   ll f[N];   int n, ans, c;   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %lld , &f[i]);     for (int i = 2; i < n; i++) {       if (f[i] == f[i - 1] + f[i - 2]) {         c++;         ans = max(ans, c + 2);       } else {         c = 0;       }     }     printf( %d n , (ans == 0 || ans == 1) ? (n == 1 ? 1 : 2) : ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int p[100001], w[100001];   vector<pair<int, int>> e[100001];   long long ans[100001], sum;   int root(int x) {     while (x != p[x]) x = p[x] = p[p[x]];     return x;   }   void pre(int x, int from) {     sum += w[x];     for (auto c : e[x])       if (c.first != from) pre(c.first, x);   }   int gao(int x, int from, int t) {     int cnt = w[x];     for (auto c : e[x]) {       if (c.first == from) continue;       cnt += gao(c.first, x, c.second);     }     e[x].clear();     ans[t] = cnt * (sum - cnt) * 2;     return cnt;   }   int main() {     int n;     scanf( %d , &n);     map<int, vector<pair<pair<int, int>, int>>> u;     for (int i = 1; i <= n; i++) w[p[i] = i] = 1;     for (int i = 1; i != n; i++) {       int x, y, c;       scanf( %d%d%d , &x, &y, &c);       u[c].push_back({{x, y}, i});     }     for (auto& r : u) {       vector<int> v;       for (auto c : r.second) {         int x = root(c.first.first);         int y = root(c.first.second);         int t = c.second;         e[x].push_back({y, t});         e[y].push_back({x, t});         v.push_back(x);         v.push_back(y);       }       sort(v.begin(), v.end());       v.resize(unique(v.begin(), v.end()) - v.begin());       for (auto x : v)         if (!e[x].empty()) {           pre(x, sum = 0);           gao(x, 0, 0);         }       for (auto c : r.second) {         int x = root(c.first.first);         int y = root(c.first.second);         if (w[x] < w[y])           w[p[x] = y] += w[x];         else           w[p[y] = x] += w[y];       }     }     long long tmp = *max_element(ans + 1, ans + n);     printf( %I64d %d n , tmp, count(ans + 1, ans + n, tmp));     for (int i = 1; i != n; i++)       if (ans[i] == tmp) printf( %d  , i);   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   char c[maxn];   long long mod = 1e9 + 7;   long long ex(long long a, long long b) {     a = a % mod;     long long ans = 1;     while (b) {       if (b % 2 == 1) {         ans = (ans * a) % mod;       }       a = (a * a) % mod;       b = b / 2;     }     return ans;   }   int main() {     int k;     scanf( %s%d , c, &k);     long long sum = 0;     int len = strlen(c);     for (int i = 0; c[i]; i++) {       if (c[i] ==  0  || c[i] ==  5 ) {         long long a1 = ex(2, i);         long long q = ex(2, len);         long long ans = ((a1 % mod) * ((ex(q, k) - 1) % mod) % mod);         long long ni = ex(q - 1, mod - 2) % mod;         sum = (sum + (ans * ni) % mod) % mod;       }     }     printf( %I64d n , sum);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   istream &operator>>(istream &is, vector<T> &arr);   template <typename T>   ostream &operator<<(ostream &os, vector<T> &arr);   int INF = 1e9 + 5;   long long C(int n, int m) {     long long ans = 1;     for (int i = 1; i <= m; i++) {       ans *= n;       ans /= i;       n--;     }     return ans;   }   int main() {     int n;     cin >> n;     vector<pair<int, string>> scores = {{0,  Kuro }, {0,  Shiro }, {0,  Katie }};     vector<string> tr(3);     cin >> tr;     for (int i = 0; i < 3; i++) {       map<char, int> charMap;       for (int j = 0; j < tr[i].length(); j++) {         charMap[tr[i][j]]++;       }       for (auto ca : charMap) {         int sc = ca.second;         int l = tr[i].length();         if (n == 1 && sc == l)           scores[i].first = max(scores[i].first, sc - 1);         else           scores[i].first = max(scores[i].first, min(sc + n, l));       }     }     sort(scores.begin(), scores.end());     if (scores[2].first == scores[1].first)       cout <<  Draw  << endl;     else       cout << scores[2].second << endl;   }   template <typename T>   istream &operator>>(istream &is, vector<T> &arr) {     typename vector<T>::iterator a;     for (a = arr.begin(); a != arr.end(); a++) {       is >> *a;     }     return is;   }   template <typename T>   ostream &operator<<(ostream &os, vector<T> &arr) {     typename vector<T>::iterator a;     for (a = arr.begin(); a != arr.end(); a++) {       os << *a <<    ;     }     os << endl;     return os;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, count = 0, max = 0;     char line;     cin >> n;     n++;     while (n--) {       char temp;       scanf( %c , &temp);       if (temp ==    ) {         if (count > max) max = count;         count = 0;       } else if (temp >=  A  && temp <=  Z )         count++;     }     if (count > max) max = count;     cout << max;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int x1, y1, x2, y2;       cin >> x1 >> y1 >> x2 >> y2;       if (y1 == y2)         cout << abs(x2 - x1) <<   n ;       else if (x1 == x2)         cout << abs(y2 - y1) <<   n ;       else {         int x, y;         x = abs(x2 - x1);         y = abs(y2 - y1);         cout << x + y + 2 <<   n ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   vector<int> graph[maxn];   vector<int> g[maxn];   bool mark[maxn];   int n, m;   int par[maxn];   int cm[maxn];   bool comp[maxn];   int mk[maxn];   int moalefe[maxn];   void dfs(int x, int y) {     mark[x] = 1;     cm[x] = y;     moalefe[y]++;     for (int v : graph[x])       if (!mark[v]) dfs(v, y);   }   void ddfs(int x) {     mk[x] = 1;     for (int v : g[x]) {       if (mk[v] == 0)         ddfs(v);       else if (mk[v] == 1)         comp[cm[v]] = 1;     }     mk[x] = 2;   }   int main() {     cin >> n >> m;     for (int i = 0; i < m; i++) {       int t1, t2;       cin >> t1 >> t2;       t1--;       t2--;       graph[t1].push_back(t2);       graph[t2].push_back(t1);       g[t1].push_back(t2);     }     int mo = 1;     for (int i = 0; i < n; i++) {       if (!mark[i]) {         dfs(i, mo);         mo++;       }     }     for (int i = 0; i < n; i++) {       if (mk[i] == 0) ddfs(i);     }     int ans = 0;     for (int i = 1; i < mo; i++) {       if (comp[i])         ans += moalefe[i];       else         ans += moalefe[i] - 1;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   const unsigned int M = 1000000007;   long long power(long long x, long long y) {     long long res = 1;     while (y > 0) {       if (y & 1) res = x * res;       y = y >> 1;       x = x * x;     }     return res;   }   long long power(long long x, long long y, long long mod) {     long long res = 1;     while (y > 0) {       if (y & 1) res = x * res % mod;       y = y >> 1;       x = x * x % mod;     }     return res;   }   using namespace std;   void nik() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);   }   signed main() {     nik();     long long test = 1;     cin >> test;     while (test--) {       long long one[100005] = {0};       string s;       cin >> s;       long long n = s.size();       s =     + s;       for (long long i = 1; i <= n; i++) {         if (s[i] ==  1 )           one[i] = one[i - 1] + 1;         else           one[i] = one[i - 1];       }       long long ans = min(one[n], n - one[n]);       if (ans == 0) {         cout << ans <<   n ;         continue;       }       for (long long i = 1; i <= n; i++) {         ans = min(ans, i - one[i] + one[n] - one[i]);       }       long long b = ans;       for (long long i = n; i >= 1; i--) {         b = min(b, (n - i + 1) - (one[n] - one[i - 1]) + one[i - 1]);       }       cout << min(ans, b) <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     vector<int> gru;     for (int i = 0; i < n; i++) {       gru.push_back(i + 1);     }     long long lead = 1;     for (int i = 0; i < k; i++) {       long long a;       cin >> a;       lead += a;       lead = lead % gru.size();       if (lead == 0) {         lead = gru.size();       }       cout << gru[lead - 1] <<    ;       gru.erase(gru.begin() + lead - 1);     }   }
#include <bits/stdc++.h>   #define debug(a) cout << #a <<  :   << a <<   n    #define debugLine() cout <<  ============== n    #define tick() cout <<  Tick n ;   #define testCases() int t; cin >> t; while(t--)   #define all(a) a.begin(), a.end()   #define fillWith(a, b) memset(a, b, sizeof(a))   #define INF_32 1e9   #define INF_64 1e18   #define Mod 1000000007   #define PI 3.14159265358979323846   #define endl   n    #define goFast() ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)   typedef long long ll;   using namespace std;      int main()   {       goFast();       testCases()       {           ll n;           cin >> n;           ll arr[n + 3];           ll sum = 0;           for(int i = 0; i < n; i++)           {               cin >> arr[i];               sum += arr[i];           }           cout << (n - sum % n) * (sum % n) << endl;       }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 50;   const int INF = 0x3f3f3f3f;   struct node {     int to, next;   } edge[maxn * 3];   struct Node {     int id;     long long val;     bool operator<(const Node& a) const { return val < a.val; }   };   int head[maxn], cnt, d[maxn], depth[maxn], ans[maxn];   int s[maxn];   void add(int u, int v) {     edge[cnt].to = v;     edge[cnt].next = head[u];     head[u] = cnt++;   }   void dfs(int k, int fa) {     for (int i = head[k]; i != -1; i = edge[i].next) {       int to = edge[i].to;       if (to == fa) continue;       depth[to] = depth[k] + 1;       dfs(to, k);       s[k] += s[to] + 1;     }   }   int main() {     int n, k;     cnt = 0;     memset(head, -1, sizeof(head));     memset(depth, -1, sizeof(depth));     memset(s, 0, sizeof(s));     scanf( %d%d , &n, &k);     for (int i = 1; i < n; i++) {       int u, v;       scanf( %d%d , &u, &v);       add(u, v);       add(v, u);       d[u]++;       d[v]++;     }     depth[1] = 0;     dfs(1, 1);     priority_queue<Node> q;     for (int i = 1; i <= n; i++)       if (d[i] == 1 && i != 1) q.push({i, depth[i]});     long long sum = 0;     while (k && !q.empty()) {       Node top = q.top();       sum += top.val;       q.pop();       k--;       for (int i = head[top.id]; i != -1; i = edge[i].next) {         int to = edge[i].to;         if (depth[to] < depth[top.id]) {           d[to]--;           if (d[to] == 1) q.push({to, depth[to] - s[to]});           break;         }       }     }     printf( %lld n , sum);   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   void in(T &x) {     x = 0;     bool f = 0;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = 1;       c = getchar();     }     while ( 0  <= c && c <=  9 ) {       x = (x << 3) + (x << 1) + (c ^ 48);       c = getchar();     }     if (f) x = -x;   }   long long n, m;   void print(long long x) {     printf( %lld , x);     exit(0);   }   signed main() {     in(n), in(m);     if (n > m) swap(n, m);     if (n == 1) print(m - m % 6 + max(0ll, (m % 6 - 3) * 2));     if ((n & 1) == 0 && (m & 1) == 0) {       if (n == 2 && m == 2)         print(0);       else         print(n * m);     }     if ((n + m) & 1) {       if (m & 1) swap(n, m);       if (m == 2) {         if (n == 3) print(4);         if (n == 7) print(12);       }       print(n * m);     } else       print(n * m - 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   void solve() {     int n, k, d;     cin >> n >> k >> d;     vector<int> dist(n, -1);     vector<vector<pair<int, int>>> za(n);     vector<int> keep(n - 1), par(n);     queue<int> q;     for (int i = (0); i < (k); ++i) {       int p;       cin >> p;       --p;       dist[p] = 0;       q.push(p);       par[p] = -1;     }     for (int i = (0); i < (n - 1); ++i) {       int x, y;       cin >> x >> y;       --x;       --y;       za[x].emplace_back(y, i);       za[y].emplace_back(x, i);     }     int res = 0;     while (!q.empty()) {       int cur = q.front();       q.pop();       for (auto edge : za[cur]) {         int u = edge.first;         int edge_no = edge.second;         if (dist[u] == -1) {           ++res;           dist[u] = dist[cur] + 1;           keep[edge_no] = 1;           q.push(u);         }       }     }     vector<int> shut;     for (int i = (0); i < (n - 1); ++i) {       if (keep[i] == 0) {         shut.push_back(i + 1);       }     }     cout << ((int)((shut).size())) << endl;     for (auto s : shut) {       cout << s <<    ;     }     cout << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int t;     t = 1;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int qq, n, m, k, l, r;   string s, s1, s2, s3;   int INF = (int)2e9 + 7;   struct st {     int x, y;   };   bool operator<(st& a, st& b) {     if (a.x != b.x) return a.x < b.x;     return a.y < b.y;   }   vector<vector<char>> v;   int x[4] = {0, 0, -1, 1}, y[4] = {-1, 1, 0, 0};   void dfs(int i, int j) {     v[i][j] =  . ;     for (int ii = 0; ii < 4; ii++) {       if (v[i + x[ii]][j + y[ii]] ==  B ) dfs(i + x[ii], j + y[ii]);     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int k1, k2, c;     char e;     cin >> n >> m;     int ans = 0;     v.assign(n + 2, vector<char>(m + 2));     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         cin >> e;         v[i][j] = e;       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (v[i][j] ==  B ) {           dfs(i, j);           ans++;         }       }     }     cout << ans <<    ;     cin >> k;     return 0;   }
#include <bits/stdc++.h>   int i, j, m, n, s, t, x, y;   int a[1000][1000], b[1000][1000], c[1000], d[1000];   int main() {     while (~scanf( %d%d%d , &n, &x, &y)) {       for (i = 0; i < 1000; i++)         for (j = 0; j < 1000; j++) {           a[i][j] = 0;           b[i][j] = 0;         }       for (i = 1; i <= n; i++) {         scanf( %d%d , &c[i], &d[i]);         a[500 + c[i]][500 + d[i]]++;         a[500 + d[i]][500 + c[i]]++;         b[501 + x - c[i]][501 + y - d[i]]++;         b[501 + x - d[i]][501 + y - c[i]]++;       }       t = 0;       for (int k = 1; k <= n; k++) {         b[501 + x - c[k]][501 + y - d[k]]--;         b[501 + x - d[k]][501 + y - c[k]]--;         for (i = 1; i <= x; i++)           for (j = 1; j <= y; j++) {             if ((i > c[k] || j > d[k]) && b[500 + i][500 + j] &&                 c[k] * d[k] + (x + 1 - i) * (y + 1 - j) > t && c[k] <= x &&                 d[k] <= y) {               t = c[k] * d[k] + (x + 1 - i) * (y + 1 - j);             }             if ((i > d[k] || j > c[k]) && b[500 + i][500 + j] &&                 c[k] * d[k] + (x + 1 - i) * (y + 1 - j) > t && c[k] <= y &&                 d[k] <= x) {               t = c[k] * d[k] + (x + 1 - i) * (y + 1 - j);             }           }         b[501 + x - c[k]][501 + y - d[k]]++;         b[501 + x - d[k]][501 + y - c[k]]++;       }       printf( %d n , t);     }   }
#include <bits/stdc++.h>   using namespace std;   int n;   vector<int> adj[100001];   vector<int> cost[3];   long long matrix[3][3] = {0};   int tree[100000];   int output[100000] = {0};   void makeTree(int a, int pos) {     tree[pos] = a;     for (auto &i : adj[a]) {       if (pos == 0 || tree[pos - 1] != i) makeTree(i, pos + 1);     }   }   long long calc(int a, int b, int i) {     if (i == n) return 0;     int c = 0 ^ 1 ^ 2 ^ a ^ b;     return cost[c][tree[i] - 1] + calc(b, c, i + 1);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cin >> n;     for (int i = 0; i < int(3); i++)       for (int j = 0; j < int(n); j++) {         int x;         cin >> x;         cost[i].push_back(x);       }     for (int i = 0; i < int(n - 1); i++) {       int a, b;       cin >> a >> b;       adj[a].push_back(b);       adj[b].push_back(a);     }     int counter = 0;     int lf;     for (int i = 0; i < int(n); i++) {       if (adj[i + 1].size() == 1) {         lf = i + 1;         counter++;       }       if (counter > 2) {         cout <<  -1 ;         return 0;       }     }     makeTree(lf, 0);     long long sml = pow(10, 15);     int x, y;     for (int i = 0; i < int(3); i++) {       for (int j = 0; j < int(3); j++) {         if (i == j) continue;         matrix[i][j] =             cost[i][tree[0] - 1] + cost[j][tree[1] - 1] + calc(i, j, 2);         sml = min(sml, matrix[i][j]);         if (sml == matrix[i][j]) {           x = i;           y = j;         }       }     }     cout << sml <<   n ;     output[tree[0] - 1] = x;     output[tree[1] - 1] = y;     for (int i = 2; i < n; i++) {       int c = 0 ^ 1 ^ 2 ^ x ^ y;       output[tree[i] - 1] = c;       x = y;       y = c;     }     for (int i = 0; i < int(n); i++) cout << output[i] + 1 <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, k, x[1010], y[1010], i, j, l, r[1010], w[1010], dad[1010], ss, flag,       use[1010], ke, t;   int rr[1010], ww[1010], use1[1010];   char s1[1010][20], s[20];   int fi(int x) { return dad[x] == x ? x : dad[x] = fi(dad[x]); }   int main() {     scanf( %d%d%d , &n, &m, &k);     for (i = 1; i <= n; i++) dad[i] = i;     for (i = 1; i <= m; i++) scanf( %d%d , &x[i], &y[i]);     for (i = 1; i <= k; i++) {       scanf( %s%d%d , s1[i], &r[i], &ss);       for (j = 1; j <= ss; j++) scanf( %d , &t), w[t] = i;     }     for (; !flag;) {       flag = 1;       for (i = 1; i <= m; i++)         if (!use[i])           if ((fi(x[i]) == fi(r[w[i]])) || (fi(y[i]) == fi(r[w[i]]))) {             flag = 0, use[i] = 1;             if (fi(x[i]) != fi(y[i])) dad[fi(x[i])] = fi(y[i]);           }     }     for (i = 1; i <= k; i++) {       scanf( %s%d%d , s, &rr[i], &ss);       for (j = 1; j <= k; j++)         if (!strcmp(s1[j], s)) break;       if (fi(rr[i]) != fi(r[j])) {         printf( NO n );         return 0;       }       for (l = 1; l <= ss; l++) {         scanf( %d , &ke);         ww[ke] = i;         if (fi(r[w[ke]]) != fi(rr[i])) {           printf( NO n );           return 0;         }       }     }     for (i = 1; i <= n; i++) dad[i] = i;     for (i = 1; i <= m; i++) use1[i] = use[i], use[i] = 0;     for (flag = 0; !flag;) {       flag = 1;       for (i = 1; i <= m; i++)         if (!use[i])           if ((fi(x[i]) == fi(rr[ww[i]])) || (fi(y[i]) == fi(rr[ww[i]]))) {             flag = 0, use[i] = 1;             if (fi(x[i]) != fi(y[i])) dad[fi(x[i])] = fi(y[i]);           }     }     for (i = 1; i <= m; i++)       if (use1[i] != use[i]) {         printf( NO n );         return 0;       }     printf( YES n );   }