p01948 Janken Master_17053
You are supposed to play the rock-paper-scissors game. There are $N$ players including you.

This game consists of multiple rounds. While the rounds go, the number of remaining players decreases. In each round, each remaining player will select an arbitrary shape independently. People who show rocks win if all of the other people show scissors. In this same manner, papers win rocks, scissors win papers. There is no draw situation due to the special rule of this game: if a round is tied based on the normal rock-paper-scissors game rule, the player who has the highest programming contest rating (this is nothing to do with the round!) will be the only winner of the round. Thus, some players win and the other players lose on each round. The losers drop out of the game and the winners proceed to a new round. They repeat it until only one player becomes the winner.

Each player is numbered from $1$ to $N$. Your number is $1$. You know which shape the other $N-1$ players tend to show, that is to say, you know the probabilities each player shows rock, paper and scissors. The $i$-th player shows rock with $r_i\%$ probability, paper with $p_i\%$ probability, and scissors with $s_i\%$ probability. The rating of programming contest of the player numbered $i$ is $a_i$. There are no two players whose ratings are the same. Your task is to calculate your probability to win the game when you take an optimal strategy based on each player's tendency and rating.



Input

The input consists of a single test case formatted as follows.


$N$
$a_1$
$a_2$ $r_2$ $p_2$ $s_2$
...
$a_N$ $r_N$ $p_N$ $s_N$


The first line consists of a single integer $N$ ($2 \leq N \leq 14$). The second line consists of a single integer $a_i$ ($1 \leq a_i \leq N$). The ($i+1$)-th line consists of four integers $a_i, r_i, p_i$ and $s_i$ ($1 \leq a_i \leq N, 0 \leq r_i, p_i, s_i \leq 100,$ $r_i + p_i + s_i = 100$) for $i=2, ..., N$. It is guaranteed that $a_1, ..., a_N$ are pairwise distinct.

Output

Print the probability to win the game in one line. Your answer will be accepted if its absolute or relative error does not exceed $10^{-6}$.

Examples

Input

2
2
1 40 40 20


Output

0.8


Input

2
1
2 50 50 0


Output

0.5


Input

3
2
1 50 0 50
3 0 0 100


Output

1


Input

3
2
3 40 40 20
1 30 10 60


Output

0.27


Input

4
4
1 34 33 33
2 33 34 33
3 33 33 34


Output

0.6591870816
#include<bits/stdc++.h>
using namespace std;
signed main(){
  int n,x;
  cin>>n>>x;
  n--;
  int a[n];
  double r[n],p[n],s[n];
  for(int i=0;i<n;i++) cin>>a[i]>>r[i]>>p[i]>>s[i];
  for(int i=0;i<n;i++){
    r[i]/=100;p[i]/=100;s[i]/=100;
  }
  double dp[1<<n];
  for(int i=0;i<(1<<n);i++)
    dp[i]=-1;
  function<double(int)> dfs=[&](int b){
    if(__builtin_popcount(b)==n) return 1.0;
    if(dp[b]>=0) return dp[b];
    vector<int> v;
    int y=-1;
    for(int i=0;i<n;i++){
      if(!((b>>i)&1)){
	v.push_back(i);
	y=max(y,a[i]);
      }
    }
   
    int m=v.size();
    double dp2[m+1][1<<3][1<<3];
    for(int i=0;i<=m;i++)
      for(int j=0;j<(1<<3);j++)
	for(int k=0;k<(1<<3);k++)
	  dp2[i][j][k]=0;
    dp2[0][0][0]=1;
    for(int i=0;i<m;i++){
      for(int j=0;j<(1<<3);j++){
	for(int k=0;k<(1<<3);k++){
	  dp2[i+1][j|1][k|((a[v[i]]>x)<<0)]+=dp2[i][j][k]*r[v[i]];
	  dp2[i+1][j|2][k|((a[v[i]]>x)<<1)]+=dp2[i][j][k]*p[v[i]];
	  dp2[i+1][j|4][k|((a[v[i]]>x)<<2)]+=dp2[i][j][k]*s[v[i]];
	}
      }
    }
    
    //cout<<m<<endl;

    double dp3[1<<3];
    for(int j=0;j<(1<<3);j++){
      dp3[j]=0;
      for(int k=0;k<(1<<3);k++)
	dp3[j]+=dp2[m][j][k];
    }
    
    /*/
      cout<<b<<":"<<endl;
      for(int j=0;j<(1<<3);j++)
      cout<<bitset<3>(j)<<":"<<dp3[j]<<endl;
    //*/
    
    //res=max(res,dp3[4]+(dp3[1]+dp3[6]));
    //res=max(res,dp3[1]+(dp3[2]+dp3[5]));
    //res=max(res,dp3[2]+(dp3[4]+dp3[3]));

    double aa=dp3[4]+dp2[m][1][0]+dp3[6]*(y<x);
    double bb=dp3[1]+dp2[m][2][0]+dp3[5]*(y<x);
    double cc=dp3[2]+dp2[m][4][0]+dp3[3]*(y<x);
    
    
    for(int i=1;i<(1<<m)-1;i++){
      int k=b;
      for(int j=0;j<m;j++)
	if((i>>j)&1) k|=1<<v[j];
      //cout<<bitset<3>(b)<<":"<<bitset<3>(i)<<endl;
      //for(int j=0;j<m;j++) cout<<v[j]<<endl;
      //cout<<b<<":"<<k<<endl;
      assert(k!=b);
      {
	double d=1.0;
	for(int j=0;j<m;j++){
	  if((i>>j)&1) d*=s[v[j]];
	  else d*=r[v[j]];
	}
	//res=max(res,d*dfs(k)+aa);
	aa+=d*dfs(k);
      }
      {
	double d=1.0;
	for(int j=0;j<m;j++){
	  if((i>>j)&1) d*=r[v[j]];
	  else d*=p[v[j]];
	}
	//res=max(res,d*dfs(k)+bb);
	bb+=d*dfs(k);
      }
      {
	double d=1.0;
	for(int j=0;j<m;j++){
	  if((i>>j)&1) d*=p[v[j]];
	  else d*=s[v[j]];
	}
	//res=max(res,d*dfs(k)+cc);
	cc+=d*dfs(k);
      }
    }
    //cout<<aa<<":"<<dp3[5]<<endl;
    //cout<<bb<<":"<<dp3[3]<<endl;
    //cout<<cc<<":"<<dp3[6]<<endl;
    
    double res=max({aa,bb,cc});
    if(y<x) res+=dp3[7];
    //cout<<b<<":"<<res<<endl;
    return dp[b]=res;
  };
  printf("%.12f\n",dfs(0));
  return 0;
}

