It is said that in 2013, there were about 100 graduate schools ready to proceed over 40,000 applications in Zhejiang Province. It would help a lot if you could write a program to automate the admission procedure.

Each applicant will have to provide two grades: the national entrance exam grade GE, and the interview grade GI. The final grade of an applicant is (GE + GI) / 2. The admission rules are:

• The applicants are ranked according to their final grades, and will be admitted one by one from the top of the rank list.
• If there is a tied final grade, the applicants will be ranked according to their national entrance exam grade GE. If still tied, their ranks must be the same.
• Each applicant may have K choices and the admission will be done according to his/her choices: if according to the rank list, it is one’s turn to be admitted; and if the quota of one’s most preferred shcool is not exceeded, then one will be admitted to this school, or one’s other choices will be considered one by one in order. If one gets rejected by all of preferred schools, then this unfortunate applicant will be rejected.
• If there is a tied rank, and if the corresponding applicants are applying to the same school, then that school must admit all the applicants with the same rank, even if its quota will be exceeded.

```#include <cstdio>
#include <vector>
#include <set>
#include <algorithm>

struct Node {
int ge;
int gi;
int tol;
int id;
};

bool cmp(const Node &a, const Node &b) {
if( a.tol != b.tol )
return a.tol > b.tol;
return a.ge > b.ge;
}

int quota[103];
Node applicants[40005];
int preferredSchools[40005][6];
std::vector<int> schoolEnrolled[103];

int main() {
int n, m, k;
scanf("%d %d %d", &n, &m, &k);
for(int i = 0; i < m; ++i) scanf("%d", &quota[i]);
for(int i = 0; i < n; ++i) {
scanf("%d %d", &(applicants[i].ge), &(applicants[i].gi) );
applicants[i].id = i;
applicants[i].tol = applicants[i].gi + applicants[i].ge;
for(int j = 0; j < k; ++j)
scanf("%d", &preferredSchools[i][j]);
}
std::sort(applicants, applicants + n, cmp);
for(int i = 0; i < n; ++i) {
for(int j = 0; j < k; ++j) {
int schoolChoice = preferredSchools[applicants[i].id][j];
if( quota[schoolChoice] > 0) {
schoolEnrolled[schoolChoice].push_back(applicants[i].id);
quota[schoolChoice]--;
break;
}
if( i > 0 && admit[i - 1] == schoolChoice &&
applicants[i - 1].ge == applicants[i].ge &&
applicants[i - 1].gi == applicants[i].gi) {
schoolEnrolled[schoolChoice].push_back(applicants[i].id);
quota[schoolChoice]--;
break;
}
}
}
for(int i = 0; i < m; ++i) {
if(schoolEnrolled[i].empty()) {
printf("\n");
continue;
}
sort(schoolEnrolled[i].begin(), schoolEnrolled[i].end());
for(int j = 0; j < schoolEnrolled[i].size(); ++j) {
if(j == 0)
printf("%d", schoolEnrolled[i][j]);
else
printf(" %d", schoolEnrolled[i][j]);

}
printf("\n");
}
return 0;
}
```