malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   const double eps = 1e-3;   const double PI = 3.1415926535897932384626433832795;   const int maxn = 9999999;   using namespace std;   char name[1001][40];   int grade[1001];   int main() {     int n;     while (~scanf( %d , &n)) {       map<string, int> mp;       for (int i = 1; i <= n; i++) {         scanf( %s %d , name[i], &grade[i]);         mp[name[i]] += grade[i];       }       int max = -9999999;       for (map<string, int>::iterator it = mp.begin(); it != mp.end(); it++)         if (it->second > max) max = it->second;       map<string, int> mp2;       for (int i = 1; i <= n; i++) {         mp2[name[i]] += grade[i];         if (mp[name[i]] == max && mp2[name[i]] >= max) {           puts(name[i]);           break;         }       }     }     return 0;   }
#include <bits/stdc++.h>      using namespace std;   typedef long long ll;   #define all(x) (x).begin(), (x).end()   typedef vector<bool> vb;   typedef vector<int> vi;   typedef vector<ll> vl;   typedef vector<vector<bool>> vvb;   typedef vector<vector<int>> vvi;   typedef vector<vector<ll>> vvl;   typedef pair<int,int> pii;   typedef pair<ll,ll> pll;   void debugF(ostream &os) {os << endl;}   template <typename Head, typename... Tail>   void debugF(ostream &os, Head H, Tail... T) { os <<     << H; debugF(os, T...); }   #define debug(...) cerr <<  [  << #__VA_ARGS__ <<  ]: , debugF(cerr, __VA_ARGS__)   template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }   template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); os << (i>0 ?    :  ) << v[i++]); return os;}   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const int mod = 998244353;      ll expMod(ll a, ll b, ll mod){       ll ans = 1;       while(b){           if(b&1) ans = (ans*a)%mod;           a = (a*a)%mod;           b >>= 1;       }       return ans;   }      int calc(vector<string> &M, vi &dp2){       int n = M.size(); int m = M[0].size();       int i,j;       int ans = 0;       for(i=0;i<n;i++){           int cc = 0;           for(j=0;j<m;j++){               if(M[i][j] ==  o ){                   cc++;                   if(j+1 >= m || M[i][j+1] !=  o ){                       ans += dp2[cc-1];                       ans %= mod;                   }               }               else                    cc = 0;           }       }       return ans;   }      void transpose(vector<string> &M){       int n = M.size(); int m = M[0].size();       vector<string> M2(m, string(n, . ));       int i,j;       for(i=0;i<n;i++){           for(j=0;j<m;j++){               M2[j][i] = M[i][j];           }       }       M = M2;   }      void solve(){       int n, m, i, j;       cin >> n >> m;       vector<string> M(n);       cin >> M;       int nw = 0;       for(i=0;i<n;i++){           nw += count(all(M[i]),  o );       }       if(nw < 2){           cout << 0 <<   n ;           return;       }          int N = max(n,m);          vi p2(nw+1);       p2[0] = 1;       for(i=1;i<=nw;i++){           p2[i] = (p2[i-1]*2)%mod;       }       ll div4 = expMod(4, mod-2, mod);              vi dp(N);       vi dp2(N); //dp2[i] = dp[0] + ... + dp[i-1]       dp[0] = p2[nw-2];       dp2[0] = 0;       for(i=1;i<N;i++){           dp[i] = p2[nw-3];           if(i-2 >= 0){               dp[i] += (dp[i-2]*div4)%mod;               dp[i] %= mod;             }           dp2[i] = (dp2[i-1] + dp[i-1])%mod;       }          auto ans = calc(M, dp2);       transpose(M);       ans += calc(M, dp2);       ans %= mod;       cout << ans <<   n ;   }      int main(){       ios::sync_with_stdio(false);       cin.tie(0);       int nt = 1;       for(int tt=1;tt<=nt;tt++){           solve();       }       return 0;   }
#include <bits/stdc++.h>   int main() {     int n, k, i, j;     int hols, arr[1000];     int temp, loop, flag = 0;     scanf( %d%d , &n, &k);     scanf( %d , &hols);     for (i = 0; i <= n; i++) {       arr[i] = 0;     }     for (i = 0; i < hols; i++) {       scanf( %d , &temp);       arr[temp] = 2;     }     for (i = 0; i <= n;) {       for (j = i; j < i + k; j++) {         if (arr[j] == 2) {           flag = 1;           loop = j;         }       }       if (flag == 1) {         flag = 0;         i = loop;       } else {         i = i + k;       }       arr[i] = 1;     }     int min = 0;     for (i = 1; i <= n; i++) {       if (arr[i] == 1 || arr[i] == 2) min++;     }     printf( %d , min);     return 0;   }
#include <bits/stdc++.h>   const double eps = 1e-9;   const double pi = acos(-1);   using namespace std;   struct sx {};   bool cmp(int a, int b) { return a > b; }   long long t1, t2, t3;   int main() {     int n, m;     cin >> n >> m;     int x = (n + m) / 3;     while (t1 < x && ((n >= 1 && m >= 2) || (n >= 2 && m >= 1))) {       if (n > m) {         n -= 2;         m -= 1;       } else {         m -= 2;         n -= 1;       }       t1++;     }     cout << t1;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string str1, str2;     cin >> str1 >> str2;     for (int i = 0; i < str1.size(); i++) {       str1[i] = tolower(str1[i]);       str2[i] = tolower(str2[i]);     }     if (str1 == str2)       cout <<  0 ;     else if (str1 < str2)       cout <<  -1 ;     else       cout <<  1 ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   vector<int> v;   set<int> g[100005];   vector<pair<int, int> > f;   int main() {     ios::sync_with_stdio(false);     cin >> n >> m;     for (int i = 1; i * i <= n; i++) {       if (n % i == 0) {         v.push_back(i);         if (i * i != n && i != 1) v.push_back(n / i);       }     }     int a, b;     for (int i = 1; i <= m; i++) {       cin >> a >> b;       g[a].insert(a);       g[b].insert(a);       f.push_back(make_pair(a, b));     }     for (auto x : v) {       bool flag = 1;       for (auto y : f) {         int l = y.first, r = y.second;         l += x, r += x;         if (l > n) l -= n;         if (r > n) r -= n;         if (g[l].count(r) || g[r].count(l))           continue;         else {           flag = 0;           break;         }       }       if (flag) {         cout <<  Yes  << endl;         exit(0);       }     }     cout <<  No ;   }
#include <bits/stdc++.h>   using namespace std;   using ull = unsigned long long;   using ll = long long;   using ld = long double;   const int mod = 1e9 + 7;   const double pi = acos(-1.0);   const int inf = INT_MAX;   const int N = (1 << 22);   int h, g, a[N];   bool ok(int i) {     while (true) {       if (a[i << 1] == 0 && a[i << 1 | 1] == 0) {         break;       }       if (a[i << 1] > a[i << 1 | 1]) {         i = i << 1;       } else {         i = i << 1 | 1;       }     }     int msb = 32 - __builtin_clz(i) - 1;     return msb >= g;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int t;     cin >> t;     while (t--) {       cin >> h >> g;       for (int i = 1; i < (1 << h); i++) cin >> a[i];       fill(a + (1 << h), a + (1 << (h + 1)), 0);       vector<int> ops;       for (int i = 1; i < (1 << g); i++) {         while (ok(i)) {           ops.push_back(i);           int j;           for (j = i; a[j << 1] || a[j << 1 | 1];) {             if (a[j << 1] > a[j << 1 | 1]) {               a[j] = a[j << 1];               j = j << 1;             } else {               a[j] = a[j << 1 | 1];               j = j << 1 | 1;             }           }           a[j] = 0;         }       }       ll ans = 0;       for (int i = 1; i < (1 << g); i++) {         ans += a[i];       }       cout << ans <<   n ;       for (int i : ops) cout << i <<    ;       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int v[1000000];   int buggy_sorting(int n) {     if (n == 1 || n == 2) return 0;     v[0] = 5;     v[1] = 6;     v[2] = 1;     for (int i = 3; i < n; i++) v[i] = i;     return 1;   }   void median() {     int t, n, k, pas, cnt;     long long int s;     cin >> t;     for (int z = 0; z < t; z++) {       cin >> n >> k;       pas = n / 2;       for (int i = 0; i < n * k; i++) cin >> v[i];       cnt = 0;       s = 0;       for (int i = n * k - 1 - pas; i >= 0; i -= pas + 1)         if (cnt < k) {           s += v[i];           cnt++;         }       cout << s <<   n ;     }   }   int main() {     int n;     cin >> n;     if (buggy_sorting(n))       for (int i = 0; i < n; i++) cout << v[i] <<    ;     else       cout << -1;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool used[100001];   int ans[100001], a[100001];   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];       if (a[i] <= n && !used[a[i]]) {         used[a[i]] = 1;         ans[i] = a[i];       }     }     int first = 1;     for (int i = 1; i <= n; i++) {       if (ans[i] == 0) {         while (used[first]) first++;         ans[i] = first;         first++;       }     }     for (int i = 1; i <= n; i++) {       cout << ans[i] <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     int s = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) s = s * 10 + ch -  0 , ch = getchar();     return s * f;   }   const int maxn = 1e5 + 10;   int n, tot, head[maxn], d[maxn], a[maxn], ans, sz[maxn];   struct data {     int to, next, w;   } edge[maxn];   void calc(int x) {     sz[x] = 1;     for (int i = head[x]; i; i = edge[i].next) {       int y = edge[i].to;       calc(y);       sz[x] += sz[y];     }   }   void dfs(int x) {     if (d[x] > a[x]) {       ans += sz[x];       return;     }     for (int i = head[x]; i; i = edge[i].next) {       int y = edge[i].to;       d[y] = d[x] + edge[i].w;       if (d[y] < 0) d[y] = 0;       dfs(y);     }   }   inline void make(int u, int v, int w) {     edge[++tot] = (data){v, head[u], w};     head[u] = tot;   }   int main() {     n = read();     for (int i = 1; i <= n; i++) a[i] = read();     for (int i = 2; i <= n; i++) {       int x = read(), y = read();       make(x, i, y);     }     calc(1);     dfs(1);     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, k, p, d, x;     cin >> n >> k >> d;     p = n - k;     for (int i = 0; i < d; i++) {       cin >> x;       x--;       if (p <= k) {         if (x % 2 == 0 && x / 2 < p) {           cout <<  . ;         } else {           cout <<  X ;         }       } else {         if (n % 2 == 0) {           if ((x % 2 == 1) && (n - 1 - x) / 2 < k) {             cout <<  X ;           } else {             cout <<  . ;           }         } else {           if (x != n - 1) {             if ((x % 2 == 1) && (n - 2 - x) / 2 < (k - 1)) {               cout <<  X ;             } else {               cout <<  . ;             }           } else {             if (k > 0)               cout <<  X ;             else               cout <<  . ;           }         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long int n;     cin >> n;     string s;     vector<long long int> arr(n + 1);     for (long long int i = 1; i <= n; i++) cin >> arr[i];     cin >> s;     vector<long long int> pre(n, 0);     if (s.back() ==  1 ) pre[n - 1] = 1;     for (int i = n - 2; i >= 0; i--) {       if (s[i] ==  1 )         pre[i] = 1 + pre[i + 1];       else         pre[i] = 0;     }     for (int i = 1; i <= n; i++) {       if (i > arr[i]) {         if (arr[i] + pre[arr[i] - 1] < i) {           cout <<  NO n ;           return;         }       } else if (i < arr[i]) {         if (i + pre[i - 1] < arr[i]) {           cout <<  NO n ;           return;         }       }     }     cout <<  YES n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t = 1;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   unsigned char G[301][301];   unsigned char bv[301];   int ints[301];   int main() {     int n;     cin >> n;     for (register int i = 1; i <= n; i++) cin >> ints[i];     for (register int i = 1; i <= n; i++) {       for (register int j = 1; j <= n; j++) {         char c;         cin >> c;         G[i][j] = c -  0 ;       }     }     for (register int k = 1; k <= n; k++) {       for (register int i = 1; i <= n; i++) {         for (register int j = 1; j <= n; j++) {           G[i][j] = G[i][j] || (G[i][k] && G[k][j]);         }       }     }     for (register int i = 1; i <= n; i++) {       G[i][i] = 1;     }     ints[0] = 0x7fffffff;     for (register int i = 1; i <= n; i++) {       int minn = 0;       for (register int j = 1; j <= n; j++) {         if (ints[j] < ints[minn] && G[i][j] && bv[j] == 0) minn = j;       }       printf( %d  , ints[minn]);       bv[minn] = 1;     }     return (0);   }
#include <bits/stdc++.h>   #pragma GCC optimize(2)   using namespace std;   const int INF = 0x3f3f3f3f;   const long long MOD = 1e9 + 7;   long long n, sum[100002][2], sqsum[100002][2], cnt[100002][2], all_7[100002],       s[100002], ten[200002];   long long solve(string str) {     n = str.length();     memset(all_7, 0, sizeof(all_7));     memset(sum, 0, sizeof(sum)), memset(sqsum, 0, sizeof(sqsum)),         memset(cnt, 0, sizeof(cnt));     cnt[0][1] = 1;     all_7[n + 1] = 1;     for (long long i = n; i >= 1; --i)       all_7[i] = all_7[i + 1] & (str[i - 1] ==  7 );     long long rest = 0;     for (long long i = 1; i <= n; ++i) {       long long num = str[i - 1] ^ 48;       for (long long j = 0; j < 2; ++j) {         for (long long jj = 4; jj <= 7; jj += 3) {           if (j && (jj > num)) break;           long long new_j = j & (jj == num);           (cnt[i][new_j] += cnt[i - 1][j]) %= MOD;           (sum[i][new_j] +=            (1ll * cnt[i - 1][j] * jj % MOD + 10ll * sum[i - 1][j])) %= MOD;           (sqsum[i][new_j] +=            (100ll * sqsum[i - 1][j] + 20ll * jj * sum[i - 1][j] +             1ll * jj * jj * cnt[i - 1][j])) %= MOD;         }       }       long long tmp = 0, A, B;       bool smaller = (str[i - 1] ==  7 );       A = 7ll * ten[n - i] % MOD + 4ll * s[n - i] % MOD;       A %= MOD;       B = 4ll * ten[n - i] % MOD + 7ll * s[n - i] % MOD;       B %= MOD;       long long Sum = sum[i - 1][0], Sqsum = sqsum[i - 1][0], Cnt = cnt[i - 1][0];       if (smaller) {         Sum += sum[i - 1][1], Sqsum += sqsum[i - 1][1], Cnt += cnt[i - 1][1];         Sum %= MOD, Sqsum %= MOD, Cnt %= MOD;       }       (tmp += (1ll * Sqsum * ten[(n - i + 1) * 2] % MOD)) %= MOD;       (tmp +=        (1ll * Sum * A % MOD + 1ll * Sum * B % MOD) * ten[n - i + 1] % MOD) %= MOD;       (tmp += 1ll * A * B % MOD * Cnt % MOD) %= MOD;       (rest += tmp) %= MOD;     }     return rest;   }   signed main() {     ios::sync_with_stdio(false);     string l, r;     s[0] = 0;     s[1] = 1;     ten[0] = 1;     ten[1] = 10;     for (long long i = 2; i <= 100000; ++i) s[i] = (10ll * s[i - 1] + 1) % MOD;     for (long long i = 2; i <= 200000; ++i) ten[i] = (10ll * ten[i - 1]) % MOD;     cin >> l >> r;     cout << (solve(r) - solve(l) + MOD) % MOD << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long n, i, j, x, k;     cin >> n >> k;     string s, t;     cin >> s;     t = s;     for (i = 0; i < n; i++) {       if (i - k >= 0) t[i] = t[i - k];     }     if (t > s) {       cout << n <<   n  << t;       return 0;     }     for (i = 0; i < n; i++) {       if (s[i] > t[i]) {         for (j = k - 1; j >= 0; j--) {           if (t[j] !=  9 ) break;         }         for (; j < n; j += k) t[j]++;         break;       }     }     for (j = 0; j < k; j++)       if (s[j] < t[j]) break;     for (i = j + 1; i < k; i++) {       for (long long p = i; p < n; p += k) t[p] =  0 ;     }     cout << n <<   n  << t;   }
#include <bits/stdc++.h>   using namespace std;   void err(istream_iterator<string> it) { cerr << endl; }   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {     cerr << *it <<   =   << a << endl;     err(++it, args...);   }   const int N = 1000 + 5, mod = 1000000007;   int n, edges;   vector<pair<int, int>> graph[N];   bool cycle;   bool vis[N];   int mxmDepth, indx, mnmDiameter;   void dfs(int node, int dep) {     vis[node] = true;     if (mxmDepth < dep) {       mxmDepth = dep;       indx = node;     }     for (auto child : graph[node]) {       if (vis[child.first]) {         cycle = true;         return;       }       mnmDiameter = min(mnmDiameter, child.second);       dfs(child.first, dep + 1);     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> edges;     set<int> st;     for (int i = 1; i <= n; i++) st.insert(i);     for (int i = 1; i <= edges; i++) {       int u, v, c;       cin >> u >> v >> c;       graph[u].push_back({v, c});       st.erase(v);     }     vector<pair<int, pair<int, int>>> ans;     for (auto par : st) {       if (graph[par].empty()) continue;       cycle = false;       mxmDepth = 0;       mnmDiameter = 1e9;       indx = -1;       dfs(par, 0);       if (cycle) continue;       ans.push_back({par, {indx, mnmDiameter}});     }     cout << ans.size() <<   n ;     for (auto it : ans) {       cout << it.first <<     << it.second.first <<     << it.second.second            <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       long long int n, r, an;       cin >> n >> r;       if (r < n)         an = (r) * (r + 1) / 2;       else {         an = (n) * (n - 1) / 2;         an++;       }       cout << an;       cout <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5;   int n;   long long seg[4 * N], lazy[4 * N];   void update(int st, int en, long long v, int idx = 1, int L = 0,               int R = n - 1) {     if (L > en || R < st) {       return;     }     if (L >= st && R <= en) {       seg[idx] += v;       lazy[idx] += v;       return;     }     seg[2 * idx] += lazy[idx];     seg[2 * idx + 1] += lazy[idx];     lazy[2 * idx] += lazy[idx];     lazy[2 * idx + 1] += lazy[idx];     lazy[idx] = 0;     update(st, en, v, 2 * idx, L, (L + R) / 2);     update(st, en, v, 2 * idx + 1, (L + R) / 2 + 1, R);     seg[idx] = min(seg[2 * idx], seg[2 * idx + 1]);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     int a[n], c[n];     for (int i = 0; i < n; ++i) {       cin >> a[i], --a[i];     }     for (int i = 0; i < n; ++i) {       cin >> c[a[i]];     }     long long s = 0;     for (int i = 0; i < n; ++i) {       update(i, i, s);       s += c[i];     }     long long ans = 9e18;     for (int i = 0; i < n - 1; ++i) {       update(0, a[i], c[a[i]]);       update(a[i], n - 1, -c[a[i]]);       ans = min(ans, seg[1]);     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     bool val = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         int a;         scanf( %d , &a);         if (i == j) {           val ^= a;         }       }     }     int q;     scanf( %d , &q);     while (q--) {       int t;       scanf( %d , &t);       if (t == 3) {         printf( %d , val);       } else {         int i;         scanf( %d , &i);         val ^= 1;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long BINF = 1e18 + 10;   signed main() {     ios_base::sync_with_stdio(false);     long long T;     cin >> T;     while (T--) {       long long n, a, b;       cin >> n >> a >> b;       vector<long long> c(n);       for (auto &it : c) {         char kek;         cin >> kek;         it = kek -  0 ;       }       vector<vector<long long>> dp(n + 1, vector<long long>(2, BINF));       dp[0][0] = b;       for (long long i = 0; i < n; i++) {         dp[i + 1][1] = min(dp[i][0] + 2 * (a + b), dp[i][1] + a + 2 * b);         if (!c[i] && (i + 1 == n || !c[i + 1])) {           dp[i + 1][0] = min(dp[i][0] + a + b, dp[i][1] + 2 * a + b);         }       }       cout << dp[n][0] <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int N;   typedef struct Nodo {     long long int v, l;   } Nodo;   int S;   Nodo segtree[2000024];   inline void st_init(int N) {     if (__builtin_popcount(N) <= 1) {       S = N;     } else {       for (; __builtin_popcount(N) > 1; N -= N & -N)         ;       S = N << 1;     }     memset(segtree, 0, (sizeof(Nodo) * S) << 1);   }   inline void st_deflag(int p) {     long long int l = segtree[p].l;     if (!l) {       return;     }     if (p < S) {       long long int &a = segtree[p << 1].l;       long long int &b = segtree[(p << 1) + 1].l;       a = l;       b = l;     }     segtree[p].v = l;     segtree[p].l = 0;   }   inline void st_update(int n) {     long long int l = segtree[n << 1].v;     long long int r = segtree[(n << 1) + 1].v;     segtree[n].v = (l > r ? l : r);   }   void st_set(int n, int a, int b, int i, int f, long long int v) {     st_deflag(n);     if (i >= a && f <= b) {       segtree[n].l = v;       st_deflag(n);       return;     } else if (f < a || i > b) {       return;     }     int d = ((f - i) >> 1) + 1;     st_set(n << 1, a, b, i, f - d, v);     st_set((n << 1) + 1, a, b, i + d, f, v);     st_update(n);   }   long long int st_query(int n, int a, int b, int i, int f) {     st_deflag(n);     if (i >= a && f <= b) {       return segtree[n].v;     } else if (f < a || i > b) {       return -0x3f3f3f3f3f3f3f3fll;     }     int d = ((f - i) >> 1) + 1;     long long int r1 = st_query(n << 1, a, b, i, f - d);     long long int r2 = st_query((n << 1) + 1, a, b, i + d, f);     return (r1 > r2 ? r1 : r2);   }   int M;   int W, H;   int main() {     int i, a;     long long R;     scanf( %d , &N);     st_init(N);     for (i = 0; i < N; i++) {       scanf( %d , &a);       st_set(1, i, i, 0, S - 1, (long long)a);     }     scanf( %d , &M);     for (i = 0; i < M; i++) {       scanf( %d %d , &W, &H);       R = st_query(1, 0, (W - 1 < N - 1 ? W - 1 : N - 1), 0, S - 1);       printf( %I64d n , R);       st_set(1, 0, (W - 1 < N - 1 ? W - 1 : N - 1), 0, S - 1, R + (long long)H);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = (long long)1e9 + 7;   const long double PI = 3.141592653589793238462643383279502884197;   priority_queue<int, vector<int>, greater<int> > pq;   vector<int> v;   int cnt[512];   pair<int, int> vec[512];   pair<int, int> sec[512];   int main() {     memset(vec, 0x3f, sizeof(vec));     memset(vec, 0x3f, sizeof(vec));     int n, m;     scanf( %d %d , &n, &m);     int t;     for (int i = 0; i < n; i++) {       scanf( %d , &t);       vector<int> kk;       int k, bit = 0;       while (t--) {         scanf( %d , &k);         k--;         bit |= 1 << k;       }       for (int j = 0; j < 512; j++)         if ((bit & j) == bit) cnt[j]++;     }     for (int i = 0; i < m; i++) {       int p, t, bit = 0;       scanf( %d %d , &p, &t);       while (t--) {         int k;         scanf( %d , &k);         k--;         bit |= (1 << k);       }       if (vec[bit].first > p) {         sec[bit] = vec[bit];         vec[bit] = {p, i + 1};       } else if (sec[bit].first > p) {         sec[bit] = {p, i + 1};       }     }     int mav = -1, mivp = 1e9, u, v;     for (int i = 0; i < 512; i++) {       if (vec[i].first > 1e9) continue;       for (int j = i + 1; j < 512; j++) {         if (i == j || vec[j].first > 1e9) continue;         int k = i | j;         if (mav < cnt[k]) {           mav = cnt[k];           mivp = vec[i].first + vec[j].first;           u = vec[i].second;           v = vec[j].second;         } else if (mav == cnt[k] && mivp > vec[i].first + vec[j].first) {           mivp = vec[i].first + vec[j].first;           u = vec[i].second;           v = vec[j].second;         }       }       if (sec[i].first > 1e9) continue;       if (mav < cnt[i]) {         mav = cnt[i];         mivp = vec[i].first + sec[i].first;         u = vec[i].second, v = sec[i].second;       } else if (mav == cnt[i] && mivp > vec[i].first + sec[i].first) {         mivp = vec[i].first + sec[i].first;         u = vec[i].second, v = sec[i].second;       }     }     printf( %d %d , u, v);   }