malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 111, dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};   bool a[N][N][4];   int w, h, n, c[N][N], now;   vector<int> ans;   int dfs(int x, int y) {     c[x][y] = now;     int res = 1;     for (int d = 0; d < 4; ++d)       if (a[x][y][d]) {         int nx = x + dx[d], ny = y + dy[d];         if (!c[nx][ny]) res += dfs(nx, ny);       }     return res;   }   int main() {     scanf( %d%d%d , &w, &h, &n);     for (int i = 0; i < w; ++i) {       for (int j = 0; j < h; ++j) {         for (int d = 0; d < 4; ++d) {           int ni = i + dx[d], nj = j + dy[d];           a[i][j][d] = ni >= 0 && ni < w && nj >= 0 && nj < h;         }       }     }     for (int i = 0; i < n; ++i) {       int x1, x2, y1, y2;       scanf( %d%d%d%d , &x1, &y1, &x2, &y2);       if (x1 == x2) {         for (int y = min(y1, y2); y < max(y1, y2); ++y) {           a[x1 - 1][y][1] = false;           a[x1][y][3] = false;         }       } else {         for (int x = min(x1, x2); x < max(x1, x2); ++x) {           a[x][y1 - 1][0] = false;           a[x][y1][2] = false;         }       }     }     for (int i = 0; i < w; ++i) {       for (int j = 0; j < h; ++j) {         if (!c[i][j]) {           ++now;           ans.push_back(dfs(i, j));         }       }     }     sort(ans.begin(), ans.end());     int m = ans.size();     for (int i = 0; i < m; ++i) {       printf( %d%s , ans[i], i + 1 == m ?   n  :    );     }   }
#include <bits/stdc++.h>   using namespace std;   double ans = 1;   int main() {     int n, m, k;     scanf( %d%d%d , &n, &m, &k);     if (k >= m)       printf( 1 n );     else if (n + k < m)       printf( 0 n );     else {       for (int i = 1; i <= k + 1; i++) ans = ans * (m - i + 1) / (n + i);       ans = 1.0 - ans;       printf( %.6lf , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<long long, long long> M[400004];   vector<long long> Z[400004];   map<long long, long long> MA;   map<long long, long long> AM;   long long MAer;   bool cmp(long long& a, long long& b) { return a > b; }   long long xa[200002], xb[200002];   signed main() {     long long n, a, b;     cin >> n;     long long maxx = 0, maxi = 0;     for (long long i = 1; i <= n; i++) {       cin >> a >> b;       MA[a] = 0, MA[b] = 0;       maxx = max(maxx, a);       if (a == maxx) {         maxi = max(maxi, b);       }       xa[i] = a, xb[i] = b;     }     for (auto& it : MA) {       it.second = ++MAer;       AM[it.second] = it.first;     }     for (long long i = MA[maxi] + 1; i <= MA[maxx]; i++) {       M[i][0] = 1;     }     for (long long i = 1; i <= n; i++) {       Z[MA[xa[i]]].push_back(MA[xb[i]]);     }     for (long long i = MA[maxx]; i > 0; i--) {       while (M[i].size() > 1) {         M[i].erase(++M[i].begin(), M[i].end());       }       for (auto& a : Z[i]) {         for (auto& b : M[i]) {           M[a][b.first] += b.second;           M[a][b.first] %= 1000000007;         }       }       for (auto& a : M[i]) {         M[i - 1][AM[i] - AM[i - 1] + a.first] += a.second;         M[i - 1][AM[i] - AM[i - 1] + a.first] %= 1000000007;       }     }     cout << M[1].begin()->second <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }   int A[100], B[40200], n, N, M[40200];   long long r1;   int lis() {     int L = 0, lo, hi, mid, i;     for (i = 0; i < N; i++) {       lo = 1;       hi = L;       while (lo <= hi) {         mid = (lo + hi) / 2 + ((lo + hi) % 2);         if (B[M[mid]] <= B[i])           lo = mid + 1;         else           hi = mid - 1;       }       M[lo] = i;       if (lo > L) L = lo;       if (i == N - n - 1) r1 = L;     }     return L;   }   int main() {     int T, i, j, k;     long long r2;     scanf( %d%d , &n, &T);     for (i = 0; i < n; i++) {       scanf( %d , &A[i]);     }     if (T <= 401) {       for (i = 0, j = 0; i < T; i++)         for (k = 0; k < n; k++) B[j++] = A[k];       N = n * T;       printf( %d n , lis());     } else {       for (i = 0, j = 0; i < 401; i++)         for (k = 0; k < n; k++) B[j++] = A[k];       N = 401 * n;       r2 = lis();       cout << r1 + (r2 - r1) * (T - 400) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline void normal(long long &a) { a = (a + 998244353) % 998244353; }   inline long long modMul(long long a, long long b) {     a %= 998244353, b %= 998244353;     normal(a), normal(b);     return (a * b) % 998244353;   }   inline long long modAdd(long long a, long long b) {     a %= 998244353, b %= 998244353;     normal(a), normal(b);     return (a + b) % 998244353;   }   inline long long modSub(long long a, long long b) {     a %= 998244353, b %= 998244353;     normal(a), normal(b);     a -= b;     normal(a);     return a;   }   inline long long modPow(long long b, long long p) {     long long r = 1;     while (p) {       if (p & 1) r = modMul(r, b);       b = modMul(b, b);       p >>= 1;     }     return r;   }   inline long long modInv(long long a) { return modPow(a, 998244353 - 2); }   inline long long modDiv(long long a, long long b) {     return modMul(a, modInv(b));   }   const long long N = 4e5 + 1;   vector<long long> V;   long long n, x, R, C, cntt[N];   map<long long, long long> M;   void solve() {     cin >> n;     for (long long i = 0; i < n; i++) {       cin >> x;       M[x]++;     }     for (auto u = (M).begin(); u != (M).end(); u++) {       cntt[u->second]++;     }     x = n;     for (long long i = n; i > 0; i--) {       if (R * C < (x / i * i) && i <= x / i) {         R = i, C = x / i;       }       x -= cntt[i];       cntt[i - 1] += cntt[i];     }     cout << R * C << endl;     cout << R <<     << C << endl;     if (!(R * C)) return;     long long ans[R][C];     x = min(R, C);     vector<pair<long long, long long> > p;     for (auto u = (M).begin(); u != (M).end(); u++) {       p.push_back({min(u->second, x), u->first});     }     sort((p).rbegin(), (p).rend());     while ((long long)((p).size())) {       while (p.back().first) {         V.push_back(p.back().second), p.back().first--;       }       p.pop_back();     }     long long i = 0, j = 0, cnt = 0;     for (long long i = 0; i < C; i++) {       for (long long j = 0; j < R; j++) {         ans[j][(i + j) % C] = V.back(), V.pop_back();       }     }     for (long long i = 0; i < R; i++) {       for (long long j = 0; j < C; j++) {         cout << ans[i][j] <<    ;       }       cout << endl;     }   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t = 1;     clock_t start, end;     start = clock();     cout << fixed << setprecision(18);     ;     while (t--) {       solve();     }     end = clock();     double time_taken = double(end - start) / double(CLOCKS_PER_SEC);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     iostream::sync_with_stdio(0);     long long n;     cin >> n;     vector<long long> q{1, 1};     while (q.back() < 1e18) q.push_back(q.back() + q[q.size() - 2]);     cout << upper_bound(q.begin(), q.end(), n) - q.begin() - 2;     return 0;   }
#include <bits/stdc++.h>   const int maxn = 1e5 + 10;   using namespace std;   long long gcd(long long p, long long q) { return q == 0 ? p : gcd(q, p % q); }   long long qpow(long long p, long long q) {     long long f = 1;     while (q) {       if (q & 1) f = f * p;       p = p * p;       q >>= 1;     }     return f;   }   inline long long read() {     long long x = 0;     int f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   int n, m, k, t, c[21][21], vis[21][21], num[4];   struct node {     int cnt, id;     bool operator<(const node& p) const { return cnt > p.cnt; }   } ca[25];   bool flag;   bool solve(int a, int b) {     int d[21][21];     int i, j;     for (i = 1; i <= n; i++)       for (j = 1; j <= m; j++) d[i][j] = c[i][j];     for (i = 1; i <= n; i++) swap(d[i][a], d[i][b]);     for (i = 1; i <= n; i++) {       int now = 0;       for (j = 1; j <= m; j++)         if (d[i][j] != j) now++;       if (now > 2) return false;     }     return true;   }   int main() {     int i, j;     scanf( %d%d , &n, &m);     for (i = 1; i <= n; i++) ca[i].id = i;     for (i = 1; i <= n; i++)       for (j = 1; j <= m; j++) {         scanf( %d , &c[i][j]);         if (c[i][j] != j) ca[i].cnt++;       }     sort(ca + 1, ca + n + 1);     if (ca[1].cnt <= 2)       puts( YES );     else if (ca[1].cnt > 4)       puts( NO );     else {       j = 0;       int pos = ca[1].id;       for (i = 1; i <= m; i++)         if (c[pos][i] != i) num[j++] = i;       for (i = 0; i <= 3; i++)         for (j = i + 1; j <= 3; j++) {           if (solve(num[i], num[j])) return 0 * puts( YES );         }       puts( NO );     }     return 0;   }
#include <bits/stdc++.h>      using namespace std;   long long dp[2000005]{};   long long dp2[2000005]{};      int main()   {       long long n, t;       cin >> t;       while (t--)       {           string ss;           cin >> n;           cin >> ss;              memset(dp, 0, n * 8 + 40);           memset(dp2, 0, n * 8 + 40);              long long prev = 0;           for (int i = 1; i <= n; i++)           {               if (ss[i - 1] ==  . )               {                   dp[i] = dp[i - 1] + prev;               }               else               {                   prev++;                   dp[i] = dp[i - 1];               }           }           prev = 0;              for (int i = n; i > 0; i--)           {               if (ss[i - 1] ==  . )               {                   dp2[i] = dp2[i + 1] + prev;               }               else               {                   prev++;                   dp2[i] = dp2[i + 1];               }           }              long long ans = dp[n];           for (int i = 1; i <= n - 1; i++)           {               ans = min(ans, dp[i] + dp2[i + 1]);           }              printf( %lld  n , ans);       }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   void qSort(int *A, int low, int high, int *ii) {     int i = low;     int j = high;     int x = A[(low + high) / 2];     do {       while (A[i] < x) ++i;       while (A[j] > x) --j;       if (i <= j) {         int temp = A[i];         int buf = ii[i];         ii[i] = ii[j];         ii[j] = buf;         A[i] = A[j];         A[j] = temp;         i++;         j--;       }     } while (i <= j);     if (low < j) qSort(A, low, j, ii);     if (i < high) qSort(A, i, high, ii);   }   int gcd(int a, int b) {     if (b == 0) {       return a;     } else {       return gcd(b, a % b);     }   }   int lcm(int a, int b) { return a / gcd(a, b) * b; }   int main() {     int n;     cin >> n;     int *mas = new int[n];     int *ii = new int[n];     for (int i = 0; i < n; i++) {       cin >> mas[i];       ii[i] = i;     }     qSort(mas, 0, n - 1, ii);     if (n % 2 == 0) {       cout << n / 2 << endl;     } else {       cout << n / 2 + 1 << endl;     }     for (int i = 0; i < n; i += 2) {       cout << ii[i] + 1 <<    ;     }     cout << endl;     if (n % 2 == 0) {       cout << n / 2 << endl;     } else {       cout << n / 2 << endl;     }     for (int i = 1; i < n; i += 2) {       cout << ii[i] + 1 <<    ;     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int n1, n2, n3, n4, n5, n6, n7;   int a, b, c;   void doA(int i) {     if (n1 >= i)       n1 -= i;     else       n1 = 0;   }   void doB(int i) {     if (n2 >= i)       n2 -= i;     else {       doA(i - n2);       n2 = 0;     }   }   void doC(int i) {     if (n3 >= i)       n3 -= i;     else {       doB(i - n3);       n3 = 0;     }   }   void work() {     int ans = 0;     ans = n7;     ans += n6;     doA(n6);     ans += n5;     doB(n5);     if (c < a + b) {       ans += n4;       doC(n4);       int ANS = 0x3fffffff;       for (int i = 0; i <= n3; i++) {         int N1 = n1, N2 = n2, N3 = n3;         int j = n3 - i;         int now = max(i, j);         if (i > j) {           doB(i - j);           doA(i - j);         } else           doB(j - i);         now += max((n2 + 1) / 2, (n1 + n2 + 2) / 3);         ANS = min(ANS, now);         n1 = N1;         n2 = N2;         n3 = N3;       }       cout << ans + ANS << endl;     } else {       int ANS = 0x3fffffff;       for (int i = n4; i <= n3 + n4; i++) {         int N1 = n1, N2 = n2, N3 = n3;         int j = n3 + n4 - i;         int now = max(i, j);         if (i > j) {           doB(i - j);           doA(i - j);         } else           doB(j - i);         now += max((n2 + 1) / 2, (n1 + n2 + 2) / 3);         ANS = min(ANS, now);         n1 = N1;         n2 = N2;         n3 = N3;       }       cout << ans + ANS << endl;     }   }   int main() {     cin >> n;     cin >> a >> b >> c;     if (c < b) swap(b, c);     if (b < a) swap(a, b);     if (c < b) swap(b, c);     int x1 = min(a + b, c), x2 = max(a + b, c);     for (int i = 1; i <= n; i++) {       int t;       scanf( %d , &t);       if (t > a + b + c) {         cout << -1 << endl;         return 0;       }       if (t <= a)         n1++;       else if (t <= b)         n2++;       else if (t <= x1)         n3++;       else if (t <= x2)         n4++;       else if (t <= a + c)         n5++;       else if (t <= b + c)         n6++;       else         n7++;     }     work();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   int n, a[5000 + 5], num[5000 + 5], res[5000 + 5][5000 * 2 + 5],       ans[5000 * 2 + 5];   inline int pow(int x, int k) {     int sum = 1;     for (; k; k >>= 1, x = 1LL * x * x % 1000000007)       if (k & 1) sum = 1LL * sum * x % 1000000007;     return sum;   }   int main() {     n = read();     num[1] = 1;     for (int i = 1; i < n; ++i)       a[i] = read(), num[i + 1] = 1LL * num[i] * a[i] % 1000000007;     for (int i = 1; i <= n; ++i) {       int x = 1, inv = pow(a[i], 1000000007 - 2);       for (int j = 1; j <= 2 * n - 2; ++j) {         x = i + j > n ? 0 : 1LL * x * a[i + j - 1] % 1000000007;         int sum = (res[i][j] + x) % 1000000007;         ans[j] = (ans[j] + 1LL * num[i] * sum) % 1000000007;         if (i < n)           res[i + 1][j + 1] = (1LL * res[i + 1][j + 1] + res[i][j] +                                1LL * x * inv % 1000000007 * (a[i] - 1)) %                               1000000007;       }       if (i < n) res[i + 1][1] = (res[i + 1][1] + 1) % 1000000007;     }     for (int i = 1; i <= n * 2 - 2; ++i)       printf( %d  , 1LL * ans[i] * (1000000007 + 1) / 2 % 1000000007);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 300010;   const int INF = 2000000010;   int n, m, k;   int mi[maxn], ma[maxn], a[maxn], sum[maxn], v[maxn], la[maxn];   vector<pair<int, int>> G;   void add(int x, int cnt) {     for (int i = x; i <= max(n, m); i += (i & -i)) {       sum[i] += cnt;     }   }   int get_sum(int x) {     int ans = 0;     for (int i = x; i >= 1; i -= (i & -i)) {       ans += sum[i];     }     return ans;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) mi[i] = ma[i] = i;     for (int i = 1; i <= m; i++) scanf( %d , &a[i]);     for (int i = 1; i <= m; i++) {       if (!v[a[i]])         ma[a[i]] = max(ma[a[i]], a[i] + get_sum(n) - get_sum(a[i])), add(a[i], 1);       else         G.push_back(make_pair(v[a[i]], i));       la[i] = v[a[i]] + 1;       v[a[i]] = i;       mi[a[i]] = 1;     }     for (int i = 1; i <= n; i++) {       if (!v[i]) {         int x = get_sum(n) - get_sum(i);         ma[i] = max(ma[i], i + x);       }     }     for (int i = 1; i <= max(n, m); i++) sum[i] = 0;     k = 0;     for (int i = 0; i < (int)G.size(); i++) {       while (k < G[i].second) {         ++k;         add(la[k], 1);         add(k + 1, -1);       }       int x = get_sum(G[i].first);       ma[a[G[i].first]] = max(ma[a[G[i].first]], x);     }     while (k < m) {       ++k;       add(la[k], 1);       add(k + 1, -1);     }     for (int i = 1; i <= n; i++) {       if (v[i] > 0) {         int x = get_sum(v[i]);         ma[i] = max(ma[i], x);       }     }     for (int i = 1; i <= n; i++) {       printf( %d %d n , mi[i], ma[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int get(long long int s, long long int w, long long int cs,                     long long int cw, long long int p) {     if (s > w) return get(w, s, cw, cs, p);     if (s * cs >= p) return p / s;     return cs + min(cw, (p - s * cs) / w);   };   void solve() {     long long int p, f;     cin >> p >> f;     long long int cs, cw;     cin >> cs >> cw;     long long int s, w;     cin >> s >> w;     long long int mx = 0;     for (long long int x = 0; x <= cs; ++x) {       if (x * s <= p) {         long long int y = min(cw, (p - x * s) / w);         mx = max(mx, x + y + get(s, w, cs - x, cw - y, f));       }     }     cout << mx <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     long long int T = 1;     cin >> T;     for (long long int i = 1; i <= T; ++i) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a[8], pro[1 << 8];   int bit_cnt[1 << 8];   vector<long long> pp;   bitset<1000000> p;   map<long long, int> H;   int N, an;   int qq(long long x) {     if (H.count(x)) return H[x];     long long X = x;     int res = 0;     for (int i = 0; i < ((int)(pp).size()) && pp[i] * pp[i] <= x; i++) {       while (x % pp[i] == 0) {         x /= pp[i];         res++;       }     }     if (x != 1) res++;     return H[X] = res;   }   int qq2(long long x) {     if (H.count(x)) {       int tmp = H[x];       if (tmp == 1) return 0;       return tmp;     }     long long X = x;     int res = 0;     for (int i = 0; i < ((int)(pp).size()) && pp[i] * pp[i] <= x; i++) {       while (x % pp[i] == 0) {         x /= pp[i];         res++;       }     }     if (x != 1) res++;     H[X] = res;     if (res == 1) return 0;     return res;   }   void dfs(int x, int mask, int v, int head) {     if (x == -1) {       if (head == 1)         an = min(an, v);       else         an = min(an, v + 1);       return;     }     if (!((mask >> x) & 1)) {       v++;       head++;     }     for (int i = 0; i < (1 << x); ++i) {       if (!i) {         dfs(x - 1, mask, v + qq2(a[x]), head);       } else if (!(mask & i) && a[x] % pro[i] == 0) {         dfs(x - 1, mask | i, v + bit_cnt[i] + qq(a[x] / pro[i]), head);       }     }   }   int main() {     for (int i = 3; i < 1000; i += 2) {       for (int j = i * i; j < 1000000; j += i + i) p[j] = 1;     }     pp.push_back(2);     for (int i = 3; i < 1000000; i += 2) {       if (!p[i]) pp.push_back(i);     }     int(n);     scanf( %d , &n);     N = n;     for (int i = 0; i < (n); ++i) cin >> a[i];     sort(a, a + n);     pro[0] = 1;     for (int i = (1); i < (1 << n); ++i) {       int k = 0;       while (!((i >> k) & 1)) k++;       bit_cnt[i] = bit_cnt[i - (1 << k)] + 1;       long long tmp1 = pro[i - (1 << k)];       long long tmp2 = a[k];       if (tmp1 > 10000000000000ll / tmp2)         pro[i] = 10000000000000ll;       else         pro[i] = tmp1 * tmp2;     }     an = 1000000;     dfs(n - 1, 0, 0, 0);     printf( %d n , an);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int x, y, a, b, num_of_results;   pair<int, int> game, results[10101];   int main() {     scanf( %d %d %d %d , &x, &y, &a, &b);     num_of_results = 0;     if (b >= x)       printf( 0 n );     else {       for (int i = a; i <= x; i++) {         for (int j = b; j <= y; j++) {           if (i > j) {             results[num_of_results++] = make_pair(i, j);           }         }       }       cout << num_of_results << endl;       for (int i = 0; i < num_of_results; i++) {         cout << results[i].first <<     << results[i].second << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 16 + 5;   string a[N], x, y;   int n, m, M = -1;   map<string, map<string, int> > mm;   bool vis[N];   void dfs(int deep, int mod) {     if (deep > n + 1) return;     if (deep == n + 1) {       int tot = 0, f = 1;       for (int i = 1; i <= n; ++i) tot += vis[i];       for (int i = 1; i <= n; ++i)         for (int j = i + 1; j <= n; ++j)           if (vis[i] && vis[j])             if (mm[a[i]][a[j]]) {               f = 0;               break;             }       if (f) {         if (mod) {           int tot = 0;           for (int i = 1; i <= n; ++i) tot += vis[i];           if (tot != M) return;           printf( %d n , M);           string res[N];           for (int i = 1; i <= 17; ++i) res[i] =  0 ;           int pos = 1;           for (int i = 1; i <= n; ++i)             if (vis[i]) res[pos++] = a[i];           sort(res + 1, res + pos);           pos = 1;           while (res[pos] !=  0 ) {             cout << res[pos] << endl;             pos++;           }           exit(0);         } else if (mod == 0)           M = max(M, tot);       }     }     vis[deep] = true;     dfs(deep + 1, mod);     vis[deep] = false;     dfs(deep + 1, mod);   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) cin >> a[i];     for (int i = 1; i <= m; ++i) {       cin >> x >> y;       mm[x][y] = mm[y][x] = 1;     }     dfs(1, 0);     dfs(1, 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1100;   struct VIS {     int c, p;     int id;     bool operator<(const VIS& t) const {       if (p == t.p) return c < t.c;       return p > t.p;     }   } A[MAXN];   struct TAB {     int c;     int id;     bool operator<(const int t) const { return c < t; }     bool operator<(const TAB& t) const { return c < t.c; }   } Tb[MAXN];   bool vis[MAXN];   struct PAIR {     int v;     int t;     bool operator<(const PAIR& t) const { return v < t.v; }   } pai[MAXN];   int len;   int sum;   int main() {     int N, K;     while (scanf( %d , &(N)) != EOF) {       for (int i = (1); i < (N + 1); ++i) {         scanf( %d%d , &A[i].c, &A[i].p);         A[i].id = i;       }       sort(A + 1, A + N + 1);       scanf( %d , &(K));       for (int i = (1); i < (K + 1); ++i) {         scanf( %d , &(Tb[i].c));         Tb[i].id = i;       }       sort(Tb + 1, Tb + K + 1);       len = 0;       sum = 0;       memset(vis, 0, sizeof(vis));       for (int i = (1); i < (N + 1); ++i) {         int p = lower_bound(Tb + 1, Tb + K + 1, A[i].c) - Tb;         while (p <= K && vis[p]) ++p;         if (p > K) continue;         vis[p] = 1;         sum += A[i].p;         pai[len].v = A[i].id;         pai[len].t = Tb[p].id;         ++len;       }       sort(pai, pai + len);       printf( %d %d n , len, sum);       for (int k = (0); k < (len); ++k) {         printf( %d %d n , pai[k].v, pai[k].t);       }     }     return 0;   }