# Question Name:Monk’s School.

```#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);

ll n,m;
cin>>n>>m;

string s[n];
map<string ,ll> pam;
//map<ll,string> pam2;
for(ll i=0;i<n;i++)
{
cin>>s[i];
pam[s[i]]=i;
//pam2[i]=s[i];
}
vector<pair<ll,string> > p[n];
string S;
for(ll i=0;i<m;i++)
{
pair<ll,string> v;
cin>>S>>v.second>>v.first;
ll idx=pam[S];
p[idx].push_back(v);
}
for(auto q=pam.begin();q!=pam.end();++q)
{
ll i=(*q).second;
S=(*q).first;
sort(p[i].begin(),p[i].end());

cout<<S<<"\n";
for(ll j=0;j<p[i].size();j++)
{
cout<<p[i][j].second<<" "<<p[i][j].first<<"\n";
}
}

}```

### Problem Description

Today is the 25th anniversary of Berland International School in Berland. On this auspicious Occasion, our friend Monk has been given the responsibility of preparing the Inventory for his school.
There are exactly N teachers and M students in the school. Each of these teachers teaches arbitary number of students. However, each student is taught by exactly one teacher.

Monk has been given the task of finding out for each teacher the Students he/she teaches. For each student Monk has been given the Student’s Name and Age. However , Monk is too busy , So he has assigned this task to us.

We need to print the name of the Teacher and the Name and age of the students that he/she teaches. However, there is a catch here. We need to print the list of students of each Teacher in Lexicographical order of their names . That is list of the teacher with lexicographically smaller name will appear before other teachers with lexicographically greater names.

In Addition , The students appearing in a particular teachers list should appear in Increasing order of their Age.

Input Format :

The first line contains two integers N and M denoting the number of Teachers and number of Students respectively. Each of the next N lines contain a single string denoting a Teachers name.It is guaranteed that each teachers name shall be unique.
The next M lines contain 2 Strings and an Integer, denoting the Teachers name, a Student’s name being taught by that Teacher and that Student’s Age. It is guaranteed that each Student’s name shall be unique and shall appear only once in the Input.

Output Format:

Print N+M lines . Print the teachers name first and then the name and age of each student taught by this teacher. The list of each teacher should appear in order of their lexicographical rank in comparison to all other teachers.

For example the list of the teacher with lexicographically smallest name should appear first, then the list of the teacher with the 2nd smallest lexicographical name and so on. The students in a particular teachers list should appear in the output in Increasing order of their Age.

Constraints:
1<=N<=100
1<=M<=10^5
1<=Age of Each Student<=106
1<=Length of each Student and Teachers Name <=35

The Name of Each Teacher and Student will consist of Lowercase English Alphabets only.

It is guaranteed that no two students with the same age shall appear in the same Teacher’s List.

Hint : You Need to Use Comparable Interface Here.

• ###### Test Case 1

Input (stdin)

```3 4
vasya
petya
kolya
vasya errichto 21
kolya petr 22
petya egor 19
vasya tourist 19
```

Expected Output

```kolya
petr 22
petya
egor 19
vasya
tourist 19
errichto 21```
• ###### Test Case 2

Input (stdin)

```3 3
cat
god
dog
cat e 2
god ee 5
dog eee 9
```

Expected Output

```cat
e 2
dog
eee 9
god
ee 5``` #### Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.
{"ft_lang_label":"__label__en","ft_lang_prob":0.8286866,"math_prob":0.7093568,"size":3407,"snap":"2022-40-2023-06","text_gpt3_token_len":871,"char_repetition_ratio":0.14046429,"word_repetition_ratio":0.062271062,"special_character_ratio":0.25887877,"punctuation_ratio":0.130854,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.96320903,"pos_list":[0,1,2,3,4],"im_url_duplicate_count":[null,null,null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-10-03T23:47:29Z\",\"WARC-Record-ID\":\"<urn:uuid:03d421f8-8842-4f5b-91b1-d9c53a024035>\",\"Content-Length\":\"124977\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:d321dbd7-301b-4031-b41a-cc6678d332d7>\",\"WARC-Concurrent-To\":\"<urn:uuid:46ec0954-1bf8-4d0c-ab9d-3cd16af119d4>\",\"WARC-IP-Address\":\"217.21.85.123\",\"WARC-Target-URI\":\"https://gadgetspidy.com/question-namemonks-school/\",\"WARC-Payload-Digest\":\"sha1:3FP47WTEHIL4NTPW7I45EKEOLXTAX2LM\",\"WARC-Block-Digest\":\"sha1:5GZM3QSB4Z3DXCXIDH3V3HUHW3H2E636\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-40/CC-MAIN-2022-40_segments_1664030337446.8_warc_CC-MAIN-20221003231906-20221004021906-00711.warc.gz\"}"}