#include <bits/stdc++.h>
#include <string.h>

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef long double ld;
typedef pair<ll, int> pll;

const int inf = 1e9;

struct data
{
    int id;
    int day;
    int t;
    int cost;
    int spend;
    data() : id(-1) {}
    data(int id, int day, int t, int cost, int spend) : id(id), day(day), t(t), cost(cost), spend(spend) {}
    bool operator<(const data& other) const
    {
        if (day != other.day) {
            return day < other.day;
        }
        return t < other.t;
    }
};

vector<char> free_time(24 * 60, true);

int str_to_time(const string& s)
{
    return ((s[0] - '0') * 10 + (s[1] - '0')) * 60 + (s[3] - '0') * 10 + s[4] - '0';
}

void occupy_day(const string& s)
{
    int l = str_to_time(s.substr(0, 5));
    int r = str_to_time(s.substr(6, 5));
    for (int i = l; i <= r; ++i) {
        free_time[i] = false;
    }
}

struct dd
{
    int last;
    int pre_last;
    int tl, tr;
    dd() : pre_last(-1) {}
    dd(int last, int pre_last, int tl, int tr) : last(last), pre_last(pre_last), tl(tl), tr(tr) {}
};

struct answer
{
    int id;
    int tl, tr;
};

void time_to_str(int t)
{
    cout << t / (24 * 60) + 1 << " ";
    t %= (24 * 60);
    int h = t / 60;
    int m = t % 60;
    if (h < 10) {
        cout << 0;
    }
    cout << h;
    cout << ":";
    if (m < 10) {
        cout << 0;
    }
    cout << m;
}

int main()
{

    //ifstream cin("input.txt");
    //freopen("input.txt", "r", stdin);

    int cnt_subjects;
    cin >> cnt_subjects;
    int n, days;
    cin >> n >> days;

    map<string, int> subjects;
    vector<string> subject_names(cnt_subjects);
    for (int i = 0; i < cnt_subjects; ++i) {
        cin >> subject_names[i];
    }
    for (int i = 0; i < cnt_subjects; ++i) {
        int val;
        cin >> val;
        subjects[subject_names[i]] = val;
    }

    for (int i = 0; i < 4; ++i) {
        string s;
        cin >> s;
        occupy_day(s);
    }

    vector<int> next_time(24 * 60 * (days + 1), -1);
    for (int i = 24 * 60 * (days + 1) - 2; i >= 0; --i) {
        int t = i % (24 * 60);
        if (free_time[(t + 1) % (24 * 60)]) {
            next_time[i] = i + 1;
        } else {
            next_time[i] = next_time[i + 1];
        }
    }

    vector<data> v;
    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        int day;
        cin >> day;
        string t;
        cin >> t;
        int cost;
        cin >> cost;
        if (subjects.count(s)) {
            --day;
            v.pb({i + 1, day, str_to_time(t), cost, subjects[s]});
        }
    }
    n = sz(v);
    sort(all(v));

    /*for (int i = 0; i < n; ++i) {
        cout << v[i].id << " " << v[i].day << " " << v[i].t << " " << v[i].cost << " " << v[i].spend << "\n";
    }*/

    vector<vector<int> > dp(n + 1, vector<int>(24 * 60 * (days + 1), -inf));
    vector<vector<dd> > pr(n + 1, vector<dd>(24 * 60 * (days + 1)));
    int qq = 0;
    if (!free_time[0]) {
        qq = next_time[0];
    }
    dp[0][qq] = 0;

    for (int j = 1; j <= n; ++j) {
        int finish = 0;
        if (!free_time[0]) {
            finish = next_time[0];
        }
        for (int c = 1; c < v[j - 1].spend; ++c) {
            finish = next_time[finish];
            /*if (j == 1) {
                cout << finish / 60 << " " << finish % 60 << "\n";
            }*/
        }
        //cout << j << " " << finish << "\n";
        for (int start = 0; start < 24 * 60 * days; ++start) {
            if (!free_time[start % (24 * 60)]) {
                continue;
            }
            for (int i = 0; i < j; ++i) {
                if (dp[i][start] == -inf) {
                    continue;
                }
                if (finish < v[j - 1].day * 24 * 60 + v[j - 1].t) {
                    if (dp[i][start] + v[j - 1].cost > dp[j][next_time[finish]]) {
                        dp[j][next_time[finish]] = dp[i][start] + v[j - 1].cost;
                        pr[j][next_time[finish]] = {v[j - 1].id, i, start, finish};
                    }
                }
            }
            finish = next_time[finish];
        }
    }

    int ans = -inf;
    int ans_i, ans_start;

    for (int i = 0; i <= n; ++i) {
        for (int start = 0; start < 24 * 60 * (days + 1); ++start) {
            if (dp[i][start] > ans) {
                ans = dp[i][start];
                ans_i = i, ans_start = start;
            }
        }
    }

    cout << ans << "\n";
    vector<answer> vv;
    while (ans_i) {
        //cout << ans_i << " " << ans_start << "\n";
        vv.pb({pr[ans_i][ans_start].last, pr[ans_i][ans_start].tl, pr[ans_i][ans_start].tr});
        int new_ans_i = pr[ans_i][ans_start].pre_last;
        int new_ans_start = pr[ans_i][ans_start].tl;
        ans_i = new_ans_i;
        ans_start = new_ans_start;
    }

    reverse(all(vv));

    cout << sz(vv) << "\n";
    for (answer& aa : vv) {
        cout << aa.id << " ";
        time_to_str(aa.tl);
        cout << " ";
        time_to_str(aa.tr);
        cout << "\n";
    }

}


#include <bits/stdc++.h>
#include <string.h>

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef long double ld;
typedef pair<ll, int> pll;

const int inf = 1e9;

struct data
{
    int id;
    int day;
    int t;
    int cost;
    int spend;
    data() : id(-1) {}
    data(int id, int day, int t, int cost, int spend) : id(id), day(day), t(t), cost(cost), spend(spend) {}
    bool operator<(const data& other) const
    {
        if (day != other.day) {
            return day < other.day;
        }
        return t < other.t;
    }
};

vector<char> free_time(24 * 60, true);

int str_to_time(const string& s)
{
    return ((s[0] - '0') * 10 + (s[1] - '0')) * 60 + (s[3] - '0') * 10 + s[4] - '0';
}

void occupy_day(const string& s)
{
    int l = str_to_time(s.substr(0, 5));
    int r = str_to_time(s.substr(6, 5));
    for (int i = l; i <= r; ++i) {
        free_time[i] = false;
    }
}

struct dd
{
    int last;
    int pre_last;
    int tl, tr;
    dd() : pre_last(-1) {}
    dd(int last, int pre_last, int tl, int tr) : last(last), pre_last(pre_last), tl(tl), tr(tr) {}
};

struct answer
{
    int id;
    int tl, tr;
};

void time_to_str(int t)
{
    cout << t / (24 * 60) + 1 << " ";
    t %= (24 * 60);
    int h = t / 60;
    int m = t % 60;
    if (h < 10) {
        cout << 0;
    }
    cout << h;
    cout << ":";
    if (m < 10) {
        cout << 0;
    }
    cout << m;
}

int main()
{

    //ifstream cin("input.txt");
    //freopen("input.txt", "r", stdin);

    int cnt_subjects;
    cin >> cnt_subjects;
    int n, days;
    cin >> n >> days;

    map<string, int> subjects;
    vector<string> subject_names(cnt_subjects);
    for (int i = 0; i < cnt_subjects; ++i) {
        cin >> subject_names[i];
    }
    for (int i = 0; i < cnt_subjects; ++i) {
        int val;
        cin >> val;
        subjects[subject_names[i]] = val;
    }

    for (int i = 0; i < 4; ++i) {
        string s;
        cin >> s;
        occupy_day(s);
    }

    bool is_free = false;
    for (int i = 0; i < 24 * 60; ++i) {
        if (free_time[i]) {
            is_free = true;
        }
    }
    if (!is_free) {
        cout << "0\n0\n";
        return 0;
    }

    vector<int> next_time(24 * 60 * (days + 1), -1);
    for (int i = 24 * 60 * (days + 1) - 2; i >= 0; --i) {
        int t = i % (24 * 60);
        if (free_time[(t + 1) % (24 * 60)]) {
            next_time[i] = i + 1;
        } else {
            next_time[i] = next_time[i + 1];
        }
    }

    vector<data> v;
    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        int day;
        cin >> day;
        string t;
        cin >> t;
        int cost;
        cin >> cost;
        if (subjects.count(s)) {
            --day;
            v.pb({i + 1, day, str_to_time(t), cost, subjects[s]});
        }
    }
    n = sz(v);
    sort(all(v));

    /*for (int i = 0; i < n; ++i) {
        cout << v[i].id << " " << v[i].day << " " << v[i].t << " " << v[i].cost << " " << v[i].spend << "\n";
    }*/

    vector<vector<int> > dp(n + 1, vector<int>(24 * 60 * (days + 1), -inf));
    vector<vector<dd> > pr(n + 1, vector<dd>(24 * 60 * (days + 1)));
    int qq = 0;
    if (!free_time[0]) {
        qq = next_time[0];
    }
    dp[0][qq] = 0;

    for (int j = 1; j <= n; ++j) {
        int finish = 0;
        if (!free_time[0]) {
            finish = next_time[0];
        }
        for (int c = 1; c < v[j - 1].spend; ++c) {
            finish = next_time[finish];
            if (finish >= v[j - 1].day * 24 * 60 + v[j - 1].t) {
                break;
            }
            /*if (j == 1) {
                cout << finish / 60 << " " << finish % 60 << "\n";
            }*/
        }
        if (finish >= v[j - 1].day * 24 * 60 + v[j - 1].t) {
            continue;
        }
        //cout << j << " " << finish << "\n";
        for (int start = 0; start < 24 * 60 * days; ++start) {
            if (!free_time[start % (24 * 60)]) {
                continue;
            }
            if (finish < v[j - 1].day * 24 * 60 + v[j - 1].t) {for (int i = 0; i < j; ++i) {
                if (dp[i][start] == -inf) {
                    continue;
                }
                if (dp[i][start] + v[j - 1].cost > dp[j][next_time[finish]]) {
                    dp[j][next_time[finish]] = dp[i][start] + v[j - 1].cost;
                    pr[j][next_time[finish]] = {v[j - 1].id, i, start, finish};
                }
            }
            finish = next_time[finish];} else break;
        }
    }

    int ans = -inf;
    int ans_i, ans_start;

    for (int i = 0; i <= n; ++i) {
        for (int start = 0; start < 24 * 60 * (days + 1); ++start) {
            if (dp[i][start] > ans) {
                ans = dp[i][start];
                ans_i = i, ans_start = start;
            }
        }
    }

    cout << ans << "\n";
    vector<answer> vv;
    while (ans_i) {
        //cout << ans_i << " " << ans_start << "\n";
        vv.pb({pr[ans_i][ans_start].last, pr[ans_i][ans_start].tl, pr[ans_i][ans_start].tr});
        int new_ans_i = pr[ans_i][ans_start].pre_last;
        int new_ans_start = pr[ans_i][ans_start].tl;
        ans_i = new_ans_i;
        ans_start = new_ans_start;
    }

    reverse(all(vv));

    cout << sz(vv) << "\n";
    for (answer& aa : vv) {
        cout << aa.id << " ";
        time_to_str(aa.tl);
        cout << " ";
        time_to_str(aa.tr);
        cout << "\n";
    }

}


#include <cinttypes>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cctype>
#include <cmath>

#include <algorithm>
#include <string>
#include <vector>
#include <map>

struct time_interval { int b, e; };

struct student { std::string subject; int index, time, pay; };

struct work_unit { int pay; bool take, d; work_unit() : pay(0), take(false), d(false) { } };

struct work_item { int index, bt, et; };

struct plan {
	int rows, cols;
	std::vector<work_unit> w;
	plan(const int rows, const int cols)
		: rows(rows), cols(cols), w(rows * cols) { }
	work_unit &operator()(const int r, const int c) { return w[c + r*cols]; }
};

static bool operator<(const student &a, const student &b)
{
	return a.time < b.time ? true  :
	       a.time > b.time ? false :
	       a.pay  < b.pay  ? true  :
	       a.pay  > b.pay  ? false : false;
}

static std::map<std::string, int> read_subjects(const int m)
{
	std::vector<std::string> subject_names;
	std::map<std::string, int> subjects;

	for (int i = 0; i < m; i++) {
		char name[101];
		if (fscanf(stdin, "%100s", name) != 1 || strlen(name) == 100) {
			fprintf(stderr, "fscanf: Subject name IO error.\n");
			exit(EXIT_FAILURE);
		}
		subject_names.push_back(name);
	}

	for (int i = 0; i < m; i++) {
		int t;
		if (fscanf(stdin, "%d", &t) != 1 || t < 1 || 1000 < t) {
			fprintf(stderr, "fscanf: Subject time IO error.\n");
			exit(EXIT_FAILURE);
		}

		subjects[subject_names[i]] = t;
	}

	return subjects;
}

static int read_time()
{
	int h, m;

	if (fscanf(stdin, "%d:%d", &h, &m) != 2 ||
		h < 0 || 23 < h || m < 0 || 59 < m) {
		fprintf(stderr, "fscanf: Time IO error.\n");
		exit(EXIT_FAILURE);
	}

	return 60*h + m;
}

static time_interval read_time_interval()
{
	int h0, m0, h1, m1;

	if (fscanf(stdin, "%d:%d-%d:%d", &h0, &m0, &h1, &m1) != 4 ||
		h0 < 0 || 23 < h0 || m0 < 0 || 59 < m0 ||
		h1 < 0 || 23 < h1 || m1 < 0 || 59 < m1) {
		fprintf(stderr, "fscanf: Time interval IO error.\n");
		exit(EXIT_FAILURE);
	}

	return { h0*60 + m0, h1*60 + m1 };
}

static std::vector<time_interval> read_action_times()
{
	std::vector<time_interval> action_times;

	for (int i = 0; i < 4; i++)
		action_times.push_back(read_time_interval());

	return action_times;
}

static std::vector<student> read_students(const int n, const int k,
	const std::map<std::string, int> &subjects,
	const std::vector<time_interval> &action_times)
{
	std::vector<student> students;

	for (int i = 0; i < n; i++) {
		char subject[101];
		int day, h, m, pay;

		if (fscanf(stdin, "%100s %d %d:%d %d",
			subject, &day, &h, &m, &pay) != 5 ||
			strlen(subject) == 100 || day < 1 || k < day ||
			h < 0 || 23 < h || m < 0 || 59 < m || pay < 1) {
			fprintf(stderr, "fscanf: Student IO error.\n");
			exit(EXIT_FAILURE);
		}

		const int et = (day - 1)*24*60 + 60*h + m;
		int wm = 0;

		for (int t = 0; t < et; t++) {
			bool work_minute = true;
			for (const time_interval &at : action_times)
				if (at.b <= t && t <= at.e)
					work_minute = false;
			wm += (work_minute ? 1 : 0);
		}

		if (subjects.find(subject) != subjects.end()) {
			students.push_back({ subject, i + 1, wm, pay });
		}
	}

	std::sort(students.begin(), students.end());

	return students;
}

static int working_minutes_per_day(const std::vector<time_interval> &action_times)
{
	int wmpd = 0;

	for (int i = 0; i < 24*60; i++) {
		bool work_minute = true;
		for (const time_interval &at : action_times)
			if (at.b <= i && i <= at.e)
				work_minute = false;
		wmpd += (work_minute ? 1 : 0);
	}

	return wmpd;
}

static int real_time(int wm, const std::vector<time_interval> &action_times)
{
	int t = -1;

	for (int s = 0; s < wm + 1; t++) {
		bool work_minute = true;
		for (const time_interval &at : action_times)
			if (at.b <= (t + 1) % (24*60) && (t + 1) % (24*60) <= at.e)
				work_minute = false;
		s += (work_minute ? 1 : 0);
	}

	return t;
}

int main(int argc, char *argv[])
{
	int m, n, k;

	if (fscanf(stdin, "%d %d %d", &m, &n, &k) != 3 ||
		m < 1 || 100 < m || n < 1 || 100 < n || k < 1 || 30 < k) {
		fprintf(stderr, "fscanf: Header IO error.\n");
		exit(EXIT_FAILURE);
	}

	std::map<std::string, int> subjects = read_subjects(m);
	const std::vector<time_interval> action_times = read_action_times();
	const std::vector<student> students = read_students(n, k, subjects, action_times);
	const int wmpd = working_minutes_per_day(action_times);
	plan p(students.size() + 1, k*wmpd);

	for (int r = 1; r < p.rows; r++)
	for (int c = 0; c < p.cols; c++) {
		const int st = subjects[students[r - 1].subject];

		if (c < students[r - 1].time && st <= c + 1) {
			const int pay = (st <= c ? p(r - 1, c - st).pay : 0) + students[r - 1].pay;
			p(r, c).take = (p(r - 1, c).pay < pay);
			p(r, c).pay = (p(r, c).take ? pay : p(r - 1, c).pay);
		} else {
			const int pay = (c > 0 ? p(r, c - 1).pay : 0);
			p(r, c).d = (p(r - 1, c).pay < pay);
			p(r, c).pay = (p(r, c).d ? pay : p(r - 1, c).pay);
		}
	}

	printf("%d\n", p(p.rows - 1, p.cols - 1).pay);

	std::vector<work_item> time_table;

	for (int r = p.rows - 1, c = p.cols - 1, d = 0; r > 0; d = p(r, c).d,
	     c -= p(r, c).take ? subjects[students[r - 1].subject] : d, r -= !d) {
		// printf("p %d %d %d\n", r, c, p(r, c).take);
		if (p(r, c).take) {
			const int bt = real_time(c + 1 - subjects[students[r - 1].subject], action_times);
			const int et = real_time(c, action_times);
			time_table.push_back({ students[r - 1].index, bt, et });
		}
	}

	std::reverse(time_table.begin(), time_table.end());

	printf("%d\n", static_cast<int>(time_table.size()));
	for (const work_item &wi : time_table)
			printf("%d %d %02d:%02d %d %02d:%02d\n",
				wi.index,
				wi.bt/24/60 + 1, (wi.bt/60) % 24, wi.bt % 60,
				wi.et/24/60 + 1, (wi.et/60) % 24, wi.et % 60);

	return EXIT_SUCCESS;
}


#include <cinttypes>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cctype>
#include <cmath>

#include <algorithm>
#include <string>
#include <vector>
#include <map>

struct time_interval { int b, e; };

struct student { std::string subject; int index, time, pay; };

struct work_unit { int pay; bool take, d; work_unit() : pay(0), take(false), d(false) { } };

struct work_item { int index, bt, et; };

struct plan {
	int rows, cols;
	std::vector<work_unit> w;
	plan(const int rows, const int cols)
		: rows(rows), cols(cols), w(rows * cols) { }
	work_unit &operator()(const int r, const int c) { return w[c + r*cols]; }
};

static bool operator<(const student &a, const student &b)
{
	return a.time < b.time ? true  :
	       a.time > b.time ? false :
	       a.pay  < b.pay  ? true  :
	       a.pay  > b.pay  ? false : false;
}

static std::map<std::string, int> read_subjects(const int m)
{
	std::vector<std::string> subject_names;
	std::map<std::string, int> subjects;

	for (int i = 0; i < m; i++) {
		char name[101];
		if (fscanf(stdin, "%100s", name) != 1 || strlen(name) == 100) {
			fprintf(stderr, "fscanf: Subject name IO error.\n");
			exit(EXIT_FAILURE);
		}
		subject_names.push_back(name);
	}

	for (int i = 0; i < m; i++) {
		int t;
		if (fscanf(stdin, "%d", &t) != 1 || t < 1 || 1000 < t) {
			fprintf(stderr, "fscanf: Subject time IO error.\n");
			exit(EXIT_FAILURE);
		}

		subjects[subject_names[i]] = t;
	}

	return subjects;
}

static int read_time()
{
	int h, m;

	if (fscanf(stdin, "%d:%d", &h, &m) != 2 ||
		h < 0 || 23 < h || m < 0 || 59 < m) {
		fprintf(stderr, "fscanf: Time IO error.\n");
		exit(EXIT_FAILURE);
	}

	return 60*h + m;
}

static time_interval read_time_interval()
{
	int h0, m0, h1, m1;

	if (fscanf(stdin, "%d:%d-%d:%d", &h0, &m0, &h1, &m1) != 4 ||
		h0 < 0 || 23 < h0 || m0 < 0 || 59 < m0 ||
		h1 < 0 || 23 < h1 || m1 < 0 || 59 < m1) {
		fprintf(stderr, "fscanf: Time interval IO error.\n");
		exit(EXIT_FAILURE);
	}

	return { h0*60 + m0, h1*60 + m1 };
}

static std::vector<time_interval> read_action_times()
{
	std::vector<time_interval> action_times;

	for (int i = 0; i < 4; i++)
		action_times.push_back(read_time_interval());

	return action_times;
}

static std::vector<student> read_students(const int n, const int k,
	const std::map<std::string, int> &subjects,
	const std::vector<time_interval> &action_times)
{
	std::vector<student> students;

	for (int i = 0; i < n; i++) {
		char subject[101];
		int day, h, m, pay;

		if (fscanf(stdin, "%100s %d %d:%d %d",
			subject, &day, &h, &m, &pay) != 5 ||
			strlen(subject) == 100 || day < 1 || k < day ||
			h < 0 || 23 < h || m < 0 || 59 < m || pay < 1) {
			fprintf(stderr, "fscanf: Student IO error.\n");
			exit(EXIT_FAILURE);
		}

		const int et = (day - 1)*24*60 + 60*h + m;
		int wm = 0;

		for (int t = 0; t < et; t++) {
			bool work_minute = true;
			for (const time_interval &at : action_times)
				if (at.b <= t % (24*60) && t % (24*60) <= at.e)
					work_minute = false;
			wm += (work_minute ? 1 : 0);
		}

		if (subjects.find(subject) != subjects.end()) {
			students.push_back({ subject, i + 1, wm, pay });
		}
	}

	std::sort(students.begin(), students.end());

	return students;
}

static int working_minutes_per_day(const std::vector<time_interval> &action_times)
{
	int wmpd = 0;

	for (int i = 0; i < 24*60; i++) {
		bool work_minute = true;
		for (const time_interval &at : action_times)
			if (at.b <= i && i <= at.e)
				work_minute = false;
		wmpd += (work_minute ? 1 : 0);
	}

	return wmpd;
}

static int real_time(int wm, const std::vector<time_interval> &action_times)
{
	int t = -1;

	for (int s = 0; s < wm + 1; t++) {
		bool work_minute = true;
		for (const time_interval &at : action_times)
			if (at.b <= (t + 1) % (24*60) && (t + 1) % (24*60) <= at.e)
				work_minute = false;
		s += (work_minute ? 1 : 0);
	}

	return t;
}

int main(int argc, char *argv[])
{
	int m, n, k;

	if (fscanf(stdin, "%d %d %d", &m, &n, &k) != 3 ||
		m < 1 || 100 < m || n < 1 || 100 < n || k < 1 || 30 < k) {
		fprintf(stderr, "fscanf: Header IO error.\n");
		exit(EXIT_FAILURE);
	}

	std::map<std::string, int> subjects = read_subjects(m);
	const std::vector<time_interval> action_times = read_action_times();
	const std::vector<student> students = read_students(n, k, subjects, action_times);
	const int wmpd = working_minutes_per_day(action_times);
	plan p(students.size() + 1, k*wmpd);

	for (int r = 1; r < p.rows; r++)
	for (int c = 0; c < p.cols; c++) {
		const int st = subjects[students[r - 1].subject];

		if (c < students[r - 1].time && st <= c + 1) {
			const int pay = (st <= c ? p(r - 1, c - st).pay : 0) + students[r - 1].pay;
			p(r, c).take = (p(r - 1, c).pay < pay);
			p(r, c).pay = (p(r, c).take ? pay : p(r - 1, c).pay);
		} else {
			const int pay = (c > 0 ? p(r, c - 1).pay : 0);
			p(r, c).d = (p(r - 1, c).pay < pay);
			p(r, c).pay = (p(r, c).d ? pay : p(r - 1, c).pay);
		}
	}

	printf("%d\n", (p.cols > 0 ? p(p.rows - 1, p.cols - 1).pay : 0));

	std::vector<work_item> time_table;

	for (int r = p.rows - 1, c = p.cols - 1, d = 0; r > 0 && c >= 0; d = p(r, c).d,
	     c -= p(r, c).take ? subjects[students[r - 1].subject] : d, r -= !d)
		if (p(r, c).take) {
			const int bt = real_time(c + 1 - subjects[students[r - 1].subject], action_times);
			const int et = real_time(c, action_times);
			time_table.push_back({ students[r - 1].index, bt, et });
		}

	std::reverse(time_table.begin(), time_table.end());

	printf("%d\n", static_cast<int>(time_table.size()));
	for (const work_item &wi : time_table)
			printf("%d %d %02d:%02d %d %02d:%02d\n",
				wi.index,
				wi.bt/24/60 + 1, (wi.bt/60) % 24, wi.bt % 60,
				wi.et/24/60 + 1, (wi.et/60) % 24, wi.et % 60);

	return EXIT_SUCCESS;
}


#include <cinttypes>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cctype>
#include <cmath>

#include <algorithm>
#include <string>
#include <vector>
#include <map>

struct time_interval { int b, e; };

struct student { std::string subject; int index, time, pay; };

struct work_unit { int pay; bool take, d; work_unit() : pay(0), take(false), d(false) { } };

struct work_item { int index, bt, et; };

struct plan {
	int rows, cols;
	std::vector<work_unit> w;
	plan(const int rows, const int cols)
		: rows(rows), cols(cols), w(rows * cols) { }
	work_unit &operator()(const int r, const int c) { return w[c + r*cols]; }
};

static bool operator<(const student &a, const student &b)
{
	return a.time < b.time ? true  :
	       a.time > b.time ? false :
	       a.pay  < b.pay  ? true  :
	       a.pay  > b.pay  ? false : false;
}

static std::map<std::string, int> read_subjects(const int m)
{
	std::vector<std::string> subject_names;
	std::map<std::string, int> subjects;

	for (int i = 0; i < m; i++) {
		char name[101];
		if (fscanf(stdin, "%100s", name) != 1 || strlen(name) == 100) {
			fprintf(stderr, "fscanf: Subject name IO error.\n");
			exit(EXIT_FAILURE);
		}
		subject_names.push_back(name);
	}

	for (int i = 0; i < m; i++) {
		int t;
		if (fscanf(stdin, "%d", &t) != 1 || t < 1 || 1000 < t) {
			fprintf(stderr, "fscanf: Subject time IO error.\n");
			exit(EXIT_FAILURE);
		}

		subjects[subject_names[i]] = t;
	}

	return subjects;
}

static int read_time()
{
	int h, m;

	if (fscanf(stdin, "%d:%d", &h, &m) != 2 ||
		h < 0 || 23 < h || m < 0 || 59 < m) {
		fprintf(stderr, "fscanf: Time IO error.\n");
		exit(EXIT_FAILURE);
	}

	return 60*h + m;
}

static time_interval read_time_interval()
{
	int h0, m0, h1, m1;

	if (fscanf(stdin, "%d:%d-%d:%d", &h0, &m0, &h1, &m1) != 4 ||
		h0 < 0 || 23 < h0 || m0 < 0 || 59 < m0 ||
		h1 < 0 || 23 < h1 || m1 < 0 || 59 < m1) {
		fprintf(stderr, "fscanf: Time interval IO error.\n");
		exit(EXIT_FAILURE);
	}

	return { h0*60 + m0, h1*60 + m1 };
}

static std::vector<time_interval> read_action_times()
{
	std::vector<time_interval> action_times;

	for (int i = 0; i < 4; i++)
		action_times.push_back(read_time_interval());

	return action_times;
}

static std::vector<student> read_students(const int n, const int k,
	const std::map<std::string, int> &subjects,
	const std::vector<time_interval> &action_times)
{
	std::vector<student> students;

	for (int i = 0; i < n; i++) {
		char subject[101];
		int day, h, m, pay;

		if (fscanf(stdin, "%100s %d %d:%d %d",
			subject, &day, &h, &m, &pay) != 5 ||
			strlen(subject) == 100 || day < 1 || k < day ||
			h < 0 || 23 < h || m < 0 || 59 < m || pay < 1) {
			fprintf(stderr, "fscanf: Student IO error.\n");
			exit(EXIT_FAILURE);
		}

		const int et = (day - 1)*24*60 + 60*h + m;
		int wm = 0;

		for (int t = 0; t < et; t++) {
			bool work_minute = true;
			for (const time_interval &at : action_times)
				if (at.b <= t && t <= at.e)
					work_minute = false;
			wm += (work_minute ? 1 : 0);
		}

		if (subjects.find(subject) != subjects.end()) {
			students.push_back({ subject, i + 1, wm, pay });
		}
	}

	std::sort(students.begin(), students.end());

	return students;
}

static int working_minutes_per_day(const std::vector<time_interval> &action_times)
{
	int wmpd = 0;

	for (int i = 0; i < 24*60; i++) {
		bool work_minute = true;
		for (const time_interval &at : action_times)
			if (at.b <= i && i <= at.e)
				work_minute = false;
		wmpd += (work_minute ? 1 : 0);
	}

	return wmpd;
}

static int real_time(int wm, const std::vector<time_interval> &action_times)
{
	int t = -1;

	for (int s = 0; s < wm + 1; t++) {
		bool work_minute = true;
		for (const time_interval &at : action_times)
			if (at.b <= (t + 1) % (24*60) && (t + 1) % (24*60) <= at.e)
				work_minute = false;
		s += (work_minute ? 1 : 0);
	}

	return t;
}

int main(int argc, char *argv[])
{
	int m, n, k;

	if (fscanf(stdin, "%d %d %d", &m, &n, &k) != 3 ||
		m < 1 || 100 < m || n < 1 || 100 < n || k < 1 || 30 < k) {
		fprintf(stderr, "fscanf: Header IO error.\n");
		exit(EXIT_FAILURE);
	}

	std::map<std::string, int> subjects = read_subjects(m);
	const std::vector<time_interval> action_times = read_action_times();
	const std::vector<student> students = read_students(n, k, subjects, action_times);
	const int wmpd = working_minutes_per_day(action_times);
	plan p(students.size() + 1, k*wmpd);

	for (int r = 1; r < p.rows; r++)
	for (int c = 0; c < p.cols; c++) {
		const int st = subjects[students[r - 1].subject];

		if (c < students[r - 1].time && st <= c + 1) {
			const int pay = (st <= c ? p(r - 1, c - st).pay : 0) + students[r - 1].pay;
			p(r, c).take = (p(r - 1, c).pay < pay);
			p(r, c).pay = (p(r, c).take ? pay : p(r - 1, c).pay);
		} else {
			const int pay = (c > 0 ? p(r, c - 1).pay : 0);
			p(r, c).d = (p(r - 1, c).pay < pay);
			p(r, c).pay = (p(r, c).d ? pay : p(r - 1, c).pay);
		}
	}

	printf("%d\n", (p.cols > 0 ? p(p.rows - 1, p.cols - 1).pay : 0));

	std::vector<work_item> time_table;

	for (int r = p.rows - 1, c = p.cols - 1, d = 0; r > 0 && c >= 0; d = p(r, c).d,
	     c -= p(r, c).take ? subjects[students[r - 1].subject] : d, r -= !d)
		if (p(r, c).take) {
			const int bt = real_time(c + 1 - subjects[students[r - 1].subject], action_times);
			const int et = real_time(c, action_times);
			time_table.push_back({ students[r - 1].index, bt, et });
		}

	std::reverse(time_table.begin(), time_table.end());

	printf("%d\n", static_cast<int>(time_table.size()));
	for (const work_item &wi : time_table)
			printf("%d %d %02d:%02d %d %02d:%02d\n",
				wi.index,
				wi.bt/24/60 + 1, (wi.bt/60) % 24, wi.bt % 60,
				wi.et/24/60 + 1, (wi.et/60) % 24, wi.et % 60);

	return EXIT_SUCCESS;
}


//lxrtxdy!
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<map>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
#define maxn 110
const int day=1440;
struct Nodes{
    string name;
    int d,h,m;
    int t,val,nd;
    int id;
}p[maxn];
map<string,int>mp;
int val[maxn],n,m,nm;
int pre[maxn][31*day][2];
int sum[31*day];
int mark[31*day],f[maxn][31*day];
string lec;
int tot;
bool cmp(Nodes p1,Nodes p2)
{
    return p1.t<p2.t;
}
void work(int t,int &dd,int &hh,int &mm)
{
    t--;
    dd=t/day;
//  printf("t=%d day=%d dd=t/day=%d\n",t,day,dd);
    dd++;
    t=t%day;
    hh=t/60;
    mm=t%60;
    //d=0;
}
void dfs(int i,int now,int cnt)
{
    if(now==0){
        printf("%d\n",cnt);
        return;
    }
    if(pre[i][now][0]==-1){
        dfs(i-1,now,cnt);
        return;
    }
    dfs(i-1,pre[i][now][0],cnt+1);
    int id=pre[i][now][1];
    int d1,h1,m1,d2,h2,m2;
    int kk=lower_bound(sum,sum+tot+1,sum[pre[i][now][0]]+1)-sum;
    work(kk,d1,h1,m1);
    work(now,d2,h2,m2);
    //printf("%d st=%d ed=%d %d %02d:%02d %d %02d:%02d\n",p[id].id,pre[now][0]+1,now,d1,h1,m1,d2,h2,m2);
    printf("%d %d %02d:%02d %d %02d:%02d\n",p[id].id,d1,h1,m1,d2,h2,m2);
}

int main()
{
    int i,j,k;
    //int tot;
    int dd,mm,hh;
    //work(100,dd,mm,hh);
    while(scanf("%d%d%d",&n,&m,&nm)!=EOF){
        mp.clear();
        for(i=1;i<=n;i++){
            cin>>lec;
            mp[lec]=i;
        }
        for(i=1;i<=n;i++){
            scanf("%d",&val[i]);
        }
        tot=nm*day;
        for(i=0;i<=tot;i++){
            mark[i]=0;
        }
        int tmp=4;
        while(tmp--){
            int h1,m1,h2,m2;
            scanf("%d:%d-%d:%d",&h1,&m1,&h2,&m2);
            //printf("%d %d %d %d\n",h1,m1,h2,m2);
            int t1=h1*60+m1+1;
            int t2=h2*60+m2+1;
            if(t1<=t2){
                for(i=0;i<nm;i++){
                    for(j=t1;j<=t2;j++){
                        mark[j+i*day]=1;
                    }
                }
            }else {
                for(i=0;i<nm;i++){
                    for(j=t1;j<=day;j++){
                        mark[j+i*day]=1;
                    }
                    for(j=1;j<=t2;j++){
                        mark[j+i*day]=1;
                    }
                }
            }
        }
        for(i=1;i<=m;i++){
            cin>>p[i].name;
            scanf("%d%d:%d%d",&p[i].d,&p[i].h,&p[i].m,&p[i].val);
            p[i].t=(p[i].d-1)*day+p[i].h*60+p[i].m+1;
            k=mp[p[i].name];
            if(k==0)p[i].nd=-1;
            else if(p[i].t<=val[k])p[i].nd=-1;
            else
            p[i].nd=val[k];
            p[i].id=i;
            //printf("%d %d %d %d\n",i,p[i].t,p[i].nd,p[i].val);
        }
        sort(p+1,p+m+1,cmp);
        for(i=0;i<=tot;i++){
            if(i==0)sum[i]=mark[i];
            else sum[i]=sum[i-1]+mark[i];
        }
        for(i=0;i<=tot;i++){
            sum[i]=i-sum[i];
        }
        for(i=0;i<=m;i++){
            for(j=0;j<=tot;j++){
                f[i][j]=-1;
            }
        }
        tmp=0;
        f[0][0]=0;
        for(i=1;i<=m;i++){
            for(j=tot;j>=0;j--){
                if(f[i-1][j]==-1)continue;
                //printf("%d %d\n",i-1,j);
                f[i][j]=f[i-1][j];
                pre[i][j][0]=-1;
                if(p[i].nd==-1||p[i].val==0)continue;
                k=lower_bound(sum,sum+tot+1,sum[j]+p[i].nd)-sum;
                if(k>=p[i].t)continue;
                if(f[i-1][j]+p[i].val>=f[i][k]){
                    f[i][k]=f[i-1][j]+p[i].val;
                    pre[i][k][0]=j;
                    pre[i][k][1]=i;
                }
                //f[k]=max(f[k],f[j]+p[i].val);
            }
            if(p[i].nd!=-1&&p[i].val>0)
            tmp+=p[i].nd;
        }
        int ans=0,id1,id2;
        for(j=1;j<=m;j++){
        for(i=0;i<=tot;i++){
            if(f[j][i]>ans){
                ans=f[j][i];
                id1=j;
                id2=i;
            }
        }
        }
    //  printf("%d %d\n",ans,id);
        if(ans==0){
            printf("0\n0\n");
            continue;
        }
        printf("%d\n",ans);
        dfs(id1,id2,0);
    }
    return 0;
}
//stO lxr!


#include<cstdio>
#include<cstring>
#include<iostream>
#include<map>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
#define pb push_back
#define N 110
#define M 43210
#define L 16
struct E
{
    int w,x,p,z;
    E(){}
    E(int _w,int _x,int _p,int _z):w(_w),x(_x),p(_p),z(_z){}
    bool operator < (const E&a) const {return x<a.x;}
};
int n,m,p,a[N];map<string,int> A;int f[N][M],g[N][M],w[M][L];bool v[M];
vector<E> B;
int gg(int x,int y)
{
    int p=x;
    for(int i=0,p2=p;i<L;i++)
        if((y>>i)&1)p=w[p2][i],p2=p+1;
    return p;
}
void ff(int x,int y,int z)
{
    if(g[x][y]==-1)printf("%d\n",z);else
    if(g[x][y]==y)ff(x-1,y,z);else
    {
        ff(x-1,g[x][y],z+1);
        int l=w[g[x][y]][0],r=y-1;
        printf("%d %d %02d:%02d %d %02d:%02d\n",B[x-1].z+1,l/1440+1,l%1440/60,l%60,r/1440+1,r%1440/60,r%60);
    }
}
int main()
{
    scanf("%d%d%d",&n,&m,&p);
    for(int i=0,t=0;i<n;i++){string s;cin>>s;A[s]=t++;}
    for(int i=0;i<n;i++)scanf("%d",a+i);
    for(int i=0;i<4;i++)
    {
        int x0,y0,x1,y1;
        scanf("%2d:%2d-%2d:%2d",&x0,&y0,&x1,&y1);
        for(int j=0;j<p;j++)
            for(int k=x0*60+y0;k<=x1*60+y1;k++)v[j*1440+k]=1;
    }
    int P=p*1440;
    for(int j=0;j<L;j++)w[P][j]=P-1;
    for(int i=P-1;i>=0;i--)
    {
        if(v[i])w[i][0]=w[i+1][0];else w[i][0]=i;
        for(int j=1;j<L;j++)w[i][j]=w[w[i][j-1]+1][j-1];
    }
    for(int i=0;i<m;i++)
    {
        string s;cin>>s;int z,x,y,p;
        scanf("%d%2d:%2d%d",&z,&x,&y,&p),--z;
        if(A.find(s)==A.end())continue;
        B.pb(E(A[s],z*1440+x*60+y,p,i));
    }
    sort(B.begin(),B.end()),m=(int)B.size();
    memset(g,-1,sizeof g);
    for(int i=0;i<m;i++)
        for(int j=0;j<P;j++)
        {
            if(f[i][j]>f[i+1][j])
                f[i+1][j]=f[i][j],g[i+1][j]=j;
            int z=gg(j,a[B[i].w]);
            if(z>=B[i].x)continue;
            if(f[i][j]+B[i].p>f[i+1][z+1])
                f[i+1][z+1]=f[i][j]+B[i].p,g[i+1][z+1]=j;
        }
    int S=0,T=0;
    for(int i=0;i<=P;i++)if(f[m][i]>S)S=f[m][i],T=i;
    printf("%d\n",S);ff(m,T,0);
    return 0;
}//hellobig_tq//hellobig_tq


#include<cstdio>
#include<cstring>
#include<iostream>
#include<map>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
#define pb push_back
#define N 110
#define M 43210
#define L 16
struct E
{
    int w,x,p,z;
    E(){}
    E(int _w,int _x,int _p,int _z):w(_w),x(_x),p(_p),z(_z){}
    bool operator < (const E&a) const {return x<a.x;}
};
int n,m,p,a[N];map<string,int> A;int f[N][M],g[N][M],w[M][L];bool v[M];
vector<E> B;
int gg(int x,int y)
{
    int p=x;
    for(int i=0,p2=p;i<L;i++)
        if((y>>i)&1)p=w[p2][i],p2=p+1;
    return p;
}
void ff(int x,int y,int z)
{
    if(g[x][y]==-1)printf("%d\n",z);else
    if(g[x][y]==y)ff(x-1,y,z);else
    {
        ff(x-1,g[x][y],z+1);
        int l=w[g[x][y]][0],r=y-1;
        printf("%d %d %02d:%02d %d %02d:%02d\n",B[x-1].z+1,l/1440+1,l%1440/60,l%60,r/1440+1,r%1440/60,r%60);
    }
}
int main()
{
    scanf("%d%d%d",&n,&m,&p);
    for(int i=0,t=0;i<n;i++){string s;cin>>s;A[s]=t++;}
    for(int i=0;i<n;i++)scanf("%d",a+i);
    for(int i=0;i<4;i++)
    {
        int x0,y0,x1,y1;
        scanf("%2d:%2d-%2d:%2d",&x0,&y0,&x1,&y1);
        for(int j=0;j<p;j++)
            for(int k=x0*60+y0;k<=x1*60+y1;k++)v[j*1440+k]=1;
    }
    int P=p*1440;
    for(int j=0;j<L;j++)w[P][j]=P-1;
    for(int i=P-1;i>=0;i--)
    {
        if(v[i])w[i][0]=w[i+1][0];else w[i][0]=i;
        for(int j=1;j<L;j++)w[i][j]=w[w[i][j-1]+1][j-1];
    }
    for(int i=0;i<m;i++)
    {
        string s;cin>>s;int z,x,y,p;
        scanf("%d%2d:%2d%d",&z,&x,&y,&p),--z;
        if(A.find(s)==A.end())continue;
        B.pb(E(A[s],z*1440+x*60+y,p,i));
    }
    sort(B.begin(),B.end()),m=(int)B.size();
    memset(g,-1,sizeof g);
    for(int i=0;i<m;i++)
        for(int j=0;j<P;j++)
        {
            if(f[i][j]>f[i+1][j])
                f[i+1][j]=f[i][j],g[i+1][j]=j;
            int z=gg(j,a[B[i].w]);
            if(z>=B[i].x)continue;
            if(f[i][j]+B[i].p>f[i+1][z+1])
                f[i+1][z+1]=f[i][j]+B[i].p,g[i+1][z+1]=j;
        }
    int S=0,T=0;
    for(int i=0;i<=P;i++)if(f[m][i]>S)S=f[m][i],T=i;
    printf("%d\n",S);ff(m,T,0);
    return 0;
}//hellobig_tq


#include <bits/stdc++.h>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
//#define   mp         make_pair
#define   mt         make_tuple
#define    clr(v,d)      memset( v, d ,sizeof(v))
#define   angle(n)      atan2((n.imag()),(n.real()))
#define   vec(a,b)       ((b)-(a))
#define   length(a)      hypot( (a.imag()),(a.real()) )
#define   normalize(a)      (a)/(length(a))
#define    dp(a,b)          (((conj(a))*(b)).real())
#define    cp(a,b)          (((conj(a))*(b)).imag())
#define    lengthsqrt(a)       dp(a,a)
#define    rotate0( a,ang)    ((a)*exp( point(0,ang) ))
#define    rotateA(about,p,ang)   (rotate0(vec(about,p),ang)+about)
#define    lcm(a,b)                ((a*b)/(__gcd(a,b)))
#define    reflection0(m,v)         (conj((v)/(m))*(m))
#define     reflectionA(m,v,p0)     (conj( (vec(p0,v))/(vec(p0,m)) ) * (vec(p0,m)) ) + p0
#define     same(p1,p2)               ( dp(  vec(p1,p2),vec(p1,p2)) < eps )
#define     point                    complex<double>
typedef  long long     ll ;
typedef  unsigned long long ull;
const double eps= (1e-10);
using namespace std;
int dcmp(double a,double b){   return fabs(a-b)<=eps ? 0: (a>b)? 1:-1  ;}
ll getBit(ll num, int idx) {return ((num >> idx) & 1ll) == 1ll;}
ll setBit1(ll num, int idx) {return num | (1ll<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}
int countNumBit1(ll mask) {int ret=0; while (mask) 	{mask &= (mask-1ll);++ret;	}return ret;}

const int MAXN = 100;
const int oops = 1<<25;

class Subject
{
    public:
        string name;
        int time;
}subject[MAXN+5];

class Job
{
    public:
        int input_id,subject_id;
        int profit,deadline;
    bool operator < (const Job &with) const
    {
        if (deadline != with.deadline)return deadline < with.deadline;
        return input_id < with.input_id;
    }
}job[MAXN+5];

char tempo[40];
map<string,int>mp;
int m,n,k;

int from[10],to[10];

int scanTime(FILE *in)
{
    int hours,minutes;
    fscanf(in,"%d:%d",&hours,&minutes);
    return hours*60 + minutes;
}

bool busy[30 * 24 * 60 + 5];
int nex[30 * 24 * 60 + 5];

int jump[1440 + 5][MAXN+5];

int best[30*24*60+5][MAXN+5];
bool choose[30*24*60+5][MAXN+5];
bool flag[30*24*60+5][MAXN+5];

int solve(int day,int ind)
{
    if (day >= k * 1440)
        return -oops;
    if (ind == n)
    return 0;

    int &ret = best[day][ind];

    if (flag[day][ind])
        return ret;

    ret = solve(day,ind+1);

    choose[day][ind]=0;

    if (~job[ind].subject_id && day + jump[day%1440][job[ind].subject_id] <= job[ind].deadline)
    {
        int temp = job[ind].profit + solve(day+jump[day%1440][job[ind].subject_id],ind+1);

        if (temp > ret)
        {
            ret = temp;
            choose[day][ind]=1;
        }
    }
    flag[day][ind]=1;
    return ret;
}

int main()
{
    FILE *in=stdin;
    int c,c2;
    fscanf(in,"%d%d%d",&m,&n,&k);
    for (c=0;c<m;c++)
    {
        fscanf(in,"%s",tempo);
        mp[subject[c].name=tempo]=c;
    }
    for (c=0;c<m;c++)
        fscanf(in,"%d",&subject[c].time);

    for (c=0;c<4;c++){
        from[c]=scanTime(in);
        fscanf(in,"-");
        to[c]=scanTime(in);
    }
    char st[40];
    for (c=0;c<n;c++)
    {
        fscanf(in,"%s",st);

        map<string,int>::iterator it = mp.find(st);
        job[c].input_id = c+1;
        job[c].subject_id = -1;
        if (it!=mp.end())
            job[c].subject_id = it->second;
        int day;
        fscanf(in,"%d",&day);

        job[c].deadline = (day-1)*1440 + scanTime(in);
        fscanf(in,"%d",&job[c].profit);
    }
    sort(job,job+n);

    int c3;

    for (c=0;c<k;c++)
        for (c2=0;c2<4;c2++)
            for (c3=from[c2];c3<=to[c2];c3++)
                busy[c*1440 + c3]=1;
    int farfree = k*1440;
    int nearfree = k*1440;
    for (int day=k*1440-1;day>=0;day--)
    {
        if (busy[day])
        {
            nex[day] = nearfree;
            farfree = -1;
        }
        else
        {
            farfree=max(farfree,day);
            nearfree = day;
            nex[day] = farfree;
        }
    }

    for (c=0;c<k*1440;c++)
        if (!busy[c])
            break;

    if (c == k*1440){
        printf("0\n0\n");
        return 0;
    }

    for (c=0;c<1440;c++)
        for (c2=0;c2<m;c2++)
        {
            int total = subject[c2].time;
            int now = c;
            while(now<k*1440 && total)
            {
                if (busy[now])now = nex[now];
                else
                {
                    int alpha = min(total,nex[now]-now+1);
                    now+=alpha;
                    total-=alpha;
                }
            }
            if (total)
                jump[c][c2]=oops;
            else jump[c][c2] = now - c;
        }

    int ret = solve(0,0);
    printf("%d\n",ret);
    int jobs=0;
    int day = 0;
    int ind = 0;

    for (ind=0;ind<n;ind++)
    {
        if (choose[day][ind])
        {
            day+=jump[day%1440][job[ind].subject_id];
            jobs++;
        }
    }
    printf("%d\n",jobs);
    for (day=0,ind=0;ind<n;ind++)
    {
        if (choose[day][ind])
        {
            int start = day;

            int ending = day + jump[day%1440][job[ind].subject_id] - 1;

            if (busy[start])

                start = nex[start];
            printf("%d %d %.2d:%.2d %d %.2d:%.2d\n",job[ind].input_id,start/1440 + 1,start%1440/60,start%1440%60,ending/1440+1,ending%1440/60,ending%1440%60);
            day = ending+1;
        }
    }

}


#include <bits/stdc++.h>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define   mt         make_tuple
#define    clr(v,d)      memset( v, d ,sizeof(v))
#define   angle(n)      atan2((n.imag()),(n.real()))
#define   vec(a,b)       ((b)-(a))
#define   length(a)      hypot( (a.imag()),(a.real()) )
#define   normalize(a)      (a)/(length(a))
#define    dp(a,b)          (((conj(a))*(b)).real())
#define    cp(a,b)          (((conj(a))*(b)).imag())
#define    lengthsqrt(a)       dp(a,a)
#define    rotate0( a,ang)    ((a)*exp( point(0,ang) ))
#define    rotateA(about,p,ang)   (rotate0(vec(about,p),ang)+about)
#define    lcm(a,b)                ((a*b)/(__gcd(a,b)))
#define    reflection0(m,v)         (conj((v)/(m))*(m))
#define     reflectionA(m,v,p0)     (conj( (vec(p0,v))/(vec(p0,m)) ) * (vec(p0,m)) ) + p0
#define     same(p1,p2)               ( dp(  vec(p1,p2),vec(p1,p2)) < eps )
#define     point                    complex<double>
typedef  long long     ll ;
typedef  unsigned long long ull;
const double eps= (1e-10);
using namespace std;
int dcmp(double a,double b){   return fabs(a-b)<=eps ? 0: (a>b)? 1:-1  ;}
ll getBit(ll num, int idx) {return ((num >> idx) & 1ll) == 1ll;}
ll setBit1(ll num, int idx) {return num | (1ll<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}
int countNumBit1(ll mask) {int ret=0; while (mask) 	{mask &= (mask-1ll);++ret;	}return ret;}

const int MAXN = 100;
const int oops = 1<<25;

class Subject
{
    public:
        string name;
        int time;
}subject[MAXN+5];

class Job
{
    public:
        int input_id,subject_id;
        int profit,deadline;
    bool operator < (const Job &with) const
    {
        if (deadline != with.deadline)return deadline < with.deadline;
        return input_id < with.input_id;
    }
}job[MAXN+5];

char tempo[40];
map<string,int>mp;
int m,n,k;

int from[10],to[10];

int scanTime(FILE *in)
{
    int hours,minutes;
    fscanf(in,"%d:%d",&hours,&minutes);
    return hours*60 + minutes;
}

bool busy[30 * 24 * 60 + 5];
int nex[30 * 24 * 60 + 5];

int jump[1440 + 5][MAXN+5];

int best[30*24*60+5][MAXN+5];
bool choose[30*24*60+5][MAXN+5];
bool flag[30*24*60+5][MAXN+5];

int solve(int day,int ind)
{
    if (day >= k * 1440)
        return -oops;
    if (ind == n)
    return 0;

    int &ret = best[day][ind];

    if (flag[day][ind])
        return ret;

    ret = solve(day,ind+1);

    choose[day][ind]=0;

    if (~job[ind].subject_id && day + jump[day%1440][job[ind].subject_id] <= job[ind].deadline)
    {
        int temp = job[ind].profit + solve(day+jump[day%1440][job[ind].subject_id],ind+1);

        if (temp > ret)
        {
            ret = temp;
            choose[day][ind]=1;
        }
    }
    flag[day][ind]=1;
    return ret;
}

int main()
{
    FILE *in=stdin;
    int c,c2;
    fscanf(in,"%d%d%d",&m,&n,&k);
    for (c=0;c<m;c++)
    {
        fscanf(in,"%s",tempo);
        mp[subject[c].name=tempo]=c;
    }
    for (c=0;c<m;c++)
        fscanf(in,"%d",&subject[c].time);

    for (c=0;c<4;c++){
        from[c]=scanTime(in);
        fscanf(in,"-");
        to[c]=scanTime(in);
    }
    string st;
    for (c=0;c<n;c++)
    {
        fscanf(in,"%s",st);

        map<string,int>::iterator it = mp.find(st);
        job[c].input_id = c+1;
        job[c].subject_id = -1;
        if (it!=mp.end())
            job[c].subject_id = it->second;
        int day;
        fscanf(in,"%d",&day);

        job[c].deadline = (day-1)*1440 + scanTime(in);
        fscanf(in,"%d",&job[c].profit);
    }
    sort(job,job+n);

    int c3;

    for (c=0;c<k;c++)
        for (c2=0;c2<4;c2++)
            for (c3=from[c2];c3<=to[c2];c3++)
                busy[c*1440 + c3]=1;
    int farfree = k*1440;
    int nearfree = k*1440;
    for (int day=k*1440-1;day>=0;day--)
    {
        if (busy[day])
        {
            nex[day] = nearfree;
            farfree = -1;
        }
        else
        {
            farfree=max(farfree,day);
            nearfree = day;
            nex[day] = farfree;
        }
    }

    for (c=0;c<k*1440;c++)
        if (!busy[c])
            break;

    if (c == k*1440){
        printf("0\n0\n");
        return 0;
    }

    for (c=0;c<1440;c++)
        for (c2=0;c2<m;c2++)
        {
            int total = subject[c2].time;
            int now = c;
            while(now<k*1440 && total)
            {
                if (busy[now])now = nex[now];
                else
                {
                    int alpha = min(total,nex[now]-now+1);
                    now+=alpha;
                    total-=alpha;
                }
            }
            if (total)
                jump[c][c2]=oops;
            else jump[c][c2] = now - c;
        }

    int ret = solve(0,0);
    printf("%d\n",ret);
    int jobs=0;
    int day = 0;
    int ind = 0;

    for (ind=0;ind<n;ind++)
    {
        if (choose[day][ind])
        {
            day+=jump[day%1440][job[ind].subject_id];
            jobs++;
        }
    }
    printf("%d\n",jobs);
    for (day=0,ind=0;ind<n;ind++)
    {
        if (choose[day][ind])
        {
            int start = day;

            int ending = day + jump[day%1440][job[ind].subject_id] - 1;

            if (busy[start])

                start = nex[start];
            printf("%d %d %.2d:%.2d %d %.2d:%.2d\n",job[ind].input_id,start/1440 + 1,start%1440/60,start%1440%60,ending/1440+1,ending%1440/60,ending%1440%60);
            day = ending+1;
        }
    }

}


#include <bits/stdc++.h>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define   mt         make_tuple
#define    clr(v,d)      memset( v, d ,sizeof(v))
#define   angle(n)      atan2((n.imag()),(n.real()))
#define   vec(a,b)       ((b)-(a))
#define   length(a)      hypot( (a.imag()),(a.real()) )
#define   normalize(a)      (a)/(length(a))
#define    dp(a,b)          (((conj(a))*(b)).real())
#define    cp(a,b)          (((conj(a))*(b)).imag())
#define    lengthsqrt(a)       dp(a,a)
#define    rotate0( a,ang)    ((a)*exp( point(0,ang) ))
#define    rotateA(about,p,ang)   (rotate0(vec(about,p),ang)+about)
#define    lcm(a,b)                ((a*b)/(__gcd(a,b)))
#define    reflection0(m,v)         (conj((v)/(m))*(m))
#define     reflectionA(m,v,p0)     (conj( (vec(p0,v))/(vec(p0,m)) ) * (vec(p0,m)) ) + p0
#define     same(p1,p2)               ( dp(  vec(p1,p2),vec(p1,p2)) < eps )
#define     point                    complex<double>
typedef  long long     ll ;
typedef  unsigned long long ull;
const double eps= (1e-10);
using namespace std;
int dcmp(double a,double b){   return fabs(a-b)<=eps ? 0: (a>b)? 1:-1  ;}
ll getBit(ll num, int idx) {return ((num >> idx) & 1ll) == 1ll;}
ll setBit1(ll num, int idx) {return num | (1ll<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}
int countNumBit1(ll mask) {int ret=0; while (mask) 	{mask &= (mask-1ll);++ret;	}return ret;}
map<string,int> mb;
int v[101],mem[24][60][31][101],arr[25][61];
int n,m,k,N,arr2[31][25][61];
vector< pair< int ,pair<int ,pair<int ,pair<int,pair<int,int> > > > > > v1;
vector< pair<int,pair<pair<int,int>,int>> > f;
 pair<int,pair<int,pair<int,int> > > nxt[24][60][31][101];
typedef struct {int id,d1,h1,m1,d2,h2,m2;} er;

er print[24][60][31][101];
int solve(int hr,int mn,int dy,int id)
{

    if(id==N)
        return 0;

    int &ret=mem[hr][mn][dy][id];

    if(ret!=-1)
        return ret;

    int p1=0,p2=0;

    int nhr,nmn,ndy,fl=1;

    int sub= v1[id].second.second.second.second.first;
    int mydy=v1[id].first;
    int myhr=v1[id].second.first;
    int mymn=v1[id].second.second.first;
    int myc=v1[id].second.second.second.first;
    int orid=v1[id].second.second.second.second.second;

    int freee= arr2[dy][hr][mn];
    int val=freee+v[sub];
    pair<int,pair<pair<int,int>,int>> pp;
    pp.first=val;
    pp.second.first.first=-1;
    pp.second.first.second=0;
    pp.second.second=0;
    auto it=lower_bound(all(f),pp);

    pair< int,pair<int,int>> op,op2;
    if(it==f.end())
        fl=0;
    else
    {
        int idx= it-f.begin();
        nhr=f[idx].second.first.first;
        nmn=f[idx].second.first.second;
        ndy=f[idx].second.second;

        if(nmn==0)
        {
            op.second.first=nhr-1;
            op.second.second=59;
        }
        else
        {
            op.second.first=nhr;
            op.second.second=nmn-1;
        }

        op.first=ndy;
        op2.first=mydy;
        op2.second.first=myhr;
        op2.second.second=mymn;
         if(op2<=op)
            fl=0;

    }
    if(fl)
    {

        p2=myc+ solve(nhr,nmn,ndy,id+1);
    }

    p1=solve(hr,mn,dy,id+1);

    if(p2>p1)
    {
        er u ;
        u.id=orid; u.d1=dy; u.h1=hr; u.m1=mn;    u.d2=op.first; u.h2=op.second.first; u.m2=op.second.second;
        print[hr][mn][dy][id]=u;
        nxt[hr][mn][dy][id]=mp(nhr,mp(nmn,mp(ndy,id+1)));
    }
    else
    {
        er u;
        u.id=-1; u.d1=-1; u.h1=-1; u.m1=-1; u.d2=-1; u.h2=-1; u.m2=-1;
        print[hr][mn][dy][id]=u;
        nxt[hr][mn][dy][id]=mp(hr,mp(mn,mp(dy,id+1)));
    }

    ret=max(p1,p2);

    return ret;
}

int main()
{
    cin>>m>>n>>k;

    string st;
    int id=1;

    for(int i=0;i<m;i++)
    {
        cin>>st;
        mb[st]=id++;
    }

    for(int i=1;i<=m;i++)
    {
        cin>>v[i];
    }

    int fl=0;
    string str;
    pair<int,int> slp,gup;
    for(int i=0;i<4;i++)
    {

       cin>>str;

       int frh=atoi(str.substr(0,2).c_str());
       int frm=atoi(str.substr(3,2).c_str());
       int th=atoi(str.substr(6,2).c_str());
       int tm=atoi(str.substr(9,2).c_str());
       if(frh==0)
        frh=24;
       if(th==0)
        th=24;

       if(!fl)
       {
           slp.first=frh;
           slp.second=frm;
           gup.first=th;
           gup.second=tm;
           fl=1;
       }

       for(int j=frh;j<=th;j++)
       {
           int sst=0,en=59;

           if(j==frh)
            sst=frm;

           if(j==th)
            en=tm;

           for(int l=sst;l<=en;l++)
           {
               arr[j][l]=1;
           }
       }
    }

    int cnt=0;
    pair<int,int> start;

    if(gup.second==59)
    {
        start.first=gup.first+1;
        start.second=0;
    }
    else
    {
        start.first=gup.first;
        start.second=gup.second+1;
    }

    for(int d=1;d<=k;d++)
    {

    for(int i=start.first;i<=slp.first;i++)
    {
        int sst=0,en=59;

        if(i==start.first)
            sst=start.second;

        if(i==slp.first)
            en=slp.second;
      for(int j=sst;j<=en;j++)
      {

          f.pb(mp(cnt,mp(mp(i,j),d)));
          arr2[d][i][j]=cnt;

          if(!arr[i][j])
            cnt++;

      }
    }
    }

    string tim,ste;
    int dy,cost;
    for(int i=0;i<n;i++)
    {

        cin>>ste>>dy>>tim>>cost;

        if(mb[ste]==0)
            continue;

        int hr=atoi(tim.substr(0,2).c_str());
        int mn=atoi(tim.substr(3,2).c_str());

        v1.pb(mp(dy,mp(hr,mp(mn,mp(cost,mp(mb[ste],i+1))))));

    }

    sort(all(v1));
    N=sz(v1);

    clr(mem,-1);

    cout<<solve(start.first,start.second,1,0)<<endl;

    int hr=start.first,mn=start.second;
    id=0;
    dy=1;

     cnt=0;
    stringstream ss;

    while(id<N)
    {
        int thr,tmn,tdy,tid;
        thr=hr; tdy=dy; tmn=mn; tid=id;
       if( print[hr][mn][dy][id].id==-1)
       {
           ;

       }
       else
       {
           int indx=print[hr][mn][dy][id].id;
           int d11=print[hr][mn][dy][id].d1;
           int d22=print[hr][mn][dy][id].d2;
           int hh1=print[hr][mn][dy][id].h1;
           int hh2=print[hr][mn][dy][id].h2;
           int mm1=print[hr][mn][dy][id].m1;
           int mm2=print[hr][mn][dy][id].m2;

            int nm=mm1,nh=hh1,nd=d11;

           while(arr[nh][nm])
           {
               if(nh==slp.first&&nm==slp.second)
                nd+=1;

               if(nm==59)
                nm=0,nh+=1;
                else
                    nm+=1;

               if(nh==slp.first&&nm==slp.second)
                nd+=1;

           }

           hh1=nh;
           mm1=nm;
           d11=nd;

           string sh1="",sh2="",sm1="",sm2="";
           if(hh1<10)
           {
               sh1+='0';
               sh1+=hh1+'0';
           }
           else
           {
               sh1+=(hh1/10)+'0';
               sh1+=(hh1%10)+'0';
           }

            if(hh2<10)
           {
               sh2+='0';
               sh2+=hh2+'0';
           }
           else
           {
               sh2+=(hh2/10)+'0';
               sh2+=(hh2%10)+'0';
           }
            if(mm1<10)
           {
               sm1+='0';
               sm1+=mm1+'0';
           }
           else
           {
               sm1+=(mm1/10)+'0';
               sm1+=(mm1%10)+'0';
           }
            if(mm2<10)
           {
               sm2+='0';
               sm2+=mm2+'0';
           }
           else
           {
               sm2+=(mm2/10)+'0';
               sm2+=(mm2%10)+'0';
           }

           ss<<indx<<" "<<d11<<" "<<sh1<<":"<<sm1<<" "<<d22<<" "<<sh2<<":"<<sm2<<endl;
           cnt++;
       }

           hr=nxt[thr][tmn][tdy][tid].first;
           mn=nxt[thr][tmn][tdy][tid].second.first;
           dy=nxt[thr][tmn][tdy][tid].second.second.first;
           id=nxt[thr][tmn][tdy][tid].second.second.second;

    }
        cout<<cnt<<endl<<ss.str();
}


#include <bits/stdc++.h>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define   mt         make_tuple
#define    clr(v,d)      memset( v, d ,sizeof(v))
#define   angle(n)      atan2((n.imag()),(n.real()))
#define   vec(a,b)       ((b)-(a))
#define   length(a)      hypot( (a.imag()),(a.real()) )
#define   normalize(a)      (a)/(length(a))
#define    dp(a,b)          (((conj(a))*(b)).real())
#define    cp(a,b)          (((conj(a))*(b)).imag())
#define    lengthsqrt(a)       dp(a,a)
#define    rotate0( a,ang)    ((a)*exp( point(0,ang) ))
#define    rotateA(about,p,ang)   (rotate0(vec(about,p),ang)+about)
#define    lcm(a,b)                ((a*b)/(__gcd(a,b)))
#define    reflection0(m,v)         (conj((v)/(m))*(m))
#define     reflectionA(m,v,p0)     (conj( (vec(p0,v))/(vec(p0,m)) ) * (vec(p0,m)) ) + p0
#define     same(p1,p2)               ( dp(  vec(p1,p2),vec(p1,p2)) < eps )
#define     point                    complex<double>
typedef  long long     ll ;
typedef  unsigned long long ull;
const double eps= (1e-10);
using namespace std;
int dcmp(double a,double b){   return fabs(a-b)<=eps ? 0: (a>b)? 1:-1  ;}
ll getBit(ll num, int idx) {return ((num >> idx) & 1ll) == 1ll;}
ll setBit1(ll num, int idx) {return num | (1ll<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}
int countNumBit1(ll mask) {int ret=0; while (mask) 	{mask &= (mask-1ll);++ret;	}return ret;}
map<string,int> mb;
int v[109],mem[24][60][39][109],arr[109][109];
int n,m,k,N,arr2[32][69][69];
vector< pair< int ,pair<int ,pair<int ,pair<int,pair<int,int> > > > > > v1;
vector< pair<int,pair<pair<int,int>,int>> > f;
 pair<int,pair<int,pair<int,int> > > nxt[24][60][39][109];
typedef struct {int id,d1,h1,m1,d2,h2,m2;} er;

er print[24][60][39][109];
int solve(int hr,int mn,int dy,int id)
{

    if(id==N)
        return 0;

    int &ret=mem[hr][mn][dy][id];

    if(ret!=-1)
        return ret;

    int p1=0,p2=0;

    int nhr,nmn,ndy,fl=1;

    int sub= v1[id].second.second.second.second.first;
    int mydy=v1[id].first;
    int myhr=v1[id].second.first;
    int mymn=v1[id].second.second.first;
    int myc=v1[id].second.second.second.first;
    int orid=v1[id].second.second.second.second.second;

    int freee= arr2[dy][hr][mn];
    int val=freee+v[sub];
    pair<int,pair<pair<int,int>,int>> pp;
    pp.first=val;
    pp.second.first.first=-1;
    pp.second.first.second=0;
    pp.second.second=0;
    auto it=lower_bound(all(f),pp);

    pair< int,pair<int,int>> op,op2;
    if(it==f.end())
        fl=0;
    else
    {
        int idx= it-f.begin();
        nhr=f[idx].second.first.first;
        nmn=f[idx].second.first.second;
        ndy=f[idx].second.second;

        if(nmn==0)
        {
            op.second.first=nhr-1;
            op.second.second=59;
        }
        else
        {
            op.second.first=nhr;
            op.second.second=nmn-1;
        }

        op.first=ndy;
        op2.first=mydy;
        op2.second.first=myhr;
        op2.second.second=mymn;
         if(op2<=op)
            fl=0;

    }
    if(fl)
    {

        p2=myc+ solve(nhr,nmn,ndy,id+1);
    }

    p1=solve(hr,mn,dy,id+1);

    if(p2>p1)
    {
        er u ;
        u.id=orid; u.d1=dy; u.h1=hr; u.m1=mn;    u.d2=op.first; u.h2=op.second.first; u.m2=op.second.second;
        print[hr][mn][dy][id]=u;
        nxt[hr][mn][dy][id]=mp(nhr,mp(nmn,mp(ndy,id+1)));
    }
    else
    {
        er u;
        u.id=-1; u.d1=-1; u.h1=-1; u.m1=-1; u.d2=-1; u.h2=-1; u.m2=-1;
        print[hr][mn][dy][id]=u;
        nxt[hr][mn][dy][id]=mp(hr,mp(mn,mp(dy,id+1)));
    }

    ret=max(p1,p2);

    return ret;
}

int main()
{
    cin>>m>>n>>k;

    string st;
    int id=1;

    for(int i=0;i<m;i++)
    {
        cin>>st;
        mb[st]=id++;
    }

    for(int i=1;i<=m;i++)
    {
        cin>>v[i];
    }

    int fl=0;
    string str;
    pair<int,int> slp,gup;
    for(int i=0;i<4;i++)
    {

       cin>>str;

       int frh=atoi(str.substr(0,2).c_str());
       int frm=atoi(str.substr(3,2).c_str());
       int th=atoi(str.substr(6,2).c_str());
       int tm=atoi(str.substr(9,2).c_str());
       if(frh==0)
        frh=24;
       if(th==0)
        th=24;

       if(!fl)
       {
           slp.first=frh;
           slp.second=frm;
           gup.first=th;
           gup.second=tm;
           fl=1;
       }

       for(int j=frh;j<=th;j++)
       {
           int sst=0,en=59;

           if(j==frh)
            sst=frm;

           if(j==th)
            en=tm;

           for(int l=sst;l<=en;l++)
           {
               arr[j][l]=1;
           }
       }
    }

    int cnt=0;
    pair<int,int> start;

    if(gup.second==59)
    {
        start.first=gup.first+1;
        start.second=0;
    }
    else
    {
        start.first=gup.first;
        start.second=gup.second+1;
    }

    for(int d=1;d<=k;d++)
    {

    for(int i=start.first;i<=slp.first;i++)
    {
        int sst=0,en=59;

        if(i==start.first)
            sst=start.second;

        if(i==slp.first)
            en=slp.second;
      for(int j=sst;j<=en;j++)
      {

          f.pb(mp(cnt,mp(mp(i,j),d)));
          arr2[d][i][j]=cnt;

          if(!arr[i][j])
            cnt++;

      }
    }
    }

    string tim,ste;
    int dy,cost;
    for(int i=0;i<n;i++)
    {

        cin>>ste>>dy>>tim>>cost;

        if(mb[ste]==0)
            continue;

        int hr=atoi(tim.substr(0,2).c_str());
        int mn=atoi(tim.substr(3,2).c_str());

        v1.pb(mp(dy,mp(hr,mp(mn,mp(cost,mp(mb[ste],i+1))))));

    }

    sort(all(v1));
    N=sz(v1);

    clr(mem,-1);

    cout<<solve(start.first,start.second,1,0)<<endl;

    int hr=start.first,mn=start.second;
    id=0;
    dy=1;

     cnt=0;
    stringstream ss;

    while(id<N)
    {
        int thr,tmn,tdy,tid;
        thr=hr; tdy=dy; tmn=mn; tid=id;
       if( print[hr][mn][dy][id].id==-1)
       {
           ;

       }
       else
       {
           int indx=print[hr][mn][dy][id].id;
           int d11=print[hr][mn][dy][id].d1;
           int d22=print[hr][mn][dy][id].d2;
           int hh1=print[hr][mn][dy][id].h1;
           int hh2=print[hr][mn][dy][id].h2;
           int mm1=print[hr][mn][dy][id].m1;
           int mm2=print[hr][mn][dy][id].m2;
           string sh1="",sh2="",sm1="",sm2="";
           if(hh1<10)
           {
               sh1+='0';
               sh1+=hh1+'0';
           }
           else
           {
               sh1+=(hh1/10)+'0';
               sh1+=(hh1%10)+'0';
           }

            if(hh2<10)
           {
               sh2+='0';
               sh2+=hh2+'0';
           }
           else
           {
               sh2+=(hh2/10)+'0';
               sh2+=(hh2%10)+'0';
           }
            if(mm1<10)
           {
               sm1+='0';
               sm1+=mm1+'0';
           }
           else
           {
               sm1+=(mm1/10)+'0';
               sm1+=(mm1%10)+'0';
           }
            if(mm2<10)
           {
               sm2+='0';
               sm2+=mm2+'0';
           }
           else
           {
               sm2+=(mm2/10)+'0';
               sm2+=(mm2%10)+'0';
           }

           ss<<indx<<" "<<d11<<" "<<sh1<<":"<<sm1<<" "<<d22<<" "<<sh2<<":"<<sm2<<endl;
           cnt++;
       }

           hr=nxt[thr][tmn][tdy][tid].first;
           mn=nxt[thr][tmn][tdy][tid].second.first;
           dy=nxt[thr][tmn][tdy][tid].second.second.first;
           id=nxt[thr][tmn][tdy][tid].second.second.second;

    }
        cout<<cnt<<endl<<ss.str();
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.*;

public class whatIsForDinner {
	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

	public static void main(String[] args) {
		FastReader sc = new FastReader();
		int n=sc.nextInt();
		int m=sc.nextInt();
		int k=sc.nextInt();
		HashMap<Integer,Integer> h=new HashMap<Integer,Integer>();
		ArrayList<Integer> l=new ArrayList<Integer>();
		while(n-->0)
		{
			int r=sc.nextInt();
			int c=sc.nextInt();
			if(!l.contains(r))
			{
				l.add(r);
			}

			if(!h.containsKey(r))
			{
				h.put(r,c);
			}
			else
			{
				h.put(r,Math.max(h.get(r),c));
			}
		}
		long sum=0;
		for(int i=0;i<l.size();i++)
		{
			sum=sum+h.get(l.get(i));
		}
		System.out.println(Math.min(k,sum));
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.*;

public class whatIsForDinner {
	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

	public static void main(String[] args) {
		FastReader sc = new FastReader();
		int n=sc.nextInt();
		int m=sc.nextInt();
		int k=sc.nextInt();
		HashMap<Integer,Integer> h=new HashMap<Integer,Integer>();
		ArrayList<Integer> l=new ArrayList<Integer>();
		while(n-->0)
		{
			int r=sc.nextInt();
			int c=sc.nextInt();
			if(!l.contains(r))
			{
				l.add(r);
			}

			if(!h.containsKey(r))
			{
				h.put(r,c);
			}
		}
		long sum=0;
		for(int i=0;i<l.size();i++)
		{
			sum=sum+h.get(l.get(i));
		}
		System.out.println(Math.min(k,sum));
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.*;

public class whatIsForDinner {
	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

	public static void main(String[] args) {
		FastReader sc = new FastReader();
		int n=sc.nextInt();
		int m=sc.nextInt();
		int k=sc.nextInt();
		HashMap<Integer,Integer> h=new HashMap<Integer,Integer>();
		ArrayList<Integer> l=new ArrayList<Integer>();
		while(n-->0)
		{
			int r=sc.nextInt();
			int c=sc.nextInt();
			if(!l.contains(r))
			{
				l.add(r);
			}

			if(!h.containsKey(r))
			{
				h.put(r,c);
			}
			else
			{
				h.put(r,Math.min(h.get(r),c));
			}
		}
		long sum=0;
		for(int i=0;i<l.size();i++)
		{
			sum=sum+h.get(l.get(i));
		}
		System.out.println(Math.min(k,sum));
	}
}


//package pkg33a;
import static java.lang.Math.min;
import java.util.*;
public class Main
{
    public static void main(String[] args)
    {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt(),m=sc.nextInt(),k=sc.nextInt();
        int array[]=new int[m+1];
        Arrays.fill(array,1000000);
        array[0]=0;
        for(int i=0;i<n;i++)
        {
            int r=sc.nextInt();
            int c=sc.nextInt();
            array[r]=min(array[r],c);
        }
        int sum=0;
        for(int i:array)
        {
            sum=sum + i;
        }
        System.out.println(min(sum,k));
    }

}


import java.util.*;
// Funny name
public class WhatIsForDinner {

    static int[][] t = null;
    static int[] i = null;

    static void solve(){
        Scanner sc = new Scanner(System.in);
        int c=sc.nextInt(), r=sc.nextInt(), n=sc.nextInt(), NOC=c, R=r, m=1000001, ans=0;
        t = new int[r][c];
        i = new int[r];
        while(--R>=0) Arrays.fill(t[R],m);
        while(NOC-->0){
            int index = sc.nextInt()-1; int no = sc.nextInt();
            t[index][i[index]]=no; i[index]++;
        }
        R = r;
        // Greeeeedy
        while(--R>=0) Arrays.sort(t[R]);
        for(int a=0; a<r; a++){
            if((t[a][0]>0)&&(t[a][0]!=m)) {
                ans+=(t[a][0]>n) ? n : t[a][0];
                n-=(t[a][0]>n) ? n : t[a][0];
                if(n<=0) break;
            }
        }
        System.out.println(ans);
        sc.close();
    }

    public static void main(String args[]) {
        solve();
    }
}


import java.util.*;

public class ExtraordinaryDice {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int k = sc.nextInt();

        int[][] arr = new int[n][2];

        for(int i=0; i<arr.length; i++) {
            arr[i][0] = sc.nextInt();
            arr[i][1] = sc.nextInt();
        }

        int[] min = new int[m+1];
        for(int i=0; i<min.length; i++) {
            min[i] = Integer.MAX_VALUE;
        }
        for(int i=1; i<=m; i++) {
            for(int j=0; j<arr.length; i++) {
                if( i == arr[j][0]) {
                    min[i] = Math.min(min[i], arr[j][1]);
                }
            }
        }

        int sum = 0;
        for(int i=1; i<min.length; i++) {
            sum += min[i];
        }
        System.out.println(Math.min(sum, k));

    }
}


import java.util.*;

public class ExtraordinaryDice {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int k = sc.nextInt();

        int[][] arr = new int[n][2];

        for(int i=0; i<arr.length; i++) {
            arr[i][0] = sc.nextInt();
            arr[i][1] = sc.nextInt();
        }

        int[] min = new int[m+1];
        for(int i=0; i<min.length; i++) {
            min[i] = Integer.MAX_VALUE;
        }

        for(int i=1; i<min.length; i++) {
            for(int j=0; j<arr.length; j++) {
                if( i == arr[j][0]) {
                    min[i] = Math.min(min[i], arr[j][1]);
                }
            }
        }

        int sum = 0;
        for(int i=1; i<min.length; i++) {
            sum += min[i];
        }
        System.out.println(Math.min(sum, k));
    }
}


#include <bits/stdc++.h>
using namespace std;

int n, m, k;
vector<int> ans;
int arr[1000006];

int main() {
	cin >> n >> m >> k;
	for (int i = 1; i <= n + m; i++) {
		if (!arr[i + 1]) {
			ans.push_back(i);
			for (int j = i; j < i + n; j++) arr[j]++;
		}
		while (arr[i] < k) {
			ans.push_back(i);
			for (int j = i; j < i + n; j++) arr[j]++;
		}
	}
	cout << ans.size() << endl;
	for (int i = 0; i < ans.size(); i++) cout << ans[i] << " ";
	cout << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n, m, k, least;
    cin >> n >> m >> k;
    vector <int> r;
    least = n + m;
    for (int i(1); i < least; ) {
        for (int j(0); j < k; j++)
            r.push_back(i);
        i += n - 1;
    }
    cout << r.size() << '\n';
    for (auto i : r)
        cout << i << ' ';

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n, m, k, least;
    cin >> n >> m >> k;
    vector <int> r;
    least = n + m;
    if (k == 1) {
        for (int i(1); i < least; ) {
            for (int j(0); j < k; j++)
                r.push_back(i);
            i += n - 1;
        }
    }
    else {
        for (int i(1); i < least; ) {
            for (int j(1); j < k + (i == 1); j++)
                r.push_back(i);
            if (i != 1)
                r.push_back(i + 1);
            i += n - 1;
        }
    }
    cout << r.size() << '\n';
    for (auto i : r)
        cout << i << ' ';

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int pleaca[100010];

int main()
{
    int n, m, k, least;
    cin >> n >> m >> k;
    vector <int> r;
    least = n + m + 1;

    int nract(0);
    for (int i(1); i < least; i++) {
        nract -= pleaca[i];
        while (nract < k) {
            nract++;
            r.push_back(i);
            pleaca[i + n]++;
        }
        if (pleaca[i + 1] == nract) {
            nract++;
            r.push_back(i);
            pleaca[i + n]++;
        }
    }
    cout << r.size() << '\n';
    for (auto i : r)
        cout << i << ' ';

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
  int n, m, k;
  scanf("%d %d %d", &n, &m, &k);
  queue<int> in, out;
  vector<int> ans;
  for(int t = 1; t < 1000000; ++t) {
    while(in.size() > 0 && in.front() == t) {
      out.push(t + n);
      in.pop();
    }
    int add = max(0, k - (int)out.size());
    for(int i = 0; i < add; ++i) {
      out.push(t + n);
      ans.push_back(t);
    }
    while(out.size() > 0 && out.front() == t + 1) {
      in.push(t + m + 1);
      out.pop();
    }
    if(out.empty()) {
      out.push(t + n);
      ans.push_back(t);
    }
  }
  n = ans.size();
  printf("%d\n", n);
  for(int i = 0; i < n; ++i) {
    printf("%d%c", ans[i], " \n"[i == n - 1]);
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
  int n, m, k;
  scanf("%d %d %d", &n, &m, &k);
  queue<int> in, out;
  vector<int> ans;
  for(int t = 1; t < 10000; ++t) {
    while(in.size() > 0 && in.front() == t) {
      out.push(t + n);
      in.pop();
    }
    int add = max(0, k - (int)out.size());
    for(int i = 0; i < add; ++i) {
      out.push(t + n);
      ans.push_back(t);
    }
    while(out.size() > 0 && out.front() == t + 1) {
      in.push(t + m + 1);
      out.pop();
    }
    if(out.empty()) {
      out.push(t + n);
      ans.push_back(t);
    }
  }
  n = ans.size();
  printf("%d\n", n);
  for(int i = 0; i < n; ++i) {
    printf("%d%c", ans[i], " \n"[i == n - 1]);
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
  int n, m, k;
  scanf("%d %d %d", &n, &m, &k);
  queue<int> in, out;
  vector<int> ans;
  for(int t = 1; t < 1000000; ++t) {
    while(in.size() > 0 && in.front() == t) {
      out.push(t + n - 1);
      in.pop();
    }
    while(out.size() > 0 && out.front() == t) {
      in.push(t + m);
      out.pop();
    }
    int add = max(0, k - (int)out.size());
    for(int i = 0; i < add; ++i) {
      out.push(t + n - 1);
      ans.push_back(t);
    }
  }
  n = ans.size();
  printf("%d\n", n);
  for(int i = 0; i < n; ++i) {
    printf("%d%c", ans[i], " \n"[i == n - 1]);
  }
  return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define si(x) scanf("%d",&x)
#define sc(ch) scanf(" %c",&ch);
#define sl(x) scanf("%I64d",&x)
#define pi(x) printf("%d ",x)
#define nl cout << '\n'
#define mp make_pair
#define pb push_back
#define f first
#define se second
#define pii pair<int,int>
#define RESET(a) memset(a,-1,sizeof(a))
#define CLEAR(a) memset(a,0,sizeof(a))
#define all(v)   v.begin(),v.end()
#define trv(it,v) for(it=v.begin();it!=v.end();it++)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define mod 1000000007
#define MIN INT_MIN
#define MAX INT_MAX
#define INF 10e8

int cnt[1005];
int main()
{
   std::ios::sync_with_stdio(false);
    //freopen("1.txt", "r", stdin);

    int n,m,k;
    cin >> n >> m >> k;
    vector<int> a;
    for(int i=1; i<=k; i++)
        a.pb(1);
    for(int i=1; i<=n; i++)
        cnt[i] = k;
    int i=n+1;
    while(i<=(n+m))
    {
        if(cnt[i] == 0){
            a.pb(i-1);
            for(int j=i; j < i+n-1; j++)
                cnt[j]++;
        }
        else if(cnt[i] < k){
            int y = k-cnt[i];
            while(cnt[i]!=k){
                cnt[i]++;
                a.pb(i);
            }
            for(int j=i+1;j < i+n;j++)
                cnt[j] += y;
        }
        else
            i++;
    }
    if(cnt[n+m+1]==0){
        a.pb(n+m);
    }
    cout << a.size();nl;
    for(auto x : a)
        cout << x << " ";

   return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define si(x) scanf("%d",&x)
#define sc(ch) scanf(" %c",&ch);
#define sl(x) scanf("%I64d",&x)
#define pi(x) printf("%d ",x)
#define nl cout << '\n'
#define mp make_pair
#define pb push_back
#define f first
#define se second
#define pii pair<int,int>
#define RESET(a) memset(a,-1,sizeof(a))
#define CLEAR(a) memset(a,0,sizeof(a))
#define all(v)   v.begin(),v.end()
#define trv(it,v) for(it=v.begin();it!=v.end();it++)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define mod 1000000007
#define MIN INT_MIN
#define MAX INT_MAX
#define INF 10e8

int cnt[100005];
int main()
{
   std::ios::sync_with_stdio(false);
   // freopen("1.txt", "r", stdin);

    int n,m,k;
    cin >> n >> m >> k;
    vector<int> a;
    for(int i=1; i<=k; i++)
        a.pb(1);
    for(int i=1; i<=n; i++)
        cnt[i] = k;
    int i=n+1;
    while(i<=(n+m))
    {
        if(cnt[i] == 0){
            a.pb(i-1);
            for(int j=i; j < i+n-1; j++)
                cnt[j]++;
        }
        else if(cnt[i] < k){
            int y = k-cnt[i];
            while(cnt[i]!=k){
                cnt[i]++;
                a.pb(i);
            }
            for(int j=i+1;j < i+n;j++)
                cnt[j] += y;
        }
        else
            i++;
    }
    if(cnt[n+m+1]==0){
        a.pb(n+m);
    }
    cout << a.size();nl;
    for(auto x : a)
        cout << x << " ";

   return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define si(x) scanf("%d",&x)
#define sc(ch) scanf(" %c",&ch);
#define sl(x) scanf("%I64d",&x)
#define pi(x) printf("%d ",x)
#define nl cout << '\n'
#define mp make_pair
#define pb push_back
#define f first
#define se second
#define pii pair<int,int>
#define RESET(a) memset(a,-1,sizeof(a))
#define CLEAR(a) memset(a,0,sizeof(a))
#define all(v)   v.begin(),v.end()
#define trv(it,v) for(it=v.begin();it!=v.end();it++)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define mod 1000000007
#define MIN INT_MIN
#define MAX INT_MAX
#define INF 10e8

int main()
{
   std::ios::sync_with_stdio(false);
    //freopen("1.txt", "r", stdin);

    int n,m,k;
    cin >> n >> m >> k;
    vector<int> a;
    for(int i=1; i<=k; i++)
        a.pb(1);

    int i=n;
    int en = n+m+1;
    while(i<en){
        if(i == en-1)
        {
            if(k == 1)
                a.pb(i);
            break;
        }
        a.pb(i);
        for(int j=2; j<=k; j++)
            a.pb(i+1);
        i += n-1;
    }
    cout << a.size();nl;
    for(auto x: a)
        cout << x <<" ";

   return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int MAXN=1005;
const int MOD=1000000007;
#define endl '\n'

int n, m, k;

void read()
{
    cin>>n>>m>>k;
}

vector<int> v;
void solve()
{
    for(int i=0; i<k; i++) v.push_back(1);

    int p=1;

//    for(int i=0; i<v.size(); i++) cout<<v[i]<<" ";
//    cout<<endl;

    p+=(n-1);

    while(p<n+m)
    {
        p+=n;
        v.push_back(n);
        for(int i=0; i<k-1; i++) v.push_back(n+1);
//        for(int i=0; i<v.size(); i++) cout<<v[i]<<" ";
//        cout<<endl;
    }

    if(p==n+m) v.push_back(n+m-1);

    cout<<v.size()<<endl;
    for(int i=0; i<v.size(); i++) cout<<v[i]<<" ";

    cout<<endl;

}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    read();
    solve();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
  int n,m,k;
  cin>>n>>m>>k;
  if(n-1>m)
    {
      cout<<2*k<<endl;
      for(int i=0;i<k;++i) cout<<"1 ";
      for(int i=0;i<k;++i) cout<<n<<" ";
      cout<<endl;
    }
  else if(n-1==m)
    {
      if(k!=1)
	{
	  cout<<2*k<<endl;
	  for(int i=0;i<k;++i) cout<<"1 ";
	  cout<<n<<" ";
	  for(int i=0;i<k-1;++i) cout<<n+1<<" ";
	  cout<<endl;
	}
      else
	{
	  cout<<2*k+1<<endl;
	  for(int i=0;i<k;++i) cout<<"1 ";
	  cout<<n<<" ";
	  for(int i=0;i<k;++i) cout<<n+1<<" ";
	  cout<<endl;
	}
    }
  else
    {
      if(n==2)
	{
	  if(k==1)
	    cout<<"4\n 1 2 3 4\n";
	  else
	    {
	      cout<<2*k+1<<endl;
	      for(int i=0;i<k;++i) cout<<"1 ";
	      cout<<n<<" ";
	      for(int i=0;i<k-1;++i) cout<<n+1<<" ";
	      cout<<n+2<<endl;
	    }
	  return 0;
	}
      cout<<2*k+1<<endl;
      for(int i=0;i<k;++i) cout<<"1 ";
      cout<<n<<" ";
      for(int i=0;i<k-1;++i) cout<<n+1<<" ";
      cout<<2*n-1<<endl;
    }
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int MAXN=1005;
const int MOD=1000000007;
#define endl '\n'

int n, m, k;

void read()
{
    cin>>n>>m>>k;
}

vector<int> v;
void solve()
{
//    cout<<n<<m<<k<<endl;
    int q=(n+m)/n, r=(n+m)%n;

    int otg=q*k+1;
    if(r!=0) otg++;

    cout<<otg<<endl;

    int p=0;
    cout<<1<<" ";
    for(int i=0; i<k-1; i++) cout<<1<<" ";
    p+=k;

    int ost=n;

    while(p<otg)
    {
        cout<<ost<<" ";
        p++;
        if(p==otg) break;
        for(int i=0; i<k-1; i++) cout<<ost+1<<" ";
        p=p+k-1;
        ost+=n-1;
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    read();
    solve();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int MAXN=1005;
const int MOD=1000000007;
#define endl '\n'

int n, m, k;

void read()
{
    cin>>n>>m>>k;
}

vector<int> v;
void solve()
{
    v.push_back(1);
    for(int i=0; i<k-1; i++) v.push_back(1);

    int ch=n;
//    cout<<ch<<endl;

    while(1)
    {
        if(ch+1>n+m&&k!=1) break;
        if(ch>n+m&&k==1) break;
        else if(ch==n+m&&k==1)
        {
            for(int i=0; i<k; i++) v.push_back(ch);
            break;
        }
/*        else if(ch==n+m-1&&k!=1)
        {
            v.push_back(ch);
            break;
        }
        */

        v.push_back(ch);
        for(int i=0; i<k-1; i++) v.push_back(ch+1);
        ch=ch+n-1;

//        cout<<ch<<endl;
    }

    cout<<v.size()<<endl;
    for(int i=0; i<v.size(); i++) cout<<v[i]<<" ";
    cout<<endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    read();
    solve();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int MAXN=1005;
const int MOD=1000000007;
#define endl '\n'

int n, m, k;

void read()
{
    cin>>n>>m>>k;
}

vector<int> v;
void solve()
{
    int q=(n+m)/n, r=(n+m)%n;

    int otg=q*k+1;
    if(r!=0) otg++;

    cout<<otg<<endl;

    int p=1;
    cout<<1<<" ";
    q--;

    while(q>=0)
    {
        for(int i=0; i<k-1; i++) cout<<p<<" ";
        cout<<p+n-1<<" ";
        p=p+n;
        q--;
    }

    if(r) cout<<n+m<<endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    read();
    solve();
    return 0;
}


using namespace std;

int main()
{
  int n,m,k;
  cin>>n>>m>>k;
  if(n-1>m)
    {
      cout<<2*k<<endl;
      for(int i=0;i<k;++i) cout<<"1 ";
      for(int i=0;i<k;++i) cout<<n<<" ";
      cout<<endl;
    }
  else if(n-1==m)
    {
      if(k!=1)
	{
	  cout<<2*k<<endl;
	  for(int i=0;i<k;++i) cout<<"1 ";
	  cout<<n<<" ";
	  for(int i=0;i<k-1;++i) cout<<n+1<<" ";
	  cout<<endl;
	}
      else
	{
	  cout<<2*k+1<<endl;
	  for(int i=0;i<k;++i) cout<<"1 ";
	  cout<<n<<" ";
	  for(int i=0;i<k;++i) cout<<n+1<<" ";
	  cout<<endl;
	}
    }
  else
    {
      if(n==2)
	{
	  if(k==1)
	    cout<<4<<endl<<"1 2 3 4"<<endl;
	  else
	    {
	      cout<<2*k+1<<endl;
	      for(int i=0;i<k;++i) cout<<"1 ";
	      cout<<n<<" ";
	      for(int i=0;i<k-1;++i) cout<<n+1<<" ";
	      cout<<n+2<<endl;
	    }
	  return 0;
	}
      cout<<2*k+1<<endl;
      for(int i=0;i<k;++i) cout<<"1 ";
      cout<<n<<" ";
      for(int i=0;i<k-1;++i) cout<<n+1<<" ";
      cout<<2*n-1<<endl;
    }
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int MAXN=1005;
const int MOD=1000000007;
#define endl '\n'

int n, m, k;

void read()
{
    cin>>n>>m>>k;
}

vector<int> v;
void solve()
{
    v.push_back(1);
    for(int i=0; i<k-1; i++) v.push_back(1);

    int ch=n;
//    cout<<ch<<endl;

    while(1)
    {
        if(ch+1>n+m&&k!=1) break;
        if(ch>n+m&&k==1) break;
        else if(ch==n+m&&k==1)
        {
            for(int i=0; i<k; i++) v.push_back(ch);
            break;
        }
        else if(ch==n+m-1&&k!=1)
        {
            v.push_back(ch);
            break;
        }

        v.push_back(ch);
        for(int i=0; i<k-1; i++) v.push_back(ch+1);
        ch=ch+n-1;

//        cout<<ch<<endl;
    }

    cout<<v.size()<<endl;
    for(int i=0; i<v.size(); i++) cout<<v[i]<<" ";
    cout<<endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    read();
    solve();
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
using namespace std;

typedef long long ll;
const int mod=1e9+7;
#define mem(s,v) memset(s,v,sizeof(s))
#define inf 0x3f3f3f3f
#define maxn 10010
#define pi (4*atan(1.0))
#define eps 1e-14

int a[maxn];

int main()
{
	int n,m,k;
	int num;
	while(~scanf("%d%d%d",&n,&m,&k)){
		num=k;
		for(int i=0;i<k;++i) a[i]=1;
		a[num]=n;
		num++;
		for(int i=1;i<k;++i){
			a[num]=n+1;
			num++;
		}
		int flag=0;
		while(a[num-1]+n-1<=a[0]+n+m-1){
			if(a[num-1]+n-1==a[0]+n+m-1){
				flag=1;break;
			}
			a[num]=a[num-1]+n-1;
			num++;
			for(int i=1;i<k;++i){
				a[num]=a[num]+1;
				num++;
			}
			//cout<<num<<endl;
		}
		if(flag) a[num]=a[num-1]+1,num++;
		cout<<num<<endl;
		cout<<a[0];
		for(int i=1;i<num;++i) cout<<" "<<a[i];
		cout<<endl;
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
using namespace std;

typedef long long ll;
const int mod=1e9+7;
#define mem(s,v) memset(s,v,sizeof(s))
#define inf 0x3f3f3f3f
#define maxn 10010
#define pi (4*atan(1.0))
#define eps 1e-14

int a[maxn];

int main()
{
	int n,m,k;
	int num;
	while(~scanf("%d%d%d",&n,&m,&k)){
		num=k;
		for(int i=0;i<k;++i) a[i]=1;
		a[num]=n;
		num++;
		for(int i=1;i<k;++i){
			a[num]=n+1;
			num++;
		}
		while(a[num-1]+n-1<a[0]+n+m-1){
			a[num]=a[num-1]+n-1;
			num++;
			for(int i=1;i<k;++i){
				a[num]=n+1;
				num++;
			}
			//cout<<num<<endl;
		}
		cout<<num<<endl;
		cout<<a[0];
		for(int i=1;i<num;++i) cout<<" "<<a[i];
		cout<<endl;
	}
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <assert.h>
#include <string.h>
using namespace std;

vector<int> out[2];

int main()
{
    //ios_base::sync_with_stdio(0);
    //cin.tie(0);
#ifndef ONLINE_JUDGE
#pragma warning (disable : 4996)
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif

    int n,m,k;
    cin>>n>>m>>k;

    int cnt=0;
    if(k==1)
    {
        for(int i=1; i <= n+m; i+=(n-1))
            out[0].push_back(i);
    }
    else
    {
        for(int i=1; i <= n+m; i+=n)
            out[0].push_back(i);

            out[1].push_back(out[0][0]);
            out[1].push_back(out[0][1]-1);

        if(out[0][out[0].size()-1]+n-1 == n+m)      //end day of last batch == n+m
        {
            for(int i=1; i < out[0].size(); i++)
            {
                cout<<out[0][i]<<" ";
                out[1].push_back(out[0][i]+1);
            }
            cout<<endl;
        }
        else
        {
            for(int i=2; i < out[0].size(); i++)
                out[1].push_back(out[0][i]+1);
        }
    }

    vector<int> Res;
    for(int i=0; i < k-(out[1].size()!=0); i++)
        for(int j=0; j < out[0].size(); j++)
            Res.push_back(out[0][j]);
    for(int i=0; i < out[1].size(); i++)
        Res.push_back(out[1][i]);

    sort(Res.begin(), Res.end());

    for(int i=0; i < Res.size(); i++)
        cout<<Res[i]<<" ";
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <assert.h>
#include <string.h>
using namespace std;

vector<int> out[2];

int main()
{
    //ios_base::sync_with_stdio(0);
    //cin.tie(0);
#ifndef ONLINE_JUDGE
#pragma warning (disable : 4996)
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif

    int n,m,k;
    cin>>n>>m>>k;

    int cnt=0;
    if(k==1)
    {
        for(int i=1; i <= n+m; i+=(n-1))
            out[0].push_back(i);
    }
    else
    {
        for(int i=1; i <= n+m; i+=n)
            out[0].push_back(i);

            out[1].push_back(out[0][0]);
            out[1].push_back(out[0][1]-1);

        if(out[0][out[0].size()-1]+n-1 == n+m)      //end day of last batch == n+m
        {
            for(int i=1; i < out[0].size(); i++)
            {
                //cout<<out[0][i]<<" ";
                out[1].push_back(out[0][i]+1);
            }
            //cout<<endl;
        }
        else
        {
            for(int i=2; i < out[0].size(); i++)
                out[1].push_back(out[0][i]+1);
        }
    }

    vector<int> Res;
    for(int i=0; i < k-(out[1].size()!=0); i++)
        for(int j=0; j < out[0].size(); j++)
            Res.push_back(out[0][j]);
    for(int i=0; i < out[1].size(); i++)
        Res.push_back(out[1][i]);

    sort(Res.begin(), Res.end());

    cout<<Res.size()<<endl;
    for(int i=0; i < Res.size(); i++)
        cout<<Res[i]<<" ";
}


#include <bits/stdc++.h>
#include <ext/hash_map>
using namespace std;
using namespace __gnu_cxx;

#define oo       1e9
#define ll       long long
#define sc(x)    scanf("%d",&x)
#define scl(x)   scanf("%lld",&x)
#define lop(i,n) for(int i=0;i<n;++i)
#define sz(x)    (int)x.size()
#define all(x)   x.begin(),x.end()
#define f        first
#define s        second

int n,m,k;
vector<int> ans;

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    sc(n),sc(m),sc(k);
    for(int i=0;i<k;i++)ans.push_back(1);
    ans.push_back(n);
    for(int i=1;i<k;i++)ans.push_back(n+1);
    if(n==m)ans.push_back(n+2);
    cout<<sz(ans)<<endl;
    for(int i=0;i<sz(ans);i++)
        cout<<ans[i]<<" ";
}


#include <bits/stdc++.h>
#include <ext/hash_map>
using namespace std;
using namespace __gnu_cxx;

#define oo       1e9
#define ll       long long
#define sc(x)    scanf("%d",&x)
#define scl(x)   scanf("%lld",&x)
#define lop(i,n) for(int i=0;i<n;++i)
#define sz(x)    (int)x.size()
#define all(x)   x.begin(),x.end()
#define f        first
#define s        second

int n,m,k;
vector<int> ans;

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    sc(n),sc(m),sc(k);
    for(int i=0;i<k;i++)ans.push_back(1);
    ans.push_back(n);
    for(int i=1;i<k;i++)ans.push_back(n+1);
    if(n+m>=ans.back()+n-1)ans.push_back(ans.back()+n-1);
    cout<<sz(ans)<<endl;
    for(int i=0;i<sz(ans);i++)
        cout<<ans[i]<<" ";
}


#include <bits/stdc++.h>
#include <ext/hash_map>
using namespace std;
using namespace __gnu_cxx;

#define oo       1e9
#define ll       long long
#define sc(x)    scanf("%d",&x)
#define scl(x)   scanf("%lld",&x)
#define lop(i,n) for(int i=0;i<n;++i)
#define sz(x)    (int)x.size()
#define all(x)   x.begin(),x.end()
#define f        first
#define s        second

int n,m,k;
vector<int> ans;

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    sc(n),sc(m),sc(k);
    for(int i=0;i<k;i++)ans.push_back(1);
    ans.push_back(n);
    for(int i=1;i<k;i++)ans.push_back(n+1);
    if(n+m>=ans.back()+n-1)ans.push_back(ans.back()+1);
    cout<<sz(ans)<<endl;
    for(int i=0;i<sz(ans);i++)
        cout<<ans[i]<<" ";
}


#include <bits/stdc++.h>
#include <ext/hash_map>
using namespace std;
using namespace __gnu_cxx;

#define oo       1e9
#define ll       long long
#define sc(x)    scanf("%d",&x)
#define scl(x)   scanf("%lld",&x)
#define lop(i,n) for(int i=0;i<n;++i)
#define sz(x)    (int)x.size()
#define all(x)   x.begin(),x.end()
#define f        first
#define s        second

int n,m,k;
vector<int> ans;

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    sc(n),sc(m),sc(k);
    for(int i=0;i<k;i++)ans.push_back(1);
    ans.push_back(n);
    for(int i=1;i<k;i++)ans.push_back(n+1);
    while(n+m>=ans.back()+n-1)ans.push_back(ans.back()+n-1);
    cout<<sz(ans)<<endl;
    for(int i=0;i<sz(ans);i++)
        cout<<ans[i]<<" ";
}


#include<bits/stdc++.h>
using namespace std;
vector<int> sol;
int main()
{
//	freopen("in.txt", "r", stdin);
//	freopen("out.txt", "w", stdout);
	int n, m, k;
	cin >> n >> m >> k;
	if (k == 1)
	{
		for (int i = 1; i <= n + m; i += n - 1)
			sol.push_back(i);

	}
	else
	{
		for (int i = 1; i <= n + m; i += n)
		{
			for (int j = 1; j < k; j++)
				sol.push_back(i);
		}
		sol.push_back(1);
		for (int i = n; i <= n + m; i += n)
			sol.push_back(i);
	}
	cout << sol.size()<<endl;
	for (int i = 0; i < n;i++)
	cout << sol[i] << " ";

}

//#include<bits/stdc++.h>
//using namespace std;
//#define mp make_pair
//#define oo (ll) 1e13
//#define f first
//#define ss second
//typedef long long ll;
//typedef pair<int, int> ii;
//ll dp[2100][4200];
//bool dp2[2100][4200];
//ii a[4000];
//int n;
//ll solve(int index, int time,ll money)
//{
//	if (index == n)
//	{
//		if (time < 2000)
//			return oo;
//		else
//			return money;
//	}
//	if (dp2[index][time])
//		return dp[index][time];
//
//
//	dp2[index][time] = 1;
//		ll op1 = solve(index + 1, min(time + a[index].f,4100), money + a[index].ss);
//		ll op2 = solve(index + 1, time - 1, money);
//		dp[index][time] = min(op1, op2);
//
//	return dp[index][time];
//
//}
//int main()
//{
//	freopen("in.txt", "r", stdin);
//	freopen("out.txt", "w", stdout);
//	//int n;
//	cin >> n;
//	memset(dp, -1, sizeof dp);
//	memset(dp2, false, sizeof dp2);
//	for (int i = 0; i < n; i++)
//	{
//		cin >> a[i].first >> a[i].second;
//
//	}
//
//	cout << solve(0,2000, 0);
//}


#include<bits/stdc++.h>
using namespace std;
vector<int> sol;
int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	int n, m, k;
	cin >> n >> m >> k;
	if (k == 1)
	{
		for (int i = 1; i <= n + m; i += n - 1)
			sol.push_back(i);

	}
	else
	{
		for (int i = 1; i <= n + m; i += n)
		{
			for (int j = 1; j < k; j++)
				sol.push_back(i);
		}
		sol.push_back(1);
		for (int i = n; i <= n + m; i += n)
			sol.push_back(i);
	}
	cout << sol.size()<<endl;
	for (int i = 0; i < sol.size();i++)
	cout << sol[i] << " ";

}

//#include<bits/stdc++.h>
//using namespace std;
//#define mp make_pair
//#define oo (ll) 1e13
//#define f first
//#define ss second
//typedef long long ll;
//typedef pair<int, int> ii;
//ll dp[2100][4200];
//bool dp2[2100][4200];
//ii a[4000];
//int n;
//ll solve(int index, int time,ll money)
//{
//	if (index == n)
//	{
//		if (time < 2000)
//			return oo;
//		else
//			return money;
//	}
//	if (dp2[index][time])
//		return dp[index][time];
//
//
//	dp2[index][time] = 1;
//		ll op1 = solve(index + 1, min(time + a[index].f,4100), money + a[index].ss);
//		ll op2 = solve(index + 1, time - 1, money);
//		dp[index][time] = min(op1, op2);
//
//	return dp[index][time];
//
//}
//int main()
//{
//	freopen("in.txt", "r", stdin);
//	freopen("out.txt", "w", stdout);
//	//int n;
//	cin >> n;
//	memset(dp, -1, sizeof dp);
//	memset(dp2, false, sizeof dp2);
//	for (int i = 0; i < n; i++)
//	{
//		cin >> a[i].first >> a[i].second;
//
//	}
//
//	cout << solve(0,2000, 0);
//}


#include <bits/stdc++.h>
#define LL long long
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
using namespace std;

int main() {
	int n,m,k,x;
	vector<int> vec;
	cin>>n>>m>>k;
	for(int i=0;i<k;i++) vec.pb(1);
	x=n;
	if(k==1){
		while(x<n+m){
			vec.pb(x);
			x+=n-1;
		}
	}
	else{
		while(x<=n+m){
			vec.pb(x);
			x++;
			for(int i=0;i<k-1;i++) vec.pb(x);
			x+=n-1;
		}
	}
	cout<<vec.size()<<endl;
	for(int i=0;i<vec.size();i++) cout<<vec[i]<<" ";
	return 0;
}


#include <bits/stdc++.h>
#define LL long long
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
using namespace std;

int main() {
	int n,m,k,x;
	vector<int> vec;
	cin>>n>>m>>k;
	for(int i=0;i<k;i++) vec.pb(1);
	x=n;
	if(k==1){
		while(x<=n+m){
			vec.pb(x);
			x+=n-1;
		}
	}
	else{
		while(x<=n+m){
			vec.pb(x);
			x++;
			if(x>n+m) break;
			for(int i=0;i<k-1;i++) vec.pb(x);
			x+=n-1;
		}
	}
	cout<<vec.size()<<endl;
	for(int i=0;i<vec.size();i++) cout<<vec[i]<<" ";
	return 0;
}


#include <bits/stdc++.h>
#define LL long long
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
using namespace std;

int main() {
	int n,m,k,x;
	vector<int> vec;
	cin>>n>>m>>k;
	for(int i=0;i<k;i++) vec.pb(1);
	x=n;
	if(k==1){
		while(x<n+m){
			vec.pb(x);
			x+=n-1;
		}
	}
	else{
		while(x<=n+m){
			vec.pb(x);
			x++;
			if(x>n+m) break;
			for(int i=0;i<k-1;i++) vec.pb(x);
			x+=n-1;
		}
	}
	cout<<vec.size()<<endl;
	for(int i=0;i<vec.size();i++) cout<<vec[i]<<" ";
	return 0;
}


#include <bits/stdc++.h>
#define LL long long
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
using namespace std;

int main() {
	int n,m,k,x;
	vector<int> vec;
	cin>>n>>m>>k;
	for(int i=0;i<k;i++) vec.pb(1);
	x=n;
	if(k==1){
		while(x<n+m){
			vec.pb(x);
			x+=n-1;
		}
	}
	else{
		while(x<n+m){
			vec.pb(x);
			x++;
			for(int i=0;i<k-1;i++) vec.pb(x);
			x+=n-1;
		}
	}
	cout<<vec.size()<<endl;
	for(int i=0;i<vec.size();i++) cout<<vec[i]<<" ";
	return 0;
}


//16:25
#include<iostream>
#include<cstdio>

using namespace std;
int n,m,k;
int a[2005];
int ans[2000005],cnt;
int main()
{
	scanf("%d%d%d",&n,&m,&k);
	int sum=0;
	for(int i=1;i<=k;++i) ans[i]=1;
	cnt=k;
	sum=k;
	a[n+1]+=k;

	for(int i=2;i<=n+m;++i)
	{
		sum-=a[i];
		if(!sum)
		{
			ans[++cnt]=i-1;
			++a[i-1+n];
			++sum;
		}
		for(int j=sum+1;j<=k;++j)
		{
			ans[++cnt]=i;
			++a[i+n];
			++sum;
		}
	}

	printf("%d\n",cnt);
	for(int i=1;i<=cnt;++i)
	{
		printf("%d ",ans[i]);
	}
	return 0;
}