#include <bits\stdc++.h>
using namespace std;
#define rep(flag,a,b) for(int flag=(a);flag<=b;flag++)
#define Rep(flag,a,b) for(int flag=(a);flag>=b;flag--)
#define mem(flag) memset(flag,0,sizeof(flag))
#define Mem(flag) memset(flag,-1,sizeof(flag))
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef vector<pi> vpi;
typedef vector<pd> vpd;
const int MAX=4e4+5e3,MAX2=1005,MAX3=105;

#define DEBUG
int dp[MAX3][MAX],s[MAX3][MAX],tSlot[MAX];
int qo[MAX],qk[MAX][MAX2];
int slot(int d,int h,int m) {
    return (d-1)*1440+h*60+m+1;
}
tuple<int,int,int> times(int n) {
    int d=int(n/1440)+1,h,m;
    int temp=n%1440;
    if(temp==0) h=23,m=59;
    else {
        if(temp%60==0) {
            h=temp/60-1;
            m=59;
        } else {
            h=int(temp/60);
            m=temp%60-1;
        }
    }
    return tuple<int,int,int> {d,h,m};
}
int m,n,k;
vector<string> subj;
vector<int> endure;
unordered_map<string,int> table;
int sh,sm,eh,em,maxTime;
vector<tuple<string,int,int,int>> task;
vector<tuple<int,int,int>> ans;
void getAns(int n,int t) {
    if(n==0) return ;
    if(s[n][t]==1) {
        string &name=get<0> (task[n]); int ltime=get<1> (task[n]);
        int last=table[name];
        int bound=min(t,ltime);
        int prevFree=qk[bound][last];
        getAns(n-1,prevFree);
        int start=qk[bound][last-1],end=tSlot[bound]==0? bound:qo[bound];
        ans.push_back(make_tuple(get<3>(task[n]),start,end));
    } else getAns(n-1,t);
}
bool less2(const tuple<string,int,int,int> &a,
           const tuple<string,int,int,int> &b) {
    return get<1> (a)<get<1> (b);
}

bool less1(const tuple<int,int,int> &a,const tuple<int,int,int> &b) {
    return get<1>(a)<get<2>(b);
}

int main() {
    #ifdef DEBUG
    ios::sync_with_stdio(false);
    cin.tie(0);
    //freopen("./input.txt","r",stdin);
    //freopen("./output.txt","w",stdout);
    int cases=1;
    while(cases--) {
    #endif
        mem(tSlot);
        scanf("%d%d%d",&m,&n,&k);
        rep(i,1,m) {
            string s;
            cin>>s;
            subj.push_back(s);
        }
        rep(i,1,m) {
            int t; scanf("%d",&t);
            endure.push_back(t);
        }
        rep(i,0,m-1) table.insert({subj[i],endure[i]});
        int timeSeg=4;
        while(timeSeg--) {
            scanf("%d:%d-%d:%d",&sh,&sm,&eh,&em);
            rep(d,1,k) {
                int start=slot(d,sh,sm);
                int end=slot(d,eh,em);
               // printf("(%d,%d)\n",start,end);
                rep(slot,start,end) tSlot[slot]=1;
            }
       }
       maxTime=k*1440;
       qo[1]=-1;
       rep(i,2,maxTime) {
           if(tSlot[i-1]==1) qo[i]=qo[i-1];
           else qo[i]=i-1;
       }
       rep(i,1,maxTime) {
           int consume=0,tempi=i;
           qk[i][consume]=tSlot[i]==0? i:qo[i];
           while(tempi!=-1&&(tSlot[tempi]==0||qo[tempi]!=-1)) {
               if(tSlot[tempi]==1) tempi=qo[qo[tempi]];
               else tempi=qo[tempi];
               consume++;
               qk[i][consume]=tempi;
               if(consume==1000) break;
           }
           if(consume<1000) {
               rep(j,consume+1,1000) qk[i][j]=-1;
           }
       }
	   task.resize(n+1);
       rep(i,1,n) {
           string s; int d,h,m,fit; char c;
           cin>>s>>d>>h>>c>>m>>fit;
           int dd=slot(d,h,m); task[i]=make_tuple(s,dd-1,fit,i);
       }
       sort(task.begin()+1,task.begin()+n+1,less2);
      /* rep(i,1,n) {
           auto &t=task[i];
           cout<<get<0>(t)<<" "<<get<1>(t)<<" "<<get<2>(t)<<endl;
       } */

	   rep(t,1,maxTime) dp[0][t]=0;
       rep(i,1,n) {
           rep(t,1,maxTime) {
               string &name=get<0>(task[i]);
               int ltime=get<1>(task[i]),fit=get<2>(task[i]);
               if(table.find(name)==table.end()) {
                   dp[i][t]=dp[i-1][t];
                   s[i][t]=0;
               } else {
                   int last=table[name];
                   int bound=min(t,ltime);
                   int a=INT_MIN,b;
                   int prevFree=qk[bound][last];
                   if(qk[bound][last-1]!=-1) {
                       a=dp[i-1][prevFree]+fit;
                   }
                   b=dp[i-1][t];
                   if(a>b) {
                       s[i][t]=1; dp[i][t]=a;
                   } else {
                       s[i][t]=0; dp[i][t]=b;
                   }
               }
           }
       }
	   printf("%d\n",dp[n][maxTime]);
       getAns(n,maxTime);
       printf("%d\n",ans.size());
       sort(ans.begin(),ans.end(),less1);
       rep(i,0,(int)ans.size()-1) {
           auto &tu=ans[i];
           const auto &s=times(get<1>(tu)),&e=times(get<2>(tu));
           printf("%d %d %02d:%02d %d %02d:%02d\n",get<0>(tu),get<0>(s),
                  get<1>(s),get<2>(s),get<0>(e),get<1>(e),get<2>(e));
       }

    #ifdef DEBUG
    }
    #endif
    return 0;
}


#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;
}


#include <iostream>
#include <cstdio>
#include<list>
#include<iomanip>
#include<cmath>
#include<queue>
#include <functional>
#include<stdio.h>
#include<assert.h>
#include<stack>
#include<sstream>
#include <cstdlib>
#include<map>
#include<algorithm>
#include<iostream>
#include<set>
#include<utility>
#include<memory.h>
#include<string>
#include<vector>
#include<numeric>
#include <unordered_map>
using namespace std;
#define ll  long long
#define pb push_back
#define sz(v)               ((int)((v).size()))
#define all(x)          (x).begin(),(x).end()
#define REP(i, v)       for(int i=0;i<sz(v);i++)
typedef pair<int,int> pii;
#define ios std::ios_base::sync_with_stdio(false);
using namespace std;;
typedef vector<int> VI;
int n,m,k;
char s[101];
string rev[101];
int subjectTime[101];
map<string,int> mp;
int id = 0;
int convert(int d,int h,int m ) {
	return d * 24 * 60  + h * 60 + m;
}
const int maxt = 30 * 24 * 60 + 24*60 + 60 + 10;
struct Entry {
	int subject;
	int deadline;
	int takes;
	int price;
	int index;
	Entry(int subject,int deadline,int price,int index) {
		this->subject = subject;
		this->deadline = deadline;
		this->price = price;
		this->takes = subjectTime[subject];
		this->index = index;
	}
	bool operator<(const Entry& o) const {
		if(deadline == o.deadline)
			return index < o.index;
		return deadline < o.deadline;
	}

};
int F[maxt];
int busy[maxt];
vector<Entry> tasks;
int dp[101][maxt];
int getDelay(int start,int plus) {

	int lo = start, hi = maxt - 1;
	int ans = 1 << 30;
	while(lo <= hi) {
		int mid = lo + (hi - lo) / 2;
		int tot = mid - start + 1;
		tot -= busy[mid];
		if(start != 0) tot += busy[start - 1];
		if(tot >= plus) ans = mid,hi = mid - 1;
		else lo = mid + 1;
	}
	return ans;
}

int solve(int ind,int curr_t) {
	if(curr_t > maxt)
		return -(1 << 28);
	if(ind == sz(tasks) )
		return 0;
	int &ret = dp[ind][curr_t];
	if(ret != -1)
		return ret;
	ret = 0;
	// leave current task
	ret = max(ret,solve(ind + 1,curr_t));
	// take current task

	int d = getDelay(curr_t,tasks[ind].takes);
	cerr << d << " " << tasks[ind].deadline << "\n";
	if(d < tasks[ind].deadline) {
		ret = max(ret,tasks[ind].price + solve(ind + 1,d + 1));
	}
	return ret;
}
struct Response {
	int ind;
	int end,start;
	int start_day,start_hour,start_min;
	int end_day,end_hour,end_min;
	int a;

	Response(int ind,int start,int end) {
		this->ind  = ind;
		this-> end = end;
		this->start = start;
		a = start;
		go();
	}
	void go() {

		start_day = start/(1440);
		start %= 1440;
		start_hour = start / 60;
		start_min = start % 60;

		end_day = end/(1440);
		end %= 1440;
		end_hour = end / 60;
		end_min = end % 60;
	}

	bool operator<(const Response& o) const {
		if(a == o.a)
			return ind < o.ind;
		return start < o.start; }

};
vector<Response> responses;
void trace(int ind,int curr_t) {

	if(ind == sz(tasks) )
		return;
	int ret = dp[ind][curr_t];
	ret = 0;
	int opt = solve(ind,curr_t);
	// leave current task
	ret = max(ret,solve(ind + 1,curr_t));
	if(opt == ret) {
		trace(ind + 1, curr_t);
		return;
	}
	// take current task
	int d = getDelay(curr_t,tasks[ind].takes);
	//cerr << d << " " << tasks[ind].deadline << "\n";
	if(d < tasks[ind].deadline) {

		ret = max(ret,tasks[ind].price + solve(ind + 1,d + 1));
		responses.pb(Response(tasks[ind].index,F[curr_t],d));
		trace(ind + 1, d + 1);
	}

}
int main() {

	scanf("%d %d %d",&n,&m,&k);
	for (int i = 0 ; i < n ; ++i) {
		string str;
		cin >> str;
		//cerr << str << "\n";
		mp[str] = i;
		rev[i] = str;
	}
	for (int i = 0 ; i < n ; ++i) {
		scanf("%d",&subjectTime[i]);
	}
	int h1,m1,h2,m2;
	// scan off time
	for(int i = 0 ; i < 4;  ++i) {
		scanf("%d:%d-%d:%d",&h1,&m1,&h2,&m2);
		for(int k = 0 ; k < 30 ; ++k) {
			// insert bad timings
			int L = convert(k,h1,m1);
			int R = convert(k,h2,m2);
			for(int j = L ; j <= R ; ++j)
				busy[j] = 1;
		}
	}
	//cerr << "here" << "\n";
	int lst = -1;
	for(int i = maxt - 1 ; i >= 0 ; --i) {
		if(!busy[i]) lst = i;
		if(lst != -1)  {
			F[i] = lst;
		}
	}
	for(int i = 1 ; i < maxt ; ++i) busy[i] += busy[i - 1];

	scanf("%d:%d-%d:%d",&h1,&m1,&h2,&m2);
	int p;
	int day;
	for(int i = 0 ; i < m ; ++i) {
		string str;
		cin >> str;

		scanf("%d %d:%d %d",&day,&h1,&m1,&p);
		--day;

		if(mp.find(str) == mp.end())
			continue;
		int t = convert(day,h1,m1);
		tasks.pb(Entry(mp[str],t,p,i));
	}
	sort(all(tasks));

	memset(dp,-1,sizeof(dp));
	cout << solve(0,0) << "\n";
	trace(0,0);
	sort(all(responses));
	printf("%d\n",sz(responses));
	REP(i,responses) {
		printf("%d %d %02d:%02d %d %02d:%02d\n",responses[i].ind + 1,responses[i].start_day + 1,responses[i].start_hour,
				responses[i].start_min,responses[i].end_day + 1,responses[i].end_hour,responses[i].end_min);
	}
}


#include <iostream>
#include <cstdio>
#include<list>
#include<iomanip>
#include<cmath>
#include<queue>
#include <functional>
#include<stdio.h>
#include<assert.h>
#include<stack>
#include<sstream>
#include <cstdlib>
#include<map>
#include<algorithm>
#include<iostream>
#include<set>
#include<utility>
#include<memory.h>
#include<string>
#include<vector>
#include<numeric>
#include <unordered_map>
using namespace std;
#define ll  long long
#define pb push_back
#define sz(v)               ((int)((v).size()))
#define all(x)          (x).begin(),(x).end()
#define REP(i, v)       for(int i=0;i<sz(v);i++)
typedef pair<int,int> pii;
#define ios std::ios_base::sync_with_stdio(false);
using namespace std;;
typedef vector<int> VI;
int n,m,k;
char s[101];
string rev[101];
int subjectTime[101];
map<string,int> mp;
set<pii> bad;
int id = 0;
int convert(int d,int h,int m ) {
	return d * 24 * 60  + h * 60 + m;
}
const int maxt = 30 * 24 * 60 + 24*60 + 60 + 10;
struct Entry {
	int subject;
	int deadline;
	int takes;
	int price;
	int index;
	Entry(int subject,int deadline,int price,int index) {
		this->subject = subject;
		this->deadline = deadline;
		this->price = price;
		this->takes = subjectTime[subject];
		this->index = index;
	}
	bool operator<(const Entry& o) const { return deadline < o.deadline; }

};
int F[maxt];
int busy[maxt];
vector<Entry> tasks;
int dp[101][maxt];
int getDelay(int start,int plus) {

	int lo = start, hi = convert(k,0,0);
	int ans = 1 << 30;
	while(lo <= hi) {
		int mid = lo + (hi - lo) / 2;
		int tot = mid - start + 1;
		tot -= busy[mid];
		if(start != 0) tot += busy[start - 1];
		if(tot >= plus) ans = mid,hi = mid - 1;
		else lo = mid + 1;
	}
	return ans;
}

int solve(int ind,int curr_t) {
	if(curr_t > maxt)
		return 1 << 30;
	if(ind == sz(tasks) )
		return 0;
	int &ret = dp[ind][curr_t];
	if(ret != -1)
		return ret;
	ret = 0;
	// leave current task
	ret = max(ret,solve(ind + 1,curr_t));
	// take current task
	int d = getDelay(curr_t,tasks[ind].takes);
	if(d < tasks[ind].deadline) {
		ret = max(ret,tasks[ind].price + solve(ind + 1,d + 1));
	}
	return ret;
}
struct Response {
	int ind;
	int end,start;
	int start_day,start_hour,start_min;
	int end_day,end_hour,end_min;

	Response(int ind,int start,int end) {
		this->ind  = ind;
		this-> end = end;
		this->start = start;
		go();
	}
	void go() {
		start_day = start/(1440);
		start %= 1440;
		start_hour = start / 60;
		start_min = start % 60;

		end_day = end/(1440);
		end %= 1440;
		end_hour = end / 60;
		end_min = end % 60;
	}

	bool operator<(const Response& o) const { return start < o.start; }

};
vector<Response> responses;
void trace(int ind,int curr_t) {

	if(ind == sz(tasks) )
		return;
	int ret = dp[ind][curr_t];
	ret = 0;
	int opt = solve(ind,curr_t);
	// leave current task
	ret = max(ret,solve(ind + 1,curr_t));
	if(opt == ret) {
		trace(ind + 1, curr_t);
		return;
	}
	// take current task
	int d = getDelay(curr_t,tasks[ind].takes);

	if(d < tasks[ind].deadline) {

		ret = max(ret,tasks[ind].price + solve(ind + 1,d + 1));
		responses.pb(Response(tasks[ind].index,F[curr_t],d));
		trace(ind + 1, d + 1);
	}

}
int main() {

	scanf("%d %d %d",&n,&m,&k);
	for (int i = 0 ; i < m ; ++i) {
		string str;
		cin >> str;
		mp[str] = i;
		rev[i] = str;
	}
	for (int i = 0 ; i < m ; ++i) {
		scanf("%d",&subjectTime[i]);
	}
	int h1,m1,h2,m2;
	// scan off time
	for(int i = 0 ; i < 4;  ++i) {
		scanf("%d:%d-%d:%d",&h1,&m1,&h2,&m2);
		for(int k = 0 ; k < 30 ; ++k) {
			// insert bad timings
			int L = convert(k,h1,m1);
			int R = convert(k,h2,m2);
			for(int j = L ; j <= R ; ++j)
				busy[j] = 1;
		}
	}
	int lst = -1;
	for(int i = maxt - 1 ; i >= 0 ; --i) {
		if(!busy[i]) lst = i;
		if(lst != -1)  {
			F[i] = lst;
		}
	}
	for(int i = 1 ; i < maxt ; ++i) busy[i] += busy[i - 1];

	scanf("%d:%d-%d:%d",&h1,&m1,&h2,&m2);
	int p;
	int day;
	for(int i = 0 ; i < n ; ++i) {
		string str;
		cin >> str;

		scanf("%d %d:%d %d",&day,&h1,&m1,&p);
		--day;
		if(mp.find(str) == mp.end())
			continue;
		int t = convert(day,h1,m1);
		tasks.pb(Entry(mp[str],t,p,i));
	}
	sort(all(tasks));
	memset(dp,-1,sizeof(dp));
	cout << solve(0,0) << "\n";
	trace(0,0);
	sort(all(responses));
	printf("%d\n",sz(responses));
	REP(i,responses) {
		printf("%d %d %02d:%02d %d %02d:%02d\n",responses[i].ind + 1,responses[i].start_day + 1,responses[i].start_hour,
				responses[i].start_min,responses[i].end_day + 1,responses[i].end_hour,responses[i].end_min);
	}
}


#include <iostream>
#include <cstdio>
#include<list>
#include<iomanip>
#include<cmath>
#include<queue>
#include <functional>
#include<stdio.h>
#include<assert.h>
#include<stack>
#include<sstream>
#include <cstdlib>
#include<map>
#include<algorithm>
#include<iostream>
#include<set>
#include<utility>
#include<memory.h>
#include<string>
#include<vector>
#include<numeric>
#include <unordered_map>
using namespace std;
#define ll  long long
#define pb push_back
#define sz(v)               ((int)((v).size()))
#define all(x)          (x).begin(),(x).end()
#define REP(i, v)       for(int i=0;i<sz(v);i++)
typedef pair<int,int> pii;
#define ios std::ios_base::sync_with_stdio(false);
using namespace std;;
typedef vector<int> VI;
int n,m,k;
char s[101];
string rev[101];
int subjectTime[101];
map<string,int> mp;
set<pii> bad;
int id = 0;
int convert(int d,int h,int m ) {
	return d * 24 * 60  + h * 60 + m;
}
const int maxt = 30 * 24 * 60 + 24*60 + 60 + 10;
struct Entry {
	int subject;
	int deadline;
	int takes;
	int price;
	int index;
	Entry(int subject,int deadline,int price,int index) {
		this->subject = subject;
		this->deadline = deadline;
		this->price = price;
		this->takes = subjectTime[subject];
		this->index = index;
	}
	bool operator<(const Entry& o) const { return deadline < o.deadline; }

};
int F[maxt];
int busy[maxt];
vector<Entry> tasks;
int dp[101][maxt];
int getDelay(int start,int plus) {

	int lo = start, hi = convert(k,0,0);
	int ans = 1 << 30;
	while(lo <= hi) {
		int mid = lo + (hi - lo) / 2;
		int tot = mid - start + 1;
		tot -= busy[mid];
		if(start != 0) tot += busy[start - 1];
		if(tot >= plus) ans = mid,hi = mid - 1;
		else lo = mid + 1;
	}
	return ans;
}

int solve(int ind,int curr_t) {
	if(curr_t > maxt)
		return 1 << 30;
	if(ind == sz(tasks) )
		return 0;
	int &ret = dp[ind][curr_t];
	if(ret != -1)
		return ret;
	ret = 0;
	// leave current task
	ret = max(ret,solve(ind + 1,curr_t));
	// take current task
	int d = getDelay(curr_t,tasks[ind].takes);
	if(d < tasks[ind].deadline) {
		ret = max(ret,tasks[ind].price + solve(ind + 1,d + 1));
	}
	return ret;
}
struct Response {
	int ind;
	int end,start;
	int start_day,start_hour,start_min;
	int end_day,end_hour,end_min;

	Response(int ind,int start,int end) {
		this->ind  = ind;
		this-> end = end;
		this->start = start;
		go();
	}
	void go() {
		start_day = start/(1440);
		start %= 1440;
		start_hour = start / 60;
		start_min = start % 60;

		end_day = end/(1440);
		end %= 1440;
		end_hour = end / 60;
		end_min = end % 60;
	}

	bool operator<(const Response& o) const { return ind < o.ind; }

};
vector<Response> responses;
void trace(int ind,int curr_t) {

	if(ind == sz(tasks) )
		return;
	int ret = dp[ind][curr_t];
	ret = 0;
	int opt = solve(ind,curr_t);
	// leave current task
	ret = max(ret,solve(ind + 1,curr_t));
	if(opt == ret) {
		trace(ind + 1, curr_t);
		return;
	}
	// take current task
	int d = getDelay(curr_t,tasks[ind].takes);

	if(d < tasks[ind].deadline) {

		ret = max(ret,tasks[ind].price + solve(ind + 1,d + 1));
		responses.pb(Response(tasks[ind].index,F[curr_t],d));
		trace(ind + 1, d + 1);
	}

}
int main() {

	scanf("%d %d %d",&n,&m,&k);
	for (int i = 0 ; i < m ; ++i) {
		string str;
		cin >> str;
		mp[str] = i;
		rev[i] = str;
	}
	for (int i = 0 ; i < m ; ++i) {
		scanf("%d",&subjectTime[i]);
	}
	int h1,m1,h2,m2;
	// scan off time
	for(int i = 0 ; i < 4;  ++i) {
		scanf("%d:%d-%d:%d",&h1,&m1,&h2,&m2);
		for(int k = 0 ; k < 30 ; ++k) {
			// insert bad timings
			int L = convert(k,h1,m1);
			int R = convert(k,h2,m2);
			for(int j = L ; j <= R ; ++j)
				busy[j] = 1;
		}
	}
	int lst = -1;
	for(int i = maxt - 1 ; i >= 0 ; --i) {
		if(!busy[i]) lst = i;
		if(lst != -1)  {
			F[i] = lst;
		}
	}
	for(int i = 1 ; i < maxt ; ++i) busy[i] += busy[i - 1];

	scanf("%d:%d-%d:%d",&h1,&m1,&h2,&m2);
	int p;
	int day;
	for(int i = 0 ; i < n ; ++i) {
		string str;
		cin >> str;

		scanf("%d %d:%d %d",&day,&h1,&m1,&p);
		--day;
		if(mp.find(str) == mp.end())
			continue;
		int t = convert(day,h1,m1);
		tasks.pb(Entry(mp[str],t,p,i));
	}
	sort(all(tasks));
	memset(dp,-1,sizeof(dp));
	cout << solve(0,0) << "\n";
	trace(0,0);
	sort(all(responses));
	printf("%d\n",sz(responses));
	REP(i,responses) {
		printf("%d %d %02d:%02d %d %02d:%02d\n",responses[i].ind + 1,responses[i].start_day + 1,responses[i].start_hour,
				responses[i].start_min,responses[i].end_day + 1,responses[i].end_hour,responses[i].end_min);
	}
}


#include <iostream>
#include <cstdio>
#include<list>
#include<iomanip>
#include<cmath>
#include<queue>
#include <functional>
#include<stdio.h>
#include<assert.h>
#include<stack>
#include<sstream>
#include <cstdlib>
#include<map>
#include<algorithm>
#include<iostream>
#include<set>
#include<utility>
#include<memory.h>
#include<string>
#include<vector>
#include<numeric>
#include <unordered_map>
using namespace std;
#define ll  long long
#define pb push_back
#define sz(v)               ((int)((v).size()))
#define all(x)          (x).begin(),(x).end()
#define REP(i, v)       for(int i=0;i<sz(v);i++)
typedef pair<int,int> pii;
#define ios std::ios_base::sync_with_stdio(false);
using namespace std;;
typedef vector<int> VI;
int n,m,k;
char s[101];
string rev[101];
int subjectTime[101];
map<string,int> mp;
set<pii> bad;
int id = 0;
int convert(int d,int h,int m ) {
	return d * 24 * 60  + h * 60 + m;
}
const int maxt = 30 * 24 * 60 + 24*60 + 60 + 10;
struct Entry {
	int subject;
	int deadline;
	int takes;
	int price;
	int index;
	Entry(int subject,int deadline,int price,int index) {
		this->subject = subject;
		this->deadline = deadline;
		this->price = price;
		this->takes = subjectTime[subject];
		this->index = index;
	}
	bool operator<(const Entry& o) const { return deadline < o.deadline; }

};
int busy[maxt];
vector<Entry> tasks;
int dp[101][max_t];
int getDelay(int start,int plus) {

	int lo = start, hi = convert(k,0,0);
	int ans = 1 << 30;
	while(lo <= hi) {
		int mid = lo + (hi - lo) / 2;
		int tot = mid - start + 1;
		tot -= busy[mid];
		if(start != 0) tot += busy[start - 1];
		if(tot >= plus) ans = mid,hi = mid - 1;
		else lo = mid + 1;
	}
	return ans;
}

int solve(int ind,int curr_t) {
	if(curr_t > maxt)
		return 1 << 30;
	if(ind == sz(tasks) )
		return 0;
	int &ret = dp[ind][curr_t];
	if(ret != -1)
		return ret;
	ret = 0;
	// leave current task
	ret = max(ret,solve(ind + 1,curr_t));
	// take current task
	int d = getDelay(curr_t,tasks[ind].takes);
	if(d < tasks[ind].deadline) {
		ret = max(ret,tasks[ind].price + solve(ind + 1,d + 1));
	}
	return ret;
}
struct Response {
	int ind;
	int end,start;
	int start_day,start_hour,start_min;
	int end_day,end_hour,end_min;

	Response(int ind,int start,int end) {
		this->ind  = ind;
		this-> end = end;
		this->start = start;
		go();
	}
	void go() {
		start_day = start/(1440);
		start %= 1440;
		start_hour = start / 60;
		start_min = start % 60;

		end_day = end/(1440);
		end %= 1440;
		end_hour = end / 60;
		end_min = end % 60;
	}

	bool operator<(const Response& o) const { return ind < o.ind; }

};
vector<Response> responses;
void trace(int ind,int curr_t) {

	if(ind == sz(tasks) )
		return;
	int ret = dp[ind][curr_t];
	ret = 0;
	int opt = solve(ind,curr_t);
	// leave current task
	ret = max(ret,solve(ind + 1,curr_t));
	if(opt == ret) {
		trace(ind + 1, curr_t);
		return;
	}
	// take current task
	int d = getDelay(curr_t,tasks[ind].takes);
	if(d < tasks[ind].deadline) {
		ret = max(ret,tasks[ind].price + solve(ind + 1,d + 1));
		responses.pb(Response(tasks[ind].index,curr_t,d));
		trace(ind + 1, d + 1);
	}

}
int main() {

	scanf("%d %d %d",&n,&m,&k);
	for (int i = 0 ; i < m ; ++i) {
		string str;
		cin >> str;
		mp[str] = i;
		rev[i] = str;
	}
	for (int i = 0 ; i < m ; ++i) {
		scanf("%d",&subjectTime[i]);
	}
	int h1,m1,h2,m2;
	// scan off time
	for(int i = 0 ; i < 4;  ++i) {
		scanf("%d:%d-%d:%d",&h1,&m1,&h2,&m2);
		for(int k = 0 ; k < 30 ; ++k) {
			// insert bad timings
			int L = convert(k,h1,m1);
			int R = convert(k,h2,m2);
			for(int j = L ; j <= R ; ++j)
				busy[j] = 1;
		}
	}
	for(int i = 1 ; i < maxt ; ++i) busy[i] += busy[i - 1];
	scanf("%d:%d-%d:%d",&h1,&m1,&h2,&m2);
	int p;
	int day;
	for(int i = 0 ; i < n ; ++i) {
		string str;
		cin >> str;

		scanf("%d %d:%d %d",&day,&h1,&m1,&p);
		--day;
		if(mp.find(str) == mp.end())
			continue;
		int t = convert(day,h1,m1);
		tasks.pb(Entry(mp[str],t,p,i));
	}
	sort(all(tasks));
	memset(dp,-1,sizeof(dp));
	cout << solve(0,0) << "\n";
	trace(0,0);
	sort(all(responses));
	printf("%d\n",sz(responses));
	REP(i,responses) {
		printf("%d %d %02d:%02d %d %02d:%02d\n",responses[i].ind + 1,responses[i].start_day + 1,responses[i].start_hour,
				responses[i].start_min,responses[i].end_day + 1,responses[i].end_hour,responses[i].end_min);
	}
}


#include <iostream>
#include <cstdio>
#include<list>
#include<iomanip>
#include<cmath>
#include<queue>
#include <functional>
#include<stdio.h>
#include<assert.h>
#include<stack>
#include<sstream>
#include <cstdlib>
#include<map>
#include<algorithm>
#include<iostream>
#include<set>
#include<utility>
#include<memory.h>
#include<string>
#include<vector>
#include<numeric>
#include <unordered_map>
using namespace std;
#define ll  long long
#define pb push_back
#define sz(v)               ((int)((v).size()))
#define all(x)          (x).begin(),(x).end()
#define REP(i, v)       for(int i=0;i<sz(v);i++)
typedef pair<int,int> pii;
#define ios std::ios_base::sync_with_stdio(false);
using namespace std;;
typedef vector<int> VI;
int n,m,k;
char s[101];
string rev[101];
int subjectTime[101];
map<string,int> mp;
int id = 0;
int convert(int d,int h,int m ) {
	return d * 24 * 60  + h * 60 + m;
}
const int maxt = 30 * 24 * 60 + 24*60 + 60 + 10;
struct Entry {
	int subject;
	int deadline;
	int takes;
	int price;
	int index;
	Entry(int subject,int deadline,int price,int index) {
		this->subject = subject;
		this->deadline = deadline;
		this->price = price;
		this->takes = subjectTime[subject];
		this->index = index;
	}
	bool operator<(const Entry& o) const {
		if(deadline == o.deadline)
			return index < o.index;
		return deadline < o.deadline;
	}

};
int F[maxt];
int busy[maxt];
vector<Entry> tasks;
int dp[101][maxt];
int getDelay(int start,int plus) {

	int lo = start, hi = maxt - 1;
	int ans = 1 << 30;
	while(lo <= hi) {
		int mid = lo + (hi - lo) / 2;
		int tot = mid - start + 1;
		tot -= busy[mid];
		if(start != 0) tot += busy[start - 1];
		if(tot >= plus) ans = mid,hi = mid - 1;
		else lo = mid + 1;
	}
	return ans;
}

int solve(int ind,int curr_t) {
	if(curr_t > maxt)
		return -(1 << 28);
	if(ind == sz(tasks) )
		return 0;
	int &ret = dp[ind][curr_t];
	if(ret != -1)
		return ret;
	ret = 0;
	// leave current task
	ret = max(ret,solve(ind + 1,curr_t));
	// take current task

	int d = getDelay(curr_t,tasks[ind].takes);
	cerr << d << " " << tasks[ind].deadline << "\n";
	if(d < tasks[ind].deadline) {
		ret = max(ret,tasks[ind].price + solve(ind + 1,d + 1));
	}
	return ret;
}
struct Response {
	int ind;
	int end,start;
	int start_day,start_hour,start_min;
	int end_day,end_hour,end_min;
	int a;

	Response(int ind,int start,int end) {
		this->ind  = ind;
		this-> end = end;
		this->start = start;
		a = start;
		go();
	}
	void go() {

		start_day = start/(1440);
		start %= 1440;
		start_hour = start / 60;
		start_min = start % 60;

		end_day = end/(1440);
		end %= 1440;
		end_hour = end / 60;
		end_min = end % 60;
	}

	bool operator<(const Response& o) const {
		if(a == o.a)
			return ind < o.ind;
		return start < o.start; }

};
vector<Response> responses;
void trace(int ind,int curr_t) {

	if(ind == sz(tasks) )
		return;
	int ret = dp[ind][curr_t];
	ret = 0;
	int opt = solve(ind,curr_t);
	// leave current task
	ret = max(ret,solve(ind + 1,curr_t));
	if(opt == ret) {
		trace(ind + 1, curr_t);
		return;
	}
	// take current task
	int d = getDelay(curr_t,tasks[ind].takes);
	//cerr << d << " " << tasks[ind].deadline << "\n";
	if(d < tasks[ind].deadline) {

		ret = max(ret,tasks[ind].price + solve(ind + 1,d + 1));
		responses.pb(Response(tasks[ind].index,F[curr_t],d));
		trace(ind + 1, d + 1);
	}

}
int main() {

	scanf("%d %d %d",&n,&m,&k);
	for (int i = 0 ; i < n ; ++i) {
		string str;
		cin >> str;
		//cerr << str << "\n";
		mp[str] = i;
		rev[i] = str;
	}
	for (int i = 0 ; i < n ; ++i) {
		scanf("%d",&subjectTime[i]);
	}
	int h1,m1,h2,m2;
	// scan off time
	for(int i = 0 ; i < 4;  ++i) {
		scanf("%d:%d-%d:%d",&h1,&m1,&h2,&m2);
		for(int k = 0 ; k < 30 ; ++k) {
			// insert bad timings
			int L = convert(k,h1,m1);
			int R = convert(k,h2,m2);
			for(int j = L ; j <= R ; ++j)
				busy[j] = 1;
		}
	}
	//cerr << "here" << "\n";
	int lst = -1;
	for(int i = maxt - 1 ; i >= 0 ; --i) {
		if(!busy[i]) lst = i;
		if(lst != -1)  {
			F[i] = lst;
		}
	}
	for(int i = 1 ; i < maxt ; ++i) busy[i] += busy[i - 1];

	scanf("%d:%d-%d:%d",&h1,&m1,&h2,&m2);
	int p;
	int day;
	for(int i = 0 ; i < m ; ++i) {
		string str;
		cin >> str;

		scanf("%d %d:%d %d",&day,&h1,&m1,&p);
		--day;

		if(mp.find(str) == mp.end())
			continue;
		int t = convert(day,h1,m1);
		tasks.pb(Entry(mp[str],t,p,i));
	}
	sort(all(tasks));

	memset(dp,-1,sizeof(dp));
	cout << solve(0,0) << "\n";
	trace(0,0);
	//sort(all(responses));
	printf("%d\n",sz(responses));
	REP(i,responses) {
		printf("%d %d %02d:%02d %d %02d:%02d\n",responses[i].ind + 1,responses[i].start_day + 1,responses[i].start_hour,
				responses[i].start_min,responses[i].end_day + 1,responses[i].end_hour,responses[i].end_min);
	}
}


#include <iostream>
#include <cstdio>
#include<list>
#include<iomanip>
#include<cmath>
#include<queue>
#include <functional>
#include<stdio.h>
#include<assert.h>
#include<stack>
#include<sstream>
#include <cstdlib>
#include<map>
#include<algorithm>
#include<iostream>
#include<set>
#include<utility>
#include<memory.h>
#include<string>
#include<vector>
#include<numeric>
#include <unordered_map>
using namespace std;
#define ll  long long
#define pb push_back
#define sz(v)               ((int)((v).size()))
#define all(x)          (x).begin(),(x).end()
#define REP(i, v)       for(int i=0;i<sz(v);i++)
typedef pair<int,int> pii;
#define ios std::ios_base::sync_with_stdio(false);
using namespace std;;
typedef vector<int> VI;
int n,m,k;
char s[101];
string rev[101];
int subjectTime[101];
map<string,int> mp;
int id = 0;
int convert(int d,int h,int m ) {
	return d * 24 * 60  + h * 60 + m;
}
const int maxt = 30 * 24 * 60 + 24*60 + 60 + 10;
struct Entry {
	int subject;
	int deadline;
	int takes;
	int price;
	int index;
	Entry(int subject,int deadline,int price,int index) {
		this->subject = subject;
		this->deadline = deadline;
		this->price = price;
		this->takes = subjectTime[subject];
		this->index = index;
	}
	bool operator<(const Entry& o) const {
		if(deadline == o.deadline)
			return index < o.index;
		return deadline < o.deadline;
	}

};
int F[maxt];
int busy[maxt];
vector<Entry> tasks;
int dp[101][maxt];
int getDelay(int start,int plus) {

	int lo = start, hi = maxt - 1;
	int ans = 1 << 30;
	while(lo <= hi) {
		int mid = lo + (hi - lo) / 2;
		int tot = mid - start + 1;
		tot -= busy[mid];
		if(start != 0) tot += busy[start - 1];
		if(tot >= plus) ans = mid,hi = mid - 1;
		else lo = mid + 1;
	}
	return ans;
}

int solve(int ind,int curr_t) {
	if(curr_t > maxt)
		return -(1 << 28);
	if(ind == sz(tasks) )
		return 0;
	int &ret = dp[ind][curr_t];
	if(ret != -1)
		return ret;
	ret = 0;
	// leave current task
	ret = max(ret,solve(ind + 1,curr_t));
	// take current task

	int d = getDelay(curr_t,tasks[ind].takes);
	//cerr << d << " " << tasks[ind].deadline << "\n";
	if(d < tasks[ind].deadline) {
		ret = max(ret,tasks[ind].price + solve(ind + 1,d + 1));
	}
	return ret;
}
struct Response {
	int ind;
	int end,start;
	int start_day,start_hour,start_min;
	int end_day,end_hour,end_min;
	int a;

	Response(int ind,int start,int end) {
		this->ind  = ind;
		this-> end = end;
		this->start = start;
		a = start;
		go();
	}
	void go() {

		start_day = start/(1440);
		start %= 1440;
		start_hour = start / 60;
		start_min = start % 60;

		end_day = end/(1440);
		end %= 1440;
		end_hour = end / 60;
		end_min = end % 60;
	}

	bool operator<(const Response& o) const {
		if(a == o.a)
			return ind < o.ind;
		return start < o.start; }

};
vector<Response> responses;
void trace(int ind,int curr_t) {

	if(ind == sz(tasks) )
		return;
	int ret = dp[ind][curr_t];
	ret = 0;
	int opt = solve(ind,curr_t);
	// leave current task
	ret = max(ret,solve(ind + 1,curr_t));
	if(opt == ret) {
		trace(ind + 1, curr_t);
		return;
	}
	// take current task
	int d = getDelay(curr_t,tasks[ind].takes);
	//cerr << d << " " << tasks[ind].deadline << "\n";
	if(d < tasks[ind].deadline) {

		ret = max(ret,tasks[ind].price + solve(ind + 1,d + 1));
		responses.pb(Response(tasks[ind].index,F[curr_t],d));
		trace(ind + 1, d + 1);
	}

}
int main() {

	scanf("%d %d %d",&n,&m,&k);
	for (int i = 0 ; i < n ; ++i) {
		string str;
		cin >> str;
		//cerr << str << "\n";
		mp[str] = i;
		rev[i] = str;
	}
	for (int i = 0 ; i < n ; ++i) {
		scanf("%d",&subjectTime[i]);
	}
	int h1,m1,h2,m2;
	// scan off time
	for(int i = 0 ; i < 4;  ++i) {
		scanf("%d:%d-%d:%d",&h1,&m1,&h2,&m2);
		for(int k = 0 ; k < 30 ; ++k) {
			// insert bad timings
			int L = convert(k,h1,m1);
			int R = convert(k,h2,m2);
			busy[L]++;
			busy[R + 1]--;
		}
	}
	for(int i = 1 ; i < maxt ; ++i) {
		busy[i] += busy[i - 1];
	}
	//cerr << "here" << "\n";
	int lst = -1;
	for(int i = maxt - 1 ; i >= 0 ; --i) {
		if(!busy[i]) lst = i;
		if(lst != -1)  {
			F[i] = lst;
		}
	}
	for(int i = 1 ; i < maxt ; ++i) busy[i] += busy[i - 1];

	scanf("%d:%d-%d:%d",&h1,&m1,&h2,&m2);
	int p;
	int day;
	for(int i = 0 ; i < m ; ++i) {
		string str;
		cin >> str;

		scanf("%d %d:%d %d",&day,&h1,&m1,&p);
		--day;

		if(mp.find(str) == mp.end())
			continue;
		int t = convert(day,h1,m1);
		tasks.pb(Entry(mp[str],t,p,i));
	}
	sort(all(tasks));

	memset(dp,-1,sizeof(dp));
	cout << solve(0,0) << "\n";
	trace(0,0);
	printf("%d\n",sz(responses));
	REP(i,responses) {
		printf("%d %d %02d:%02d %d %02d:%02d\n",responses[i].ind + 1,responses[i].start_day + 1,responses[i].start_hour,
				responses[i].start_min,responses[i].end_day + 1,responses[i].end_hour,responses[i].end_min);
	}
}


#include <iostream>
#include <cstdio>
#include<list>
#include<iomanip>
#include<cmath>
#include<queue>
#include <functional>
#include<stdio.h>
#include<assert.h>
#include<stack>
#include<sstream>
#include <cstdlib>
#include<map>
#include<algorithm>
#include<iostream>
#include<set>
#include<utility>
#include<memory.h>
#include<string>
#include<vector>
#include<numeric>
#include <unordered_map>
using namespace std;
#define ll  long long
#define pb push_back
#define sz(v)               ((int)((v).size()))
#define all(x)          (x).begin(),(x).end()
#define REP(i, v)       for(int i=0;i<sz(v);i++)
typedef pair<int,int> pii;
#define ios std::ios_base::sync_with_stdio(false);
using namespace std;;
typedef vector<int> VI;
int n,m,k;
char s[101];
string rev[101];
int subjectTime[101];
map<string,int> mp;
set<pii> bad;
int id = 0;
int convert(int d,int h,int m ) {
	return d * 24 * 60  + h * 60 + m;
}
const int maxt = 30 * 24 * 60 + 24*60 + 60 + 10;
struct Entry {
	int subject;
	int deadline;
	int takes;
	int price;
	int index;
	Entry(int subject,int deadline,int price,int index) {
		this->subject = subject;
		this->deadline = deadline;
		this->price = price;
		this->takes = subjectTime[subject];
		this->index = index;
	}
	bool operator<(const Entry& o) const { return deadline < o.deadline; }

};
int busy[maxt];
vector<Entry> tasks;
int dp[101][1 << 20];
int getDelay(int start,int plus) {

	int lo = start, hi = convert(k,0,0);
	int ans = 1 << 30;
	while(lo <= hi) {
		int mid = lo + (hi - lo) / 2;
		int tot = mid - start + 1;
		tot -= busy[mid];
		if(start != 0) tot += busy[start - 1];
		if(tot >= plus) ans = mid,hi = mid - 1;
		else lo = mid + 1;
	}
	return ans;
}

int solve(int ind,int curr_t) {
	if(curr_t > maxt)
		return 1 << 30;
	if(ind == sz(tasks) )
		return 0;
	int &ret = dp[ind][curr_t];
	if(ret != -1)
		return ret;
	ret = 0;
	// leave current task
	ret = max(ret,solve(ind + 1,curr_t));
	// take current task
	int d = getDelay(curr_t,tasks[ind].takes);
	if(d < tasks[ind].deadline) {
		ret = max(ret,tasks[ind].price + solve(ind + 1,d + 1));
	}
	return ret;
}
struct Response {
	int ind;
	int end,start;
	int start_day,start_hour,start_min;
	int end_day,end_hour,end_min;

	Response(int ind,int start,int end) {
		this->ind  = ind;
		this-> end = end;
		this->start = start;
		go();
	}
	void go() {
		start_day = start/(1440);
		start %= 1440;
		start_hour = start / 60;
		start_min = start % 60;

		end_day = end/(1440);
		end %= 1440;
		end_hour = end / 60;
		end_min = end % 60;
	}

	bool operator<(const Response& o) const { return ind < o.ind; }

};
vector<Response> responses;
void trace(int ind,int curr_t) {

	if(ind == sz(tasks) )
		return;
	int ret = dp[ind][curr_t];
	ret = 0;
	int opt = solve(ind,curr_t);
	// leave current task
	ret = max(ret,solve(ind + 1,curr_t));
	if(opt == ret) {
		trace(ind + 1, curr_t);
		return;
	}
	// take current task
	int d = getDelay(curr_t,tasks[ind].takes);
	if(d < tasks[ind].deadline) {
		ret = max(ret,tasks[ind].price + solve(ind + 1,d + 1));
		responses.pb(Response(tasks[ind].index,curr_t,d));
		trace(ind + 1, d + 1);
	}

}
int main() {

	scanf("%d %d %d",&n,&m,&k);
	for (int i = 0 ; i < m ; ++i) {
		string str;
		cin >> str;
		mp[str] = i;
		rev[i] = str;
	}
	for (int i = 0 ; i < m ; ++i) {
		scanf("%d",&subjectTime[i]);
	}
	int h1,m1,h2,m2;
	// scan off time
	for(int i = 0 ; i < 4;  ++i) {
		scanf("%d:%d-%d:%d",&h1,&m1,&h2,&m2);
		for(int k = 0 ; k < 30 ; ++k) {
			// insert bad timings
			int L = convert(k,h1,m1);
			int R = convert(k,h2,m2);
			for(int j = L ; j <= R ; ++j)
				busy[j] = 1;
		}
	}
	for(int i = 1 ; i < maxt ; ++i) busy[i] += busy[i - 1];
	scanf("%d:%d-%d:%d",&h1,&m1,&h2,&m2);
	int p;
	int day;
	for(int i = 0 ; i < n ; ++i) {
		string str;
		cin >> str;

		scanf("%d %d:%d %d",&day,&h1,&m1,&p);
		--day;
		if(mp.find(str) == mp.end())
			continue;
		int t = convert(day,h1,m1);
		tasks.pb(Entry(mp[str],t,p,i));
	}
	sort(all(tasks));
	memset(dp,-1,sizeof(dp));
	cout << solve(0,0) << "\n";
	trace(0,0);
	sort(all(responses));
	printf("%d\n",sz(responses));
	REP(i,responses) {
		printf("%d %d %02d:%02d %d %02d:%02d\n",responses[i].ind + 1,responses[i].start_day + 1,responses[i].start_hour,
				responses[i].start_min,responses[i].end_day + 1,responses[i].end_hour,responses[i].end_min);
	}
}


#include <iostream>
#include <cstdio>
#include<list>
#include<iomanip>
#include<cmath>
#include<queue>
#include <functional>
#include<stdio.h>
#include<assert.h>
#include<stack>
#include<sstream>
#include <cstdlib>
#include<map>
#include<algorithm>
#include<iostream>
#include<set>
#include<utility>
#include<memory.h>
#include<string>
#include<vector>
#include<numeric>
#include <unordered_map>
using namespace std;
#define ll  long long
#define pb push_back
#define sz(v)               ((int)((v).size()))
#define all(x)          (x).begin(),(x).end()
#define REP(i, v)       for(int i=0;i<sz(v);i++)
typedef pair<int,int> pii;
#define ios std::ios_base::sync_with_stdio(false);
using namespace std;;
typedef vector<int> VI;
int n,m,k;
char s[101];
string rev[101];
int subjectTime[101];
map<string,int> mp;
int id = 0;
int convert(int d,int h,int m ) {
	return d * 24 * 60  + h * 60 + m;
}
const int maxt = 30 * 24 * 60 + 24*60 + 60 + 10;
struct Entry {
	int subject;
	int deadline;
	int takes;
	int price;
	int index;
	Entry(int subject,int deadline,int price,int index) {
		this->subject = subject;
		this->deadline = deadline;
		this->price = price;
		this->takes = subjectTime[subject];
		this->index = index;
	}
	bool operator<(const Entry& o) const {
		if(deadline == o.deadline)
			return index < o.index;
		return deadline < o.deadline;
	}

};
int F[maxt];
int busy[maxt];
vector<Entry> tasks;
int dp[101][maxt];
int getDelay(int start,int plus) {

	int lo = start, hi = maxt - 1;
	int ans = 1 << 30;
	while(lo <= hi) {
		int mid = lo + (hi - lo) / 2;
		int tot = mid - start + 1;
		tot -= busy[mid];
		if(start != 0) tot += busy[start - 1];
		if(tot >= plus) ans = mid,hi = mid - 1;
		else lo = mid + 1;
	}
	return ans;
}

int solve(int ind,int curr_t) {
	if(curr_t > maxt)
		return -(1 << 28);
	if(ind == sz(tasks) )
		return 0;
	int &ret = dp[ind][curr_t];
	if(ret != -1)
		return ret;
	ret = 0;
	// leave current task
	ret = max(ret,solve(ind + 1,curr_t));
	// take current task

	int d = getDelay(curr_t,tasks[ind].takes);
	//cerr << d << " " << tasks[ind].deadline << "\n";
	if(d < tasks[ind].deadline) {
		ret = max(ret,tasks[ind].price + solve(ind + 1,d + 1));
	}
	return ret;
}
struct Response {
	int ind;
	int end,start;
	int start_day,start_hour,start_min;
	int end_day,end_hour,end_min;
	int a;

	Response(int ind,int start,int end) {
		this->ind  = ind;
		this-> end = end;
		this->start = start;
		a = start;
		go();
	}
	void go() {

		start_day = start/(1440);
		start %= 1440;
		start_hour = start / 60;
		start_min = start % 60;

		end_day = end/(1440);
		end %= 1440;
		end_hour = end / 60;
		end_min = end % 60;
	}

	bool operator<(const Response& o) const {
		if(a == o.a)
			return ind < o.ind;
		return start < o.start; }

};
vector<Response> responses;
void trace(int ind,int curr_t) {

	if(ind == sz(tasks) )
		return;
	int ret = dp[ind][curr_t];
	ret = 0;
	int opt = solve(ind,curr_t);
	// leave current task
	ret = max(ret,solve(ind + 1,curr_t));
	if(opt == ret) {
		trace(ind + 1, curr_t);
		return;
	}
	// take current task
	int d = getDelay(curr_t,tasks[ind].takes);
	//cerr << d << " " << tasks[ind].deadline << "\n";
	if(d < tasks[ind].deadline) {

		ret = max(ret,tasks[ind].price + solve(ind + 1,d + 1));
		responses.pb(Response(tasks[ind].index,F[curr_t],d));
		trace(ind + 1, d + 1);
	}

}
int main() {

	scanf("%d %d %d",&n,&m,&k);
	for (int i = 0 ; i < n ; ++i) {
		string str;
		cin >> str;
		//cerr << str << "\n";
		mp[str] = i;
		rev[i] = str;
	}
	for (int i = 0 ; i < n ; ++i) {
		scanf("%d",&subjectTime[i]);
	}
	int h1,m1,h2,m2;
	// scan off time
	for(int i = 0 ; i < 4;  ++i) {
		scanf("%d:%d-%d:%d",&h1,&m1,&h2,&m2);
		for(int k = 0 ; k < 30 ; ++k) {
			// insert bad timings
			int L = convert(k,h1,m1);
			int R = convert(k,h2,m2);
			for(int j = L ; j <= R ; ++j)
				busy[j] = 1;
		}
	}
	//cerr << "here" << "\n";
	int lst = -1;
	for(int i = maxt - 1 ; i >= 0 ; --i) {
		if(!busy[i]) lst = i;
		if(lst != -1)  {
			F[i] = lst;
		}
	}
	for(int i = 1 ; i < maxt ; ++i) busy[i] += busy[i - 1];

	scanf("%d:%d-%d:%d",&h1,&m1,&h2,&m2);
	int p;
	int day;
	for(int i = 0 ; i < m ; ++i) {
		string str;
		cin >> str;

		scanf("%d %d:%d %d",&day,&h1,&m1,&p);
		--day;

		if(mp.find(str) == mp.end())
			continue;
		int t = convert(day,h1,m1);
		tasks.pb(Entry(mp[str],t,p,i));
	}
	sort(all(tasks));

	memset(dp,-1,sizeof(dp));
	cout << solve(0,0) << "\n";
	trace(0,0);

	printf("%d\n",sz(responses));
	REP(i,responses) {
		printf("%d %d %02d:%02d %d %02d:%02d\n",responses[i].ind + 1,responses[i].start_day + 1,responses[i].start_hour,
				responses[i].start_min,responses[i].end_day + 1,responses[i].end_hour,responses[i].end_min);
	}
}


#include <iostream>
#include <cstdio>
#include<list>
#include<iomanip>
#include<cmath>
#include<queue>
#include <functional>
#include<stdio.h>
#include<assert.h>
#include<stack>
#include<sstream>
#include <cstdlib>
#include<map>
#include<algorithm>
#include<iostream>
#include<set>
#include<utility>
#include<memory.h>
#include<string>
#include<vector>
#include<numeric>
#include <unordered_map>
using namespace std;
#define ll  long long
#define pb push_back
#define sz(v)               ((int)((v).size()))
#define all(x)          (x).begin(),(x).end()
#define REP(i, v)       for(int i=0;i<sz(v);i++)
typedef pair<int,int> pii;
#define ios std::ios_base::sync_with_stdio(false);
using namespace std;;
typedef vector<int> VI;
int n,m,k;
char s[101];
string rev[101];
int subjectTime[101];
map<string,int> mp;
int id = 0;
int convert(int d,int h,int m ) {
	return d * 24 * 60  + h * 60 + m;
}
const int maxt = 30 * 24 * 60 + 24*60 + 60 + 10;
struct Entry {
	int subject;
	int deadline;
	int takes;
	int price;
	int index;
	Entry(int subject,int deadline,int price,int index) {
		this->subject = subject;
		this->deadline = deadline;
		this->price = price;
		this->takes = subjectTime[subject];
		this->index = index;
	}
	bool operator<(const Entry& o) const {
		if(deadline == o.deadline)
			return index < o.index;
		return deadline < o.deadline;
	}

};
int F[maxt];
int busy[maxt];
vector<Entry> tasks;
int dp[101][maxt];
int getDelay(int start,int plus) {

	int lo = start, hi = maxt - 1;
	int ans = 1 << 30;
	while(lo <= hi) {
		int mid = lo + (hi - lo) / 2;
		int tot = mid - start + 1;
		tot -= busy[mid];
		if(start != 0) tot += busy[start - 1];
		if(tot >= plus) ans = mid,hi = mid - 1;
		else lo = mid + 1;
	}
	return ans;
}

int solve(int ind,int curr_t) {
	if(curr_t > maxt)
		return -(1 << 28);
	if(ind == sz(tasks) )
		return 0;
	int &ret = dp[ind][curr_t];
	if(ret != -1)
		return ret;
	ret = 0;
	// leave current task
	ret = max(ret,solve(ind + 1,curr_t));
	// take current task

	int d = getDelay(curr_t,tasks[ind].takes);
	cerr << d << " " << tasks[ind].deadline << "\n";
	if(d < tasks[ind].deadline) {
		ret = max(ret,tasks[ind].price + solve(ind + 1,d + 1));
	}
	return ret;
}
struct Response {
	int ind;
	int end,start;
	int start_day,start_hour,start_min;
	int end_day,end_hour,end_min;

	Response(int ind,int start,int end) {
		this->ind  = ind;
		this-> end = end;
		this->start = start;
		go();
	}
	void go() {
		start_day = start/(1440);
		start %= 1440;
		start_hour = start / 60;
		start_min = start % 60;

		end_day = end/(1440);
		end %= 1440;
		end_hour = end / 60;
		end_min = end % 60;
	}

	bool operator<(const Response& o) const {
		if(start == o.start)
			return ind < o.ind;
		return start < o.start; }

};
vector<Response> responses;
void trace(int ind,int curr_t) {

	if(ind == sz(tasks) )
		return;
	int ret = dp[ind][curr_t];
	ret = 0;
	int opt = solve(ind,curr_t);
	// leave current task
	ret = max(ret,solve(ind + 1,curr_t));
	if(opt == ret) {
		trace(ind + 1, curr_t);
		return;
	}
	// take current task
	int d = getDelay(curr_t,tasks[ind].takes);
	//cerr << d << " " << tasks[ind].deadline << "\n";
	if(d < tasks[ind].deadline) {

		ret = max(ret,tasks[ind].price + solve(ind + 1,d + 1));
		responses.pb(Response(tasks[ind].index,F[curr_t],d));
		trace(ind + 1, d + 1);
	}

}
int main() {

	scanf("%d %d %d",&n,&m,&k);
	for (int i = 0 ; i < n ; ++i) {
		string str;
		cin >> str;
		//cerr << str << "\n";
		mp[str] = i;
		rev[i] = str;
	}
	for (int i = 0 ; i < n ; ++i) {
		scanf("%d",&subjectTime[i]);
	}
	int h1,m1,h2,m2;
	// scan off time
	for(int i = 0 ; i < 4;  ++i) {
		scanf("%d:%d-%d:%d",&h1,&m1,&h2,&m2);
		for(int k = 0 ; k < 30 ; ++k) {
			// insert bad timings
			int L = convert(k,h1,m1);
			int R = convert(k,h2,m2);
			for(int j = L ; j <= R ; ++j)
				busy[j] = 1;
		}
	}
	//cerr << "here" << "\n";
	int lst = -1;
	for(int i = maxt - 1 ; i >= 0 ; --i) {
		if(!busy[i]) lst = i;
		if(lst != -1)  {
			F[i] = lst;
		}
	}
	for(int i = 1 ; i < maxt ; ++i) busy[i] += busy[i - 1];

	scanf("%d:%d-%d:%d",&h1,&m1,&h2,&m2);
	int p;
	int day;
	for(int i = 0 ; i < m ; ++i) {
		string str;
		cin >> str;

		scanf("%d %d:%d %d",&day,&h1,&m1,&p);
		--day;

		if(mp.find(str) == mp.end())
			continue;
		int t = convert(day,h1,m1);
		tasks.pb(Entry(mp[str],t,p,i));
	}
	sort(all(tasks));

	memset(dp,-1,sizeof(dp));
	cout << solve(0,0) << "\n";
	trace(0,0);
	sort(all(responses));
	printf("%d\n",sz(responses));
	REP(i,responses) {
		printf("%d %d %02d:%02d %d %02d:%02d\n",responses[i].ind + 1,responses[i].start_day + 1,responses[i].start_hour,
				responses[i].start_min,responses[i].end_day + 1,responses[i].end_hour,responses[i].end_min);
	}
}


#include <iostream>
#include <cstdio>
#include<list>
#include<iomanip>
#include<cmath>
#include<queue>
#include <functional>
#include<stdio.h>
#include<assert.h>
#include<stack>
#include<sstream>
#include <cstdlib>
#include<map>
#include<algorithm>
#include<iostream>
#include<set>
#include<utility>
#include<memory.h>
#include<string>
#include<vector>
#include<numeric>
#include <unordered_map>
using namespace std;
#define ll  long long
#define pb push_back
#define sz(v)               ((int)((v).size()))
#define all(x)          (x).begin(),(x).end()
#define REP(i, v)       for(int i=0;i<sz(v);i++)
typedef pair<int,int> pii;
#define ios std::ios_base::sync_with_stdio(false);
using namespace std;;
typedef vector<int> VI;
int n,m,k;
char s[101];
string rev[101];
int subjectTime[101];
map<string,int> mp;
set<pii> bad;
int id = 0;
int convert(int d,int h,int m ) {
	return d * 24 * 60  + h * 60 + m;
}
const int maxt = 30 * 24 * 60 + 24*60 + 60 + 10;
struct Entry {
	int subject;
	int deadline;
	int takes;
	int price;
	int index;
	Entry(int subject,int deadline,int price,int index) {
		this->subject = subject;
		this->deadline = deadline;
		this->price = price;
		this->takes = subjectTime[subject];
		this->index = index;
	}
	bool operator<(const Entry& o) const { return deadline < o.deadline; }

};
int busy[maxt];
vector<Entry> tasks;
int dp[101][maxt];
int getDelay(int start,int plus) {

	int lo = start, hi = convert(k,0,0);
	int ans = 1 << 30;
	while(lo <= hi) {
		int mid = lo + (hi - lo) / 2;
		int tot = mid - start + 1;
		tot -= busy[mid];
		if(start != 0) tot += busy[start - 1];
		if(tot >= plus) ans = mid,hi = mid - 1;
		else lo = mid + 1;
	}
	return ans;
}

int solve(int ind,int curr_t) {
	if(curr_t > maxt)
		return 1 << 30;
	if(ind == sz(tasks) )
		return 0;
	int &ret = dp[ind][curr_t];
	if(ret != -1)
		return ret;
	ret = 0;
	// leave current task
	ret = max(ret,solve(ind + 1,curr_t));
	// take current task
	int d = getDelay(curr_t,tasks[ind].takes);
	if(d < tasks[ind].deadline) {
		ret = max(ret,tasks[ind].price + solve(ind + 1,d + 1));
	}
	return ret;
}
struct Response {
	int ind;
	int end,start;
	int start_day,start_hour,start_min;
	int end_day,end_hour,end_min;

	Response(int ind,int start,int end) {
		this->ind  = ind;
		this-> end = end;
		this->start = start;
		go();
	}
	void go() {
		start_day = start/(1440);
		start %= 1440;
		start_hour = start / 60;
		start_min = start % 60;

		end_day = end/(1440);
		end %= 1440;
		end_hour = end / 60;
		end_min = end % 60;
	}

	bool operator<(const Response& o) const { return ind < o.ind; }

};
vector<Response> responses;
void trace(int ind,int curr_t) {

	if(ind == sz(tasks) )
		return;
	int ret = dp[ind][curr_t];
	ret = 0;
	int opt = solve(ind,curr_t);
	// leave current task
	ret = max(ret,solve(ind + 1,curr_t));
	if(opt == ret) {
		trace(ind + 1, curr_t);
		return;
	}
	// take current task
	int d = getDelay(curr_t,tasks[ind].takes);
	if(d < tasks[ind].deadline) {
		ret = max(ret,tasks[ind].price + solve(ind + 1,d + 1));
		responses.pb(Response(tasks[ind].index,curr_t,d));
		trace(ind + 1, d + 1);
	}

}
int main() {

	scanf("%d %d %d",&n,&m,&k);
	for (int i = 0 ; i < m ; ++i) {
		string str;
		cin >> str;
		mp[str] = i;
		rev[i] = str;
	}
	for (int i = 0 ; i < m ; ++i) {
		scanf("%d",&subjectTime[i]);
	}
	int h1,m1,h2,m2;
	// scan off time
	for(int i = 0 ; i < 4;  ++i) {
		scanf("%d:%d-%d:%d",&h1,&m1,&h2,&m2);
		for(int k = 0 ; k < 30 ; ++k) {
			// insert bad timings
			int L = convert(k,h1,m1);
			int R = convert(k,h2,m2);
			for(int j = L ; j <= R ; ++j)
				busy[j] = 1;
		}
	}
	for(int i = 1 ; i < maxt ; ++i) busy[i] += busy[i - 1];
	scanf("%d:%d-%d:%d",&h1,&m1,&h2,&m2);
	int p;
	int day;
	for(int i = 0 ; i < n ; ++i) {
		string str;
		cin >> str;

		scanf("%d %d:%d %d",&day,&h1,&m1,&p);
		--day;
		if(mp.find(str) == mp.end())
			continue;
		int t = convert(day,h1,m1);
		tasks.pb(Entry(mp[str],t,p,i));
	}
	sort(all(tasks));
	memset(dp,-1,sizeof(dp));
	cout << solve(0,0) << "\n";
	trace(0,0);
	sort(all(responses));
	printf("%d\n",sz(responses));
	REP(i,responses) {
		printf("%d %d %02d:%02d %d %02d:%02d\n",responses[i].ind + 1,responses[i].start_day + 1,responses[i].start_hour,
				responses[i].start_min,responses[i].end_day + 1,responses[i].end_hour,responses[i].end_min);
	}
}


#include <bits/stdc++.h>

using namespace std;

typedef long long lint;
typedef long double ldouble;

const int MINUTES_PER_DAY=60*24, N=110, TOTAL=N*MINUTES_PER_DAY;

struct Query {
	int t, p, r, id;
};

map<string, int> T;
vector<string> subjects;
bool can[TOTAL], chosen[TOTAL][N];
vector<pair<int, int>> busy;
int init[N][TOTAL], pay[N], dp[TOTAL][N], arr[N];
vector<Query> vet;
stack<Query> ans;

void back(int i, int j) {
	while (j) {
		if (chosen[i][j]) {
			ans.push({arr[j], init[j][i], i});
			if (!init[j][i]) break;
			i=init[j][i];
			j--;
		} else if (i and dp[i-1][j]>dp[i][j-1]) i--;
		else j--;
	}
	printf("%d\n", (int)ans.size());
	while (!ans.empty()) {
		Query x=ans.top();
		ans.pop();
		int id=x.t, t1=x.p, t2=x.r;
		int d1=t1/MINUTES_PER_DAY, h1=t1%MINUTES_PER_DAY/60, m1=t1%60;
		int d2=t2/MINUTES_PER_DAY, h2=t2%MINUTES_PER_DAY/60, m2=t2%60;
		printf("%d %d %02d:%02d %d %02d:%02d\n", id, d1, h1, m1, d2, h2, m2);
	}
}

int main() {
	int m, n, k;
	cin>>m>>n>>k;
	subjects.resize(m);
	for (int i=0; i<m; i++) {
		cin>>subjects[i];
	}
	for (int i=0; i<m; i++) {
		int x;
		cin>>x;
		T[subjects[i]]=x;
	}
	for (int i=0; i<4; i++) {
		string str;
		cin>>str;
		int h1, m1, h2, m2;
		sscanf(str.c_str(), "%d:%d-%d:%d", &h1, &m1, &h2, &m2);
		int t1=h1*60+m1, t2=h2*60+m2;
		if (t1<=t2) busy.push_back({t1, t2});
		else {
			busy.push_back({t1, MINUTES_PER_DAY-1});
			busy.push_back({0, t2});
		}
	}
	for (int i=1; i<=k; i++) for (int j=0; j<MINUTES_PER_DAY; j++) {
		bool valid=true;
		for (auto it: busy) if (j>=it.first and j<=it.second) valid=false;
		can[i*MINUTES_PER_DAY+j]=valid;
	}
	memset(init, -1, sizeof(init));
	for (int i=1; i<=n; i++) {
		string str, aux;
		int d, h, m;
		cin>>str>>d>>aux>>pay[i];
		sscanf(aux.c_str(), "%d:%d", &h, &m);
		if (T.find(str)==T.end()) continue;
		int t=-T[str];
		d=d*MINUTES_PER_DAY+h*60+m;
		vet.push_back({d, pay[i], t, i});
	}
	sort(vet.begin(), vet.end(), [](Query i, Query j){return i.t<j.t;});
	n=(int)vet.size();
	for (int i=0; i<n; i++) {
		int t=vet[i].r, d=vet[i].t, f=0;
		while (f<d and !can[f]) f++;
		int j=f;
		pay[i+1]=vet[i].p;
		arr[i+1]=vet[i].id;
		for (; j<d; j++) {
			t+=can[j];
			while (t>0) t-=can[f++];
			while (f<d and !can[f]) f++;
			if (!t) {
				init[i+1][j]=f;
			}
		}
	}
	for (int i=0; i<TOTAL; i++) for (int j=1; j<=n; j++) {
		dp[i][j]=dp[i][j-1];
		if (i and dp[i-1][j]>dp[i][j]) dp[i][j]=dp[i-1][j];
		if (init[j][i]!=-1) {
			int x=pay[j]+(init[j][i]?dp[init[j][i]-1][j-1]:0);
			if (dp[i][j]<x) {
				dp[i][j]=x;
				chosen[i][j]=true;
			}
		}
	}
	printf("%d\n", dp[TOTAL-1][n]);
	back(TOTAL-1, n);
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#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 <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;

//BEGINTEMPLATE_BY_ACRUSH_TOPCODER
#define SIZE(X) ((int)(X.size()))//NOTES:SIZE(
#define LENGTH(X) ((int)(X.length()))//NOTES:LENGTH(
#define MP(X,Y) make_pair(X,Y)//NOTES:MP(
typedef long long int64;//NOTES:int64
typedef unsigned long long uint64;//NOTES:uint64
#define two(X) (1<<(X))//NOTES:two(
#define twoL(X) (((int64)(1))<<(X))//NOTES:twoL(
#define contain(S,X) (((S)&two(X))!=0)//NOTES:contain(
#define containL(S,X) (((S)&twoL(X))!=0)//NOTES:containL(
const double pi=acos(-1.0);//NOTES:pi
const double eps=1e-11;//NOTES:eps
template<class T> inline void checkmin(T &a,T b){if(b<a) a=b;}//NOTES:checkmin(
template<class T> inline void checkmax(T &a,T b){if(b>a) a=b;}//NOTES:checkmax(
template<class T> inline T sqr(T x){return x*x;}//NOTES:sqr
typedef pair<int,int> ipair;//NOTES:ipair
template<class T> inline T lowbit(T n){return (n^(n-1))&n;}//NOTES:lowbit(
template<class T> inline int countbit(T n){return (n==0)?0:(1+countbit(n&(n-1)));}//NOTES:countbit(
//Numberic Functions
template<class T> inline T gcd(T a,T b)//NOTES:gcd(
  {if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template<class T> inline T lcm(T a,T b)//NOTES:lcm(
  {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}
template<class T> inline T euclide(T a,T b,T &x,T &y)//NOTES:euclide(
  {if(a<0){T d=euclide(-a,b,x,y);x=-x;return d;}
   if(b<0){T d=euclide(a,-b,x,y);y=-y;return d;}
   if(b==0){x=1;y=0;return a;}else{T d=euclide(b,a%b,x,y);T t=x;x=y;y=t-(a/b)*y;return d;}}
template<class T> inline vector<pair<T,int> > factorize(T n)//NOTES:factorize(
  {vector<pair<T,int> > R;for (T i=2;n>1;){if (n%i==0){int C=0;for (;n%i==0;C++,n/=i);R.push_back(make_pair(i,C));}
   i++;if (i>n/i) i=n;}if (n>1) R.push_back(make_pair(n,1));return R;}
template<class T> inline bool isPrimeNumber(T n)//NOTES:isPrimeNumber(
  {if(n<=1)return false;for (T i=2;i*i<=n;i++) if (n%i==0) return false;return true;}
template<class T> inline T eularFunction(T n)//NOTES:eularFunction(
  {vector<pair<T,int> > R=factorize(n);T r=n;for (int i=0;i<R.size();i++)r=r/R[i].first*(R[i].first-1);return r;}
//Matrix Operations
const int MaxMatrixSize=40;//NOTES:MaxMatrixSize
template<class T> inline void showMatrix(int n,T A[MaxMatrixSize][MaxMatrixSize])//NOTES:showMatrix(
  {for (int i=0;i<n;i++){for (int j=0;j<n;j++)cout<<A[i][j];cout<<endl;}}
template<class T> inline T checkMod(T n,T m) {return (n%m+m)%m;}//NOTES:checkMod(
template<class T> inline void identityMatrix(int n,T A[MaxMatrixSize][MaxMatrixSize])//NOTES:identityMatrix(
  {for (int i=0;i<n;i++) for (int j=0;j<n;j++) A[i][j]=(i==j)?1:0;}
template<class T> inline void addMatrix(int n,T C[MaxMatrixSize][MaxMatrixSize],T A[MaxMatrixSize][MaxMatrixSize],T B[MaxMatrixSize][MaxMatrixSize])//NOTES:addMatrix(
  {for (int i=0;i<n;i++) for (int j=0;j<n;j++) C[i][j]=A[i][j]+B[i][j];}
template<class T> inline void subMatrix(int n,T C[MaxMatrixSize][MaxMatrixSize],T A[MaxMatrixSize][MaxMatrixSize],T B[MaxMatrixSize][MaxMatrixSize])//NOTES:subMatrix(
  {for (int i=0;i<n;i++) for (int j=0;j<n;j++) C[i][j]=A[i][j]-B[i][j];}
template<class T> inline void mulMatrix(int n,T C[MaxMatrixSize][MaxMatrixSize],T _A[MaxMatrixSize][MaxMatrixSize],T _B[MaxMatrixSize][MaxMatrixSize])//NOTES:mulMatrix(
  { T A[MaxMatrixSize][MaxMatrixSize],B[MaxMatrixSize][MaxMatrixSize];
  for (int i=0;i<n;i++) for (int j=0;j<n;j++) A[i][j]=_A[i][j],B[i][j]=_B[i][j],C[i][j]=0;
  for (int i=0;i<n;i++) for (int j=0;j<n;j++) for (int k=0;k<n;k++) C[i][j]+=A[i][k]*B[k][j];}
template<class T> inline void addModMatrix(int n,T m,T C[MaxMatrixSize][MaxMatrixSize],T A[MaxMatrixSize][MaxMatrixSize],T B[MaxMatrixSize][MaxMatrixSize])//NOTES:addModMatrix(
  {for (int i=0;i<n;i++) for (int j=0;j<n;j++) C[i][j]=checkMod(A[i][j]+B[i][j],m);}
template<class T> inline void subModMatrix(int n,T m,T C[MaxMatrixSize][MaxMatrixSize],T A[MaxMatrixSize][MaxMatrixSize],T B[MaxMatrixSize][MaxMatrixSize])//NOTES:subModMatrix(
  {for (int i=0;i<n;i++) for (int j=0;j<n;j++) C[i][j]=checkMod(A[i][j]-B[i][j],m);}
template<class T> inline T multiplyMod(T a,T b,T m) {return (T)((((int64)(a)*(int64)(b)%(int64)(m))+(int64)(m))%(int64)(m));}//NOTES:multiplyMod(
template<class T> inline void mulModMatrix(int n,T m,T C[MaxMatrixSize][MaxMatrixSize],T _A[MaxMatrixSize][MaxMatrixSize],T _B[MaxMatrixSize][MaxMatrixSize])//NOTES:mulModMatrix(
  { T A[MaxMatrixSize][MaxMatrixSize],B[MaxMatrixSize][MaxMatrixSize];
  for (int i=0;i<n;i++) for (int j=0;j<n;j++) A[i][j]=_A[i][j],B[i][j]=_B[i][j],C[i][j]=0;
  for (int i=0;i<n;i++) for (int j=0;j<n;j++) for (int k=0;k<n;k++) C[i][j]=(C[i][j]+multiplyMod(A[i][k],B[k][j],m))%m;}
template<class T> inline T powerMod(T p,int e,T m)//NOTES:powerMod(
  {if(e==0)return 1%m;else if(e%2==0){T t=powerMod(p,e/2,m);return multiplyMod(t,t,m);}else return multiplyMod(powerMod(p,e-1,m),p,m);}
//Point&Line
double dist(double x1,double y1,double x2,double y2){return sqrt(sqr(x1-x2)+sqr(y1-y2));}//NOTES:dist(
double distR(double x1,double y1,double x2,double y2){return sqr(x1-x2)+sqr(y1-y2);}//NOTES:distR(
template<class T> T cross(T x0,T y0,T x1,T y1,T x2,T y2){return (x1-x0)*(y2-y0)-(x2-x0)*(y1-y0);}//NOTES:cross(
int crossOper(double x0,double y0,double x1,double y1,double x2,double y2)//NOTES:crossOper(
  {double t=(x1-x0)*(y2-y0)-(x2-x0)*(y1-y0);if (fabs(t)<=eps) return 0;return (t<0)?-1:1;}
bool isIntersect(double x1,double y1,double x2,double y2,double x3,double y3,double x4,double y4)//NOTES:isIntersect(
  {return crossOper(x1,y1,x2,y2,x3,y3)*crossOper(x1,y1,x2,y2,x4,y4)<0 && crossOper(x3,y3,x4,y4,x1,y1)*crossOper(x3,y3,x4,y4,x2,y2)<0;}
bool isMiddle(double s,double m,double t){return fabs(s-m)<=eps || fabs(t-m)<=eps || (s<m)!=(t<m);}//NOTES:isMiddle(
//Translator
bool isUpperCase(char c){return c>='A' && c<='Z';}//NOTES:isUpperCase(
bool isLowerCase(char c){return c>='a' && c<='z';}//NOTES:isLowerCase(
bool isLetter(char c){return c>='A' && c<='Z' || c>='a' && c<='z';}//NOTES:isLetter(
bool isDigit(char c){return c>='0' && c<='9';}//NOTES:isDigit(
char toLowerCase(char c){return (isUpperCase(c))?(c+32):c;}//NOTES:toLowerCase(
char toUpperCase(char c){return (isLowerCase(c))?(c-32):c;}//NOTES:toUpperCase(
template<class T> string toString(T n){ostringstream ost;ost<<n;ost.flush();return ost.str();}//NOTES:toString(
int toInt(string s){int r=0;istringstream sin(s);sin>>r;return r;}//NOTES:toInt(
int64 toInt64(string s){int64 r=0;istringstream sin(s);sin>>r;return r;}//NOTES:toInt64(
double toDouble(string s){double r=0;istringstream sin(s);sin>>r;return r;}//NOTES:toDouble(
template<class T> void stoa(string s,int &n,T A[]){n=0;istringstream sin(s);for(T v;sin>>v;A[n++]=v);}//NOTES:stoa(
template<class T> void atos(int n,T A[],string &s){ostringstream sout;for(int i=0;i<n;i++){if(i>0)sout<<' ';sout<<A[i];}s=sout.str();}//NOTES:atos(
template<class T> void atov(int n,T A[],vector<T> &vi){vi.clear();for (int i=0;i<n;i++) vi.push_back(A[i]);}//NOTES:atov(
template<class T> void vtoa(vector<T> vi,int &n,T A[]){n=vi.size();for (int i=0;i<n;i++)A[i]=vi[i];}//NOTES:vtoa(
template<class T> void stov(string s,vector<T> &vi){vi.clear();istringstream sin(s);for(T v;sin>>v;vi.push_bakc(v));}//NOTES:stov(
template<class T> void vtos(vector<T> vi,string &s){ostringstream sout;for (int i=0;i<vi.size();i++){if(i>0)sout<<' ';sout<<vi[i];}s=sout.str();}//NOTES:vtos(
//Fraction
template<class T> struct Fraction{T a,b;Fraction(T a=0,T b=1);string toString();};//NOTES:Fraction
  template<class T> Fraction<T>::Fraction(T a,T b){T d=gcd(a,b);a/=d;b/=d;if (b<0) a=-a,b=-b;this->a=a;this->b=b;}
  template<class T> string Fraction<T>::toString(){ostringstream sout;sout<<a<<"/"<<b;return sout.str();}
  template<class T> Fraction<T> operator+(Fraction<T> p,Fraction<T> q){return Fraction<T>(p.a*q.b+q.a*p.b,p.b*q.b);}
  template<class T> Fraction<T> operator-(Fraction<T> p,Fraction<T> q){return Fraction<T>(p.a*q.b-q.a*p.b,p.b*q.b);}
  template<class T> Fraction<T> operator*(Fraction<T> p,Fraction<T> q){return Fraction<T>(p.a*q.a,p.b*q.b);}
  template<class T> Fraction<T> operator/(Fraction<T> p,Fraction<T> q){return Fraction<T>(p.a*q.b,p.b*q.a);}
//ENDTEMPLATE_BY_ACRUSH_TOPCODER

const int maxsize=100+5;
const int maxs=30*1440+5;

int n,m,k,s;
int ID[30][1440],E1[maxs],E2[maxs];
map<string,int> MS;
int time_used[maxsize];
int p[maxsize],d[maxsize],g[maxsize],id[maxsize];
int f[maxsize][maxs];

void out_time(int s)
{
	printf("%d %02d:%02d",E1[s],E2[s]/60,E2[s]%60);
}
void out(int n,int s,int d=0)
{
	while (1)
	{
		if (s-1>=0 && f[n][s]==f[n][s-1]) s--;
		else if (n-1>=0 && f[n][s]==f[n-1][s]) n--;
		else break;
	}
	if (n==0 || s==0 || f[n][s]==0)
	{
		printf("%d\n",d);
		return;
	}
	out(n-1,s-g[n-1],d+1);
	printf("%d ",id[n-1]);
	out_time(s-g[n-1]+1);
	printf(" ");
	out_time(s);
	printf("\n");
}
int main()
{
#ifdef _MSC_VER
	freopen("input.txt","r",stdin);
#endif
	scanf("%d%d%d",&m,&n,&k);
	MS.clear();
	for (int i=0;i<m;i++)
	{
		char s[1024];
		scanf("%s",s);
		MS[s]=i;
	}
	for (int i=0;i<m;i++)
		scanf("%d",&time_used[i]);
	memset(ID,255,sizeof(ID));
	for (int i=0;i<4;i++)
	{
		char s[1024];
		scanf("%s",s);
		for (int k=0;s[k];k++) if (s[k]=='-' || s[k]==':') s[k]=' ';
		istringstream sin(s);
		int a1,b1,a2,b2;
		sin>>a1>>b1>>a2>>b2;
		a1=a1*60+b1;
		a2=a2*60+b2;
		ID[0][a1]=-2;
		ID[0][a2]=-2;
		for (;a1!=a2;a1=(a1+1)%1440) ID[0][a1]=-2;
	}
	s=0;
	for (int a=0;a<1440;a++)
		if (ID[0][a]==-1)
			ID[0][a]=(++s);
	for (int d=1;d<k;d++)
		for (int a=0;a<1440;a++)
			if (ID[0][a]>0)
				ID[d][a]=(++s);
	for (int ps=0,d=0;d<k;d++) for (int a=0;a<1440;a++)
		if (ID[d][a]>0)
		{
			ps=ID[d][a];
			E1[ps]=d+1;
			E2[ps]=a;
		}
		else
			ID[d][a]=ps;
	int count=0;
	for (int i=0;i<n;i++)
	{
		int day,price;
		char s1[1024],s2[1024];
		scanf("%s%d%s%d",s1,&day,s2,&price);
		day--;
		if (MS.find(s1)==MS.end())
			continue;
		for (int k=0;s2[k];k++) if (s2[k]==':') s2[k]=' ';
		istringstream sin(s2);
		int a,b;
		sin>>a>>b;
		a=a*60+b;
		if ((--a)<0) a=1440-1,day--;
		if (day<0) continue;
		if (ID[day][a]<=0)
			continue;
		id[count]=i+1;
		d[count]=ID[day][a];
		g[count]=time_used[MS[s1]];
		p[count++]=price;
	}
	n=count;
	for (int i=0;i<n;i++)
		for (int j=i+1;j<n;j++)
			if (d[j]<d[i])
			{
				swap(d[i],d[j]);
				swap(g[i],g[j]);
				swap(p[i],p[j]);
				swap(id[i],id[j]);
			}
	memset(f,0,sizeof(f));
	for (int step=0;step<n;step++)
	{
		int g0=g[step],p0=p[step],d0=d[step];
		int *current=f[step+1];
		int *prev=f[step];
		for (int i=0;i<=s;i++)
		{
			int key=prev[i];
			if (i-1>=0)
			{
				int t=current[i-1];
				if (t>key) key=t;
			}
			if (i<=d0 && i>=g0)
			{
				int t=prev[i-g0]+p0;
				if (t>key) key=t;
			}
			current[i]=key;
		}
	}
	printf("%d\n",f[n][s]);
	out(n,s);
	return 0;
}


#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <cassert>

using namespace std;

#define pb push_back
#define mp make_pair
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define foreach(e, x) for (__typeof(x.begin()) e = x.begin(); e != x.end(); ++e)
typedef long long LL;
typedef pair<int, int> PII;

const int T = 1440;
int m, n, k;
map<string, int> ma;
string s[100];
bool f[T * 30 + 3];
int sum[T * 30 + 3];
int taskT[100], taskDL[100], taskRew[100];
int d[T * 30 + 3][101] = {}, p[T * 30 + 3][101];
vector<string> ans;
int ord[100];

int strToTime(int d, string s) {
    --d;
    int t = ((s[0] - '0') * 10 + s[1] - '0') * 60 + (s[3] - '0') * 10 + s[4] - '0';
    t += d * T;
    return t;
}

string timeToStr(int t) {
    ostringstream oss;
    oss << t / T + 1 << ' ';
    t %= T;
    oss << t / 600;
    t %= 600;
    oss << t / 60 << ':';
    t %= 60;
    oss << t / 10;
    t %= 10;
    oss << t;
    return oss.str();
}

bool cmp(const int &lhs, const int &rhs) {
    return taskDL[lhs] < taskDL[rhs];
}

int main() {
    ios_base::sync_with_stdio(false);
    cin >> m >> n >> k;
    REP(i, m) cin >> s[i];
    REP(i, m) {
        int t;
        cin >> t;
        ma[s[i]] = t;
    }
    REP(i, T) f[i] = true;
    REP(i, 4) {
        string s;
        cin >> s;
        int from = ((s[0] - '0') * 10 + s[1] - '0') * 60 + (s[3] - '0') * 10 + s[4] - '0';
        int to = ((s[6] - '0') * 10 + s[7] - '0') * 60 + (s[9] - '0') * 10 + s[10] - '0';
        for (int j = from; j <= to; ++j) {
            f[j] = false;
        }
    }
    for (int i = 1; i < k; ++i) {
        int dif = i * T;
        REP(j, T) f[j + dif] = f[j];
    }
    sum[0] = 0;
    REP(i, k * T) sum[i + 1] = sum[i] + f[i];
    REP(i, n) {
        string s;
        cin >> s;
        auto it = ma.find(s);
        if (it == ma.end()) {
            taskT[i] = 100000;
        } else {
            taskT[i] = it->second;
        }
        int td;
        cin >> td >> s;
        taskDL[i] = strToTime(td, s);
        cin >> taskRew[i];
    }
    REP(i, n) ord[i] = i;
    sort(ord, ord + n, cmp);
    REP(i, k * T) REP(j, n) if (i == 0 || d[i][j] != 0) {
        int ind = ord[j];
        int lo = i, hi = taskDL[ind], mid;
        while (lo < hi) {
            mid = (lo + hi) >> 1;
            if (sum[mid + 1] - sum[i] < taskT[ind])
                lo = mid + 1;
            else
                hi = mid;
        }
        if (d[i][j + 1] < d[i][j]) {
            d[i][j + 1] = d[i][j];
            p[i][j + 1] = i;
        }
        if (lo < taskDL[ind] && d[lo + 1][j + 1] < d[i][j] + taskRew[ind]) {
            d[lo + 1][j + 1] = d[i][j] + taskRew[ind];
            p[lo + 1][j + 1] = i;
        }
    }
    int best = 0, ii = 0, jj = 0;
    REP(i, k * T + 1) REP(j, n + 1) if (d[i][j] > best) {
        best = d[i][j];
        ii = i;
        jj = j;
    }
    while (jj) {
        if (p[ii][jj] != ii) {
            ostringstream oss;
            oss << ord[jj - 1] + 1 << ' ';
            int begTime = p[ii][jj];
            while (!f[begTime]) ++begTime;
            oss << timeToStr(begTime) << ' ';
            oss << timeToStr(ii - 1);
            ans.pb(oss.str());
        }
        ii = p[ii][jj];
        --jj;
    }
    reverse(ans.begin(), ans.end());
    cout << best << '\n' << (int)ans.size() << '\n';
    for (string s : ans) cout << s << '\n';
    return 0;
}


#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;
}


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

map<string,int>isase;

struct info{
string s;
int d,h,m,c,f,id;
}help[101];

struct info_time{
int h,m,d;
}ar[100000],a[4][2];

struct info_ans{
int id,s,e;
}o;

vector<info_ans>vec;

int t,n,m;

bool fun(int i,int h,int m)
{
    int s,e,md;
    md=h*60+m;
    s=a[i][0].h*60+a[i][0].m;
    e=a[i][1].h*60+a[i][1].m;
    if(md>=s&&md<=e) return 0;
    return 1;
}

int dp[102][50000];

int go(int h,int m)
{
    if(h>=n) {
            dp[h][m]=0;
            return 0;
    }
    if(m>=t) {
            dp[h][m]=0;
            return 0;
    }

    if(dp[h][m]!=-1) return dp[h][m];

    int c1=0,c2=0,v;

    v=isase[help[h].s];

    if(v!=0&&m+v-1<=help[h].f&&help[h].f!=-1)
    {
        c1=help[h].c+go(h+1,m+v);
    }
    c2=go(h+1,m);
    return dp[h][m]=max(c1,c2);

}

void call(int h,int m)
{
    if(h>=n) {
            return ;
    }
    if(m>=t) {
            return ;
    }

    int c1=0,c2=0,v;

    v=isase[help[h].s];

    if(v!=0&&m+v-1<=help[h].f&&help[h].f!=-1)
    {
        c1=help[h].c+dp[h+1][m+v];
    }
    c2=dp[h+1][m];

    if(c1>c2)
    {
        o.id=h;
        o.s=m;
        o.e=m+v-1;
        vec.push_back(o);
        call(h+1,m+v);
    }
    else
    {
        call(h+1,m);
    }

    return ;

}

bool comp(info x,info y)
{
    return x.f<y.f;
}

int main()
{
    string s[101];
    int d,i,j,l,k;

     scanf("%d%d%d",&m,&n,&d);

    for(i=0;i<m;i++)
        cin>>s[i];
    for(i=0;i<m;i++)
    {
        scanf("%d",&t);
        isase[s[i]]=t;
    }

    for(i=0;i<4;i++)
    scanf("%d:%d-%d:%d",&a[i][0].h,&a[i][0].m,&a[i][1].h,&a[i][1].m);
    t=0;
    for(i=1;i<=d;i++)
    {
        for(j=0;j<24;j++)
        for(k=0;k<60;k++)
        {
            if(fun(0,j,k)&&fun(1,j,k)&&fun(2,j,k)&&fun(3,j,k))
            {
                ar[t].h=j;
                ar[t].m=k;
                ar[t].d=i;
                t++;
            }
        }
    }

    for(i=0;i<n;i++)
        {
            help[i].id=i;
            cin>>help[i].s;
            scanf("%d %d:%d %d",&help[i].d,&help[i].h,&help[i].m,&help[i].c);
            help[i].f=-1;
            for(j=0;j<t;j++)
                if(ar[j].d<help[i].d)
                {
                    help[i].f=j;
                }
                else if(ar[j].d==help[i].d)
                {
                     int e,m;
                      m=ar[j].h*60+ar[j].m;
                      e=help[i].h*60+help[i].m;
                    if(m<e)
                      help[i].f=j;
                }
        }

  sort(help,help+n,comp);

    memset(dp,-1,sizeof(dp));

    printf("%d\n",go(0,0));
    call(0,0);
    j=vec.size();

    printf("%d\n",j);

    for(i=0;i<j;i++)
    {
        printf("%d %d ",help[vec[i].id].id+1,ar[vec[i].s].d);
        if(ar[vec[i].s].h<10)printf("0%d:",ar[vec[i].s].h);
        else printf("%d:",ar[vec[i].s].h);
        if(ar[vec[i].s].m<10)printf("0%d",ar[vec[i].s].m);
        else printf("%d",ar[vec[i].s].m);
        printf(" %d ",ar[vec[i].e].d);
       if(ar[vec[i].e].h<10)printf("0%d:",ar[vec[i].e].h);
        else printf("%d:",ar[vec[i].e].h);
        if(ar[vec[i].e].m<10)printf("0%d\n",ar[vec[i].e].m);
        else printf("%d\n",ar[vec[i].e].m);

    }

}


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

map<string,int>isase;

struct info{
string s;
int d,h,m,c,f,id;
}help[101];

struct info_time{
int h,m,d;
}ar[100000],a[4][2];

struct info_ans{
int id,s,e;
}o;

vector<info_ans>vec;

int t,n,m;

bool fun(int i,int h,int m)
{
    int s,e,md;
    md=h*60+m;
    s=a[i][0].h*60+a[i][0].m;
    e=a[i][1].h*60+a[i][1].m;
    if(md>=s&&md<=e) return 0;
    return 1;
}

int dp[102][50000];

int go(int h,int m)
{
    if(h>=n) {
            dp[h][m]=0;
            return 0;
    }
    if(m>=t) {
            dp[h][m]=0;
            return 0;
    }

    if(dp[h][m]!=-1) return dp[h][m];

    int c1=0,c2=0,v;

    v=isase[help[h].s];

    if(v!=0&&m+v-1<=help[h].f&&help[h].f!=-1)
    {
        c1=help[h].c+go(h+1,m+v);
    }
    c2=go(h+1,m);
    return dp[h][m]=max(c1,c2);

}

void call(int h,int m)
{
    if(h>=n) {
            return ;
    }
    if(m>=t) {
            return ;
    }

    int c1=0,c2=0,v;

    v=isase[help[h].s];

    if(v!=0&&m+v-1<=help[h].f&&help[h].f!=-1)
    {
        c1=help[h].c+dp[h+1][m+v];
    }
    c2=dp[h+1][m];

    if(c1>c2)
    {
        o.id=h;
        o.s=m;
        o.e=m+v-1;
        vec.push_back(o);
        call(h+1,m+v);
    }
    else
    {
        call(h+1,m);
    }

    return ;

}

bool comp(info x,info y)
{
    return x.f<y.f;
}

int main()
{
    string s[101];
    int d,i,j,l,k;
    cin>>m>>n>>d;

    for(i=0;i<m;i++)
        cin>>s[i];
    for(i=0;i<m;i++)
    {
        cin>>t;
        isase[s[i]]=t;
    }

    for(i=0;i<4;i++)
    scanf("%d:%d-%d:%d",&a[i][0].h,&a[i][0].m,&a[i][1].h,&a[i][1].m);
    t=0;
    for(i=1;i<=d;i++)
    {
        for(j=0;j<24;j++)
        for(k=0;k<60;k++)
        {
            if(fun(0,j,k)&&fun(1,j,k)&&fun(2,j,k)&&fun(3,j,k))
            {
                ar[t].h=j;
                ar[t].m=k;
                ar[t].d=i;
                t++;
            }
        }
    }

    for(i=0;i<n;i++)
        {
            help[i].id=i;
            cin>>help[i].s;
            scanf("%d %d:%d %d",&help[i].d,&help[i].h,&help[i].m,&help[i].c);
            help[i].f=-1;
            for(j=0;j<t;j++)
                if(ar[j].d<help[i].d)
                {
                    help[i].f=j;
                }
                else if(ar[j].d==help[i].d)
                {
                     int e,m;
                      m=ar[j].h*60+ar[j].m;
                      e=help[i].h*60+help[i].m;
                    if(m<e)
                      help[i].f=j;
                }
        }

  sort(help,help+n,comp);

    memset(dp,-1,sizeof(dp));

    cout<<go(0,0)<<endl;
    call(0,0);
    cout<<vec.size()<<endl;

    for(i=0;i<vec.size();i++)
    {
        cout<<help[vec[i].id].id+1<<" "<<ar[vec[i].s].d<<" ";
        if(ar[vec[i].s].h<10)cout<<0<<ar[vec[i].s].h<<":";
        else cout<<ar[vec[i].s].h<<":";
        if(ar[vec[i].s].m<10)cout<<0<<ar[vec[i].s].m;
        else cout<<ar[vec[i].s].m;
        cout<<" "<<ar[vec[i].e].d<<" ";
        if(ar[vec[i].e].h<10)cout<<0<<ar[vec[i].e].h<<":";
        else cout<<ar[vec[i].e].h<<":";
        if(ar[vec[i].e].m<10)cout<<0<<ar[vec[i].e].m<<endl;
        else cout<<ar[vec[i].e].m<<endl;

    }

}


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

using namespace std;

int main() {
  int n, m, dd, hh, mm, t;
  int sep[16];
  char buf[80];
  vector<string> todo;
  map<string, int> cost;
  vector<pair<int, int> > time;
  vector<vector<pair<int, bool> > > dp;
  vector<pair<pair<int, int>, pair<int, int> > > job;

  scanf("%d%d%d", &n, &m, &dd);
  for (int i = 0; i < n; ++i) {
    scanf("%s", buf);
    todo.push_back(buf);
  }
  for (int i = 0; i < n; ++i) {
    scanf("%d", &cost[todo[i]]);
  }

  for (int i = 0; i < 8; ++i) {
    scanf("%*[^0-9]%d:%d", &hh, &mm);
    sep[i] = hh * 60 + mm;
  }
  for (int i = 1, k = 0; i <= dd; ++i) {
    for (int j = 0; j < 24 * 60; ++j) {
      if (k % 2 == 0 && j == sep[k]) {
        k = (k + 1) % 8;
      }
      if (k % 2 == 0) {
        time.push_back(make_pair(i, j));
      }
      if (k % 2 != 0 && j == sep[k]) {
        k = (k + 1) % 8;
      }
    }
  }

  for (int i = 0; i < m; ++i) {
    scanf("%s%d%d:%d%d", buf, &dd, &hh, &mm, &t);
    if (cost.count(buf) == 0) {
      continue;
    }
    job.push_back(make_pair(make_pair(lower_bound(time.begin(), time.end(),
                                                  make_pair(dd, hh * 60 + mm)) -
                                          time.begin(),
                                      i),
                            make_pair(cost[buf], t)));
  }
  sort(job.begin(), job.end());
  reverse(job.begin(), job.end());

  n = time.size();
  m = job.size();
  dp = vector<vector<pair<int, bool> > >(1, vector<pair<int, bool> >(n + 1));
  for (int i = 0; i < m; ++i) {
    t = job[i].second.first;
    dp.push_back(dp.back());
    for (int j = 0; j <= n; ++j) {
      dp[i + 1][j].second = false;
    }
    for (int j = t; j <= job[i].first.first; ++j) {
      if (dp[i + 1][j - t].first < dp[i][j].first + job[i].second.second) {
        dp[i + 1][j - t].first = dp[i][j].first + job[i].second.second;
        dp[i + 1][j - t].second = true;
      }
    }
  }

  printf("%d\n", dp[m][0].first);
  todo.clear();
  for (int i = m - 1, j = 0; i >= 0; --i) {
    if (dp[i + 1][j].second) {
      t = j + job[i].second.first - 1;
      sprintf(buf, "%d %d %02d:%02d %d %02d:%02d", job[i].first.second + 1,
              time[j].first, time[j].second / 60, time[j].second % 60,
              time[t].first, time[t].second / 60, time[t].second % 60);
      todo.push_back(buf);
      j = t + 1;
    }
  }
  printf("%d\n", todo.size());
  for (int i = 0; i < (int)todo.size(); ++i) {
    puts(todo[i].c_str());
  }

  return 0;
}


//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!//hello


//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!//hello//QwQ,It is Just a test


#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 (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";
    }

}