Problem: Ron is a master of a ramen shop.

Recently, he has noticed some customers wait for a long time. This has been caused by lack of seats during lunch time. Customers loses their satisfaction if they waits for a long time, and even some of them will give up waiting and go away. For this reason, he has decided to increase seats in his shop. To determine how many seats are appropriate, he has asked you, an excellent programmer, to write a simulator of customer behavior.

Customers come to his shop in groups, each of which is associated with the following four parameters:

* Ti : when the group comes to the shop
* Pi : number of customers
* Wi : how long the group can wait for their seats
* Ei : how long the group takes for eating



The i-th group comes to the shop with Pi customers together at the time Ti . If Pi successive seats are available at that time, the group takes their seats immediately. Otherwise, they waits for such seats being available. When the group fails to take their seats within the time Wi (inclusive) from their coming and strictly before the closing time, they give up waiting and go away. In addition, if there are other groups waiting, the new group cannot take their seats until the earlier groups are taking seats or going away.

The shop has N counters numbered uniquely from 1 to N. The i-th counter has Ci seats. The group prefers “seats with a greater distance to the nearest group.” Precisely, the group takes their seats according to the criteria listed below. Here, SL denotes the number of successive empty seats on the left side of the group after their seating, and SR the number on the right side. SL and SR are considered to be infinity if there are no other customers on the left side and on the right side respectively.

1. Prefers seats maximizing min{SL, SR}.
2. If there are multiple alternatives meeting the first criterion, prefers seats maximizing max{SL, SR}.
3. If there are still multiple alternatives, prefers the counter of the smallest number.
4. If there are still multiple alternatives, prefers the leftmost seats.



When multiple groups are leaving the shop at the same time and some other group is waiting for available seats, seat assignment for the waiting group should be made after all the finished groups leave the shop.

Your task is to calculate the average satisfaction over customers. The satisfaction of a customer in the i-th group is given as follows:

* If the group goes away without eating, -1.
* Otherwise, (Wi - ti )/Wi where ti is the actual waiting time for the i-th group (the value ranges between 0 to 1 inclusive).



Input

The input consists of multiple datasets.

Each dataset has the following format:


N M T
C1 C2 ... CN
T1 P1 W1 E1
T2 P2 W2 E2
...
TM PM WM EM


N indicates the number of counters, M indicates the number of groups and T indicates the closing time. The shop always opens at the time 0. All input values are integers.

You can assume that 1 ≤ N ≤ 100, 1 ≤ M ≤ 10000, 1 ≤ T ≤ 109, 1 ≤ Ci ≤ 100, 0 ≤ T1 < T2 < ... < TM < T, 1 ≤ Pi ≤ max Ci, 1 ≤ Wi ≤ 109 and 1 ≤ Ei ≤ 109.

The input is terminated by a line with three zeros. This is not part of any datasets.

Output

For each dataset, output the average satisfaction over all customers in a line. Each output value may be printed with an arbitrary number of fractional digits, but may not contain an absolute error greater than 10-9.

Example

Input

1 4 100
7
10 1 50 50
15 2 50 50
25 1 50 50
35 3 50 50
1 2 100
5
30 3 20 50
40 4 40 50
1 2 100
5
49 3 20 50
60 4 50 30
1 2 100
5
50 3 20 50
60 4 50 30
2 3 100
4 2
10 4 20 20
30 2 20 20
40 4 20 20
0 0 0


Output

0.7428571428571429
0.4285714285714285
0.5542857142857143
-0.1428571428571428
0.8000000000000000

Solution (in CPP):

Solution:
#include <iostream>
#include <vector>
#include <queue>
#include <cstring>

using namespace std;

class Event{
public:
	int time, group, type;
	Event(int t, int g, int p) : time(t), group(g), type(p) {}
	bool operator < (const Event &e) const { return make_pair(time,type) > make_pair(e.time,e.type); }
};

int main(){
	int n, m, t;
	int c[100], pos[10000], T[10000], P[10000], W[10000], E[10000];
	int seat[100][100];
	int left[100], right[100], seq[100];
	bool out[10000], in[10000];
	double score[10000];
	while(cin >> n >> m >> t, n){
		for(int i=0;i<n;i++) cin >> c[i];
		memset(pos, -1, sizeof(pos));
		memset(out,false,sizeof(out));
		memset(in, false,sizeof(in));
		memset(seat, -1, sizeof(seat));
		priority_queue<Event> qu;
		queue<int> wait;
		for(int i=0;i<m;i++){
			cin >> T[i] >> P[i] >> W[i] >> E[i];
			qu.push(Event(T[i],i,1));
			qu.push(Event(T[i]+W[i],i,3));
		}
		while(!qu.empty()){
			Event e = qu.top(); qu.pop();
			if(e.type == 0){
				for(int i=0;i<c[pos[e.group]];i++){
					if(seat[pos[e.group]][i] == e.group) seat[pos[e.group]][i] = -1;
				}
				if(e.time<t) qu.push(Event(e.time,-1,2));
			}
			if(e.type == 1){
				while(!wait.empty()&&out[wait.front()]){ wait.pop(); }
				if(wait.empty()){
					int idxA = -1, idxB = -1, mScore = -1, MScore = -1;
					for(int i=0;i<n;i++){
						if(c[i] < P[e.group]) continue;
						left[0] = seat[i][0]==-1 ? 10000 : -1;
						for(int j=1;j<c[i];j++){
							if(seat[i][j]!=-1) left[j] = -1;
							else if(left[j-1]==10000) left[j] = 10000;
							else left[j] = left[j-1]+1;
						}
						right[c[i]-1] = seat[i][c[i]-1]==-1 ? 10000 : -1;
						for(int j=c[i]-2;j>=0;j--){
							if(seat[i][j]!=-1) right[j] = -1;
							else if(right[j+1]==10000) right[j] = 10000;
							else right[j] = right[j+1]+1;
						}
						for(int j=0;j<c[i];j++){
							if(seat[i][j]!=-1) seq[j] = -1;
							else if(j==0) seq[j] = 0;
							else seq[j] = seq[j-1]+1;
						}
						for(int j=0;j+P[e.group]-1<c[i];j++){
							if(left[j]!=-1&&seq[j]+P[e.group]-1==seq[j+P[e.group]-1]){
								if(idxA == -1||make_pair(mScore,MScore)<make_pair(min(left[j],right[j+P[e.group]-1]),max(left[j],right[j+P[e.group]-1]))){
									idxA = i; 
									idxB = j; 
									mScore = min(left[j],right[j+P[e.group]-1]);
									MScore = max(left[j],right[j+P[e.group]-1]);
								}
							}
						}
					}
					if(idxA == -1) { wait.push(e.group); continue; }
					for(int i=0;i<P[e.group];i++) seat[idxA][idxB+i] = e.group;
					pos[e.group] = idxA;
					in[e.group] = true;
					score[e.group] = 1.0;
					qu.push(Event(e.time+E[e.group], e.group, 0));
				} else {
					wait.push(e.group);
				}
			}
			if(e.type == 2){
				while(!wait.empty()){
					if(out[wait.front()]){ wait.pop(); continue; }
					int group = wait.front();
					int idxA = -1, idxB = -1, mScore = -1, MScore = -1;
					for(int i=0;i<n;i++){
						if(c[i] < P[group]) continue;
						left[0] = seat[i][0]==-1 ? 10000 : -1;
						for(int j=1;j<c[i];j++){
							if(seat[i][j]!=-1) left[j] = -1;
							else if(left[j-1]==10000) left[j] = 10000;
							else left[j] = left[j-1]+1;
						}
						right[c[i]-1] = seat[i][c[i]-1]==-1 ? 10000 : -1;
						for(int j=c[i]-2;j>=0;j--){
							if(seat[i][j]!=-1) right[j] = -1;
							else if(right[j+1]==10000) right[j] = 10000;
							else right[j] = right[j+1]+1;
						}
						for(int j=0;j<c[i];j++){
							if(seat[i][j]!=-1) seq[j] = -1;
							else if(j==0) seq[j] = 0;
							else seq[j] = seq[j-1]+1;
						}
						for(int j=0;j+P[group]-1<c[i];j++){
							if(left[j]!=-1&&seq[j]+P[group]-1==seq[j+P[group]-1]){
								if(idxA == -1||make_pair(mScore,MScore)<make_pair(min(left[j],right[j+P[group]-1]),max(left[j],right[j+P[group]-1]))){
									idxA = i; 
									idxB = j; 
									mScore = min(left[j],right[j+P[group]-1]);
									MScore = max(left[j],right[j+P[group]-1]);
								}
							}
						}
					}
					if(idxA == -1) break;
					for(int i=0;i<P[group];i++) seat[idxA][idxB+i] = group;
					pos[group] = idxA;

					in[group] = true;
					score[group] = (T[group]+W[group]-e.time)/(double)W[group];
					qu.push(Event(e.time+E[group], group, 0));
					wait.pop();
				}
			}
			if(e.type == 3){
				if(in[e.group] == true) continue;
				out[e.group] = true;
				score[e.group] = -1.0;
				if(e.time<t) qu.push(Event(e.time,-1,2));
			}
		}
		double ans = 0.0;
		int sum = 0;
		for(int i=0;i<m;i++){
			ans += score[i]*P[i];
			sum += P[i];
		}
		printf("%.10lf\n", ans/sum);
	}
}