#include <cstdio>
#include <set>
#include <map>
#include <unordered_map>
#include <string>
#include <iostream>
#include <vector>

using namespace std;

void test1_iterators() {
	set<int> s = {7, 1, 3, 5, 1};
	for (int x : s) 
		printf("%d ", x);
	puts("");
	
	for (auto it = s.begin(); it != s.end(); it++) 
		printf("%d ", *it);
	puts("");
	
	for (auto it = s.rbegin(); it != s.rend(); it++) 
		printf("%d ", *it); 
	puts("");
	auto pos = s.lower_bound(4); // первый >= 4
	
	for (auto it = pos; it != s.end(); it++)
		printf("%d ", *it);
	puts("");
	
	for (auto it = set<int>::reverse_iterator(pos); it != s.rend(); it++) 
		printf("%d ", *it); 
	puts("");
}

void test2_students() {
	map<string, vector<string>> names; // red-black tree
	// names["aba"] = {"ab", "cc"};
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		string name, surname;
		cin >> name >> surname;
		names[surname].push_back(name); // O(logn)
	}
	unordered_map<string, vector<string>> names2; // hash_table, O(1)
	for (int i = 0; i < n; i++) {
		string name, surname;
		cin >> name >> surname;
		names2[surname].push_back(name); // O(1)
	}
/**
	for (auto p : names)
	for (auto p : names2)
*/	
}

void test3_set_union() {
	set<int> a, b; // {1, 2}, {1, 3}
	for (int x : a) b.insert(x); // {1, 2, 3}
}

void test4_set_diff() {
	set<int> a, b; // b={1, 2, 3}, a={1, 4}
	for (int x : a) b.erase(x); // {2, 3}
}

int main() {
	test1_iterators();
	test2_students();
	
	set<int> a = {1, 2, 3};
	set<int> b = {4, 5, 7};
	a.insert(b.begin(), b.end()); // union
	a.erase(b.begin(), b.end()); // difference
	// intersection ?
	set<int> c;
	for (int x : a)
		if (b.count(x))
			c.insert(x);
	
	vector<int> x(10, 0);
	x.insert(x.begin() + 7, a.begin(), a.end());
	
	
}