#include <algorithm>
#include <map>
#include <string>
#include <vector>
#include <iostream>
 
using namespace std;
 
bool subject_is_done(string sbj, const map<string, vector<string>>& dates)
{
	for (auto& p : dates)
	{
		if (find(p.second.begin(), p.second.end(), sbj) != p.second.end())
			return true;
	}
	return false;
}
 
bool maestro_is_free(const pair<string, vector<string>>& p, 
	const pair<string, vector<string>>& date)
{
	for (auto& sbj : p.second)
	{
		if (find(date.second.begin(), date.second.end(), sbj) != date.second.end())
			return false;
	}
	return true;
}
 
int main()
{
	map<string, vector<string>> subjects;
	map<string, vector<string>> dates;
 
	dates["2.9. Montag"];
	dates["3.9. Dienstag"];
	dates["4.9. Mittwoch"];
	dates["5.9. Donnerstag"];
	dates["6.9. Freitag"];
 
	subjects["Mister A"] = {"Deutsch", "Religion", "Chemie"};
	subjects["Mister B"] = {"Deutsch", "Sport", "Informatik"};
	subjects["Mister C"] = {"Mathe", "Physik", "Informatik"};
	subjects["Mister X"] = {"Englisch", "Biologie", "Chemie"};
 
	for (auto& date : dates)
	{
		for (auto& p : subjects)
		{
			for (auto& sbj : p.second)
			{
				// Ekliger Hack, aber was soll's
				if (!subject_is_done(sbj, dates) && maestro_is_free(p, date))
				{
					date.second.push_back(sbj);
				}
			}
		}
	}
 
	for (auto& p : dates)
	{
		std::cout << p.first << ": ";
		for (auto& sbj : p.second)
		{
			std::cout << sbj << ", ";
		}
		std::cout << '\n';
	}
}