malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   bool debug = 0;   int n, m, k;   int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};   string direc =  RDLU ;   long long ln, lk, lm;   char s[105][105];   int cal(int x) { return x * (x - 1) / 2; }   void fmain() {     scanf( %d , &n);     for (int(i) = 1; (i) <= (int)(n); (i)++) scanf( %s , s[i] + 1);     for (int(i) = 1; (i) <= (int)(n); (i)++) {       m = 0;       for (int(j) = 1; (j) <= (int)(n); (j)++)         if (s[i][j] ==  C ) m++;       k += cal(m);     }     for (int(j) = 1; (j) <= (int)(n); (j)++) {       m = 0;       for (int(i) = 1; (i) <= (int)(n); (i)++)         if (s[i][j] ==  C ) m++;       k += cal(m);     }     printf( %d n , k);   }   int main() {     fmain();     return 0;   }
#include <algorithm>   #include <climits>   #include <cmath>   #include <cstdio>   #include <cstring>   #include <fstream>   #include <functional>   #include <iomanip>   #include <iostream>   #include <map>   #include <queue>   #include <set>   #include <stack>   #include <string>   #include <vector>   #define pb push_back   #define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)   #define mem(a) memset(a, 0, sizeof(a))   using namespace std;   typedef long long ll;   typedef unsigned long long ull;   typedef long double ld;   typedef double db;   typedef pair<ll, ll> P;   const int maxn = 2e5 + 10;   int n, m;   vector<int> vec[maxn];   int dis[maxn];   bool vis[maxn];   int dp[maxn];   void bfs()   {       queue<P> q;       dis[1] = 0;       q.push(P{1, 0});       while (q.size())       {           P p = q.front();           q.pop();           int po = p.first;           int d = p.second;           if (vis[po])               continue;           vis[po] = 1;           dis[po] = d;           for (auto v : vec[po])           {               q.push(P(v, d + 1));           }       }   }   void dfs(int x)   {       vis[x] = 1;       dp[x] = dis[x];       for(auto u:vec[x])       {           if(!vis[u]&& dis[x]<dis[u])               dfs(u);           if(dis[x]<dis[u])               dp[x] = min(dp[x], dp[u]);           else               dp[x] = min(dp[x], dis[u]);       }   }   void solve()   {       cin >> n >> m;       for (int i = 1; i <= n; i++)           vec[i].clear(), dis[i] = 0, vis[i] = 0, dp[i] = 1e7;       for (int i = 1; i <= m; i++)       {           int x, y;           cin >> x >> y;           vec[x].pb(y);       }       bfs();       for (int i = 1; i <= n; i++)           vis[i] = 0;       dfs(1);       for (int i = 1; i <= n;i++)           cout << dp[i] <<    ;       cout << endl;   }   int main()   {       IOS;       int t;       cin >> t;       while (t--)           solve();       return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int ar[n], i, b;       b = n;       for (i = 0; i < n; i++) cin >> ar[i];       sort(ar, ar + n);       for (i = 0; i < n; i++) {         if (ar[i] < b)           b--;         else           break;       }       cout << b <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string str, result =   , tmp;     map<string, int> array;     cin >> str;     for (long long i = 0; i < 10; i++) cin >> tmp, array[tmp] = i;     tmp =   ;     for (long long i = 0; i < 80; i++) {       tmp += str[i];       if ((i + 1) % 10 == 0) result += array[tmp] +  0 , tmp =   ;     }     cout << result << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void fast() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);   }   int32_t main() {     fast();     long long t;     cin >> t;     while (t--) {       long long n, k;       cin >> n >> k;       priority_queue<long long> b;       priority_queue<long long, vector<long long>, greater<long long>> a;       long long d;       long long sum = 0;       for (long long i = 0; i < n; i++) {         cin >> d;         a.push(d);         sum += d;       }       for (long long i = 0; i < n; i++) {         cin >> d;         b.push(d);       }       for (long long i = 0; i < k; i++) {         if (a.top() < b.top()) {           long long a1 = a.top();           long long b1 = b.top();           a.pop();           b.pop();           b.push(a1);           a.push(b1);           sum = sum - a1 + b1;         } else           break;       }       cout << sum << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int r, h;   int main() {     scanf( %d%d , &r, &h);     double tt = h + r * 1.0 / 2;     double re = tt / r - (int)(tt / r);     int ans;     if (fabs(re) < 0.00001) {       ans = (int)(tt / r) * 2;     } else {       ans = (int)(tt / r) * 2;       re = h + r - (int)(tt / r) * r;       double mm = re - sqrt(3.0) / 2 * r;       if (mm > 0.00001) ans++;     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     long long int a, b, n;     while (t--) {       cin >> a >> b >> n;       n %= 3;       if (n == 0)         cout << a << endl;       else if (n == 1)         cout << b << endl;       else         cout << (a ^ b) << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int q;     cin >> q;     while (q != 0) {       int n;       cin >> n;       int one = 0;       if (n == 1)         cout <<  FastestFinger  << endl;       else if (n == 2)         cout <<  Ashishgup  << endl;       else if (n % 2 != 0)         cout <<  Ashishgup  << endl;       else {         int t = n;         int count = 0, last = n;         set<int> s;         while (n != 1) {           for (int i = 2; i <= sqrt(n); i++) {             if ((n % i) == 0) {               if (i % 2 != 0) {                 s.insert(i);                 count++;               }               n = (n / i);             }           }           if (n == last) break;           last = n;         }         if (n % 2 != 0) {           s.insert(n);           count++;         }         for (auto a : s) {           t = (t / a);         }         if ((t == 2 && count != 1) || t == 1)           cout <<  Ashishgup  << endl;         else if (t == 2 && count == 1)           cout <<  FastestFinger  << endl;         else if (count != 0)           cout <<  Ashishgup  << endl;         else           cout <<  FastestFinger  << endl;       }       q--;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int read() {     int x = 0, f = 0;     char ch = 0;     while (!isdigit(ch)) f |= (ch ==  - ), ch = getchar();     while (isdigit(ch)) (x *= 10) += (ch ^ 48), ch = getchar();     return f ? -x : x;   }   void Ot(int x) {     if (x < 0) putchar( - ), x = -x;     if (x >= 10) Ot(x / 10);     putchar(x % 10 + 48);   }   void Print(int x, char til =   n ) {     Ot(x);     putchar(til);   }   int Max(int x, int y) { return x > y ? x : y; }   int Min(int x, int y) { return x < y ? x : y; }   int Abs(int x) { return x < 0 ? -x : x; }   vector<int> G, P;   int n, ans;   char Getch() {     char c = getchar();     while (c !=  .  && c !=  *  && c !=  P ) c = getchar();     return c;   }   bool check(int x) {     int t = 1, pos = G[t - 1];     for (register int i = 0; i < P.size(); i++) {       int way = P[i] - pos;       if (way > 0 && way > x) return 0;       while (1) {         int len = P[i] - pos;         if (1ll * way * len < 0) {           if (Abs(len) < Abs(way))             len = Abs(len) * 2 + Abs(way);           else             len = Abs(len) + Abs(way) * 2;         } else           len = Abs(len);         if (len <= x)           t++, pos = G[t - 1];         else           break;         if (t > G.size()) return 1;       }     }     return 0;   }   signed main() {     n = read();     for (register int i = 1; i <= n; i++) {       char ch = Getch();       if (ch ==  P )         P.push_back(i);       else if (ch ==  * )         G.push_back(i);     }     if (!G.size()) return Print(0), 0;     int L = 0, R = 2 * n;     while (L <= R) {       register int mid = (L + R) >> 1;       if (check(mid))         ans = mid, R = mid - 1;       else         L = mid + 1;     }     Print(ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const int N = 3e5 + 10;   const long long mod = 998244353;   const double PI = acos(-1);   inline int ab(int x) { return x < 0 ? -x : x; }   inline int mm(int x, int p) { return x >= p ? x - p : x < 0 ? x + p : x; }   int main() {     int n, ans = 0, now = 0, pre = INF;     scanf( %d , &n);     for (int i = 1, x; i <= n; ++i) {       scanf( %d , &x);       if (x > pre * 2) {         ans = max(ans, now);         pre = x;         now = 1;       } else {         now++;         pre = x;       }     }     ans = max(ans, now);     printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> graph[(int)2e5 + 5];   int visited[(int)2e5 + 5];   vector<int64_t> values;   int64_t dfs(int node, int depth) {     if (visited[node] == 1) return 0;     visited[node] = 1;     int64_t child = 0;     for (int i = 0; i < graph[node].size(); i++) {       if (visited[graph[node][i]] == 0) child += dfs(graph[node][i], depth + 1);     }     values.push_back(depth - (int64_t)child);     return child + 1;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     int t = 1;     while (t--) {       int total_city, num_of_industry, u, v;       cin >> total_city >> num_of_industry;       for (int i = 1; i < total_city; i++) {         cin >> u >> v;         graph[u].push_back(v);         graph[v].push_back(u);       }       dfs(1, 0);       sort(values.begin(), values.end(), greater<int>());       int64_t sum = 0;       for (int i = 0; i < num_of_industry; i++) {         sum += values[i];       }       cout << sum;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1024;   int dp[N];   int n, k;   vector<int> ans;   int f(int i) {     if (i >= n) return 0;     if (i + k >= n) return 1e9;     if (dp[i] != -1) return dp[i];     return dp[i] = f(i + 2 * k + 1) + 1;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> k;     memset(dp, -1, sizeof dp);     int r = 1e9, best = -1;     for (int i = 0, ThxDem = k + 1; i < ThxDem; ++i)       if (r > f(i + k + 1) + 1) {         r = f(i + k + 1) + 1;         best = i;       }     while (best < n) {       ans.push_back(best + 1);       best += 2 * k + 1;     }     assert(((int)(ans).size()) == r);     cout << r <<   n ;     for (int x : ans) cout << x <<    ;     cout <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   bool cmp(int a, int b) {     if (a > b) {       return true;     } else {       return false;     }   }   int main() {     int n, k, le[26], cnt = 1;     for (int i = 0; i < 26; i++) {       le[i] = 0;     }     char c, ch;     cin >> n >> k;     getchar();     cin >> ch;     if (n == k & n == 1) {       cout << 1;       return 0;     }     for (int i = 0; i < n - 1; i++) {       cin >> c;       if (c == ch) {         cnt++;       }       if (c != ch || i == n - 2) {         le[ch -  a ] += cnt / k;         cnt = 1;         ch = c;       }     }     sort(le, le + 26, cmp);     cout << le[0];   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int maxn = 2e5 + 5;   struct node {     int u, v, ne;   } e[maxn << 1];   int n;   int head[maxn], len;   int ve[maxn], b[maxn];   void add(int u, int v) {     e[len].u = u;     e[len].v = v;     e[len].ne = head[u];     head[u] = len++;   }   void dfs(int x, int p, int k) {     ve[x] = 1;     b[x] = k;     for (int i = head[x]; ~i; i = e[i].ne) {       int v = e[i].v;       if (v == p) continue;       dfs(v, x, k ^ 1);       ve[x] += ve[v];     }     return;   }   int main() {     memset(head, -1, sizeof(head));     cin >> n;     for (int i = 1, x, y; i < n; i++) {       scanf( %d %d , &x, &y);       add(x, y);       add(y, x);     }     dfs(1, 0, 0);     long long ans = 0, sum = 0;     for (int i = 1; i <= n; i++) {       ans += 1ll * ve[i] * (n - ve[i]);       sum += b[i];     }     ans += sum * (n - sum);     cout << ans / 2 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long x = 0;     char ch = getchar();     bool f = 0;     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) f = 1;     for (; isdigit(ch); ch = getchar()) x = x * 10 + ch -  0 ;     return f ? -x : x;   }   void write(long long x) {     if (x < 0) putchar( - ), x = -x;     if (x >= 10) write(x / 10);     putchar(x % 10 +  0 );   }   void writeln(long long x) {     write(x);     puts(  );   }   void writep(long long x) {     write(x);     putchar(   );   }   const int N = 1000005;   int n, cnt;   struct info {     long long x, y, z;     int id;   } a[N], b[N];   bool cmp(info a, info b) {     if (a.x != b.x) return a.x < b.x;     if (a.y != b.y) return a.y < b.y;     return a.z < b.z;   }   void solve(bool d) {     cnt = 0;     sort(a + 1, a + n + 1, cmp);     for (int i = 1, j = 1; i <= n; i = j + 1) {       j = i;       if (d) {         while (j + 1 <= n && a[j + 1].x == a[j].x && a[j + 1].y == a[j].y) j++;       } else         while (j + 1 <= n && a[j + 1].x == a[j].x) j++;       for (int k = i; k <= j; k += 2) {         if (k + 1 > j) break;         writep(a[k].id);         writeln(a[k + 1].id);       }       if ((j - i + 1) % 2) b[++cnt] = a[j];     }     if (cnt == 0) exit(0);     n = cnt;     for (int i = (int)(1); i <= (int)(n); i++) a[i] = b[i];   }   int main() {     n = read();     for (int i = (int)(1); i <= (int)(n); i++)       a[i].x = read(), a[i].y = read(), a[i].z = read(), a[i].id = i;     solve(1);     solve(0);     for (int i = 1; i <= n; i += 2) writep(a[i].id), writeln(a[i + 1].id);   }
#include <bits/stdc++.h>   using namespace std;   using ll = int_fast64_t;   constexpr int mod = 1e9 + 7;   constexpr int inf = (1 << 30) - 1;   constexpr ll infll = (1LL << 61) - 1;   #pragma GCC target( avx2 )   #pragma GCC optimize( O3 )   #pragma GCC optimize( unroll-loops )   int main() {     ios::sync_with_stdio(false), cin.tie(nullptr);     int N;     cin >> N;     map<pair<int, int>, int> mp;     vector<pair<int, int>> v(N);     for (int i = 0; i < N; i++) {       cin >> v[i].first >> v[i].second;       if (mp[v[i]] != 0) {         cout << mp[v[i]] <<     << i + 1 <<   n ;         return 0;       }       mp[v[i]] = i + 1;       v[i].second *= -1;     }     sort(v.begin(), v.end());     set<int> st;     int ans1 = -1, ans2 = -1;     for (int i = 0; i < N; i++) {       v[i].second *= -1;       st.erase(st.begin(), st.lower_bound(v[i].first));       if (!st.empty() && st.lower_bound(v[i].second) != st.end()) {         ans1 = i;       }       st.insert(v[i].second);     }     if (ans1 == -1) {       cout << -1 <<     << -1 <<   n ;       return 0;     }     for (int i = 0; i < N; i++) {       if (i == ans1) continue;       if (v[i].first <= v[ans1].first && v[ans1].second <= v[i].second) ans2 = i;     }     cout << mp[v[ans1]] <<     << mp[v[ans2]] <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 3010;   long long a[N], b[N], n, m;   long long sa = 0, sb = 0, bestSa, bestSb;   pair<int, int> ansOne, ansTwo;   vector<long long> va, vb;   void add(long long *arr, int size, vector<long long> &v) {     for (int i = 0; i < size; ++i)       for (int j = i + 1; j < size; ++j) v.push_back(arr[i] + arr[j]);   }   long long one() {     long long ba = sa;     long long bb = sb;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         long long nsa = sa - a[i] + b[j], nsb = sb - b[j] + a[i];         if (llabs(nsa - nsb) < llabs(ba - bb)) {           ba = nsa;           bb = nsb;           ansOne = pair<int, int>(i + 1, j + 1);         }       }     }     return llabs(ba - bb);   }   long long two() {     long long diff = llabs(sa - sb);     for (int i = 0; i < (int)va.size(); ++i) {       long long x = va[i];       long long y = x + ((sb - sa) / 2);       int at = lower_bound(vb.begin(), vb.end(), y) - vb.begin();       for (int j = at - 1; j <= at; ++j) {         if (j >= 0 and j < (int)vb.size()) {           long long nsa = sa - x + vb[j];           long long nsb = sb - vb[j] + x;           if (llabs(nsa - nsb) < diff) {             diff = llabs(nsa - nsb);             ansTwo = pair<int, int>(x, vb[j]);           }         }       }     }     return diff;   }   pair<int, int> find(long long e, long long *arr, int size) {     for (int i = 0; i < size; ++i)       for (int j = i + 1; j < size; ++j)         if (arr[i] + arr[j] == e) return pair<int, int>(i + 1, j + 1);   }   void solve() {     long long d0 = llabs(sa - sb), d1 = one(), d2 = d1;     if (n > 1 and m > 1) {       d2 = two();     }     long long best = min(d0, min(d1, d2));     cout << best <<   n ;     if (best == d0) {       cout <<  0 n ;     } else if (best == d1) {       cout <<  1 n ;       cout << ansOne.first <<     << ansOne.second <<   n ;     } else {       vector<pair<int, int> > pans;       pans.push_back(find(ansTwo.first, a, n));       pans.push_back(find(ansTwo.second, b, m));       cout <<  2 n ;       cout << pans[0].first <<     << pans[1].first <<   n ;       cout << pans[0].second <<     << pans[1].second <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> a[i];       sa += a[i];     }     cin >> m;     for (int i = 0; i < m; ++i) {       cin >> b[i];       sb += b[i];     }     add(a, n, va);     add(b, m, vb);     sort(vb.begin(), vb.end());     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = (int)1e9;   const int mod = (int)1e9 + 7;   const int MAXN = (int)3e5 + 5;   vector<int> primes[1000005];   int x, p, k;   vector<pair<int, int> > v(1 << 7);   int calc(int a) {     int cnt = 1;     int num = 0;     int tmp = a;     a = 0;     for (int i = 1; i < (1 << primes[p].size()); i++) {       if (cnt * 2 == i) {         cnt *= 2;         num++;       }       v[i] = {v[i - cnt].first * primes[p][num], v[i - cnt].second + 1};       if (v[i].second % 2) {         a += tmp / v[i].first;       } else {         a -= tmp / v[i].first;       }     }     return tmp - a;   }   void solve() {     cin >> x >> p >> k;     k += calc(x);     int l = x + 1, r = 6e6 + 5e5 + 3e4 + 4e3 + 5e2;     while (l < r) {       int m = (l + r) / 2;       if (calc(m) >= k) {         r = m;       } else {         l = m + 1;       }     }     cout << l <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     for (int i = 2; i < 1000005; i++) {       if (!primes[i].size()) {         for (int j = i; j < 1000005; j += i) {           primes[j].push_back(i);         }       }     }     v[0] = {1, 0};     int t = 1;     cin >> t;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     int t[n];     for (int i = 0; i < n; i++) {       cin >> t[i];     }     sort(t, t + n);     bool b = true;     int j = 0;     if (t[0] > 1) {       cout << 1;     } else {       while ((b == true) && (j < n)) {         if (t[j + 1] == t[j] + 1) {           j++;         } else {           b = false;         }       }       cout << t[j] + 1;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e6 + 500;   const long double eps = (1e-12);   const int logn = 21;   const double Pi = acos(-1.0);   const long long pp = 998244353;   int lowbit(int x) { return x & (-x); }   const long long INF = 1e11 + 7;   long long dp[3][205][4];   long long a[MAXN];   long long pre[MAXN];   long long lst[MAXN];   signed main() {     long long n;     scanf( %lld , &n);     for (long long i = 1; i <= n; i++) {       scanf( %lld , &a[i]);     }     dp[0][1][2] = 1;     long long now = 0;     for (long long i = 1; i <= n; i++) {       now ^= 1;       for (long long j = 1; j <= 200; j++) {         pre[j] = lst[j] = 0;         for (long long k = 0; k <= 2; k++) dp[now][j][k] = 0;       }       for (long long k = 0; k <= 2; k++) pre[1] += dp[now ^ 1][1][k];       for (long long j = 2; j <= 200; j++) {         for (long long k = 0; k <= 2; k++) pre[j] += dp[now ^ 1][j][k];         pre[j] %= pp;         pre[j] += pre[j - 1];         pre[j] %= pp;       }       for (long long k = 1; k <= 2; k++) lst[200] += dp[now ^ 1][200][k];       for (long long j = 199; j > 0; j--) {         for (long long k = 1; k <= 2; k++) lst[j] += dp[now ^ 1][j][k];         lst[j] %= pp;         lst[j] += lst[j + 1];         lst[j] %= pp;       }       for (long long j = 1; j <= 200; j++) {         dp[now][j][0] += pre[j - 1];         dp[now][j][0] %= pp;         dp[now][j][1] +=             dp[now ^ 1][j][0] + dp[now ^ 1][j][1] + dp[now ^ 1][j][2];         dp[now][j][1] %= pp;         dp[now][j][2] += lst[j + 1];         dp[now][j][2] %= pp;       }       if (a[i] != -1) {         for (long long j = 1; j <= 200; j++) {           if (j == a[i]) continue;           for (long long k = 0; k <= 2; k++) {             dp[now][j][k] = 0;           }         }       }     }     long long ans = 0;     for (long long j = 1; j <= 200; j++) {       for (long long k = 1; k <= 2; k++) {         ans += dp[now][j][k];         ans %= pp;       }     }     printf( %lld , ans);     return 0;   }
#include <bits/stdc++.h>   int min(int a, int b) { return a < b ? a : b; }   int next[1 + (200 * (200 - 1) / 2)], jj[1 + (200 * (200 - 1) / 2)];   int link(int l, int j) {     static int l_ = 1;     next[l_] = l;     jj[l_] = j;     return l_++;   }   int ao[200], cc[200], dd[200], qq[3][200];   int solve(int n, int c_) {     static int dd_[200], head[3], cnt[3];     int i, j, l, k, t, c;     memcpy(dd_, dd, n * sizeof *dd);     memset(head, 0, sizeof head);     memset(cnt, 0, sizeof cnt);     for (i = 0; i < n; i++)       if (dd_[i] == 0) {         c = cc[i];         qq[c][head[c] + cnt[c]++] = i;       }     k = 0, t = 0;     while (k < n) {       while (cnt[c_]) {         i = qq[c_][cnt[c_]--, head[c_]++];         k++, t++;         for (l = ao[i]; l; l = next[l]) {           j = jj[l];           if (--dd_[j] == 0) {             c = cc[j];             qq[c][head[c] + cnt[c]++] = j;           }         }       }       c_ = (c_ + 1) % 3;       t++;     }     return t - 1;   }   int main() {     int n, i, j, k;     scanf( %d , &n);     for (i = 0; i < n; i++) scanf( %d , &cc[i]), cc[i]--;     for (i = 0; i < n; i++) {       scanf( %d , &k);       while (k--) {         scanf( %d , &j), j--;         ao[j] = link(ao[j], i);         dd[i]++;       }     }     printf( %d n , min(solve(n, 0), min(solve(n, 1), solve(n, 2))));     return 0;   }