malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int t;     cin >> t;     while (t--) {       long long n;       cin >> n;       vector<long long> arr(n);       int neg = 0;       int pos = 0;       for (long long i = 0; i < n; i++) {         cin >> arr[i];         if (arr[i] < 0)           neg++;         else           pos++;       }       sort(arr.begin(), arr.end());       long long ans = 1;       ans = arr[n - 1] * arr[n - 2] * arr[n - 3] * arr[n - 4] * arr[n - 5];       ans = max(ans, arr[0] * arr[1] * arr[n - 1] * arr[n - 2] * arr[n - 3]);       ans = max(ans, arr[0] * arr[1] * arr[2] * arr[3] * arr[n - 1]);       cout << ans << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> arr[n];     map<long long, int> mp;     vector<long long> summer(n);     for (int i = 0; i < n; i++) {       int m;       cin >> m;       int tmp;       long long sum = 0;       for (int j = 0; j < m; j++) {         cin >> tmp;         arr[i].push_back(tmp);         sum += tmp;       }       summer[i] = sum;       for (int j = 0; j < m; j++) {         long long key = sum - arr[i][j];         if (mp.find(key) != mp.end()) {           if (mp[key] != i) {             cout <<  YES n  << i + 1 <<     << j + 1 <<   n ;             int cur = mp[key];             cout << cur + 1 <<    ;             int check = summer[cur] - key;             for (int k = 0; k < arr[cur].size(); k++) {               if (arr[cur][k] == check) {                 cout << k + 1;                 return 0;               }             }           }         } else {           mp[key] = i;         }       }     }     cout <<  NO ;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> f[100005];   int n, m, temp, flag = 0;   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> temp;       f[temp].push_back(i + 1);     }     int j = 0, ans[100005];     for (int i = 0; i < m; i++) {       cin >> temp;       if (f[temp].size() == 0) {         flag = 2;         break;       } else if (f[temp].size() > 1 && flag != 2) {         flag = 1;       } else if (flag == 0) {         ans[j++] = f[temp][0];       }     }     if (flag == 0) {       cout <<  Possible n ;       for (int i = 0; i < m; i++) cout << ans[i] <<    ;       cout << endl;     } else if (flag == 1) {       cout <<  Ambiguity n ;     } else {       cout <<  Impossible n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int get_set(int v, vector<int>& parent) {     if (v != parent[v]) {       parent[v] = get_set(parent[v], parent);     }     return parent[v];   }   void union_set(int a, int b, vector<int>& parent, vector<int>& rang) {     a = get_set(a, parent);     b = get_set(b, parent);     if (a != b) {       if (rang[a] < rang[b]) {         swap(a, b);       }       parent[b] = a;       rang[a] += rang[b];     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int n, m, a, s = 0, k, p, l, r;     cin >> n >> m;     vector<map<int, int>> x(n), y(m);     vector<int> parent(n * m), rang(n * m, 0);     vector<pair<int, int>> q(n * m);     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         cin >> a;         q[s] = make_pair(a, s);         parent[s] = s;         rang[s] = 1;         if (x[i].count(a) != 0) {           union_set(s, i * m + x[i][a], parent, rang);         }         if (y[j].count(a) != 0) {           union_set(s, y[j][a] * m + j, parent, rang);         }         x[i][a] = j;         y[j][a] = i;         s++;       }     for (int i = 0; i < n * m; i++) rang[i] = 0;     sort(begin(q), end(q));     for (int i = 0; i < n * m; i++) {       a = q[i].first;       s = q[i].second;       l = s / m;       r = s % m;       swap(q[i].first, q[i].second);       k = get_set(s, parent);       k = rang[k];       auto j = x[l].find(a);       j++;       if (j != end(x[l])) {         p = get_set(l * m + j->second, parent);         rang[p] = max(k + 1, rang[p]);       }       j = y[r].find(a);       j++;       if (j != end(y[r])) {         p = get_set(j->second * m + r, parent);         rang[p] = max(k + 1, rang[p]);       }     }     sort(begin(q), end(q));     for (int i = 0; i < n * m; i++) {       k = get_set(q[i].first, parent);       k = rang[k];       cout << k + 1 <<    ;       if ((q[i].first + 1) % m == 0) cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, tmp;     bool b;     cin >> n >> m;     vector<int> t(n, -1);     while (m--) {       cin >> tmp;       t[tmp - 1]++;     }     m = 1000;     for (int i = 0; i < n; i++) {       m = min(m, t[i]);     }     cout << m + 1;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 200009;   const long long MOD = 119 << 23 | 1;   class {    public:     struct N {       N(int a, int b, int c, int d) {         sta[0] = a;         sta[1] = b;         sta[2] = c;         sta[3] = d;       }       int sta[4];     };     int f[1 << 18];     int trans[4][4][4] = {0,  -1, -1, -1, 1,  2,  -1, -1, 2,  2,  1,  -1, 3,                           3,  3,  3,  1,  2,  -1, -1, 2,  2,  -1, -1, 3,  3,                           3,  3,  -1, 3,  3,  3,  2,  2,  1,  -1, 3,  3,  3,                           3,  -1, -1, 2,  2,  -1, -1, 3,  3,  3,  3,  3,  3,                           -1, 3,  3,  3,  -1, -1, 3,  3,  -1, -1, -1, 3};     N gao(N x, N y) {       N res = {-MOD, -MOD, -MOD, -MOD};       for (int i = 0; i < 4; ++i) {         for (int j = 0; j < 4; ++j) {           for (int k = 0; k < 4; k++) {             if (trans[i][j][k] != -1) {               res.sta[k] = max(res.sta[k], x.sta[i] + y.sta[j] + trans[i][j][k]);             }           }         }       }       return res;     }     void solve() {       int n, k;       cin >> n >> k;       for (int i = 0; i < k; ++i) {         int t;         cin >> t;         f[t]++;       }       vector<N> F;       for (int i = 1; i <= (1 << n); i += 2) {         if (f[i] + f[i + 1] == 2) {           F.push_back(N(-MOD, -MOD, -MOD, 1));         } else if (f[i] + f[i + 1]) {           F.push_back(N(-MOD, 1, 1, -MOD));         } else {           F.push_back(N(0, -MOD, -MOD, -MOD));         }       }       while (F.size() != 1) {         vector<N> G;         for (int i = 0; i < F.size(); i += 2) {           G.push_back(gao(F[i], F[i + 1]));         }         swap(G, F);       }       cout << max(max(F[0].sta[0], F[0].sta[1] + 1),                   max(F[0].sta[2] + 1, F[0].sta[3] + 1))            <<   n ;     }   } NSPACE;   int main() {     ;     ios_base::sync_with_stdio(false);     cout.tie(0);     cin.tie(0);     NSPACE.solve();   }
#include <bits/stdc++.h>   using namespace std;   int32_t main() {     long long t;     cin >> t;     for (long long q = 0; q < t; q++) {       long long a, b, k;       cin >> a >> b >> k;       vector<long long> x(a * b);       for (long long i = 0; i < a * b; i++) {         x[i] = (i % a % b != i % b % a);       }       long long all = 0;       for (long long i = 0; i < a * b; i++) {         all += x[i];       }       vector<long long> sum_pref(a * b + 1, 0);       for (long long i = 0; i < a * b; i++) {         sum_pref[i + 1] = sum_pref[i] + x[i];       }       for (long long i = 0; i < k; i++) {         long long l, r;         cin >> l >> r;         r++;         long long ans = (r / (a * b) - l / (a * b)) * all;         ans += sum_pref[r % (a * b)];         ans -= sum_pref[l % (a * b)];         cout << ans <<    ;       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct zfc {     char a[101];     int la;   } a[101];   bool cmp(zfc a, zfc b) { return a.la < b.la; }   bool cha(zfc a, zfc b) {     int flag;     for (int i = 0; i <= b.la - a.la; i++) {       flag = 0;       for (int j = 0; j < a.la; j++)         if (a.a[j] != b.a[j + i]) {           flag = 1;           break;         }       if (flag == 0) return 1;     }     return 0;   }   int n, flag1;   int main() {     scanf( %d , &n);     gets(a[0].a);     for (int i = 1; i <= n; i++) {       gets(a[i].a);       a[i].la = strlen(a[i].a);     }     sort(a + 1, a + 1 + n, cmp);     for (int i = 1; i <= n; ++i) {       flag1 = 0;       for (int j = 1; j < i; ++j)         if (cha(a[j], a[i]) == 0) {           flag1 = 1;           break;         }       if (flag1 == 1) {         printf( NO );         return 0;       }     }     printf( YES n );     for (int i = 1; i <= n; i++) puts(a[i].a);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int winner[300005];   int ans[300005];   int range[300005];   int find_winner(int v) {     if (v == winner[v]) return v;     return winner[v] = find_winner(winner[v]);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, m;     cin >> n >> m;     for (int i = 1; i <= n; i++) {       winner[i] = i;       range[i] = i;       ans[i] = i;     }     while (m--) {       int l, r, x;       cin >> l >> r >> x;       int i = 0;       for (i = l; i <= r; i++) {         int w = find_winner(i);         ans[w] = x;         winner[w] = x;         i = range[w];       }       range[x] = i - 1;     }     for (int i = 1; i <= n; i++) {       if (i == ans[i])         cout <<  0  ;       else         cout << ans[i] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using ull = unsigned long long;   const double PI = acos(-1.0);   const long long EPS = (1e-10);   const long long N = 1e5 * 2 + 10;   const long long inf = 1e9 * 2 + 10;   const ll INF = 1e18 * 2 + 10;   const long long MOD = 1e9 + 7;   long long nxt() {     long long x;     cin >> x;     return x;   }   long long fcmp(double a, double b) {     return (fabs(a - b) < EPS ? 0 : a > b ? 1 : -1);   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     long long k, b, n, t;     cin >> k >> b >> n >> t;     long long z = 1, res = n;     while (k * z + b <= t) {       z = k * z + b;       res--;     }     cout << (res > 0 ? (res) : (0));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long mult(long long a, long long b, long long p = 1000000007) {     long long ans = ((a % p) * (b % p)) % p;     return (ans + p) % p;   }   long long add(long long a, long long b, long long p = 1000000007) {     long long ans = (a % p + b % p) % p;     return (ans + p) % p;   }   long long fpow(long long n, long long k, long long p = 1000000007) {     long long r = 1;     for (; k; k >>= 1) {       if (k & 1) r = r * n % p;       n = n * n % p;     }     return r;   }   long long inv(long long a, long long p = 1000000007) {     return fpow(a, p - 2, p);   }   long long n, m, k;   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     cin >> n >> m >> k;     vector<pair<long long, long long> > arr(n);     vector<long long> orig(n);     for (long long i = 0; i < n; i++) {       cin >> arr[i].first;       arr[i].second = i;       orig[i] = arr[i].first;     }     sort(arr.begin(), arr.end(), greater<pair<long long, long long> >());     vector<bool> has(n, 0);     long long s = 0;     for (long long i = 0; i < m * k; i++) {       s += arr[i].first;       has[arr[i].second] = 1;     }     cout << s << endl;     vector<long long> ans;     long long ov = 0;     for (long long i = 0; i < n;) {       long long cnt = 0, j = i;       while (cnt < m) {         if (has[j] == 1) {           cnt++;         }         j++;       }       ov++;       i = j;       if (ov == k) break;       cout << i <<    ;       ans.push_back(i);     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int tree[2000004];   int A[500002];   long long modular_pow(long long base, long long exponent, long long modulus) {     long long result = 1;     while (exponent > 0) {       if (exponent % 2 == 1) result = (result * base) % modulus;       exponent = exponent >> 1;       base = (base * base) % modulus;     }     return result;   }   void build(int node, int start, int end) {     if (start == end) {       tree[node] = A[start];     } else {       int mid = (start + end) / 2;       build(2 * node, start, mid);       build(2 * node + 1, mid + 1, end);       tree[node] = tree[2 * node] + tree[2 * node + 1];     }   }   int query(int node, int start, int end, int l, int r) {     if (r < start or end < l) {       return 0;     }     if (l <= start and end <= r) {       return tree[node];     }     int mid = (start + end) / 2;     int p1 = query(2 * node, start, mid, l, r);     int p2 = query(2 * node + 1, mid + 1, end, l, r);     return (p1 + p2);   }   int main() {     int n, d;     scanf( %d %d , &n, &d);     int ar[n];     for (int i = 0; i < n; i++) scanf( %d , &ar[i]);     sort(ar, ar + n);     long long int ans = 0;     for (int i = 0; i < n - 1; i++) {       if (ar[i + 1] - ar[i] > 2 * d) {         ans += 2;         continue;       }       if (ar[i + 1] - ar[i] == 2 * d) {         ans++;         continue;       }     }     ans += 2;     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   int main() {     long n(0);     scanf( %ld , &n);     std::map<long, long> solutions;     bool possible(1);     for (int k = 0; k < n; k++) {       long number(0), participant(0);       scanf( %ld %ld , &number, &participant);       if (solutions.find(participant) != solutions.end()) {         if (number > 1 + solutions[participant]) {           possible = 0;           break;         }         if (number > solutions[participant]) {           solutions[participant] = number;         }       } else {         if (number > 0) {           possible = 0;           break;         } else {           solutions.insert(std::pair<long, long>(participant, 0));         }       }     }     puts(possible ?  YES  :  NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   struct node {     int x, p;   } a[N];   int d, n, m, top, xx, nexttttt[N], last, q[N];   long long ans;   bool cmp(node a, node b) { return a.x < b.x; }   int main() {     scanf( %d%d%d , &d, &n, &m);     for (int i = 1; i <= m; i++) scanf( %d%d , &a[i].x, &a[i].p);     sort(a + 1, a + m + 1, cmp);     a[m + 1].x = d;     a[m + 1].p = 0;     for (int i = m + 1; i >= 0; i--) {       if (a[i].x - a[i - 1].x > n) {         puts( -1 );         return 0;       }       while (top && a[i].p < a[q[top]].p) top--;       nexttttt[i] = q[top];       q[++top] = i;     }     for (int i = 0; i <= m; i++) {       xx = max(0, min(a[nexttttt[i]].x - a[i].x, n) - last);       ans += 1ll * xx * a[i].p;       last -= a[i + 1].x - a[i].x - xx;     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, i, a[3][30], half;   long long ans, ans1, ans2;   struct node {     long long x, y, z;     bool operator<(const node& T) const {       if (x != T.x)         return x < T.x;       else if (y != T.y)         return y < T.y;       else         return z < T.z;     }   };   map<node, long long> b;   void pt(long long s, long long s1) {     long long val = 0;     long long temp = s;     long long temp1 = s1;     for (int w = 0; w < half; w++) {       if (s % 3 == 1 || s % 3 == 2) val += a[0][w];       s /= 3;     }     for (int w = half; w < n; w++) {       if (s1 % 3 == 1 || s1 % 3 == 2) val += a[0][w];       s1 /= 3;     }     if (val > ans) {       ans = val;       ans1 = temp;       ans2 = temp1;     }   }   void solve(int ind, long long s, long long r, long long w, long long mask) {     if (ind == -1) {       long long g = min(s, min(r, w));       s -= g;       r -= g;       w -= g;       b[{s, r, w}] = mask;     } else {       solve(ind - 1, s, r + a[1][ind], w + a[2][ind], mask * 3);       solve(ind - 1, s + a[0][ind], r, w + a[2][ind], mask * 3 + 1);       solve(ind - 1, s + a[0][ind], r + a[1][ind], w, mask * 3 + 2);     }   }   void solve1(int ind, long long s, long long r, long long w, long long mask) {     if (ind == half - 1) {       long long g = min(s, min(r, w));       node temp = {s, r, w};       s -= g;       r -= g;       w -= g;       if (s >= r && s >= w) {         if (b[{0, s - r, s - w}]) {           pt(b[{0, s - r, s - w}], mask);         }       }       if (r >= s && r >= w) {         if (b[{r - s, 0, r - w}]) {           pt(b[{r - s, 0, r - w}], mask);         }       }       if (w >= s && w >= r) {         if (b[{w - s, w - r, 0}]) {           pt(b[{w - s, w - r, 0}], mask);         }       }     } else {       solve1(ind - 1, s, r + a[1][ind], w + a[2][ind], mask * 3);       solve1(ind - 1, s + a[0][ind], r, w + a[2][ind], mask * 3 + 1);       solve1(ind - 1, s + a[0][ind], r + a[1][ind], w, mask * 3 + 2);     }   }   int main() {     scanf( %d , &n);     b.clear();     for (i = 0; i < n; i++) scanf( %d%d%d , &a[0][i], &a[1][i], &a[2][i]);     if (n == 1) {       if (a[0][0] == 0 && a[1][0] == 0)         printf( LM n );       else if (a[0][0] == 0 && a[2][0] == 0)         printf( LW n );       else if (a[1][0] == 0 && a[2][0] == 0)         printf( MW n );       else         printf( Impossible n );       return 0;     }     half = (n + 1) / 2;     ans = -1000000000;     solve(half - 1, 0, 0, 0, 0);     solve1(n - 1, 0, 0, 0, 0);     if (ans == -1000000000)       return 0 * printf( Impossible n );     else {       for (i = 0; i < half; i++) {         if (ans1 % 3 == 0)           printf( MW n );         else if (ans1 % 3 == 1)           printf( LW n );         else           printf( LM n );         ans1 /= 3;       }       for (i = half; i < n; i++) {         if (ans2 % 3 == 0)           printf( MW n );         else if (ans2 % 3 == 1)           printf( LW n );         else           printf( LM n );         ans2 /= 3;       }     }   }
#include <bits/stdc++.h>   using namespace std;   stack<int> s1;   char a[200005];   int flag[200005];   int main() {     int n, k;     scanf( %d%d , &n, &k);     memset(flag, 0, sizeof(flag));     scanf( %s , a);     int l = 0;     for (int i = 0; i < n; i++) {       if (l == k) break;       if (a[i] ==  ( ) {         s1.push(i);       }       if (a[i] ==  )  && !s1.empty()) {         l += 2;         flag[i] = 1;         flag[s1.top()] = 1;         s1.pop();       }     }     for (int i = 0; i < n; i++) {       if (flag[i]) printf( %c , a[i]);     }     printf(  n );   }
#include <bits/stdc++.h>   using namespace std;   int mult(int a, int b) {     long long res = ((long long)a * b) % 1000000007;     return res;   }   int binaryPow(int n, int p) {     int acc = 1;     while (p) {       if (p & 1) acc = mult(acc, n);       n = mult(n, n);       p /= 2;     }     return acc;   }   int modularInv(int n) { return binaryPow(n, 1000000007 - 2); }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int k, pa, pb;     cin >> k >> pa >> pb;     int pd = modularInv(pa + pb);     int dp[k + 1][k + 1];     for (int i = k; i >= 1; i--) {       for (int j = k; j >= 0; j--) {         if (i + j < k) {           dp[i][j] = mult(               (mult(pa, dp[i + 1][j]) + mult(pb, dp[i][i + j])) % 1000000007, pd);         } else {           dp[i][j] = (i + j + mult(pa, modularInv(pb))) % 1000000007;         }       }     }     cout << dp[1][0] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int getint() {     int s = 0, o = 1;     char c;     for (c = getchar(); c <  0  || c >  9 ; c = getchar())       if (c ==  - ) o = -1;     for (; c >=  0  && c <=  9 ; c = getchar()) s *= 10, s += c -  0 ;     return s * o;   }   const int mod = (int)1e9 + 7;   struct Mat {     int n;     long long x;     int a[31][31];     void operator*=(const Mat &p) {       int c[31][31];       for (int i = 0; i < n; i++)         for (int j = 0; j < n; j++) {           long long r = 0;           for (int k = 0; k < n; k++) r += (1ll * a[i][k] * p.a[k][j]) % mod;           c[i][j] = r % mod;           if (c[i][j] < 0) c[i][j] += mod;         }       for (int i = 0; i < n; i++)         for (int j = 0; j < n; j++) a[i][j] = c[i][j];     }     void write() {       for (int i = 0; i < n; i++) {         for (int j = 0; j < n; j++) printf( %d  , a[i][j]);         printf(  n );       }     }   } A[70][30], B[70][30];   long long n;   int k;   Mat I;   Mat calc(int i, int j, long long n) {     Mat r = I;     if (n == 0) return r;     for (int timer = 0; timer < k; timer++) {       if (n >= A[i][j].x)         r *= A[i][j];       else         r *= calc(i - 1, j, n);       n -= A[i][j].x;       if (n <= 0) break;       j = (j + 1) % k;     }     return r;   }   int main(int argc, char const *argv[]) {     scanf( %I64d%d , &n, &k);     I.n = k + 1;     for (int i = 0; i < I.n; i++)       for (int j = 0; j < I.n; j++) I.a[i][j] = i == j;     for (int i = 0; i < k; i++) {       Mat &M = A[0][i];       M.n = k + 1, M.x = 1;       for (int t = 0; t < k + 1; t++)         for (int s = 0; s < k + 1; s++) M.a[t][s] = (t == s || t == i);       Mat &N = B[0][i];       N.n = k + 1, N.x = 1;       for (int t = 0; t < k + 1; t++)         for (int s = 0; s < k + 1; s++) {           if (t == i) N.a[t][s] = -1;           if (t == s) N.a[t][s] = 1;         }     }     int i;     for (i = 0;; i++) {       long long _x = A[i][0].x * k;       if (_x > n || _x < 0) break;       Mat &M = A[i + 1][0];       M = A[i][0];       M.x = _x;       for (int p = 1; p < k; ++p) M *= A[i][p];       for (int j = 1; j < k; ++j) {         Mat &M = A[i + 1][j];         M = B[i][j - 1];         M *= A[i + 1][j - 1];         M *= A[i][j - 1];         M.x = _x;       }       Mat &N = B[i + 1][0];       N = B[i][k - 1];       N.x = _x;       for (int p = k - 2; p >= 0; --p) N *= B[i][p];       for (int j = 1; j < k; ++j) {         Mat &N = B[i + 1][j];         N = B[i][j - 1];         N *= B[i + 1][j - 1];         N *= A[i][j - 1];         N.x = _x;       }     }     Mat res = calc(i, 0, n);     long long r = 0;     for (int i = 0; i < k + 1; i++) r += res.a[i][k];     printf( %I64d n , r % mod);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<int, int> values;   map<int, bool> reverseVisited;   map<int, vector<int> > rev;   stack<int> lastVisited;   map<int, bool> visited;   map<int, vector<int> > cities;   void dfs(int init) {     visited[init] = true;     for (int i = 0; i < cities[init].size(); i++) {       if (!visited[cities[init][i]]) {         dfs(cities[init][i]);       }     }     lastVisited.push(init);   }   void dfs2(int init, long long int &mini, long long int &ww) {     reverseVisited[init] = true;     if (mini > values[init])       mini = values[init], ww = 1;     else if (mini == values[init])       ww++;     for (int i = 0; i < rev[init].size(); i++) {       if (!reverseVisited[rev[init][i]]) dfs2(rev[init][i], mini, ww);     }   }   int main() {     std::ios::sync_with_stdio(false);     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       int w;       cin >> w;       values[i] = w;     }     int m;     cin >> m;     while (m--) {       int u, v;       cin >> u >> v;       cities[u].push_back(v);       rev[v].push_back(u);       visited[u] = false;       reverseVisited[v] = false;     }     for (int i = 1; i <= n; i++) {       if (!visited[i]) {         dfs(i);       }     }     long long int minMoney = 0, numWays = 1;     while (!lastVisited.empty()) {       long long int po = 1000000007;       int q = lastVisited.top();       lastVisited.pop();       if (!reverseVisited[q]) {         long long int ww = 0;         dfs2(q, po, ww);         minMoney += po;         if (ww > 0) numWays *= ww;         numWays %= 1000000007;       }     }     cout << minMoney <<     << numWays << endl;   }