#include <bits/stdc++.h>   using namespace std;   int main() {     int requestNum;     cin >> requestNum;     vector<pair<int, pair<int, int>>> vect(requestNum);     for (int i = 0; i < requestNum; i++) {       int num, money;       cin >> num >> money;       vect.push_back(make_pair(money, make_pair(num, i + 1)));     }     sort(vect.rbegin(), vect.rend());     int tablesNum;     cin >> tablesNum;     vector<pair<int, int>> maxPeople(tablesNum);     for (int i = 0; i < tablesNum; i++) {       cin >> maxPeople[i].first;       maxPeople[i].second = i + 1;     }     sort(maxPeople.begin(), maxPeople.end());     vector<bool> tablesFull(tablesNum, false);     long long int totalMoney = 0;     vector<pair<long, long>> result;     for (int i = 0; i < requestNum; i++) {       for (int j = 0; j < tablesNum; j++) {         if (vect[i].second.first <= maxPeople[j].first && !tablesFull[j]) {           result.push_back(make_pair(vect[i].second.second, maxPeople[j].second));           totalMoney += vect[i].first;           tablesFull[j] = true;           break;         }       }     }     cout << result.size() <<     << totalMoney << endl;     for (int i = 0; i < result.size(); i++) {       cout << result[i].first <<     << result[i].second << endl;     }     return 0;   }   