3327 {
3328 int n;
3329 int m;
3330 cin >> n >> m;
3331 unordered_map<string, room> rooms;
3332 unordered_map<char, unordered_set<student *>> levels;
3333 unordered_map<string, unordered_map<string, int>> dates;
3334 for(int i = 0; i < n; i++) {
3336 cin >> stu->id >> stu->grade;
3337 stu->level = stu->id[0];
3338 stu->room = stu->id.substr(1, 3);
3339 stu->date = stu->id.substr(4, 6);
3340 rooms[stu->room].sum += stu->grade;
3341 rooms[stu->room].count++;
3342 levels[stu->level].insert(stu);
3343 dates[stu->date][stu->room]++;
3344 }
3345 for(int i = 0; i < m; i++) {
3346 int typ;
3347 cin >> typ;
3348 cout << "Case " << i + 1 << ": " << typ << ' ';
3349 if(typ == 1) {
3350 char l;
3351 cin >> l;
3352 cout << l << endl;
3353 if(static_cast<unsigned int>(levels.contains(l)) != 0U) {
3354 vector<student *> vec;
3355 for(auto *const pstu: levels[l]) {
3356 vec.emplace_back(pstu);
3357 }
3358 sort(vec.begin(), vec.end(), p_stu_comp());
3359 for(auto *stu: vec) {
3360 cout << stu->id << ' ' << stu->grade << endl;
3361 }
3362 } else {
3363 cout << "NA" << endl;
3364 }
3365 } else if(typ == 2) {
3366 string room_id;
3367 cin >> room_id;
3368 cout << room_id << endl;
3369 if(static_cast<unsigned int>(rooms.contains(room_id)) != 0U) {
3370 cout << rooms[room_id].count << ' ' << rooms[room_id].sum << endl;
3371 } else {
3372 cout << "NA" << endl;
3373 }
3374 } else if(typ == 3) {
3375 string date;
3376 cin >> date;
3377 cout << date << endl;
3378 if(dates[date].empty()) {
3379 cout << "NA" << endl;
3380 continue;
3381 }
3382 vector<pair<string, int>>
vec;
3383 for(const auto &room_cnt: dates[date]) {
3384 vec.emplace_back(room_cnt);
3385 }
3387 for(const auto &[id, cnt]: vec) {
3388 cout << id << ' ' << cnt << endl;
3389 }
3390 } else {
3391 string op;
3392 cout << op << endl;
3393 cout << "NA" << endl;
3394 }
3395 }
3396 return 0;
3397 }