1 #include <iostream>
2 #include <vector>
3 #include <new>
4 #include <queue>
5 using namespace std;
6
7 bool pan_duan( int &n,queue<int> &v4,int × )
8 {
9 if ( n != 0 )
10 {
11 v4.push(times + 30); // 直接 进取 吃了 30 分钟
12 --n;
13 return true;
14 }
15 else
16 {
17 int time2 = v4.front();
18 if ( times >= time2 )
19 {
20 v4.pop();
21 v4.push( times + 30 );
22 return true;
23 }
24 else if ( times + 30 >= time2 )
25 {
26 v4.pop();
27 v4.push( time2 + 30 );
28 return true;
29 }
30 else return false;
31 }
32 }
33
34
35 int main()
36 {
37 //freopen("in.txt","r",stdin );
38 int a,b,c;
39 while ( scanf ( "%d",&a ) )
40 {
41 scanf ( "%d",&b );
42 scanf ( "%d",&c );
43 if ( a == 0 && b == 0 && c == 0 )
44 break;
45 queue<int> v1; //1~2
46 queue<int> v2; //3~4;
47 queue<int> v3; //5~6;
48 int t,t1,s,n;
49 char ch,ch1;
50 int num = 0;
51 bool y;
52 while ( 1 )
53 {
54 cin >> ch1;
55 if ( ch1 == '#' )
56 break;
57 else cin >> t1 >> ch >> s >> n;
58 t1 = ( ch1 - '0' ) * 10 + t1;
59 int time;
60 time = t1 * 60 + s; // 等待
61 //cout << time << "fen" << endl;
62 if ( n >= 1 && n <= 2 )
63 y = pan_duan( a,v1,time );
64 else if ( n >= 3 && n <= 4 )
65 y = pan_duan( b,v2,time );
66 else if ( n >= 5 && n <= 6 )
67 y = pan_duan( c,v3,time );
68 if ( y == true )
69 num += n;
70 }
71 cout << num << endl;
72 }
73 return 0;
74 }
75
76