#include <iostream>
using namespace std;
int matrix[2][101], ord[101], n, count = 1;
void sort() {
int finished = 0, size = n, swapped;
while(!finished) {
swapped = 0;
for(int i = 1; i < size; ++i) {
if(matrix[1][ord[i]] > matrix[1][ord[i+1]]) {
int temp = ord[i];
ord[i] = ord[i+1];
ord[i+1] = temp;
swapped = 1;
}
}
if(swapped) size--;
else finished = 1;
}
}
int main(int argc, char const *argv[]) {
int hour1, min1, hour2, min2;
cout<<"Number of Spectacles = ";
cin>>n;
for(int i = 1; i <= n; ++i) {
ord[i] = i;
cin>>hour1>>min1>>hour2>>min2;
matrix[ 0 ][ i ] = hour1 * 60 + min1;
matrix[ 1 ][ i ] = hour2 * 60 + min2;
}
for(int i = 1; i <= n; ++i) {
cout<<ord[i]<<" "<<matrix[0][i]<<" "<<matrix[1][i]<<"\n";
}
for(int i = 1; i <= n; ++i) {
cout<<ord[i]<<" ";
}
sort();
cout<<endl;
for(int i = 1; i <= n; ++i) {
cout<<ord[i]<<" ";
}
cout<<endl;
int curr = matrix[1][ord[1]];
cout<<ord[1]<<" ";
for(int i = 2; i <= n; ++i) {
if(matrix[0][ord[i]] >= curr) {
cout<<ord[ i ]<<" ";
curr = matrix[ 1 ][ ord[ i ] ];
count++;
}
}
cout<<"Count = "<<count;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBtYXRyaXhbMl1bMTAxXSwgb3JkWzEwMV0sIG4sIGNvdW50ID0gMTsKCnZvaWQgc29ydCgpIHsKICAgICBpbnQgZmluaXNoZWQgPSAwLCBzaXplID0gbiwgc3dhcHBlZDsKICAgICB3aGlsZSghZmluaXNoZWQpIHsKICAgICAgIHN3YXBwZWQgPSAwOwogICAgICAgZm9yKGludCBpID0gMTsgaSA8IHNpemU7ICsraSkgewogICAgICAgICBpZihtYXRyaXhbMV1bb3JkW2ldXSA+IG1hdHJpeFsxXVtvcmRbaSsxXV0pIHsKICAgICAgICAgICAgaW50IH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SB7CgogICAgICBpZihtYXRyaXhbMF1bb3JkW2ldXSA+PSBjdXJyKSB7CgogICAgICAgIGNvdXQ8PG9yZFsgaSBdPDwiICI7CgogICAgICAgIGN1cnIgPSBtYXRyaXhbIDEgXVsgb3JkWyBpIF0gXTsKCiAgICAgICAgY291bnQrKzsKICAgICAgfQogIH0KCiAgY291dDw8IkNvdW50ID0gIjw8Y291bnQ7CgogIHJldHVybiAwOwp9
MTAKNSAwMCAxNCAwMAoxNCAwMCAxNyAwMAo4IDAwIDEzIDAwCjEzIDAwIDE1IDAwCjE1IDAwIDE3IDAwCjMgMDAgNiAwMAo0IDAwIDcgMDAKNiAwMCA5IDAwCjExIDAwIDE0IDAwCjEwIDAwIDExIDAw
10
5 00 14 00
14 00 17 00
8 00 13 00
13 00 15 00
15 00 17 00
3 00 6 00
4 00 7 00
6 00 9 00
11 00 14 00
10 00 11 00