1 #include <bits/stdc++.h>
2 using namespace std;
3 const int maxn = 1000;
4 struct node {
5 int s,t,a,d;
6 bool operator<(const node &x) const {
7 if(a == x.a) return t < x.t;
8 return a < x.a;
9 }
10 } course[maxn];
11 int n;
12 bool used[maxn];
13 priority_queue<node>q;
14 bool cmp(const node &x,const node &y) {
15 return x.t < y.t;
16 }
17 int main() {
18 int ret;
19 bool flag;
20 while(~scanf("%d",&n)) {
21 memset(used,false,sizeof used);
22 flag = true;
23 while(!q.empty()) q.pop();
24 for(int i = ret = 0; i < n; ++i)
25 scanf("%d %d %d %d",&course[i].s,&course[i].t,&course[i].a,&course[i].d);
26 sort(course,course+n,cmp);
27 for(int i = 0; i < n; ++i) {
28 for(int j = course[i].t; course[i].a > 0 && j > 0 && course[i].s < 60; --j) {
29 if(!used[j]) {
30 used[j] = true;
31 course[i].s = min(100,course[i].s + course[i].a);
32 course[i].a = max(0,course[i].a - course[i].d);
33 }
34 }
35 if(course[i].s < 60) {
36 flag = false;
37 break;
38 } else q.push(course[i]);
39 }
40 while(flag && !q.empty()) {
41 node now = q.top();
42 q.pop();
43 if(now.s == 100 || now.a == 0) {
44 ret += now.s;
45 continue;
46 }
47 bool mark = false;
48 for(int i = now.t; i > 0; --i) {
49 if(!used[i]) {
50 mark = used[i] = true;
51 now.s = min(100,now.s + now.a);
52 now.a = max(0,now.a - now.d);
53 break;
54 }
55 }
56 if(mark) q.push(now);
57 else ret += now.s;
58 }
59 if(flag) printf("%d\n",ret);
60 else puts("you are unlucky");
61 }
62 return 0;
63 }