// In the name of God

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <complex>
#include <cmath>
#include <fstream>
#include <iomanip>
#define pb push_back
#define x first
#define y second

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> point;
typedef pair<int,int> pii;
typedef pair<pii,pii> ppii;

const int maxn = 100 + 10;

int n,m,k;
string l[maxn];
int t[maxn],T;
int w[5][3];
vector<pii> v;
ppii a[maxn];
int vis[24*30*60+10];
int cor[24*30*60+10];
int dp[maxn][24*30*60+10];
int par[maxn][24*30*60+10];

inline bool cmp(ppii fi,ppii se)
{
  return fi.x.y < se.x.y;
}

inline int solve(int work,int time)
{
  time++;
  int &ret = dp[work][time];
  if(ret > -1)
    return ret;

  if(work == 0)
    return ret = 0;

  int need = t[a[work].x.x];
  if(need <= time){
    int Max = solve(work-1,min(time-1-need,a[work-1].x.y) ) + a[work].y.x;
    int Max_ = solve(work-1,min(time-1,a[work-1].x.y) );
    if(Max > Max_)
      par[work][time] = 1;
    return ret = max(Max,Max_);
  }
  else
    return ret = solve(work-1,min(time-1,a[work-1].x.y) );
}

inline void Out_(int Time)
{
  int t = cor[Time];
  cout << t / 1440 + 1 << " ";
  int p,q;
  t %= 1440;
  p = t / 60;
  q = t % 60;
  if(p < 10)
    cout << '0' << p << ':';
  else
    cout << p << ':';
  if(q < 10)
    cout << '0' << q;
  else
    cout << q;
}

int main()
{
  ios_base::sync_with_stdio(false);

  cin >> n >> m >> k;
  for(int i=1;i<=n;++i)
    cin >> l[i];
  for(int i=1;i<=n;++i)
    cin >> t[i];
  for(int i=1;i<=4;++i){
    int p,q;
    int p_,q_;
    char g,g_;
    cin >> p >> g >> q >> g_ >> p_ >> g >> q_;
    w[i][1] = p*60+q;
    w[i][2] = p_*60+q_;
  }

  if(w[1][1] != 0)
    w[1][1] = w[1][1] - 24*60;
  for(int i=1;i<=k;++i)
    for(int j=1;j<=4;++j)
      v.pb(pii(24*60*(i-1)+w[j][1],24*60*(i-1)+w[j][2]) );

  if(v[0].x < 0){
    v.pb(pii(k*60*24+v[0].x,k*60*24) );
    v[0].x = 0;
  }

  for(int i=0;i<v.size();++i)
    for(int j=v[i].x;j<=v[i].y;++j)
      vis[j] = 1;

  int cp = m;
  for(int i=1,cur=1;i<=m;++i,cur++){
    string hlp;
    cin >> hlp;
    for(int j=1;j<=n;++j)
      if(hlp == l[j])
	a[i].x.x = j;
    int day;
    cin >> day;
    int p,q;
    char g;
    cin >> p >> g >> q;
    a[i].x.y = (day-1)*24*60+p*60+q;
    cin >> a[i].y.x;
    a[i].y.y = cur;
    if(a[i].x.x == 0){
      a[m] = a[i];
      i--;
      m--;
    }
  }

  for(int i=1;i<=m;++i){
    int q = 0;
    bool flag = false;
    for(int j=0;j<v.size();++j)
      if(a[i].x.y >= v[j].x)
	if(a[i].x.y > v[j].y)
	  q += v[j].y - v[j].x + 1;
	else{
	  q += a[i].x.y - v[j].x + 1;
	  flag = true;
	}
    a[i].x.y -= q;
    if(flag == false)
      a[i].x.y--;
  }

  sort(a+1,a+1+m,cmp);

  int cur = 0;
  for(int i=0;i<k*24*60;++i)
    if(vis[i] == 0){
      cor[cur++] = i;
      T++;
    }
  T--;

  //cerr << cor[0] << endl;

  memset(dp,-1,sizeof dp);
  cout << solve(m,min(a[m].x.y,T) ) << endl;

  vector<int> ans;
  int ind,time;
  time = min(a[m].x.y,T);
  ind = m;
  for(;ind > 0;){
    time++;
    int need = t[a[ind].x.x];
    int nex = par[ind][time];
    if(nex == 1){
      ans.push_back(ind);
      time = min(time-1-need,a[ind-1].x.y);
      ind--;
    }
    else{
      time = min(time-1,a[ind-1].x.y) ;
      ind--;
    }
  }

  cout << ans.size() << endl;
  int Min = 0;
  for(int i=ans.size()-1;i>=0;--i){
    cout << a[ans[i]].y.y << " ";
    Out_(Min);
    cout << " ";
    Out_(Min+t[a[ans[i]].x.x]-1);
    cout << endl;
    Min += t[a[ans[i]].x.x];
  }

  return 0;
}


// In the name of God

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <complex>
#include <cmath>
#include <fstream>
#include <iomanip>
#define pb push_back
#define x first
#define y second

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> point;
typedef pair<int,int> pii;
typedef pair<pii,pii> ppii;

const int maxn = 100 + 10;

int n,m,k;
string l[maxn];
int t[maxn],T;
int w[5][3];
vector<pii> v;
ppii a[maxn];
int vis[24*30*60+10];
int cor[24*30*60+10];
int dp[maxn][24*30*60+10];
int par[maxn][24*30*60+10];

inline bool cmp(ppii fi,ppii se)
{
  return fi.x.y < se.x.y;
}

inline int solve(int work,int time)
{
  time++;
  int &ret = dp[work][time];
  if(ret > -1)
    return ret;

  if(work == 0)
    return ret = 0;

  int need = t[a[work].x.x];
  if(need <= time){
    int Max = solve(work-1,min(time-1-need,a[work-1].x.y) ) + a[work].y.x;
    int Max_ = solve(work-1,min(time-1,a[work-1].x.y) );
    if(Max > Max_)
      par[work][time] = 1;
    return ret = max(Max,Max_);
  }
  else
    return ret = solve(work-1,min(time-1,a[work-1].x.y) );
}

inline void Out_(int Time)
{
  int t = cor[Time];
  cout << t / 1440 + 1 << " ";
  int p,q;
  t %= 1440;
  p = t / 60;
  q = t % 60;
  if(p < 10)
    cout << '0' << p << ':';
  else
    cout << p << ':';
  if(q < 10)
    cout << '0' << q;
  else
    cout << q;
}

int main()
{
  ios_base::sync_with_stdio(false);

  cin >> m >> n >> k;
  for(int i=1;i<=n;++i)
    cin >> l[i];
  for(int i=1;i<=n;++i)
    cin >> t[i];
  for(int i=1;i<=4;++i){
    int p,q;
    int p_,q_;
    char g,g_;
    cin >> p >> g >> q >> g_ >> p_ >> g >> q_;
    w[i][1] = p*60+q;
    w[i][2] = p_*60+q_;
  }

  if(w[1][1] != 0)
    w[1][1] = w[1][1] - 24*60;
  for(int i=1;i<=k;++i)
    for(int j=1;j<=4;++j)
      v.pb(pii(24*60*(i-1)+w[j][1],24*60*(i-1)+w[j][2]) );

  if(v[0].x < 0){
    v.pb(pii(k*60*24+v[0].x,k*60*24) );
    v[0].x = 0;
  }

  for(int i=0;i<v.size();++i)
    for(int j=v[i].x;j<=v[i].y;++j)
      vis[j] = 1;

  int cp = m;
  for(int i=1,cur=1;i<=m;++i,cur++){
    string hlp;
    cin >> hlp;
    for(int j=1;j<=n;++j)
      if(hlp == l[j])
	a[i].x.x = j;
    int day;
    cin >> day;
    int p,q;
    char g;
    cin >> p >> g >> q;
    a[i].x.y = (day-1)*24*60+p*60+q;
    cin >> a[i].y.x;
    a[i].y.y = cur;
    if(a[i].x.x == 0){
      a[m] = a[i];
      i--;
      m--;
    }
  }

  for(int i=1;i<=m;++i){
    int q = 0;
    bool flag = false;
    for(int j=0;j<v.size();++j)
      if(a[i].x.y >= v[j].x)
	if(a[i].x.y > v[j].y)
	  q += v[j].y - v[j].x + 1;
	else{
	  q += a[i].x.y - v[j].x + 1;
	  flag = true;
	}
    a[i].x.y -= q;
    if(flag == false)
      a[i].x.y--;
  }

  sort(a+1,a+1+m,cmp);

  int cur = 0;
  for(int i=0;i<k*24*60;++i)
    if(vis[i] == 0){
      cor[cur++] = i;
      T++;
    }
  T--;

  //cerr << cor[0] << endl;

  memset(dp,-1,sizeof dp);
  cout << solve(m,min(a[m].x.y,T) ) << endl;

  vector<int> ans;
  int ind,time;
  time = min(a[m].x.y,T);
  ind = m;
  for(;ind > 0;){
    time++;
    int need = t[a[ind].x.x];
    int nex = par[ind][time];
    if(nex == 1){
      ans.push_back(ind);
      time = min(time-1-need,a[ind-1].x.y);
      ind--;
    }
    else{
      time = min(time-1,a[ind-1].x.y) ;
      ind--;
    }
  }

  cout << ans.size() << endl;
  int Min = 0;
  for(int i=ans.size()-1;i>=0;--i){
    cout << a[ans[i]].y.y << " ";
    Out_(Min);
    cout << " ";
    Out_(Min+t[a[ans[i]].x.x]-1);
    cout << endl;
    Min += t[a[ans[i]].x.x];
  }

  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]=0;
			}
		}
		tmp=0;
		f[0][0]=0;
		for(i=1;i<=m;i++){
			//tmp+=p[i].t;
		//	if(p[i].nd==-1||p[i].val==0)continue;
			j=lower_bound(sum,sum+tot+1,tmp)-sum;
			//printf("***%d: find=%d id=%d ",i,tmp,j);
			j=min(j,tot);
			j=min(j,p[i].t-p[i].nd-1);
		//	printf("%d\n",j);
			for(;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(i==2&&j==570){
					printf("&&&&&%d %d %d\n",j,j+p[i].nd,k);
				}*/
				if(k>tot)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);
			}
			tmp+=p[i].nd;
		}
		int ans=0,id;
		for(i=0;i<=tot;i++){
			if(f[m][i]>ans){
				ans=f[m][i];
				id=i;
			}
		}
	//	printf("%d %d\n",ans,id);
		if(ans==0){
			printf("0\n0\n");
			continue;
		}
		printf("%d\n",ans);
		dfs(m,id,0);
	}
	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]=0;
			}
		}
		tmp=0;
		f[0][0]=0;
		for(i=1;i<=m;i++){
			//tmp+=p[i].t;
		//	if(p[i].nd==-1||p[i].val==0)continue;
			j=lower_bound(sum,sum+tot+1,tmp)-sum;
			//printf("***%d: find=%d id=%d ",i,tmp,j);
			j=min(j,tot);
			j=min(j,p[i].t-p[i].nd-1);
		//	printf("%d\n",j);
			for(;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(i==2&&j==570){
					printf("&&&&&%d %d %d\n",j,j+p[i].nd,k);
				}*/
				if(k>tot)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,id;
		for(i=0;i<=tot;i++){
			if(f[m][i]>ans){
				ans=f[m][i];
				id=i;
			}
		}
	//	printf("%d %d\n",ans,id);
		if(ans==0){
			printf("0\n0\n");
			continue;
		}
		printf("%d\n",ans);
		dfs(m,id,0);
	}
	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]=0;
            }
        }
        tmp=0;
        f[0][0]=0;
        for(i=1;i<=m;i++){
            j=lower_bound(sum,sum+tot+1,tmp)-sum;
            //printf("***%d: find=%d id=%d ",i,tmp,j);
            j=min(j,tot);
            j=min(j,p[i].t-p[i].nd-1);
        //  printf("%d\n",j);
            for(;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<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++){
			//tmp+=p[i].t;
		//	if(p[i].nd==-1||p[i].val==0)continue;
			j=lower_bound(sum,sum+tot+1,tmp)-sum;
			//printf("***%d: find=%d id=%d ",i,tmp,j);
			j=min(j,tot);
			j=min(j,p[i].t-p[i].nd-1);
		//	printf("%d\n",j);
			for(;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(i==2&&j==570){
					printf("&&&&&%d %d %d\n",j,j+p[i].nd,k);
				}*/
				if(k>tot)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);
			}
			tmp+=p[i].nd;
		}
		int ans=0,id;
		for(i=0;i<=tot;i++){
			if(f[m][i]>ans){
				ans=f[m][i];
				id=i;
			}
		}
	//	printf("%d %d\n",ans,id);
		if(ans==0){
			printf("0\n0\n");
			continue;
		}
		printf("%d\n",ans);
		dfs(m,id,0);
	}
	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[31*day][2];
int sum[31*day];
int mark[31*day],f[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 now,int cnt)
{
    if(now==0){
        printf("%d\n",cnt);
        return;
    }
    dfs(pre[now][0],cnt+1);
    int id=pre[now][1];
    int d1,h1,m1,d2,h2,m2;
    int kk=lower_bound(sum,sum+tot+1,sum[pre[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++){
            f[i]=0;
            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];
        }
        tmp=0;
        for(i=1;i<=m;i++){
            //tmp+=p[i].t;
            if(p[i].nd==-1||p[i].val==0)continue;
            j=lower_bound(sum,sum+tot+1,tmp)-sum;
            //printf("***%d: find=%d id=%d ",i,tmp,j);
            j=min(j,tot);
            j=min(j,p[i].t-p[i].nd-1);
        //  printf("%d\n",j);
            for(;j>=0;j--){
                k=lower_bound(sum,sum+tot+1,sum[j]+p[i].nd)-sum;
            /*  if(i==2&&j==570){
                    printf("&&&&&%d %d %d\n",j,j+p[i].nd,k);
                }*/
                if(k>tot)continue;
                if(f[j]+p[i].val>=f[k]){
                    f[k]=f[j]+p[i].val;
                    pre[k][0]=j;
                    pre[k][1]=i;
                }
                //f[k]=max(f[k],f[j]+p[i].val);
            }
            tmp+=p[i].nd;
        }
        int ans=0,id;
        for(i=0;i<=tot;i++){
            if(f[i]>ans){
                ans=f[i];
                id=i;
            }
        }
    //  printf("%d %d\n",ans,id);
        if(ans==0){
            printf("0\n0\n");
            continue;
        }
        printf("%d\n",ans);
        dfs(id,0);
    }
    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<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]=0;
			}
		}
		tmp=0;
		f[0][0]=0;
		for(i=1;i<=m;i++){
			//tmp+=p[i].t;
		//	if(p[i].nd==-1||p[i].val==0)continue;
			j=lower_bound(sum,sum+tot+1,tmp)-sum;
			//printf("***%d: find=%d id=%d ",i,tmp,j);
			j=min(j,tot);
			j=min(j,p[i].t-p[i].nd-1);
		//	printf("%d\n",j);
			for(;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(i==2&&j==570){
					printf("&&&&&%d %d %d\n",j,j+p[i].nd,k);
				}*/
				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,id;
		for(i=0;i<=tot;i++){
			if(f[m][i]>ans){
				ans=f[m][i];
				id=i;
			}
		}
	//	printf("%d %d\n",ans,id);
		if(ans==0){
			printf("0\n0\n");
			continue;
		}
		printf("%d\n",ans);
		dfs(m,id,0);
	}
	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]=0;
            }
        }
        tmp=0;
        f[0][0]=0;
        for(i=1;i<=m;i++){
            //tmp+=p[i].t;
        //  if(p[i].nd==-1||p[i].val==0)continue;
            j=lower_bound(sum,sum+tot+1,tmp)-sum;
            //printf("***%d: find=%d id=%d ",i,tmp,j);
            j=min(j,tot);
            j=min(j,p[i].t-p[i].nd-1);
        //  printf("%d\n",j);
            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(i==2&&j==570){
                    printf("&&&&&%d %d %d\n",j,j+p[i].nd,k);
                }*/
                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<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[31*day][2];
int sum[31*day];
int mark[31*day],f[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 now,int cnt)
{
    if(now==0){
        printf("%d\n",cnt);
        return;
    }
    dfs(pre[now][0],cnt+1);
    int id=pre[now][1];
    int d1,h1,m1,d2,h2,m2;
    int kk=lower_bound(sum,sum+tot+1,sum[pre[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++){
            f[i]=0;
            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];
        }
        tmp=0;
        for(i=1;i<=m;i++){
            //tmp+=p[i].t;
            if(p[i].nd==-1||p[i].val==0)continue;
            j=lower_bound(sum,sum+tot+1,tmp)-sum;
            //printf("***%d: find=%d id=%d ",i,tmp,j);
            j=min(j,tot);
            j=min(j,p[i].t-p[i].nd-1);
        //  printf("%d\n",j);
            for(;j>=0;j--){
                k=lower_bound(sum,sum+tot+1,sum[j]+p[i].nd)-sum;
            /*  if(i==2&&j==570){
                    printf("&&&&&%d %d %d\n",j,j+p[i].nd,k);
                }*/
                if(k>tot)continue;
                if(f[j]+p[i].val>=f[k]){
                    f[k]=f[j]+p[i].val;
                    pre[k][0]=j;
                    pre[k][1]=i;
                }
                //f[k]=max(f[k],f[j]+p[i].val);
            }
            tmp+=p[i].nd;
        }
        int ans=0,id;
        for(i=0;i<=tot;i++){
            if(f[i]>ans){
                ans=f[i];
                id=i;
            }
        }
    //  printf("%d %d\n",ans,id);
        if(ans==0){
            printf("0\n");
            continue;
        }
        printf("%d\n",ans);
        dfs(id,0);
    }
    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;
}


// 10 monthes remaining for red =D
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;

const int maxtime=50000;
map<string,int>sub;
int rest[4][2];
int tme[maxtime];
int val[100+10][maxtime];
int lastk[100+10][maxtime];
int last[100+10][maxtime];
int tot;
int fromTime(int d,int hh,int mm){
	return (d-1)*24*60 + hh*60 + mm;
}
void toTime(int v,int& d,int& hh,int &mm){
	mm=v%60;
	v/=60;
	hh=v%24;
	v/=24;
	d=v+1;
}
bool isRest(int hh,int mm){
	int it=fromTime(1,hh,mm);
	for(int i=0;i<4;i++){
		if(it>=rest[i][0] && it<=rest[i][1])
			return true;
	}
	return false;
}

struct employ{
	int dl;
	int idx;
	int len,pay;
	bool friend operator < (const employ& p1,const employ& p2){
		return p1.dl<p2.dl;
	}
};
int n,m,nk;
string names[100+10];
char line[100+10];
employ es[100+10];
void pass(int idx){
	copy(val[idx - 1],val[idx - 1]+tot,val[idx]);
	copy(last[idx - 1],last[idx - 1]+tot,last[idx]);
	copy(lastk[idx - 1],lastk[idx - 1]+tot,lastk[idx]);
	int cost=es[idx].len;
	int i;
	for(i=tot-1;i>=0 && tme[i]>=es[idx].dl;i--);
	if(i<cost)return;
	for(;i>=cost;i--){
		if(val[idx][i-cost] + es[idx].pay > val[idx][i]){
			val[idx][i]= val[idx][i-cost] + es[idx].pay;
			last[idx][i] = idx;
			lastk[idx][i] = idx - 1;
		}
	}
}

void output(int x,int k){
	if(last[k][x]<=0)return;
	output(x - es[last[k][x]].len,lastk[k][x]);
	int dd,h1,m1,dl,h2,m2;
	toTime(tme[x],dd,h1,m1);
	toTime(tme[x-es[last[k][x]].len+1],dl,h2,m2);
	printf("%d %d %02d:%02d %d %02d:%02d\n",es[last[k][x]].idx,
			dl,h2,m2,dd,h1,m1);
}
int main(){
	cin>>m>>n>>nk;
	int cost,dd,h1,m1,h2,dl,m2;
	for(int i=0;i<m;i++){
		cin>>names[i];
	}
	for(int i=0;i<m;i++){
		cin>>cost;
		sub.insert(make_pair(names[i],cost));
	}
	for(int i=0;i<4;i++){
		cin>>line;
		sscanf(line,"%d:%d-%d:%d",&h1,&m1,&h2,&m2);
		rest[i][0]=fromTime(1,h1,m1);
		rest[i][1]=fromTime(1,h2,m2);
	}
	tot=1;
	tme[0]=-1;
	for(int i=1;i<=nk;i++)
		for(int j=0;j<=23;j++)
			for(int k=0;k<=59;k++){
				if(!isRest(j,k))
					tme[tot++]=fromTime(i,j,k);
			}
	/*for(int i=0;i<tot;i++)
		cout<<tme[i]<<' ';
	cout<<endl;*/
	fill(last[0],last[0]+tot,-1);
	fill(lastk[0],lastk[0]+tot,-1);
	fill(val[0],val[0]+tot,0);
	string csub;
	int pay;
	int k=1;
	for(int i=1;i<=n;i++){
		cin>>csub>>dd>>line>>pay;
		sscanf(line,"%d:%d",&h1,&m1);
		if(sub.find(csub)!=sub.end()){
			es[k].len=sub[csub];
			es[k].dl=fromTime(dd,h1,m1);
			es[k].pay = pay;
			es[k].idx=i;
			k++;
		}
	}
	n = k - 1;
	sort(es+1,es+1+n);
	int besti=-1,best=0;
	for(int i=1;i<=n;i++){
		pass(i);
	}

	for(int i=1;i<tot;i++){
		if(last[n][i]>0 && val[n][i]>best){
			best=val[n][i];
			besti=i;
		}
	}
	if(besti<0)
		printf("0\n0\n");
	else{
		printf("%d\n",best);
		int j=besti,k=n,tj;
		int cnt=0;
		while(last[k][j]>0){
			cnt++;
			tj = j - es[last[k][j]].len;
			k = lastk[k][j];
			j = tj;
		}
		printf("%d\n",cnt);
		j = besti;
		output(j,n);
	}
	return 0;
}


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


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

struct Student
{
    int dur, bytime, pay, index;
};

const int MAXN = 101;
const int MAXTIMEMINS = 50000;
int n, m, tdays, mt1, mtall;
map<string ,int> slist;
int stime[MAXN];
int schedule[4][2];
int dp[MAXTIMEMINS];
int pre[MAXTIMEMINS];
int ansarr[MAXN][2];
int anslen;
int helplist[MAXN];
int paylist[MAXN];
Student stus[MAXN];

bool comp(Student a, Student b)
{
    return a.bytime < b.bytime || a.bytime == b.bytime && a.pay > b.pay;
}

int TimeDiff(int a, int b)
{
    return a / 100 * 60 + a % 100 - b / 100 * 60 - b % 100;
}

void ConverTimeToInt(char *timest, int *a)
{
    a[0] = (timest[0] - '0') * 1000 + (timest[1] - '0') * 100 + (timest[3] - '0') * 10 + (timest[4] - '0') * 1;
    a[1] = (timest[6] - '0') * 1000 + (timest[7] - '0') * 100 + (timest[9] - '0') * 10 + (timest[10] - '0') * 1;

    return;
}

int CalcMaxTime()
{
    int ret = 0;

    ret += TimeDiff(schedule[0][0], 0);
    for(int i = 0; i < 3; i ++)
        ret += TimeDiff(schedule[i + 1][0], schedule[i][1]) - 1;
    ret += TimeDiff(2359, schedule[3][1]);
    return ret;
}

int CalcTimeInDay(int t)
{
    int ret = 0;

    if(t >= schedule[0][0])
        ret += TimeDiff(schedule[0][0], 0);
    else
    {
        ret += TimeDiff(t, 0) + 1;
        return ret;
    }

    for(int i = 0; i < 3; i ++)
    if(t >= schedule[i + 1][0])
        ret += TimeDiff(schedule[i + 1][0], schedule[i][1]) - 1;
    else
    {
        ret += max(TimeDiff(t, schedule[i][1]), 0);
        return ret;
    }

    ret += max(TimeDiff(t, schedule[3][1]), 0);

    return ret;
}

int ConvertTimeByDelta(int starttime, int delta)
{
    return (starttime / 100 + (starttime % 100 + delta) / 60) * 100 + (starttime % 100 + delta) % 60;
}

int IntToTime(int t)
{
    int sum = 0, ret;

    if(TimeDiff(schedule[0][0], 0) >= t)
    {
        ret = ConvertTimeByDelta(0, t - 1);
        return ret;
    }
    else
        sum += TimeDiff(schedule[0][0], 0);

    for(int i = 0; i < 3; i ++)
    if(sum + TimeDiff(schedule[i + 1][0], schedule[i][1]) - 1 < t)
        sum += TimeDiff(schedule[i + 1][0], schedule[i][1]) - 1;
    else
    {
        ret = ConvertTimeByDelta(schedule[i][1], t - sum);
        return ret;
    }

    ret = ConvertTimeByDelta(schedule[3][1], t - sum);

    return ret;
}

int CalcMinutes(int day, char *t)
{
    int t0 = (t[0] - '0') * 1000 + (t[1] - '0') * 100 + (t[3] - '0') * 10 + (t[4] - '0');

    return (day - 1) * mt1 + CalcTimeInDay(t0 - 1);
}

void PrintTime(int t)
{
    printf(" %d", (t - 1) / mt1 + 1);
    int s = IntToTime((t - 1) % mt1 + 1);
    printf(" %02d:%02d", s / 100, s % 100);

    return;
}

int main()
{
    char st[40], st0[40], st1[40];
    int ans, ansk;

    // freopen("D:\\1.in", "r", stdin);
    // freopen("D:\\1.out", "w", stdout);

    scanf("%d%d%d", &m, &n, &tdays);
    for(int i = 0; i < m; i ++)
        scanf("%s", st), slist[st] = i;
    for(int i = 0; i < m; i ++)
        scanf("%d", &(stime[i]));

    for(int i = 0; i < 4; i ++)
        scanf("%s", st), ConverTimeToInt(st, schedule[i]);

    mt1 = CalcMaxTime();
    mtall = mt1 * tdays;

    ans = 0; ansk = 0;
    for(int i = 0; i < n; i ++)
    {
        int byday, pay, sindex, dur, bytime;
        scanf("%s%d%s%d", st0, &byday, st1, &pay);
        if(slist.find(st0) == slist.end())
        {
            stus[i].index = -1;
            continue;
        }
        sindex = slist[st0];
        dur = stime[sindex];
        bytime = CalcMinutes(byday, st1);
        helplist[i + 1] = dur;
        paylist[i + 1] = pay;

        stus[i].bytime = bytime;
        stus[i].dur = dur;
        stus[i].index = i + 1;
        stus[i].pay = pay;
    }

    sort(stus, stus + n, comp);

    for(int i = 1; i < MAXTIMEMINS; i ++)
        dp[i] = -1;
    dp[0] = 0;

    for(int i = 0; i < n; i ++)
    {
        if(stus[i].index == -1)
            continue;
        for(int j = stus[i].bytime; j >= stus[i].dur; j --)
        if(dp[j - stus[i].dur] != -1 && dp[j - stus[i].dur] + stus[i].pay > dp[j])
        {
            dp[j] = dp[j - stus[i].dur] + stus[i].pay, pre[j] = stus[i].index;
            if(dp[j] > ans)
                ans = dp[j], ansk = j;
        }
    }

    printf("%d\n", ans);
    while(ans > 0)
    {
        ans -= paylist[pre[ansk]];
        ansarr[anslen][0] = pre[ansk];
        ansk = ansk - helplist[pre[ansk]];
        ansarr[anslen][1] = ansk + 1;
        anslen ++;
    }
    printf("%d\n", anslen);
    for(int i = anslen - 1; i >= 0; i --)
    {
        printf("%d", ansarr[i][0]);
        PrintTime(ansarr[i][1]);
        PrintTime(ansarr[i][1] + helplist[ansarr[i][0]] - 1);
        printf("\n");
    }

	return 0;
}


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

struct Student
{
    int dur, bytime, pay, index;
};

const int MAXN = 101;
const int MAXTIMEMINS = 50000;
int n, m, tdays, mt1, mtall;
map<string ,int> slist;
int stime[MAXN];
int schedule[4][2];
int dp[MAXTIMEMINS];
int pre[MAXTIMEMINS];
int ansarr[MAXN][2];
int anslen;
int helplist[MAXN];
Student stus[MAXN];

bool comp(Student a, Student b)
{
    return a.bytime < b.bytime || a.bytime == b.bytime && a.pay > b.pay;
}

int TimeDiff(int a, int b)
{
    return a / 100 * 60 + a % 100 - b / 100 * 60 - b % 100;
}

void ConverTimeToInt(char *timest, int *a)
{
    a[0] = (timest[0] - '0') * 1000 + (timest[1] - '0') * 100 + (timest[3] - '0') * 10 + (timest[4] - '0') * 1;
    a[1] = (timest[6] - '0') * 1000 + (timest[7] - '0') * 100 + (timest[9] - '0') * 10 + (timest[10] - '0') * 1;

    return;
}

int CalcMaxTime()
{
    int ret = 0;

    ret += TimeDiff(schedule[0][0], 0);
    for(int i = 0; i < 3; i ++)
        ret += TimeDiff(schedule[i + 1][0], schedule[i][1]) - 1;
    ret += TimeDiff(2359, schedule[3][1]);
    return ret;
}

int CalcTimeInDay(int t)
{
    int ret = 0;

    if(t >= schedule[0][0])
        ret += TimeDiff(schedule[0][0], 0);
    else
    {
        ret += TimeDiff(t, 0) + 1;
        return ret;
    }

    for(int i = 0; i < 3; i ++)
    if(t >= schedule[i + 1][0])
        ret += TimeDiff(schedule[i + 1][0], schedule[i][1]) - 1;
    else
    {
        ret += max(TimeDiff(t, schedule[i][1]), 0);
        return ret;
    }

    ret += max(TimeDiff(t, schedule[3][1]), 0);

    return ret;
}

int ConvertTimeByDelta(int starttime, int delta)
{
    return (starttime / 100 + (starttime % 100 + delta) / 60) * 100 + (starttime % 100 + delta) % 60;
}

int IntToTime(int t)
{
    int sum = 0, ret;

    if(TimeDiff(schedule[0][0], 0) >= t)
    {
        ret = ConvertTimeByDelta(0, t - 1);
        return ret;
    }
    else
        sum += TimeDiff(schedule[0][0], 0);

    for(int i = 0; i < 3; i ++)
    if(sum + TimeDiff(schedule[i + 1][0], schedule[i][1]) - 1 < t)
        sum += TimeDiff(schedule[i + 1][0], schedule[i][1]) - 1;
    else
    {
        ret = ConvertTimeByDelta(schedule[i][1], t - sum);
        return ret;
    }

    ret = ConvertTimeByDelta(schedule[3][1], t - sum);

    return ret;
}

int CalcMinutes(int day, char *t)
{
    int t0 = (t[0] - '0') * 1000 + (t[1] - '0') * 100 + (t[3] - '0') * 10 + (t[4] - '0');

    return (day - 1) * mt1 + CalcTimeInDay(t0 - 1);
}

void PrintTime(int t)
{
    printf(" %d", (t - 1) / mt1 + 1);
    int s = IntToTime((t - 1) % mt1 + 1);
    printf(" %02d:%02d", s / 100, s % 100);

    return;
}

int main()
{
    char st[40], st0[40], st1[40];
    int ans, ansk;

    // freopen("D:\\1.in", "r", stdin);
    // freopen("D:\\1.out", "w", stdout);

    scanf("%d%d%d", &m, &n, &tdays);
    for(int i = 0; i < m; i ++)
        scanf("%s", st), slist[st] = i;
    for(int i = 0; i < m; i ++)
        scanf("%d", &(stime[i]));

    for(int i = 0; i < 4; i ++)
        scanf("%s", st), ConverTimeToInt(st, schedule[i]);

    mt1 = CalcMaxTime();
    mtall = mt1 * tdays;

    ans = 0; ansk = 0;
    for(int i = 0; i < n; i ++)
    {
        int byday, pay, sindex, dur, bytime;
        scanf("%s%d%s%d", st0, &byday, st1, &pay);
        if(slist.find(st0) == slist.end())
        {
            stus[i].index = -1;
            continue;
        }
        sindex = slist[st0];
        dur = stime[sindex];
        bytime = CalcMinutes(byday, st1);
        helplist[i + 1] = dur;

        stus[i].bytime = bytime;
        stus[i].dur = dur;
        stus[i].index = i + 1;
        stus[i].pay = pay;
    }

    sort(stus, stus + n, comp);

    for(int i = 0; i < n; i ++)
    {
        if(stus[i].index == -1)
            continue;
        for(int j = stus[i].bytime; j >= stus[i].dur; j --)
        if(dp[j - stus[i].dur] + stus[i].pay > dp[j])
        {
            dp[j] = dp[j - stus[i].dur] + stus[i].pay, pre[j] = stus[i].index;
            if(dp[j] > ans)
                ans = dp[j], ansk = j;
        }
    }

    printf("%d\n", ans);
    while(pre[ansk] > 0)
    {
        ansarr[anslen][0] = pre[ansk];
        ansk = ansk - helplist[pre[ansk]];
        ansarr[anslen][1] = ansk + 1;
        anslen ++;
    }
    printf("%d\n", anslen);
    for(int i = anslen - 1; i >= 0; i --)
    {
        printf("%d", ansarr[i][0]);
        PrintTime(ansarr[i][1]);
        PrintTime(ansarr[i][1] + helplist[ansarr[i][0]] - 1);
        printf("\n");
    }

	return 0;
}


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

struct Student
{
    int dur, bytime, pay, index;
};

const int MAXN = 101;
const int MAXTIMEMINS = 50000;
int n, m, tdays, mt1, mtall;
map<string ,int> slist;
int stime[MAXN];
int schedule[4][2];
int dp[MAXTIMEMINS];
int pre[MAXTIMEMINS];
int ansarr[MAXN][2];
int anslen;
int helplist[MAXN];
Student stus[MAXN];

bool comp(Student a, Student b)
{
    return a.bytime < b.bytime;
}

int TimeDiff(int a, int b)
{
    return a / 100 * 60 + a % 100 - b / 100 * 60 - b % 100;
}

void ConverTimeToInt(char *timest, int *a)
{
    a[0] = (timest[0] - '0') * 1000 + (timest[1] - '0') * 100 + (timest[3] - '0') * 10 + (timest[4] - '0') * 1;
    a[1] = (timest[6] - '0') * 1000 + (timest[7] - '0') * 100 + (timest[9] - '0') * 10 + (timest[10] - '0') * 1;

    return;
}

int CalcMaxTime()
{
    int ret = 0;

    if(schedule[0][0] == 0) schedule[0][0] = 2400;

    for(int i = 0; i < 4; i ++)
        ret += TimeDiff(schedule[(i + 1) % 4][0], schedule[i][1]) - 1;

    return ret;
}

int CalcTimeInDay(int t)
{
    int ret = 0;

    for(int i = 0; i < 4; i ++)
    if(t >= schedule[(i + 1) % 4][0])
        ret += TimeDiff(schedule[(i + 1) % 4][0], schedule[i][1]) - 1;
    else
    {
        ret += max(TimeDiff(t, schedule[i][1]), 0);
        break;
    }

    return ret;
}

int ConvertTimeByDelta(int starttime, int delta)
{
    return (starttime / 100 + (starttime % 100 + delta) / 60) * 100 + (starttime % 100 + delta) % 60;
}

int IntToTime(int t)
{
    int sum = 0, ret;

    for(int i = 0; i < 4; i ++)
    if(sum + TimeDiff(schedule[(i + 1) % 4][0], schedule[i][1]) - 1 < t)
        sum += TimeDiff(schedule[(i + 1) % 4][0], schedule[i][1]) - 1;
    else
    {
        ret = ConvertTimeByDelta(schedule[i][1], t - sum);
        break;
    }

    return ret;
}

int CalcMinutes(int day, char *t)
{
    int t0 = (t[0] - '0') * 1000 + (t[1] - '0') * 100 + (t[3] - '0') * 10 + (t[4] - '0');

    return (day - 1) * mt1 + CalcTimeInDay(t0 - 1);
}

void PrintTime(int t)
{
    printf(" %d", (t - 1) / mt1 + 1);
    int s = IntToTime((t - 1) % mt1 + 1);
    printf(" %02d:%02d", s / 100, s % 100);

    return;
}

int main()
{
    char st[40], st0[40], st1[40];
    int ans, ansk;

    // freopen("D:\\1.in", "r", stdin);
    // freopen("D:\\1.out", "w", stdout);

    scanf("%d%d%d", &n, &m, &tdays);
    for(int i = 0; i < m; i ++)
        scanf("%s", st), slist[st] = i;
    for(int i = 0; i < m; i ++)
        scanf("%d", &(stime[i]));

    for(int i = 0; i < 4; i ++)
        scanf("%s", st), ConverTimeToInt(st, schedule[i]);

    mt1 = CalcMaxTime();
    mtall = mt1 * tdays;

    ans = -1;
    for(int i = 0; i < n; i ++)
    {
        int byday, pay, sindex, dur, bytime;
        scanf("%s%d%s%d", st0, &byday, st1, &pay);
        if(slist.find(st0) == slist.end())
        {
            stus[i].index = -1;
            continue;
        }
        sindex = slist[st0];
        dur = stime[sindex];
        bytime = CalcMinutes(byday, st1);
        helplist[i + 1] = dur;

        stus[i].bytime = bytime;
        stus[i].dur = dur;
        stus[i].index = i + 1;
        stus[i].pay = pay;
    }

    sort(stus, stus + n, comp);

    for(int i = 0; i < n; i ++)
    {
        if(stus[i].index == -1)
            continue;
        for(int j = stus[i].bytime; j >= stus[i].dur; j --)
        if(dp[j - stus[i].dur] + stus[i].pay > dp[j])
        {
            dp[j] = dp[j - stus[i].dur] + stus[i].pay, pre[j] = stus[i].index;
            if(dp[j] > ans)
                ans = dp[j], ansk = j;
        }
    }

    printf("%d\n", ans);
    while(pre[ansk] > 0)
    {
        ansarr[anslen][0] = pre[ansk];
        ansk = ansk - helplist[pre[ansk]];
        ansarr[anslen][1] = ansk + 1;
        anslen ++;
    }
    printf("%d\n", anslen);
    for(int i = anslen - 1; i >= 0; i --)
    {
        printf("%d", ansarr[i][0]);
        PrintTime(ansarr[i][1]);
        PrintTime(ansarr[i][1] + helplist[ansarr[i][0]] - 1);
        printf("\n");
    }

	return 0;
}


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

struct Student
{
    int dur, bytime, pay, index;
};

const int MAXN = 101;
const int MAXTIMEMINS = 50000;
int n, m, tdays, mt1, mtall;
map<string ,int> slist;
int stime[MAXN];
int schedule[4][2];
int dp[MAXTIMEMINS];
int pre[MAXTIMEMINS];
int ansarr[MAXN][2];
int anslen;
int helplist[MAXN];
Student stus[MAXN];

bool comp(Student a, Student b)
{
    return a.bytime < b.bytime;
}

int TimeDiff(int a, int b)
{
    return a / 100 * 60 + a % 100 - b / 100 * 60 - b % 100;
}

void ConverTimeToInt(char *timest, int *a)
{
    a[0] = (timest[0] - '0') * 1000 + (timest[1] - '0') * 100 + (timest[3] - '0') * 10 + (timest[4] - '0') * 1;
    a[1] = (timest[6] - '0') * 1000 + (timest[7] - '0') * 100 + (timest[9] - '0') * 10 + (timest[10] - '0') * 1;

    return;
}

int CalcMaxTime()
{
    int ret = 0;

    if(schedule[0][0] == 0) schedule[0][0] = 2400;

    for(int i = 0; i < 4; i ++)
        ret += TimeDiff(schedule[(i + 1) % 4][0], schedule[i][1]) - 1;

    return ret;
}

int CalcTimeInDay(int t)
{
    int ret = 0;

    for(int i = 0; i < 4; i ++)
    if(t >= schedule[(i + 1) % 4][0])
        ret += TimeDiff(schedule[(i + 1) % 4][0], schedule[i][1]) - 1;
    else
    {
        ret += max(TimeDiff(t, schedule[i][1]), 0);
        break;
    }

    return ret;
}

int ConvertTimeByDelta(int starttime, int delta)
{
    return (starttime / 100 + (starttime % 100 + delta) / 60) * 100 + (starttime % 100 + delta) % 60;
}

int IntToTime(int t)
{
    int sum = 0, ret;

    for(int i = 0; i < 4; i ++)
    if(sum + TimeDiff(schedule[(i + 1) % 4][0], schedule[i][1]) - 1 < t)
        sum += TimeDiff(schedule[(i + 1) % 4][0], schedule[i][1]) - 1;
    else
    {
        ret = ConvertTimeByDelta(schedule[i][1], t - sum);
        break;
    }

    return ret;
}

int CalcMinutes(int day, char *t)
{
    int t0 = (t[0] - '0') * 1000 + (t[1] - '0') * 100 + (t[3] - '0') * 10 + (t[4] - '0');

    return (day - 1) * mt1 + CalcTimeInDay(t0 - 1);
}

void PrintTime(int t)
{
    printf(" %d", (t - 1) / mt1 + 1);
    int s = IntToTime((t - 1) % mt1 + 1);
    printf(" %02d:%02d", s / 100, s % 100);

    return;
}

int main()
{
    char st[40], st0[40], st1[40];
    int ans, ansk;

    // freopen("D:\\1.in", "r", stdin);
    // freopen("D:\\1.out", "w", stdout);

    scanf("%d%d%d", &m, &n, &tdays);
    for(int i = 0; i < m; i ++)
        scanf("%s", st), slist[st] = i;
    for(int i = 0; i < m; i ++)
        scanf("%d", &(stime[i]));

    for(int i = 0; i < 4; i ++)
        scanf("%s", st), ConverTimeToInt(st, schedule[i]);

    mt1 = CalcMaxTime();
    mtall = mt1 * tdays;

    ans = 0;
    for(int i = 0; i < n; i ++)
    {
        int byday, pay, sindex, dur, bytime;
        scanf("%s%d%s%d", st0, &byday, st1, &pay);
        if(slist.find(st0) == slist.end())
        {
            stus[i].index = -1;
            continue;
        }
        sindex = slist[st0];
        dur = stime[sindex];
        bytime = CalcMinutes(byday, st1);
        helplist[i + 1] = dur;

        stus[i].bytime = bytime;
        stus[i].dur = dur;
        stus[i].index = i + 1;
        stus[i].pay = pay;
    }

    sort(stus, stus + n, comp);

    for(int i = 0; i < n; i ++)
    {
        if(stus[i].index == -1)
            continue;
        for(int j = stus[i].bytime; j >= stus[i].dur; j --)
        if(dp[j - stus[i].dur] + stus[i].pay > dp[j])
        {
            dp[j] = dp[j - stus[i].dur] + stus[i].pay, pre[j] = stus[i].index;
            if(dp[j] > ans)
                ans = dp[j], ansk = j;
        }
    }

    printf("%d\n", ans);
    while(pre[ansk] > 0)
    {
        ansarr[anslen][0] = pre[ansk];
        ansk = ansk - helplist[pre[ansk]];
        ansarr[anslen][1] = ansk + 1;
        anslen ++;
    }
    printf("%d\n", anslen);
    for(int i = anslen - 1; i >= 0; i --)
    {
        printf("%d", ansarr[i][0]);
        PrintTime(ansarr[i][1]);
        PrintTime(ansarr[i][1] + helplist[ansarr[i][0]] - 1);
        printf("\n");
    }

	return 0;
}


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

struct Student
{
    int dur, bytime, pay, index;
};

const int MAXN = 101;
const int MAXTIMEMINS = 50000;
int n, m, tdays, mt1, mtall;
map<string ,int> slist;
int stime[MAXN];
int schedule[4][2];
int dp[MAXTIMEMINS];
int pre[MAXTIMEMINS];
int ansarr[MAXN][2];
int anslen;
int helplist[MAXN];
Student stus[MAXN];

bool comp(Student a, Student b)
{
    return a.bytime < b.bytime;
}

int TimeDiff(int a, int b)
{
    return a / 100 * 60 + a % 100 - b / 100 * 60 - b % 100;
}

void ConverTimeToInt(char *timest, int *a)
{
    a[0] = (timest[0] - '0') * 1000 + (timest[1] - '0') * 100 + (timest[3] - '0') * 10 + (timest[4] - '0') * 1;
    a[1] = (timest[6] - '0') * 1000 + (timest[7] - '0') * 100 + (timest[9] - '0') * 10 + (timest[10] - '0') * 1;

    return;
}

int CalcMaxTime()
{
    int ret = 0;

    if(schedule[0][0] == 0) schedule[0][0] = 2400;

    for(int i = 0; i < 4; i ++)
        ret += TimeDiff(schedule[(i + 1) % 4][0], schedule[i][1]) - 1;

    return ret;
}

int CalcTimeInDay(int t)
{
    int ret = 0;

    for(int i = 0; i < 4; i ++)
    if(t >= schedule[(i + 1) % 4][0])
        ret += TimeDiff(schedule[(i + 1) % 4][0], schedule[i][1]) - 1;
    else
    {
        ret += max(TimeDiff(t, schedule[i][1]), 0);
        break;
    }

    return ret;
}

int ConvertTimeByDelta(int starttime, int delta)
{
    return (starttime / 100 + (starttime % 100 + delta) / 60) * 100 + (starttime % 100 + delta) % 60;
}

int IntToTime(int t)
{
    int sum = 0, ret;

    for(int i = 0; i < 4; i ++)
    if(sum + TimeDiff(schedule[(i + 1) % 4][0], schedule[i][1]) - 1 < t)
        sum += TimeDiff(schedule[(i + 1) % 4][0], schedule[i][1]) - 1;
    else
    {
        ret = ConvertTimeByDelta(schedule[i][1], t - sum);
        break;
    }

    return ret;
}

int CalcMinutes(int day, char *t)
{
    int t0 = (t[0] - '0') * 1000 + (t[1] - '0') * 100 + (t[3] - '0') * 10 + (t[4] - '0');

    return (day - 1) * mt1 + CalcTimeInDay(t0 - 1);
}

void PrintTime(int t)
{
    printf(" %d", (t - 1) / mt1 + 1);
    int s = IntToTime((t - 1) % mt1 + 1);
    printf(" %02d:%02d", s / 100, s % 100);

    return;
}

int main()
{
    char st[40], st0[40], st1[40];
    int ans, ansk;

    // freopen("D:\\1.in", "r", stdin);
    // freopen("D:\\1.out", "w", stdout);

    scanf("%d%d%d", &m, &n, &tdays);
    for(int i = 0; i < m; i ++)
        scanf("%s", st), slist[st] = i;
    for(int i = 0; i < m; i ++)
        scanf("%d", &(stime[i]));

    for(int i = 0; i < 4; i ++)
        scanf("%s", st), ConverTimeToInt(st, schedule[i]);

    mt1 = CalcMaxTime();
    mtall = mt1 * tdays;

    ans = 0; ansk = 0;
    for(int i = 0; i < n; i ++)
    {
        int byday, pay, sindex, dur, bytime;
        scanf("%s%d%s%d", st0, &byday, st1, &pay);
        if(slist.find(st0) == slist.end())
        {
            stus[i].index = -1;
            continue;
        }
        sindex = slist[st0];
        dur = stime[sindex];
        bytime = CalcMinutes(byday, st1);
        helplist[i + 1] = dur;

        stus[i].bytime = bytime;
        stus[i].dur = dur;
        stus[i].index = i + 1;
        stus[i].pay = pay;
    }

    sort(stus, stus + n, comp);

    for(int i = 0; i < n; i ++)
    {
        if(stus[i].index == -1)
            continue;
        for(int j = stus[i].bytime; j >= stus[i].dur; j --)
        if(dp[j - stus[i].dur] + stus[i].pay > dp[j])
        {
            dp[j] = dp[j - stus[i].dur] + stus[i].pay, pre[j] = stus[i].index;
            if(dp[j] > ans)
                ans = dp[j], ansk = j;
        }
    }

    printf("%d\n", ans);
    while(pre[ansk] > 0)
    {
        ansarr[anslen][0] = pre[ansk];
        ansk = ansk - helplist[pre[ansk]];
        ansarr[anslen][1] = ansk + 1;
        anslen ++;
    }
    printf("%d\n", anslen);
    for(int i = anslen - 1; i >= 0; i --)
    {
        printf("%d", ansarr[i][0]);
        PrintTime(ansarr[i][1]);
        PrintTime(ansarr[i][1] + helplist[ansarr[i][0]] - 1);
        printf("\n");
    }

	return 0;
}


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

struct Student
{
    int dur, bytime, pay, index;
};

const int MAXN = 105;
const int MAXTIMEMINS = 50000;
int n, m, tdays, mt1, mtall;
map<string ,int> slist;
int stime[MAXN];
int schedule[4][2];
int dp[MAXTIMEMINS];
int path[MAXTIMEMINS][MAXN];
int pre[MAXTIMEMINS];
int ansarr[MAXN][2];
int anslen;
int helplist[MAXN];
int paylist[MAXN];
Student stus[MAXN];

bool comp(Student a, Student b)
{
    return a.bytime < b.bytime || a.bytime == b.bytime && a.pay > b.pay;
}

int TimeDiff(int a, int b)
{
    return a / 100 * 60 + a % 100 - b / 100 * 60 - b % 100;
}

void ConverTimeToInt(char *timest, int *a)
{
    a[0] = (timest[0] - '0') * 1000 + (timest[1] - '0') * 100 + (timest[3] - '0') * 10 + (timest[4] - '0') * 1;
    a[1] = (timest[6] - '0') * 1000 + (timest[7] - '0') * 100 + (timest[9] - '0') * 10 + (timest[10] - '0') * 1;

    return;
}

int CalcMaxTime()
{
    int ret = 0;

    ret += TimeDiff(schedule[0][0], 0);
    for(int i = 0; i < 3; i ++)
        ret += TimeDiff(schedule[i + 1][0], schedule[i][1]) - 1;
    ret += TimeDiff(2359, schedule[3][1]);
    return ret;
}

int CalcTimeInDay(int t)
{
    int ret = 0;

    if(t >= schedule[0][0])
        ret += TimeDiff(schedule[0][0], 0);
    else
    {
        ret += TimeDiff(t, 0) + 1;
        return ret;
    }

    for(int i = 0; i < 3; i ++)
    if(t >= schedule[i + 1][0])
        ret += TimeDiff(schedule[i + 1][0], schedule[i][1]) - 1;
    else
    {
        ret += max(TimeDiff(t, schedule[i][1]), 0);
        return ret;
    }

    ret += max(TimeDiff(t, schedule[3][1]), 0);

    return ret;
}

int ConvertTimeByDelta(int starttime, int delta)
{
    return (starttime / 100 + (starttime % 100 + delta) / 60) * 100 + (starttime % 100 + delta) % 60;
}

int IntToTime(int t)
{
    int sum = 0, ret;

    if(TimeDiff(schedule[0][0], 0) >= t)
    {
        ret = ConvertTimeByDelta(0, t - 1);
        return ret;
    }
    else
        sum += TimeDiff(schedule[0][0], 0);

    for(int i = 0; i < 3; i ++)
    if(sum + TimeDiff(schedule[i + 1][0], schedule[i][1]) - 1 < t)
        sum += TimeDiff(schedule[i + 1][0], schedule[i][1]) - 1;
    else
    {
        ret = ConvertTimeByDelta(schedule[i][1], t - sum);
        return ret;
    }

    ret = ConvertTimeByDelta(schedule[3][1], t - sum);

    return ret;
}

int CalcMinutes(int day, char *t)
{
    int t0 = (t[0] - '0') * 1000 + (t[1] - '0') * 100 + (t[3] - '0') * 10 + (t[4] - '0');

    return (day - 1) * mt1 + CalcTimeInDay(t0 - 1);
}

void PrintTime(int t)
{
    printf(" %d", (t - 1) / mt1 + 1);
    int s = IntToTime((t - 1) % mt1 + 1);
    printf(" %02d:%02d", s / 100, s % 100);

    return;
}

int main()
{
    char st[40], st0[40], st1[40];
    int ans, ansk;

    // freopen("D:\\1.in", "r", stdin);
    // freopen("D:\\1.out", "w", stdout);

    scanf("%d%d%d", &m, &n, &tdays);
    for(int i = 0; i < m; i ++)
        scanf("%s", st), slist[st] = i;
    for(int i = 0; i < m; i ++)
        scanf("%d", &(stime[i]));

    for(int i = 0; i < 4; i ++)
        scanf("%s", st), ConverTimeToInt(st, schedule[i]);

    mt1 = CalcMaxTime();
    mtall = mt1 * tdays;

    ans = 0; ansk = 0;
    for(int i = 0; i < n; i ++)
    {
        int byday, pay, sindex, dur, bytime;
        scanf("%s%d%s%d", st0, &byday, st1, &pay);
        if(slist.find(st0) == slist.end())
        {
            stus[i].index = -1;
            continue;
        }
        sindex = slist[st0];
        dur = stime[sindex];
        bytime = CalcMinutes(byday, st1);
        helplist[i + 1] = dur;
        paylist[i + 1] = pay;

        stus[i].bytime = bytime;
        stus[i].dur = dur;
        stus[i].index = i + 1;
        stus[i].pay = pay;
    }

    sort(stus, stus + n, comp);

    for(int i = 1; i < MAXTIMEMINS; i ++)
        dp[i] = -1;
    dp[0] = 0;
    path[0][0] = 0;

    for(int i = 0; i < n; i ++)
    {
        if(stus[i].index == -1)
            continue;
        for(int j = stus[i].bytime; j >= stus[i].dur; j --)
        if(dp[j - stus[i].dur] != -1 && dp[j - stus[i].dur] + stus[i].pay > dp[j])
        {
            dp[j] = dp[j - stus[i].dur] + stus[i].pay, pre[j] = stus[i].index;
            for(int k = 1; k <= path[j - stus[i].dur][0]; k ++)
                path[j][k] = path[j - stus[i].dur][k];
            path[j][0] = path[j - stus[i].dur][0] + 1;
            path[j][path[j][0]] = stus[i].index;
            if(dp[j] > ans)
                ans = dp[j], ansk = j;
        }
    }

    printf("%d\n", ans);
    int flag = ansk;
    for(int i = path[ansk][0]; i >= 1; i --)
    {
        ans -= paylist[path[ansk][i]];
        ansarr[anslen][0] = path[ansk][i];
        flag = flag - helplist[path[ansk][i]];
        ansarr[anslen][1] = flag + 1;
        anslen ++;
    }
    printf("%d\n", anslen);
    for(int i = anslen - 1; i >= 0; i --)
    {
        printf("%d", ansarr[i][0]);
        PrintTime(ansarr[i][1]);
        PrintTime(ansarr[i][1] + helplist[ansarr[i][0]] - 1);
        printf("\n");
    }

	return 0;
}


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

struct Student
{
    int dur, bytime, pay, index;
};

const int MAXN = 101;
const int MAXTIMEMINS = 50000;
int n, m, tdays, mt1, mtall;
map<string ,int> slist;
int stime[MAXN];
int schedule[4][2];
int dp[MAXTIMEMINS];
int path[MAXTIMEMINS][40];
int pre[MAXTIMEMINS];
int ansarr[MAXN][2];
int anslen;
int helplist[MAXN];
int paylist[MAXN];
Student stus[MAXN];

bool comp(Student a, Student b)
{
    return a.bytime < b.bytime || a.bytime == b.bytime && a.pay > b.pay;
}

int TimeDiff(int a, int b)
{
    return a / 100 * 60 + a % 100 - b / 100 * 60 - b % 100;
}

void ConverTimeToInt(char *timest, int *a)
{
    a[0] = (timest[0] - '0') * 1000 + (timest[1] - '0') * 100 + (timest[3] - '0') * 10 + (timest[4] - '0') * 1;
    a[1] = (timest[6] - '0') * 1000 + (timest[7] - '0') * 100 + (timest[9] - '0') * 10 + (timest[10] - '0') * 1;

    return;
}

int CalcMaxTime()
{
    int ret = 0;

    ret += TimeDiff(schedule[0][0], 0);
    for(int i = 0; i < 3; i ++)
        ret += TimeDiff(schedule[i + 1][0], schedule[i][1]) - 1;
    ret += TimeDiff(2359, schedule[3][1]);
    return ret;
}

int CalcTimeInDay(int t)
{
    int ret = 0;

    if(t >= schedule[0][0])
        ret += TimeDiff(schedule[0][0], 0);
    else
    {
        ret += TimeDiff(t, 0) + 1;
        return ret;
    }

    for(int i = 0; i < 3; i ++)
    if(t >= schedule[i + 1][0])
        ret += TimeDiff(schedule[i + 1][0], schedule[i][1]) - 1;
    else
    {
        ret += max(TimeDiff(t, schedule[i][1]), 0);
        return ret;
    }

    ret += max(TimeDiff(t, schedule[3][1]), 0);

    return ret;
}

int ConvertTimeByDelta(int starttime, int delta)
{
    return (starttime / 100 + (starttime % 100 + delta) / 60) * 100 + (starttime % 100 + delta) % 60;
}

int IntToTime(int t)
{
    int sum = 0, ret;

    if(TimeDiff(schedule[0][0], 0) >= t)
    {
        ret = ConvertTimeByDelta(0, t - 1);
        return ret;
    }
    else
        sum += TimeDiff(schedule[0][0], 0);

    for(int i = 0; i < 3; i ++)
    if(sum + TimeDiff(schedule[i + 1][0], schedule[i][1]) - 1 < t)
        sum += TimeDiff(schedule[i + 1][0], schedule[i][1]) - 1;
    else
    {
        ret = ConvertTimeByDelta(schedule[i][1], t - sum);
        return ret;
    }

    ret = ConvertTimeByDelta(schedule[3][1], t - sum);

    return ret;
}

int CalcMinutes(int day, char *t)
{
    int t0 = (t[0] - '0') * 1000 + (t[1] - '0') * 100 + (t[3] - '0') * 10 + (t[4] - '0');

    return (day - 1) * mt1 + CalcTimeInDay(t0 - 1);
}

void PrintTime(int t)
{
    printf(" %d", (t - 1) / mt1 + 1);
    int s = IntToTime((t - 1) % mt1 + 1);
    printf(" %02d:%02d", s / 100, s % 100);

    return;
}

int main()
{
    char st[40], st0[40], st1[40];
    int ans, ansk;

    // freopen("D:\\1.in", "r", stdin);
    // freopen("D:\\1.out", "w", stdout);

    scanf("%d%d%d", &m, &n, &tdays);
    for(int i = 0; i < m; i ++)
        scanf("%s", st), slist[st] = i;
    for(int i = 0; i < m; i ++)
        scanf("%d", &(stime[i]));

    for(int i = 0; i < 4; i ++)
        scanf("%s", st), ConverTimeToInt(st, schedule[i]);

    mt1 = CalcMaxTime();
    mtall = mt1 * tdays;

    ans = 0; ansk = 0;
    for(int i = 0; i < n; i ++)
    {
        int byday, pay, sindex, dur, bytime;
        scanf("%s%d%s%d", st0, &byday, st1, &pay);
        if(slist.find(st0) == slist.end())
        {
            stus[i].index = -1;
            continue;
        }
        sindex = slist[st0];
        dur = stime[sindex];
        bytime = CalcMinutes(byday, st1);
        helplist[i + 1] = dur;
        paylist[i + 1] = pay;

        stus[i].bytime = bytime;
        stus[i].dur = dur;
        stus[i].index = i + 1;
        stus[i].pay = pay;
    }

    sort(stus, stus + n, comp);

    for(int i = 1; i < MAXTIMEMINS; i ++)
        dp[i] = -1;
    dp[0] = 0;
    path[0][0] = 0;

    for(int i = 0; i < n; i ++)
    {
        if(stus[i].index == -1)
            continue;
        for(int j = stus[i].bytime; j >= stus[i].dur; j --)
        if(dp[j - stus[i].dur] != -1 && dp[j - stus[i].dur] + stus[i].pay > dp[j])
        {
            dp[j] = dp[j - stus[i].dur] + stus[i].pay, pre[j] = stus[i].index;
            for(int k = 1; k <= path[j - stus[i].dur][0]; k ++)
                path[j][k] = path[j - stus[i].dur][k];
            path[j][0] = path[j - stus[i].dur][0] + 1;
            path[j][path[j][0]] = stus[i].index;
            if(dp[j] > ans)
                ans = dp[j], ansk = j;
        }
    }

    printf("%d\n", ans);
    int flag = ansk;
    for(int i = path[ansk][0]; i >= 1; i --)
    {
        ans -= paylist[path[ansk][i]];
        ansarr[anslen][0] = path[ansk][i];
        flag = flag - helplist[path[ansk][i]];
        ansarr[anslen][1] = flag + 1;
        anslen ++;
    }
    printf("%d\n", anslen);
    for(int i = anslen - 1; i >= 0; i --)
    {
        printf("%d", ansarr[i][0]);
        PrintTime(ansarr[i][1]);
        PrintTime(ansarr[i][1] + helplist[ansarr[i][0]] - 1);
        printf("\n");
    }

	return 0;
}


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

using namespace std;

int horaminutoatiempo(int h,int m)
{
  return 60*h+m;
}

int diahoraminutoatiempo(int d,int h,int m)
{
  return 60*(24*d+h)+m;
}

void tiempoadiahoraminuto(int t,int &d,int &h,int &m)
{
  m=t%60;
  h=(t/60)%24;
  d=t/(60*24);
}

struct peticion {
  int duracion;
  int tiempolimite;
  int index;
  int precio;
};

bool operator<(peticion p1,peticion p2)
{
  return p1.tiempolimite<p2.tiempolimite;
}

struct informacion {
  int indiceanterior;
  int index;
  int tiemporealini;
  int tiemporealfin;
};

bool operator<(informacion i1,informacion i2)
{
  return i1.tiemporealini<i2.tiemporealini;
}

int main()
{
  int m,n,totaldias;
  cin>>m>>n>>totaldias;
  vector<string> subject(m);
  for (int i=0;i<m;i++) cin>>subject[i];
  map<string,int> subjecttotime;
  for (int i=0;i<m;i++) cin>>subjecttotime[subject[i]];
  vector<int> restriccioninf(4);
  vector<int> restriccionsup(4);
  for (int i=0;i<4;i++) {
    int hinf,minf,hsup,msup;
    char c1,c2,c3;
    cin>>hinf>>c1>>minf>>c2>>hsup>>c3>>msup;
    restriccioninf[i]=horaminutoatiempo(hinf,minf);
    restriccionsup[i]=horaminutoatiempo(hsup,msup);
  }
  vector<int> tiempolineal(60*24*totaldias,-1);
  vector<int> tiemporeal;
  {
    int h=0;int m=0;
    for (int i=0;i<int(tiempolineal.size());i++) {
      int trestrict=horaminutoatiempo(h,m);
      bool restringido=false;
      for (int j=0;j<4 and not restringido;j++)
	restringido=restriccioninf[j]<=trestrict and
	  trestrict<=restriccionsup[j];
      if (not restringido) {
	tiempolineal[i]=int(tiemporeal.size());
	tiemporeal.push_back(i);
      }
      m++;
      if (m==60) {
	h++;m=0;if (h==24) h=0;
      }
    }
    int lasttime=int(tiemporeal.size());
    tiemporeal.push_back(int(tiempolineal.size()));
    for (int i=int(tiempolineal.size())-1;i>=0;i--)
      if (tiempolineal[i]==-1) tiempolineal[i]=lasttime;
      else lasttime=tiempolineal[i];
  }
  int totaltiempo=int(tiemporeal.size());
  vector<peticion> input(n);
  for (int i=0;i<n;i++) {
    string s;int d,h,m;char c;int p;
    cin>>s>>d>>h>>c>>m>>p;
    peticion &inp=input[i];
    inp.duracion=subjecttotime[s];
    d--;
    inp.tiempolimite=tiempolineal[diahoraminutoatiempo(d,h,m)];
    inp.index=i;
    inp.precio=p;
  }
  sort(input.begin(),input.end());

  vector<int> valor(totaltiempo,-1);
  valor[0]=0;
  vector<int> indice(totaltiempo);
  indice[0]=-1;
  vector<informacion> info;
  for (int i=0;i<n;i++) {
    peticion &inp=input[i];
    if (inp.duracion>0) {
      for (int j=inp.tiempolimite-inp.duracion;j>=0;j--) {
	if (valor[j]!=-1 and (valor[j+inp.duracion]<valor[j]+inp.precio)) {
	  informacion inf;
	  inf.index=inp.index;
	  inf.indiceanterior=indice[j];
	  inf.tiemporealini=tiemporeal[j];
	  inf.tiemporealfin=tiemporeal[j+inp.duracion-1];
	  valor[j+inp.duracion]=valor[j]+inp.precio;
	  indice[j+inp.duracion]=int(info.size());
	  info.push_back(inf);
	}
      }
    }
  }
  int imax=0;
  for (int i=0;i<totaltiempo;i++)
    if (valor[i]>valor[imax]) imax=i;
  cout<<valor[imax]<<endl;
  vector<informacion> sol;
  imax=indice[imax];
  while (imax!=-1) {
    sol.push_back(info[imax]);
    imax=info[imax].indiceanterior;
  }
  cout<<int(sol.size())<<endl;
  sort(sol.begin(),sol.end());
  for (int i=0;i<int(sol.size());i++) {
    informacion &inf=sol[i];
    cout<<inf.index+1;
    int d,h,m;
    tiempoadiahoraminuto(inf.tiemporealini,d,h,m);
    d++;
    cout<<" "<<d<<" "<<h/10<<h%10<<":"<<m/10<<m%10;
    tiempoadiahoraminuto(inf.tiemporealfin,d,h,m);
    d++;
    cout<<" "<<d<<" "<<h/10<<h%10<<":"<<m/10<<m%10<<endl;
  }
}


#include <algorithm>
#include <iostream>
#include <sstream>
#include <complex>
#include <numeric>
#include <cstring>
#include <vector>
#include <string>
#include <cstdio>
#include <queue>
#include <cmath>
#include <map>
#include <set>

using namespace std;

#define all(a)			(a).begin(), (a).end()
#define sz(a)			int((a).size())
#define FOR(i, a, b)	for (int i(a); i < b; ++i)
#define REP(i, n)		FOR(i, 0, n)
#define UN(v)			sort(all(v)), (v).erase(unique((v).begin(), (v).end()), (v).end())
#define CL(a, b)		memset(a, b, sizeof a)
#define pb				push_back
#define X				first
#define Y				second

typedef long long ll;
typedef vector <int> vi;
typedef pair <int, int> pii;

int m, n, k, dtime[111];
string dis[111];
pii busy[4];
int freeTimePerDay;

int readTime() {
	int h, m;
	scanf("%d:%d", &h, &m);
	return h * 60 + m;
}

int duration(pii s) { return max(s.Y - s.X + 1, 0); }

pii operator & (const pii &a, const pii &b) {
	return pii(max(a.X, b.X), min(a.Y, b.Y));
}

struct stupid {
	int id, day, time, money, freetime, index;
	void read(int index) {
		this->index = index;
		string s;
		cin >> s >> day;
		time = readTime();
		cin >> money;
		id = -1;
		REP (i, m) if (s == dis[i]) id = i;
		freetime = time + freeTimePerDay * (day - 1);
		pii q(0, time - 1);
		REP (i, 4) freetime -= duration(q & busy[i]);
	}
} s[111];

bool operator < (const stupid &a, const stupid &b) { return a.freetime < b.freetime; }

int F[111][50000];

void printTime(int t) {
	int day = t / freeTimePerDay + 1;
	t -= (day - 1) * freeTimePerDay;
	cout << day << ' ';
	REP (i, 4) {
		if (busy[i].X <= t) t += duration(busy[i]);
	}
	printf("%02d:%02d", t / 60, t % 60);
}

struct task {
	int student, startTime, endTime;
	void print() {
		cout << student + 1 << ' ';
		printTime(startTime);
		cout << ' ';
		printTime(endTime);
		cout << endl;
	}
};

vector <task> ans;

int f(int i, int now) {
	if (i == n) return 0;
	int &res = F[i][now];
	if (res < 0) {
		res = f(i + 1, now);
		if (s[i].id >= 0 && now + dtime[s[i].id] <= s[i].freetime) {
			res = max(res, f(i + 1, now + dtime[s[i].id]) + s[i].money);
		}
	}
	return res;
}

void restore(int i, int now) {
	if (i == n) return;
	int res = f(i, now);
	if (res == f(i + 1, now)) restore(i + 1, now);
	else {
		ans.pb((task){s[i].index, now, now + dtime[s[i].id] - 1});
		restore(i + 1, now + dtime[s[i].id]);
	}
}

int main(){
	#ifdef LocalHost
	freopen("x.in", "r", stdin);
	freopen("x.out", "w", stdout);
	#endif
	cin >> m >> n >> k;
	REP (i, m) cin >> dis[i];
	REP (i, m) cin >> dtime[i];
	freeTimePerDay = 24 * 60;
	REP (i, 4) {
		busy[i].X = readTime();
		scanf("-");
		busy[i].Y = readTime();
		freeTimePerDay -= duration(busy[i]);
	}
	REP (i, n) s[i].read(i);
	sort(s, s + n);
	CL(F, -1);
	cout << f(0, 0) << endl;
	restore(0, 0);
	cout << ans.size() << endl;
	REP (i, sz(ans))
		ans[i].print();
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 111, M = 60*24*33;

int m, n, k;
int mt[M], mb[M];

struct P {
  int t, v, d, id;
} p[N];

int d;

int read_time() {
  char c1,c2,c3,c4;
  scanf(" %c%c%*c%c%c%*c", &c1, &c2, &c3, &c4);
  return ((c1-'0') * 10 + (c2-'0')) * 60 + (c3-'0') * 10 + c4 - '0';
}

void write_time(int t) {
  printf("%d ", t / d + 1);
  t = mt[t%d];
  printf("%02d:%02d", t/60, t%60);
}

string sb[N];
map<string, int> ms;
int S1, S2, B1, B2, L1, L2, D1, D2;

long f[M][N];
int g[M][N];

int main() {
  scanf("%d%d%d", &m, &n, &k);
  for (int i = 0; i < m; ++i)
    cin >> sb[i];
  for (int i = 0; i < m; ++i) {
    int tm;
    scanf("%d", &tm);
    ms[sb[i]] = tm;
  }

  S1 = read_time(); S2 = read_time();
  B1 = read_time(); B2 = read_time();
  L1 = read_time(); L2 = read_time();
  D1 = read_time(); D2 = read_time();

  d = 24*60;
  d -= S2 + 1 - S1;
  d -= B2 + 1 - B1;
  d -= L2 + 1 - L1;
  d -= D2 + 1 - D1;

  int cur = 0;
  for (int i = 0; i < d; ++i) {
    while (S1 <= cur && cur <= S2) {
      mb[cur] = S1 == 0 ? 0 : mb[S1 - 1] + 1;
      ++cur;
    }
    while (S1 > S2 && (0 <= cur && cur <= S2)) {
      mb[cur] = -1;
      ++cur;
    }
    while (S1 > S2 && (S1 <= cur)) {
      mb[cur] = mb[S1 - 1] + 1;
      ++cur;
    }
    while (B1 <= cur && cur <= B2) {
      mb[cur] = mb[B1 - 1] + 1;
      ++cur;
    }
    while (L1 <= cur && cur <= L2) {
      mb[cur] = mb[L1 - 1] + 1;
      ++cur;
    }
    while (D1 <= cur && cur <= D2) {
      mb[cur] = mb[D1 - 1] + 1;
      ++cur;
    }
    mt[i] = cur;
    mb[cur] = i;
    ++cur;
  }

  for (int i = 0; i < n; ++i) {
    string s;
    int td;
    cin >> s >> td;
    int mm = read_time();
    cin >> p[i].v;
    p[i].t = ms.count(s) ? ms[s] : M + 1;
    p[i].d = mb[mm] < 0 ? (td - 2) * d + mb[S1 - 1] + 1 : (td - 1) * d + mb[mm];
    p[i].id = i+1;
  }

  sort(p, p+n, [](const P& a, const P& b){ return a.d < b.d; });

  /*
  for (int i = 0; i < n; ++i) {
    cout << "# " << p[i].id << " " << p[i].t << " ";
    write_time(p[i].d);
    cout << " " << p[i].v << endl;
  }*/
  int best = 0;
  for (int i = 0; i <= k * d; ++i) {
    for (int j = 0; j < n; ++j) {
      if (f[i][j] > f[i][j+1]) {
        f[i][j+1] = f[i][j];
        g[i][j+1] = 0;
        //cerr << " >- f[" <<i<<"]["<<j+1<<"] = " << f[i][j+1] <<endl;
      }
      int ni = i + p[j].t;
      if (ni <= p[j].d && ni <= k * d) {
        if (f[i][j] + p[j].v > f[ni][j+1]) {
          f[ni][j+1] = f[i][j] + p[j].v;
          g[ni][j+1] = 1;
          //cerr << " >+ f[" <<ni<<"]["<<j+1<<"] = " << f[ni][j+1] <<endl;
        }
      }
    }

    if (f[i][n] > f[best][n]) best = i;
  }

  vector<pair<int, int>> ans;
  int i = best, j = n;
  while (j) {
    if (g[i][j]) {
      --j;
      i -= p[j].t;
      //cerr << "> " << best << " " << i << " " << j << endl;
      ans.emplace_back(i, j);
    } else {
      --j;
    }
  }

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

  printf("%ld\n%ld\n", f[best][n], ans.size());
  for (const auto& pr : ans) {
    printf("%d ", p[pr.second].id);
    write_time(pr.first);
    printf(" ");
    write_time(pr.first + p[pr.second].t - 1);
    puts("");
  }
}


#include <bits/stdc++.h>
using namespace std;
const int N = 111, M = 60*24*33;

int m, n, k;
int mt[M], mb[M];

struct P {
  int t, v, d, id;
} p[N];

int d;

int read_time() {
  char c1,c2,c3,c4;
  scanf(" %c%c%*c%c%c%*c", &c1, &c2, &c3, &c4);
  return ((c1-'0') * int(10) + (c2-'0')) * 60 + (c3-'0') * 10 + c4 - '0';
}

void write_time(int t) {
  printf("%d ", t / d + 1);
  t = mt[t%d];
  printf("%02d:%02d", t/60, t%60);
}

string sb[N];
map<string, int> ms;
int S1, S2, B1, B2, L1, L2, D1, D2;

long f[M][N];
int g[M][N];

int main() {
  scanf("%d%d%d", &m, &n, &k);
  for (int i = 0; i < m; ++i)
    cin >> sb[i];
  for (int i = 0; i < m; ++i) {
    int tm;
    scanf("%d", &tm);
    ms[sb[i]] = tm;
  }

  S1 = read_time(); S2 = read_time();
  B1 = read_time(); B2 = read_time();
  L1 = read_time(); L2 = read_time();
  D1 = read_time(); D2 = read_time();

  d = 24*60;
  d -= S2 + 1 - S1;
  d -= B2 + 1 - B1;
  d -= L2 + 1 - L1;
  d -= D2 + 1 - D1;

  int cur = 0;
  int last = 0;
  for (int i = 0; i <= d; ++i) {
    while (S1 <= cur && cur <= S2) {
      mb[cur++] = last + 1;
    }
    /*
    while (S1 > S2 && (0 <= cur && cur <= S2)) {
      mb[cur++] = -1;
    }
    */
    while (B1 <= cur && cur <= B2) {
      mb[cur++] = last + 1;
    }
    while (L1 <= cur && cur <= L2) {
      mb[cur++] = last + 1;
    }
    while (D1 <= cur && cur <= D2) {
      mb[cur++] = last + 1;
    }
    /*
    while (S1 > S2 && (S1 <= cur)) {
      mb[cur++] = last + 1
    }
    */
    mt[i] = cur;
    mb[cur] = i;
    last = i;
    ++cur;
  }
  //cerr << "@@@ " << cur / 60 << ":" << cur%60 << endl;

  for (int i = 0; i < n; ++i) {
    string s;
    int td;
    cin >> s >> td;
    int mm = read_time();
    cin >> p[i].v;
    p[i].t = ms.count(s) ? ms[s] : M + 1;
    p[i].d = mb[mm] < 0 ? (td - 2) * d + mb[S1 - 1] + 1 : (td - 1) * d + mb[mm];
    p[i].id = i+1;
  }

  sort(p, p+n, [](const P& a, const P& b){ return a.d < b.d; });
  /*
  for (int i = 0; i < n; ++i) {
    cout << "# " << p[i].id << " " << p[i].t << " ";
    write_time(p[i].d);
    cout << " " << p[i].v << endl;
  }
  */
  int best = 0;
  for (int i = 0; i <= k * d; ++i) {
    for (int j = 0; j < n; ++j) {
      if (f[i][j] > f[i][j+1]) {
        f[i][j+1] = f[i][j];
        g[i][j+1] = 0;
        //cerr << " >- f[" <<i<<"]["<<j+1<<"] = " << f[i][j+1] <<endl;
      }
      int ni = i + p[j].t;
      if (ni <= p[j].d && ni <= k * d) {
        if (f[i][j] + p[j].v > f[ni][j+1]) {
          f[ni][j+1] = f[i][j] + p[j].v;
          g[ni][j+1] = 1;
          //cerr << " >+ f[" <<ni<<"]["<<j+1<<"] = " << f[ni][j+1] <<endl;
        }
      }
    }

    if (f[i][n] > f[best][n]) best = i;
  }

  vector<pair<int, int>> ans;
  int i = best, j = n;
  while (j) {
    if (g[i][j]) {
      --j;
      i -= p[j].t;
      //cerr << "> " << best << " " << i << " " << j << endl;
      ans.emplace_back(i, j);
    } else {
      --j;
    }
  }

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

  printf("%ld\n%ld\n", f[best][n], ans.size());
  for (const auto& pr : ans) {
    printf("%d ", p[pr.second].id);
    write_time(pr.first);
    printf(" ");
    write_time(pr.first + p[pr.second].t - 1);
    puts("");
  }
}


#include <bits/stdc++.h>
using namespace std;
const int N = 111, M = 60*24*33;

int m, n, k;
int mt[M], mb[M];

struct P {
  int t, v, d, id;
} p[N];

int d;

int read_time() {
  char c1,c2,c3,c4;
  scanf(" %c%c%*c%c%c%*c", &c1, &c2, &c3, &c4);
  return ((c1-'0') * 10 + (c2-'0')) * 60 + (c3-'0') * 10 + c4 - '0';
}

void write_time(int t) {
  printf("%d ", t / d + 1);
  t = mt[t%d];
  printf("%02d:%02d", t/60, t%60);
}

string sb[N];
map<string, int> ms;
int S1, S2, B1, B2, L1, L2, D1, D2;

long f[M][N];
int g[M][N];

int main() {
  scanf("%d%d%d", &m, &n, &k);
  for (int i = 0; i < m; ++i)
    cin >> sb[i];
  for (int i = 0; i < m; ++i) {
    int tm;
    scanf("%d", &tm);
    ms[sb[i]] = tm;
  }

  S1 = read_time(); S2 = read_time();
  B1 = read_time(); B2 = read_time();
  L1 = read_time(); L2 = read_time();
  D1 = read_time(); D2 = read_time();

  d = 24*60;
  d -= S2 + 1 - S1;
  d -= B2 + 1 - B1;
  d -= L2 + 1 - L1;
  d -= D2 + 1 - D1;

  int cur = 0;
  for (int i = 0; i < d; ++i) {
    while (cur <= S2) {
      mb[cur] = -1;
      ++cur;
    }
    while (B1 <= cur && cur <= B2) {
      mb[cur] = mb[B1 - 1] + 1;
      ++cur;
    }
    while (L1 <= cur && cur <= L2) {
      mb[cur] = mb[L1 - 1] + 1;
      ++cur;
    }
    while (D1 <= cur && cur <= D2) {
      mb[cur] = mb[D1 - 1] + 1;
      ++cur;
    }
    mt[i] = cur;
    mb[cur] = i;
    ++cur;
  }

  for (int i = 0; i < n; ++i) {
    string s;
    int td;
    cin >> s >> td;
    int mm = read_time();
    cin >> p[i].v;
    p[i].t = ms.count(s) ? ms[s] : M + 1;
    p[i].d = mb[mm] < 0 ? (td - 2) * d + mb[S1] : (td - 1) * d + mb[mm];
    p[i].id = i+1;
  }

  sort(p, p+n, [](const P& a, const P& b){ return a.d < b.d; });

  /*
  for (int i = 0; i < n; ++i) {
    cout << "# " << p[i].id << " " << p[i].t << " ";
    write_time(p[i].d);
    cout << " " << p[i].v << endl;
  }*/
  int best = 0;
  for (int i = 0; i <= k * d; ++i) {
    for (int j = 0; j < n; ++j) {
      if (f[i][j] > f[i][j+1]) {
        f[i][j+1] = f[i][j];
        g[i][j+1] = 0;
        //cerr << " >- f[" <<i<<"]["<<j+1<<"] = " << f[i][j+1] <<endl;
      }
      int ni = i + p[j].t;
      if (ni <= p[j].d && ni <= k * d) {
        if (f[i][j] + p[j].v > f[ni][j+1]) {
          f[ni][j+1] = f[i][j] + p[j].v;
          g[ni][j+1] = 1;
          //cerr << " >+ f[" <<ni<<"]["<<j+1<<"] = " << f[ni][j+1] <<endl;
        }
      }
    }

    if (f[i][n] > f[best][n]) best = i;
  }

  vector<pair<int, int>> ans;
  int i = best, j = n;
  while (j) {
    if (g[i][j]) {
      --j;
      i -= p[j].t;
      //cerr << "> " << best << " " << i << " " << j << endl;
      ans.emplace_back(i, j);
    } else {
      --j;
    }
  }

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

  printf("%ld\n%ld\n", f[best][n], ans.size());
  for (const auto& pr : ans) {
    printf("%d ", p[pr.second].id);
    write_time(pr.first);
    printf(" ");
    write_time(pr.first + p[pr.second].t - 1);
    puts("");
  }
}