Problem:
Janken Master
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}$.
Sample Input 1
2
2
1 40 40 20
Output for Sample Input 1
0.8
Since you have the higher rating than the other player, you will win the game if you win or draw in the first round.
Sample Input 2
2
1
2 50 50 0
Output for Sample Input 2
0.5
You must win in the first round.
Sample Input 3
3
2
1 50 0 50
3 0 0 100
Output for Sample Input 3
1
In the first round, your best strategy is to show a rock. You will win the game with $50\%$ in this round. With the other $50\%$, you and the second player proceed to the second round and you must show a rock to win the game.
Sample Input 4
3
2
3 40 40 20
1 30 10 60
Output for Sample Input 4
0.27
Sample Input 5
4
4
1 34 33 33
2 33 34 33
3 33 33 34
Output for Sample Input 5
0.6591870816

Submitted solutions:

code_snippet: //tekitou hash demo tooru to uresii
#include<bits/stdc++.h>
using namespace std;

using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,s,t) for(int i=s;i<t;i++)

using vi=vector<int>;

int main() {
    
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int N;
    cin>>N;
    vector<int> A(N);
    vector<array<double,3>> R(N);
    N--;
    cin>>A[N];
    rep(i,N){
        cin>>A[i]>>R[i][0]>>R[i][1]>>R[i][2];
        rep(j,3)R[i][j]/=100.0;
    }

    vector<double> DP(1<<N,0.0);
    DP[0]=1.0;
    rep(bit,1<<N){
        if(bit==0)continue;
        array<double,3> res;
        res[0]=res[1]=res[2]=0;
        bool is_high=1;
        rep(i,N){
            if(bit&(1<<i)){
                if(A[i]>A[N])is_high=0;
            }
        }
        if(is_high){
            vector<double> PP(6,1.0);
            rep(i,N){
                if(bit&(1<<i)){
                    rep(j,3){
                        PP[j]*=R[i][j];
                        PP[j+3]*=(1.0-R[i][j]);
                    }
                }
            }
            // rep(d,6)cout<<PP[d]<<" \n"[d==5];
            double ps=PP[3]+PP[4]+PP[5];
            rep(j,3){
                res[j]+=2.0*PP[j]+1.0+PP[j+3]-ps;
            }
        }


        rep(r,3){
            for (ll b = bit; b >= 0; b = (b - 1) & bit) {
                if(b==bit)continue;
                // b:win
                double p=1.0;
                rep(i,N){
                    if(bit&(1<<i)){
                        if(b&(1<<i))p*=R[i][(r)%3];
                        else p*=R[i][(r+2)%3];
                    }
                }
                res[r]+=p*DP[b];
                if (b == 0)break;
            }
        }
        DP[bit]=max({res[0],res[1],res[2]});
        
    }
    cout<<fixed<<setprecision(15);
    cout<<DP[(1<<N)-1]<<endl;

}
accuracy: 1
time_ms: 180
memory_kb: 3624
final_rank: 9

code_snippet: #include <iostream>
#include <vector>
#include <cassert>
#include <iomanip>
#include <algorithm>
int N;
int A[14];
long double P[3][14];
long double solve() {
    std::vector<long double> dp(1 << N);
    std::vector<bool> vis(1 << N);
    std::vector probsame(3, std::vector<long double>(1 << N));
    for (int bit{} ; bit < (1 << N) ; bit++) {
        if (bit & 1) continue;
        for (int i{} ; i < 3 ; i++) probsame[i][bit] = 1;
        for (int i{} ; i < N ; i++) if (bit & (1 << i)) {
            for (int j{} ; j < 3 ; j++) probsame[j][bit] *= P[j][i];
        }
    }
    // std::vector app(8, std::vector<long double>(1 << N));
    // app[0][0] = 1;
    // for (int bit{} ; bit < (1 << N) ; bit++) {
    //     if (bit & 1) continue;
    //     for (int i{1} ; i < N ; i++) {
    //         if (bit & (1 << i)) continue;
    //         for (int a{} ; a < 8 ; a++) {
    //             for (int j{} ; j < 3 ; j++) {
    //                 app[a | (1 << j)][bit | (1 << i)] *= P[j][i];
    //             }
    //         }
    //     }
    // }
    auto dfs{[&](auto dfs, int bit) -> long double {
        assert(bit & 1);
        if (vis[bit]) return dp[bit];
        vis[bit] = true;
        // std::cout << bit << std::endl;
        if (bit == 1) return dp[bit] = 1;
        long double res{};
        for (int i{} ; i < 3 ; i++) { // 自分の出す手
            long double val{}, probsum{};
            // 引き分けにならない
            for (int cur{(bit - 1) & bit} ; cur ; cur = (cur - 1) & bit) if (cur & 1) {
                int mask{bit ^ cur};
                assert(!(mask & 1));
                assert(mask);
                long double prob{probsame[i][cur^1] * probsame[(i+2)%3][mask]};
                probsum += prob;
                val += prob * dfs(dfs, cur);
            }
            // 自分が負けになる
            for (int cur{(bit - 1) & bit} ; cur ; cur = (cur - 1) & bit) if (cur & 1) {
                int mask{bit ^ cur};
                assert(!(mask & 1));
                assert(mask);
                long double prob{probsame[i][cur^1] * probsame[(i+1)%3][mask]};
                probsum += prob;
            }
            // 引き分けになる
            int max{};
            for (int j{1} ; j < N ; j++) if (bit & (1 << j)) max = std::max(max, A[j]);
            if (A[0] > max) { // 自分が強くないと駄目
                val += 1 - probsum; 
            }
            res = std::max(res, val);
        }
        return dp[bit] = res;
    }};
    return dfs(dfs, (1 << N) - 1);
}
int main() {
    std::cin >> N;
    std::cin >> A[0];
    for (int i{1} ; i < N ; i++) {
        std::cin >> A[i] >> P[0][i] >> P[1][i] >> P[2][i];
        P[0][i] /= 100;
        P[1][i] /= 100;
        P[2][i] /= 100;
    }
    std::cout << std::fixed << std::setprecision(8) << solve() << '\n';
}
accuracy: 1
time_ms: 60
memory_kb: 4468
final_rank: 10

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end())
#define SZ(v) (int)v.size()
#define MIN(v) *min_element(ALL(v))
#define MAX(v) *max_element(ALL(v))
#define LB(v, x) int(lower_bound(ALL(v), (x)) - (v).begin())
#define UB(v, x) int(upper_bound(ALL(v), (x)) - (v).begin())

using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;

template <typename T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T, typename U> T ceil(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U> T floor(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T> int popcnt(T x) {
    return __builtin_popcountll(x);
}
template <typename T> int topbit(T x) {
    return (x == 0 ? -1 : 63 - __builtin_clzll(x));
}
template <typename T> int lowbit(T x) {
    return (x == 0 ? -1 : __builtin_ctzll(x));
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "P(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#ifdef LOCAL
#define show(...) _show(0, #__VA_ARGS__, __VA_ARGS__)
#else
#define show(...) true
#endif
template <typename T> void _show(int i, T name) {
    cerr << '\n';
}
template <typename T1, typename T2, typename... T3>
void _show(int i, const T1 &a, const T2 &b, const T3 &...c) {
    for (; a[i] != ',' && a[i] != '\0'; i++)
        cerr << a[i];
    cerr << ":" << b << " ";
    _show(i + 1, a, c...);
}

/**
 * @brief template
 */

int main() {
    int N;
    cin >> N;
    N--;
    int A1;
    cin >> A1;
    vector<int> A(N);
    vector<vector<double>> X(N,vector<double>(3));
    rep(i,0,N) {
        cin >> A[i];
        cin >> X[i][0] >> X[i][2] >> X[i][1];
        rep(j,0,3) {
            X[i][j] /= 100.0;
        }
    }
    vector<double> DP(1<<N);
    DP[0] = 1.0;
    rep(i,1,1<<N) {
        bool check = true;
        vector<bool> B(N,false);
        rep(j,0,N) {
            if (i&(1<<j)) {
                if (A[j] > A1) check = false;
                B[j] = true;
            }
        }
        if (check) {
            double MAX = 0.0;
            rep(j,0,3) {
                double SUM = 0.0;
                for (int k = i; ; k=(k-1)&i) {
                    if (k == 0) break;
                    double MUL = 1.0;
                    rep(l,0,N) {
                        if (!B[l]) continue;
                        if (k & (1<<l)) {
                            MUL *= X[l][(j+2)%3];
                        }
                        else {
                            MUL *= X[l][j];
                        }
                    }
                    SUM += MUL;
                }
                for (int k = i; ; k=(k-1)&i) {
                    if (k == i) continue;
                    double MUL = 1.0 - DP[k];
                    rep(l,0,N) {
                        if (!B[l]) continue;
                        if (k & (1<<l)) {
                            MUL *= X[l][j];
                        }
                        else {
                            MUL *= X[l][(j+1)%3];
                        }
                    }
                    SUM += MUL;
                    if (k == 0) break;
                }
                chmax(MAX, 1.0-SUM);
            }
            DP[i] = MAX;
        }
        else {
            double MAX = 0.0;
            rep(j,0,3) {
                double SUM = 0.0;
                for (int k = i; ; k=(k-1)&i) {
                    if (k == i) continue;
                    double MUL = DP[k];
                    rep(l,0,N) {
                        if (!B[l]) continue;
                        if (k & (1<<l)) {
                            MUL *= X[l][j];
                        }
                        else {
                            MUL *= X[l][(j+1)%3];
                        }
                    }
                    SUM += MUL;
                    if (k == 0) break;
                }
                chmax(MAX,SUM);
            }
            DP[i] = MAX;
        }
    }
    printf("%.12f\n", DP[(1<<N)-1]);
}
accuracy: 1
time_ms: 380
memory_kb: 3624
final_rank: 15

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

using ld = long double;

int main(){
    cout << fixed << setprecision(10);

    int N; cin >> N;
    int YOU; cin >> YOU;
    vector<int> A(N - 1), R(N - 1), P(N - 1), S(N - 1);
    for(int i = 0; i < N - 1; i++){
        cin >> A[i] >> R[i] >> P[i] >> S[i];
    }

    vector<vector<ld>> hand(3, vector<ld>(N - 1));
    // R->S S->P P->R
    for(int i = 0; i < N - 1; i++){
        hand[0][i] = ld(R[i]) / 100; 
        hand[1][i] = ld(S[i]) / 100;    
        hand[2][i] = ld(P[i]) / 100;    
    }
    // for(int i = 0; i < N - 1; i++){ cout << A[i] << " "; } cout << endl;
    // for(int i = 0; i < N - 1; i++){ cout << R[i] << " "; } cout << endl;
    // for(int i = 0; i < N - 1; i++){ cout << P[i] << " "; } cout << endl;
    // for(int i = 0; i < N - 1; i++){ cout << S[i] << " "; } cout << endl;

    int K = N - 1;
    int M = (1 << K);
    vector<ld> dp(M, -1);
    dp[0] = 1;

    auto rec = [&](auto f, const int state) -> ld {
        if(dp[state] != -1) return dp[state];

        ld res = 0;

        for(int i = 0; i < 3; i++){
            ld val = 0;
            int win = i, lose = (i + 1) % 3;
            // win
            ld winRate = 0;
            for(int u = (state - 1) & state;; u = (u - 1) & state){
                ld perc = 1;
                for(int j = 0; j < K; j++){
                    if(!(state & (1 << j))) continue;
                    if(u & (1 << j)) perc *= hand[win][j];
                    else perc *= hand[lose][j];
                }
                winRate += perc;
                val += perc * f(f, u);
                if(u == 0) break;
            }
            // lose
            ld loseRate = 0;
            win = (i - 1 + 3) % 3, lose = i;
            for(int u = state; u > 0; u = (u - 1) & state){
                ld perc = 1;
                for(int j = 0; j < K; j++){
                    if(!(state & (1 << j))) continue;
                    if(u & (1 << j)) perc *= hand[win][j];
                    else perc *= hand[lose][j];
                }
                loseRate += perc;
            }
            // draw
            ld drawRate = 1 - winRate - loseRate;
            int mx = YOU;
            for(int i = 0; i < K; i++){
                if(state & (1 << i)) mx = max(mx, A[i]);
            }
            if(mx == YOU) val += drawRate;
            assert(val - 1e-6 < 1);
            res = max(res, val);
        }

        return dp[state] = res;
    };

    cout << rec(rec, M - 1) << endl;
}
accuracy: 1
time_ms: 410
memory_kb: 3620
final_rank: 17

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(v) v.begin(), v.end()
#define rng(i, l, r) for(int i = int(l); i < int(r); i++)
#define rep(i, n) rng(i, 0, n)
#define sz(v) int(v.size())
#define foa(s, v) for(auto &s : v)

using ld = long double;

int n;

void solve() {
	int rate;
	cin >> rate;
	--n;
	vector<pair<int, array<ld, 3>>> hu;
	rep(i, n) {
		int a;
		ld r, p, s;
		cin >> a >> r >> p >> s;
		array<ld, 3> ar{r / 100, p / 100, s / 100};
		hu.push_back({a, ar});
	}
	vector dp(1 << n, (ld)0);
	dp[0] = 1;
	rng(b, 1, 1 << n) {
		vector<ld> prob(3);
		vector<int> hito;
		int rmx = 0;
		rep(i, n) if(b >> i & 1) hito.push_back(i), rmx = max(rmx, hu[i].first);
		rep(k, 3) {
			ld res = 0;
			for(int u = (b - 1) & b;; u = (u - 1) & b) {
				ld ret = 1;
				foa(v, hito) {
					if(u >> v & 1) {
						ret *= hu[v].second[k];
					} else {
						ret *= hu[v].second[(k + 2) % 3];
					}
				}
				res += ret * dp[u];
				if(u == 0) break;
			}
			// jibun rate itiban takai
			// aiko ok
			if(rmx < rate) {
				int h = sz(hito);
				vector ep(h + 1, vector(4, ld(0)));
				ep[0][0] = 1;
				rep(i, h) {
					rep(ob, 4) {
						auto now = ep[i][ob];
						rep(l, 3) {
							int diff = (l - k + 3) % 3;
							if(diff == 0)
								ep[i + 1][ob] += now * hu[hito[i]].second[l];
							else
								ep[i + 1][ob | (1 << (diff - 1))] += now * hu[hito[i]].second[l];
						}
					}
				}
				res += ep.back().front() + ep.back().back();
			}

			dp[b] = max(dp[b], res);
		}
	}
	cout << fixed << setprecision(15);
	cout << dp.back() << endl;
}

int main() {
	while(cin >> n && n) solve();
}
accuracy: 1
time_ms: 150
memory_kb: 3664
final_rank: 7

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, t) for (int i = (int)(s); i < (int)(t); ++i)
#define revrep(i, t, s) for (int i = (int)(t)-1; i >= (int)(s); --i)
#define all(x) begin(x), end(x)
template <typename T> bool chmax(T& a, const T& b) { return a < b ? (a = b, 1) : 0; }
template <typename T> bool chmin(T& a, const T& b) { return a > b ? (a = b, 1) : 0; }

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);

    int N;
    cin >> N;
    --N;
    int me;
    cin >> me;
    vector<int> a(N);
    vector<vector<double>> prob_hand(N, vector<double>(3));
    rep(i,0,N) {
        cin >> a[i];
        rep(j,0,3) cin >> prob_hand[i][j], prob_hand[i][j] /= 100;
    }

    vector<vector<double>> p(1<<N, vector<double>(1<<3));
    rep(S,1,1<<N) {
        p[S][0] = 1;
        rep(i,0,N) {
            if (S>>i&1) {
                vector<double> np(1<<3);
                rep(T,0,1<<3) {
                    rep(j,0,3) {
                        np[T|(1<<j)] += p[S][T] * prob_hand[i][j];
                    }
                }
                p[S].swap(np);
            }
        }
    }

    vector<double> prob(1<<N);  // prob of winning when players in S are remaining
    prob[0] = 1;
    rep(S,1,1<<N) {
        bool highest = true;
        rep(i,0,N) if ((S>>i&1) && a[i] > me) highest = false;

        rep(i,0,3) {
            double t = 0;

            // win by hand
            int j = (i+2)%3;
            t += p[S][1<<j];
            for (int T = (S-1)&S; T != 0; T = (T-1)&S) {
                t += p[T][1<<i] * p[S^T][1<<j] * prob[T];
            }

            // win by rating
            if (highest) {
                int mask = (1<<3)-1;
                t += p[S][1<<i] + p[S][mask] + p[S][mask^(1<<i)];
            }
            chmax(prob[S], t);
        }
    }
    cout << prob.back() << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 4240
final_rank: 3

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
using ll = long long;
template<class T> bool chmin(T &a,const T b){if(a>b){a=b;return 1;}return 0;}
template<class T> bool chmax(T &a,const T b){if(a<b){a=b;return 1;}return 0;}
const int INF = (1<<30)-1;
#define all(p) p.begin(),p.end()
const int mod=998244353;
using ld = long double;

int main(){
	int N;
	cin>>N;
	int my;
	cin>>my;
	vector<int> A(N-1);
	vector<vector<ld>> pro(N-1,vector<ld>(3));
	rep(i,0,N-1){
		cin>>A[i];
		rep(j,0,3){
			cin>>pro[i][2-j];
			pro[i][2-j]/=(ld)100;
		}
	}
	vector<ld> dp((1<<(N-1)));
	dp[0]=1;
	rep(i,1,(1<<(N-1))){
		vector<int> p;
		int draw=1;
		rep(j,0,N-1){
			if(i&(1<<j)){
				p.push_back(j);
				if(my<A[j]) draw=0;
			}
		}
		int L=p.size();
		vector<vector<ld>> q((1<<L),vector<ld>(3,1));
		vector<int> ind(1<<L);
		vector<ld> sum(3);
		rep(j,0,(1<<L)-1){
			rep(l,0,L) rep(k,0,3){
				if(j&(1<<l)){
					q[j][k]*=pro[p[l]][k];
					if(k==0) ind[j]+=(1<<p[l]);
				}else{
					q[j][k]*=pro[p[l]][(k+1)%3];
				}
			}
			rep(k,0,3){
				sum[k]+=q[j][k];
			}
		}
		//cout<<"# "<<i<<" "<<draw<<"\n";
		rep(k,0,3){
			ld tmp=0,x=1;
			rep(j,0,(1<<L)-1){
				tmp+=dp[ind[j]]*q[j][k];
			}
			x=1-sum[k]-sum[(k+2)%3]+q[0][(k+2)%3]-q[0][(k+1)%3];
			//cout<<tmp<<" "<<x<<"\n";
			if(draw) tmp+=x;
			chmax(dp[i],tmp);
		}
		//cout<<dp[i]<<"\n";
	}
	cout<<fixed<<setprecision(20)<<dp[(1<<(N-1))-1]<<"\n";
}
accuracy: 1
time_ms: 220
memory_kb: 4120
final_rank: 14

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; --i)

#define all(c) std::begin(c), std::end(c)

#ifdef LOCAL
#define debug(...) debug_impl(#__VA_ARGS__, __VA_ARGS__)
template <class T, class ...Args> void debug_impl(string s, T&& f, Args &&...args) {
    cerr << "(" << s << "): " << "(" << forward<T>(f);
    ((cerr << ", " << forward<Args>(args)), ..., (cerr << ")\n"));
}
#else
#define debug(...) void(0)
#endif

template <class T> bool chmax(T& a, const T& b) { return b > a ? (a = b, true) : false; }
template <class T> bool chmin(T& a, const T& b) { return b < a ? (a = b, true) : false; }


template <class T> istream& operator>>(istream& in, vector<T>& v) {
    for (auto& e : v) in >> e;
    return in;
}
template <class ...Args> void read(Args&... args) {
    (cin >> ... >> args);
}

template <class T> ostream& operator<<(ostream& out, const vector<T>& v) {
    int n = v.size();
    rep(i, n) {
        out << v[i];
        if (i + 1 != n) out << ' ';
    }
    return out;
}

template <class T, class ...Tails> void print(T&& h, Tails &&... tails) {
    cout << h, ((cout << ' ' << forward<Tails>(tails)), ..., (cout << '\n'));
}

using ld = long double;

template <class T> using vc = vector<T>;
template <class T> using vvc = vector<vc<T>>;
#define si(c) (int)(c).size()
#define eb emplace_back
#define mkp make_pair
#define unless(A) if(!(A))

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(20);

    int n; read(n);
    vc<int> a(n);
    vc<ld> r(n), p(n), s(n);
    rep(i, n) {
        if(i == 0) read(a[0]);
        else {
            read(a[i], r[i], p[i], s[i]);
            r[i] /= 100.0;
            p[i] /= 100.0;
            s[i] /= 100.0;
        }
    }
    vc<ld> dp((1<<n), 0.0);
    dp[1] = 1.0;
    rep(bit, (1<<n)) {
        if(bit == 1) {
            dp[bit] = 1.0;
        } else if(bit & 1) {
            ld ma = 0.0;
            // Aはr
            {
                ld res = 1.0; // 引き分け
                ld win_prob = 0.0;
                for(int nbit = bit; ; nbit = (nbit - 1) & bit) {
                    if(nbit == bit) continue;
                    if(nbit & 1) {
                        // A win : Aはr, S - Aはs
                        {
                            ld val = 1.0;
                            rep(i, n) {
                                if(i == 0) continue;
                                unless(bit & (1<<i)) continue;
                                if(nbit & (1<<i)) {
                                    val *= r[i];
                                } else {
                                    val *= s[i];
                                }
                            }
                            res -= val;
                            win_prob += val * dp[nbit];
                        }
                        // A lose : Aはr, S - Aはp
                        {
                            ld val = 1.0;
                            rep(i, n) {
                                if(i == 0) continue;
                                unless(bit & (1<<i)) continue;
                                if(nbit & (1<<i)) {
                                    val *= r[i];
                                } else {
                                    val *= p[i];
                                }
                            }
                            res -= val;
                        }
                    }
                    if(nbit == 0) break;
                }
                {
                    int ssrs = -1;
                    int val = -1;
                    rep(i, n) {
                        if(bit & (1<<i)) {
                            if(chmax(val, a[i])) {
                                ssrs = i;
                            }
                        }
                    }
                    if(ssrs == 0) {
                        win_prob += res;
                    }
                }
                chmax(ma, win_prob);
            }
            // Aはs
            {
                ld res = 1.0; // 引き分け
                ld win_prob = 0.0;
                for(int nbit = bit; ; nbit = (nbit - 1) & bit) {
                    if(nbit == bit) continue;
                    if(nbit & 1) {
                        // A win : Aはs, S - Aはp
                        {
                            ld val = 1.0;
                            rep(i, n) {
                                if(i == 0) continue;
                                unless(bit & (1<<i)) continue;
                                if(nbit & (1<<i)) {
                                    val *= s[i];
                                } else {
                                    val *= p[i];
                                }
                            }
                            res -= val;
                            win_prob += val * dp[nbit];
                        }
                        // A lose : Aはs, S - Aはr
                        {
                            ld val = 1.0;
                            rep(i, n) {
                                if(i == 0) continue;
                                unless(bit & (1<<i)) continue;
                                if(nbit & (1<<i)) {
                                    val *= s[i];
                                } else {
                                    val *= r[i];
                                }
                            }
                            res -= val;
                        }
                    }
                    if(nbit == 0) break;
                }
                {
                    int ssrs = -1;
                    int val = -1;
                    rep(i, n) {
                        if(bit & (1<<i)) {
                            if(chmax(val, a[i])) {
                                ssrs = i;
                            }
                        }
                    }
                    if(ssrs == 0) {
                        win_prob += res;
                    }
                }
                chmax(ma, win_prob);
            }
            // Aはp
            {
                ld res = 1.0; // 引き分け
                ld win_prob = 0.0;
                for(int nbit = bit; ; nbit = (nbit - 1) & bit) {
                    if(nbit == bit) continue;
                    if(nbit & 1) {
                        // A win : Aはp, S - Aはr
                        {
                            ld val = 1.0;
                            rep(i, n) {
                                if(i == 0) continue;
                                unless(bit & (1<<i)) continue;
                                if(nbit & (1<<i)) {
                                    val *= p[i];
                                } else {
                                    val *= r[i];
                                }
                            }
                            res -= val;
                            win_prob += val * dp[nbit];
                        }
                        // A lose : Aはp, S - Aはs
                        {
                            ld val = 1.0;
                            rep(i, n) {
                                if(i == 0) continue;
                                unless(bit & (1<<i)) continue;
                                if(nbit & (1<<i)) {
                                    val *= p[i];
                                } else {
                                    val *= s[i];
                                }
                            }
                            res -= val;
                        }
                    }
                    if(nbit == 0) break;
                }
                {
                    int ssrs = -1;
                    int val = -1;
                    rep(i, n) {
                        if(bit & (1<<i)) {
                            if(chmax(val, a[i])) {
                                ssrs = i;
                            }
                        }
                    }
                    if(ssrs == 0) {
                        win_prob += res;
                    }
                }
                chmax(ma, win_prob);
            }
            dp[bit] = ma;
        } else {
            dp[bit] = 0.0;
        }
    }
    print(dp[(1<<n) - 1]);
}
accuracy: 1
time_ms: 380
memory_kb: 3664
final_rank: 16

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define eps 1e-9
#define INF 2000000000              // 2e9
#define LLINF 2000000000000000000ll // 2e18 (llmax:9e18)
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define drep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)

#define popcount __builtin_popcount
#define next __next
#define prev __prev

#ifndef LOCAL
#define dmp(...) ;
#else
#define dmp(...)                                                               \
  cerr << "[ " << #__VA_ARGS__ << " ] : " << dump_str(__VA_ARGS__) << endl
#endif

// ---------------- Utility ------------------

template <class T>
bool chmin(T &a, const T &b) {
  if (a <= b) return false;
  a = b;
  return true;
}

template <class T>
bool chmax(T &a, const T &b) {
  if (a >= b) return false;
  a = b;
  return true;
}

template <class T>
using MaxHeap = priority_queue<T>;

template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;

template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}

// ----------------- Input -------------------

template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  return is >> p.first >> p.second;
}

template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}

// ----------------- Output ------------------

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  return os << p.first << ',' << p.second;
}

template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for (const T &e : v) os << e << " ";
  return os;
}

template <class T>
ostream &operator<<(ostream &os, const deque<T> &d) {
  for (const T &e : d) os << e << " ";
  return os;
}

template <class T>
ostream &operator<<(ostream &os, const set<T> &s) {
  os << "{ ";
  for (const T &e : s) os << e << " ";
  return os << "}";
}

template <class T, class U>
ostream &operator<<(ostream &os, const map<T, U> &m) {
  os << "{ ";
  for (const auto &[key, val] : m) os << "( " << key << " -> " << val << " ) ";
  return os << "}";
}

template <class TupleTy, size_t... I>
void dump_tuple(ostream &os, const TupleTy t, std::index_sequence<I...>) {
  (..., (os << (I == 0 ? "" : ",") << std::get<I>(t)));
}

template <class... Args>
ostream &operator<<(ostream &os, const tuple<Args...> &t) {
  os << "(";
  dump_tuple(os, t, std::make_index_sequence<sizeof...(Args)>());
  return os << ")";
}

void dump_str_rec(ostringstream &) {}

template <class Head, class... Tail>
void dump_str_rec(ostringstream &oss, Head &&head, Tail &&... tail) {
  oss << ", " << head;
  dump_str_rec(oss, forward<Tail>(tail)...);
}

template <class T, class... U>
string dump_str(T &&arg, U &&... args) {
  ostringstream oss;
  oss << arg;
  dump_str_rec(oss, forward<U>(args)...);
  return oss.str();
}

// --------------- Fast I/O ------------------

void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}

// ------------------ ACL --------------------

// #include <atcoder/modint>
// constexpr int MOD = 998244353;
// constexpr int MOD = 1000000007;
// using mint = atcoder::static_modint<MOD>;
// ostream &operator<<(ostream &os, const mint &v) {
//   return os << v.val();
// }

// ------------ End of template --------------

#define endl "\n"
using ll = long long;
using pii = pair<int, int>;

const bool multitest = false;

void solve() {
  int N;
  cin >> N;
  vector<int> a(N);
  auto rps = vect(N, vect(3, 0));
  cin >> a[0];
  for (int i = 1; i < N; i++) {
    cin >> a[i] >> rps[i][0] >> rps[i][1] >> rps[i][2];
  }

  vector<double> dp(1 << N, -1);
  // 残りSになってから0が優勝する確率
  auto rec = [&](auto &&f, int S) {
    if (dp[S] != -1) return dp[S];

    if ((S & 1) == 0) return dp[S] = 0.0;
    if (S == 1) return dp[S] = 1.0;

    pair<int, int> mx_rating(a[0], 0);
    for (int i = 1; i < N; i++) {
      if ((S >> i) & 1) chmax(mx_rating, pii(a[i], i));
    }

    double mx = 0.0;
    auto tmp = rps[0];
    // z: 0の戦略
    for (int z = 0; z < 3; z++) {
      rps[0][z] = 100;
      rps[0][(z + 1) % 3] = 0;
      rps[0][(z + 2) % 3] = 0;

      double rem = 1.0;
      double res = 0.0;

      for (int T = S;; T = (T - 1) & S) {
        if (T == S) continue;
        if (T == 0) break;
        for (int i = 0; i < 3; i++) {
          // TがiでS^Tが(i + 1) % 3、S^Tの勝ち
          double p = 1.0;
          for (int j = 0; j < N; j++) {
            if (!((S >> j) & 1)) continue;
            if ((T >> j) & 1) {
              p *= rps[j][i] / 100.0;
            } else {
              p *= rps[j][(i + 1) % 3] / 100.0;
            }
          }
          res += p * f(f, S ^ T);
          rem -= p;
        }
      }
      rps[0] = tmp;

      if (mx_rating.second == 0) res += rem;
      chmax(mx, res);
    }

    return dp[S] = mx;
  };

  // cout << rec(rec, 3) << endl;
  cout << rec(rec, (1 << N) - 1) << endl;
  return;
}

int main() {
  fastio();
  if (!multitest) {
    solve();
  } else {
    cerr << "[Warning] Multi testcase mode on" << endl;
    int t;
    cin >> t;
    while (t--) solve();
  }
  return 0;
}
accuracy: 1
time_ms: 1050
memory_kb: 3656
final_rank: 19

code_snippet: #pragma GCC ta g("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define DEBUG
#ifdef DEBUG
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << '{';
    for(int i = 0; i < (int)v.size(); i++) {
        if(i) { os << ','; }
        os << v[i];
    }
    os << '}';
    return os;
}
void debugg() { cerr << endl; }
template <class T, class... Args>
void debugg(const T &x, const Args &... args) {
    cerr << " " << x;
    debugg(args...);
}
#define debug(...)                                                             \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]: ", debugg(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = (1<<30)-1;
const ll linf = 1LL<<61;
const int MAX = 510000;
int dy[8] = {0,1,0,-1,1,-1,-1,1};
int dx[8] = {-1,0,1,0,1,-1,1,-1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    int sz = a.size();
    for(auto itr = a.begin(); itr != a.end(); itr++){
		cout << *itr;
        sz--;
        if(sz) cout << " ";
	}
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){
	cout << a << " " << b << "\n";
}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
void mark() {cout << "#" << "\n";}
ll pcount(ll x) {return __builtin_popcountll(x);}
//#include <atcoder/maxflow>
//using namespace atcoder;
//const int mod = 1e9 + 7;
const int mod = 998244353;

double dp[1<<14];

int main(){
    int n; cin >> n; n--;
    int A; cin >> A;
    vl a(n);
    vvl b(n,vl(3));
    rep(i,n){
        cin >> a[i];
        rep(j,3) cin >> b[i][j];
        swap(b[i][1],b[i][2]);
    }
    dp[0] = 1;
    REP(bit,1,1<<n){
        vl ls;
        rep(i,n) if(bit>>i&1) ls.push_back(i);
        vd res(3,0);
        for(int S=bit-1; S>=0; S--){
            S &= bit;
            vd p(3,1);
            rep(i,3){
                for(auto x : ls){
                    if(S>>x&1) p[i] *= (double)b[x][i] / 100; //勝ち
                    else p[i] *= (double)b[x][(i+1)%3] / 100; //負け
                }
            }
            if(S == 0){
                bool f = true;
                for(auto x : ls) if(A < a[x]) f = false;
                if(f){
                    vd pp(3,1);
                    rep(i,3){
                        double u = 1, v = 1;
                        for(auto x : ls){
                            u *= (double)(b[x][i] + b[x][(i+2)%3]) / 100;
                            v *= (double)(b[x][i] + b[x][(i+1)%3]) / 100;
                        }
                        pp[i] = 1 - u - v + p[(i+2)%3] * 2 + p[i];
                    }
                    rep(i,3) p[i] = pp[i];
                }
            }
            rep(i,3) res[i] += dp[S] * p[i];
        }
        dp[bit] = *max_element(all(res));
    }
    printf("%.10f\n",dp[(1<<n)-1]);
}
accuracy: 1
time_ms: 120
memory_kb: 3616
final_rank: 5

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=300005;
const ll INF=1LL<<40;
int N;
int a[15];
double p[15][3],dp[1<<14];
bool seen[1<<14];

double solve(int S){
    if(seen[S]) return dp[S];
    if(!(S&1)) return dp[S]=0;
    if(S==1) return dp[S]=1;
    
    seen[S]=true;
    
    double res=0;
    vector<double> pp(3,1.0);
    bool rate=true;
    for(int t=0;t<3;t++){
        for(int i=1;i<N;i++){
            if(S&(1<<i)) pp[t]*=p[i][t];
        }
    }
    for(int i=1;i<N;i++){
        if(S&(1<<i)){
            if(a[0]<a[i]) rate=false;
        }
    }
    
    for(int t=0;t<3;t++){
        double win=0,psum=1;
        for(int s=0;s<3;s++){
            if(t==s){
                if(rate) win+=pp[s];
            }else if((t+1)%3==s) win+=pp[s];
            
            psum-=pp[s];
            
            for(int bit=S;;bit=(bit-1)&S){
                if(bit&1) continue;
                if(bit==0) break;
                if(bit==S-1) continue;
                
                double pe=1;
                for(int i=1;i<N;i++){
                    if(S&(1<<i)){
                        if(bit&(1<<i)) pe*=p[i][(s+1)%3];
                        else pe*=p[i][s];
                    }
                }
                
                if(t==s){
                    win+=pe*solve(S-bit);
                }else if((t+1)%3==s){
                    if(rate) win+=pe;
                }
                
                psum-=pe;
            }
        }
        
        if(rate) win+=psum;
        
        chmax(res,win);
    }
    
    return dp[S]=res;
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>N;
    cin>>a[0];
    for(int i=1;i<N;i++){
        cin>>a[i]>>p[i][0]>>p[i][2]>>p[i][1];
        for(int j=0;j<3;j++) p[i][j]/=100;
    }
    cout<<fixed<<setprecision(25)<<solve((1<<N)-1)<<endl;
}
accuracy: 1
time_ms: 560
memory_kb: 3736
final_rank: 18

code_snippet: #include <bits/stdc++.h>
using namespace std;
int main(){
  cout << fixed << setprecision(20);
  int N;
  cin >> N;
  int A;
  cin >> A;
  N--;
  vector<int> a(N);
  vector<vector<double>> p(N, vector<double>(3));
  for (int i = 0; i < N; i++){
    cin >> a[i];
    for (int j = 0; j < 3; j++){
      cin >> p[i][j];
      p[i][j] /= 100;
    }
  }
  vector<double> dp(1 << N, 0);
  dp[0] = 1;
  for (int i = 1; i < (1 << N); i++){
    for (int j = 0; j < 3; j++){
      double t = 1;
      double s = 0;
      for (int k = i; k > 0; k = (k - 1) & i){
        double r1 = 1, r2 = 1;
        for (int l = 0; l < N; l++){
          if ((i >> l & 1) == 1){
            if ((k >> l & 1) == 1){
              r1 *= p[l][(j + 2) % 3];
              r2 *= p[l][(j + 1) % 3];
            } else {
              r1 *= p[l][j % 3];
              r2 *= p[l][j % 3];
            }
          }
        }
        t -= r1;
        t -= r2;
        s += r1 * dp[i - k];
      }
      int mx = 0;
      for (int k = 0; k < N; k++){
        if ((i >> k & 1) == 1){
          mx = max(mx, a[k]);
        }
      }
      if (A > mx){
        s += t;
      }
      dp[i] = max(dp[i], s);
    }
  }
  cout << dp[(1 << N) - 1] << endl;
}
accuracy: 1
time_ms: 160
memory_kb: 3316
final_rank: 4

code_snippet: #pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
#include<array>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
constexpr ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acosl(-1.0);

ll mod_pow(ll x, ll n, ll m = mod) {
	if (n < 0) {
		ll res = mod_pow(x, -n, m);
		return mod_pow(res, m - 2, m);
	}
	if (abs(x) >= m)x %= m;
	if (x < 0)x += m;
	ll res = 1;
	while (n) {
		if (n & 1)res = res * x % m;
		x = x * x % m; n >>= 1;
	}
	return res;
}
struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n % mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, ll n) {
	if (n == 0)return modint(1);
	modint res = (a * a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }
modint operator/=(modint& a, modint b) { a = a / b; return a; }
const int max_n = 1 << 2;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
modint combP(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[a - b];
}

template<typename T>
struct SegT {
private:
	int sz; vector<T> node;
	T init_c;
	function<T(T, T)> f;
public:
	SegT(vector<T> v, T _init_c, function<T(T, T)> _f) {
		init_c = _init_c; f = _f;
		int n = v.size();
		sz = 1;
		while (sz < n)sz *= 2;
		node.resize(2 * sz - 1, init_c);
		rep(i, n) {
			node[i + sz - 1] = v[i];
		}
		per(i, sz - 1) {
			node[i] = f(node[2 * i + 1], node[2 * i + 2]);
		}
	}
	SegT(int n, T _init_c, function<T(T, T)> _f) {
		init_c = _init_c; f = _f;
		sz = 1;
		while (sz < n)sz *= 2;
		node.resize(2 * sz - 1, init_c);
	}
	void update(int k, T a) {
		k += sz - 1;
		node[k] = a;
		while (k > 0) {
			k = (k - 1) / 2;
			node[k] = f(node[k * 2 + 1], node[k * 2 + 2]);
		}
	}
	T query(int a, int b, int k = 0, int l = 0, int r = -1) {
		if (r < 0)r = sz;
		if (r <= a || b <= l)return init_c;
		else if (a <= l && r <= b)return node[k];
		else {
			T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
			T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
			return f(vl, vr);
		}
	}
	int sear(int l, T x, function<bool(T, T)> f) {
		if (f(x, node[l+sz-1]))return l;
		l += sz - 1;
		while (l > 0) {
			int p = (l - 1) / 2;
			if (2 * p + 1 == l) {
				if (f(x, node[2 * p + 2])) {
					l = 2 * p + 2; break;
				}
			}
			l = p;
		}
		if (l == 0)return sz;
		while (l<sz-1) {
			if (f(x, node[2 * l + 1])) {
				l = 2 * l + 1;
			}
			else {
				l = 2 * l + 2;
			}
		}
		return l - (sz - 1);
	}
};

struct BIT {
private:
	vector<ll> node; int n;
public:
	BIT(int n_) {
		n = n_; node.resize(n, 0);
	}
	//0-indexed
	void add(int a, ll w) {
		for (int i = a; i < n; i |= i + 1)node[i] += w;
	}
	//[0,a)
	ll sum(int a) {
		ll ret = 0;
		for (int i = a - 1; i >= 0; i = (i & (i + 1)) - 1)ret += node[i];
		return ret;
	}
	//[a,b)
	ll sum(int a, int b) {
		return sum(b) - sum(a);
	}
};

void solve() {
	int n; cin >> n;
	vector<int> a(n);
	vector<vector<ld>> c(n, vector<ld>(3));
	rep(i, n) {
		cin >> a[i];
		if (i > 0)rep(j, 3) {
			cin >> c[i][j];
			c[i][j] /= 100.0;
		}
		if (i > 0) {
			swap(c[i][1], c[i][2]);
		}
	}
	vector<ld> memo(1 << n);
	vector<bool> used(1 << n);
	function<ld(int)> dfs = [&](int s)->ld {
		if (used[s])return memo[s];
		used[s] = true;
		if (s == 1)return memo[s] = 1;
		if ((s & 1) == 0)return memo[s] = 0;
		ld res = 0;
		rep(col, 3) {
			ld csum = 0;
			for (int b = s;; b = (b - 1) & s) {
				if (b > 0 && b < s) {
					if (b & 1) {
						ld pro = 1;
						//col and col+1
						rep1(i, n-1)if (s & (1 << i)) {
							if (b & (1 << i))pro *= c[i][col];
							else pro *= c[i][(col + 1) % 3];
						}
						csum += pro * dfs(b);
					}
				}
				if (b == 0)break;
			}
			//aiko
			int ma = 0;
			rep(i, n)if (s & (1 << i))ma = max(ma, a[i]);
			if (ma == a[0]) {
				ld ad = 1;
				//only t and t+1
				rep(t, 3) {
					int nt = (t + 1) % 3;
					if ((t + 2) % 3 == col)continue;
					ld pro = 1;
					rep1(i, n-1)if (s & (1 << i)) {
						pro *= c[i][t] + c[i][nt];
					}
					ad -= pro;
				}
				//only t
				rep(t, 3) {
					if (t != col)continue;
					ld pro = 1;
					rep1(i, n - 1)if (s & (1 << i)) {
						pro *= c[i][t];
					}
					ad += 2 * pro;
				}
				//cout << "?? " << s << " " << csum << " " << ad << "\n";
				csum += ad;
			}
			res = max(res, csum);
		}
		return memo[s] = res;
	};
	ld ans = dfs((1 << n) - 1);
	cout << ans << "\n";
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(10);
	//init_f();
	//init();
	//expr();
	//int t; cin >> t;rep(i,t)
	solve();
	return 0;
}
accuracy: 1
time_ms: 170
memory_kb: 3656
final_rank: 8

code_snippet: #line 1 "main.cpp"
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>

using namespace std;
using ldouble = long double;

void solve() {
    int n, sx;
    cin >> n >> sx;
    --n;

    vector<int> xs(n);
    auto prob = vector(n, vector(3, 0.L));

    for (int i = 0; i < n; ++i) {
        cin >> xs[i];
        for (auto& p : prob[i]) {
            cin >> p;
            p /= 100;
        }
    }

    vector<ldouble> dp(1 << n, 0);
    dp[0] = 1;

    for (int b = 1; b < (1 << n); ++b) {
        vector<int> is;
        for (int i = 0; i < n; ++i) {
            if ((b >> i) & 1) is.push_back(i);
        }
        int m = is.size();

        bool strong = all_of(is.begin(), is.end(),
                             [&](int i) { return xs[i] < sx; });

        for (int t = 0; t < 3; ++t) {
            // tとt+1のみ 自分はt+1を出す
            ldouble score = 0, winp = 0;

            // 勝つ場合
            for (int c = 0; c < (1 << m) - 1; ++c) {
                // 全部1を除外

                ldouble p = 1;
                int nb = 0;
                for (int i = 0; i < m; ++i) {
                    int d = ((c >> i) & 1);

                    if (d) nb |= (1 << is[i]);
                    p *= prob[is[i]][(t + d) % 3];
                }

                score += p * dp[nb];
                winp += p;
            }

            // 負ける場合
            ldouble losep = 0;
            for (int c = 1; c < (1 << m); ++c) {
                ldouble p = 1;
                for (int i = 0; i < m; ++i) {
                    int d = ((c >> i) & 1);
                    p *= prob[is[i]][(t + d + 1) % 3];
                }
                losep += p;
            }

            // あいこの場合
            if (strong) score += 1 - winp - losep;

            dp[b] = max(dp[b], score);
        }
    }

    cout << dp.back() << "\n";
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    solve();

    return 0;
}
accuracy: 1
time_ms: 210
memory_kb: 3636
final_rank: 12

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <math.h>
#include <stack>
using namespace std;
typedef long long ll;

int n,m;
int a[14];
double p[14][3];
double dp[1<<14];
double pp[1<<13][6];
int ma[1<<13];

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cin >> n >> m; n--;
	for(int i=0;i<n;i++){
		cin >> a[i];
		cin >> p[i][0] >> p[i][1] >> p[i][2];
		p[i][0]/=100,p[i][1]/=100,p[i][2]/=100;
	}
	dp[0]=1;
	for(int i=0;i<(1<<n);i++){
		for(int j=0;j<3;j++){
			double res=1;
			for(int k=0;k<n;k++){
				if((1<<k)&i){
					res*=p[k][j];
				}
			}
			pp[i][j]=res;
		}
		for(int j=0;j<3;j++){
			double res=1;
			for(int k=0;k<n;k++){
				if((1<<k)&i){
					res*=(1-p[k][j]);
				}
			}
			pp[i][j+3]=res;
		}
	}
	for(int i=0;i<(1<<n);i++){
		int res=0;
		for(int j=0;j<n;j++){
			if((i>>j)&1){
				res=max(res,a[j]);
			}
		}
		ma[i]=res;
	}
	for(int s=1;s<(1<<n);s++){
		double rrr=0,sss=0,ppp=0;
		for(int t=0;t<s;t++){
			if((s&t)==t){
				double winr,wins,winp;
				winr=pp[s-t][2]*pp[t][0];
				winp=pp[s-t][0]*pp[t][1];
				wins=pp[s-t][1]*pp[t][2];
				rrr+=dp[t]*winr;
				sss+=dp[t]*wins;
				ppp+=dp[t]*winp;
			}
		}
		double drowr,drows,drowp;
		drowp=(1-(pp[s][5]+pp[s][3]-pp[s][1]*2));
		drows=(1-(pp[s][4]+pp[s][3]-pp[s][2]*2));
		drowr=(1-(pp[s][5]+pp[s][4]-pp[s][0]*2));
		if(ma[s]<m){
			rrr+=drowr;
			ppp+=drowp;
			sss+=drows;
		}
		dp[s]+=max({rrr,sss,ppp});
	}
	printf("%.9f\n",dp[(1<<n)-1] );
}
accuracy: 1
time_ms: 20
memory_kb: 3800
final_rank: 2

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define REP(i, n) for (int i = 0; i < (n); i++)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    n--;
    int A;
    cin >> A;
    vector<int> a(n);
    vector<vector<double>> b(3, vector<double>(n));
    REP(i, n) cin >> a[i] >> b[0][i] >> b[1][i] >> b[2][i];
    REP(i, n) b[0][i] /= 100, b[1][i] /= 100, b[2][i] /= 100;

    vector<double> dp(1 << n, -1);
    dp[0] = 1;
    function<double(int)> dfs = [&](int S) {
        if (dp[S] != -1) return dp[S];
        double ret = 0;
        bool ok = true;
        REP(i, n) {
            if ((S >> i & 1) && a[i] > A) ok = false;
        }
        REP(c, 3) {
            double acc = 0.0;
            double draw = 1.0;
            for (int T = S;; T = (T - 1) & S) {
                if (T == S) continue;
                double win = 1.0, lose = 1.0;
                REP(i, n) {
                    if ((S >> i & 1) == 0) continue;
                    win *= ((T >> i & 1) ? b[c][i] : b[(c + 2) % 3][i]);
                    lose *= ((T >> i & 1) ? b[(c) % 3][i] : b[(c + 1) % 3][i]);
                }
                acc += dfs(T) * win;
                draw -= win + lose;
                // acc += exp(dfs(T) + win);
                // draw -= exp(win) + exp(lose);
                if (T == 0) break;
            }
            if (ok) acc += draw;
            ret = max(ret, acc);
        }
        return dp[S] = ret;
    };
    int all = (1 << n) - 1;
    dfs(all);
    // REP(i, 1 << n) cout << i << " " << dp[i] << endl;
    cout << setprecision(20) << dp[all] << endl;
}
accuracy: 1
time_ms: 220
memory_kb: 3356
final_rank: 11

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define int long long
// #define double long double
#define REP(i, n) for (int i = 0; i < (n); i++)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    n--;
    int A;
    cin >> A;
    vector<int> a(n);
    vector<vector<double>> b(3, vector<double>(n));
    REP(i, n) cin >> a[i] >> b[0][i] >> b[1][i] >> b[2][i];
    REP(i, n) b[0][i] /= 100, b[1][i] /= 100, b[2][i] /= 100;

    vector<double> dp(1 << n, -1);
    dp[0] = 1;
    function<double(int)> dfs = [&](int S) {
        if (dp[S] != -1) return dp[S];
        double ret = 0;
        bool ok = true;
        REP(i, n) {
            if ((S >> i & 1) && a[i] > A) ok = false;
        }
        REP(c, 3) {
            double acc = 0.0;
            double draw = 1.0;
            for (int T = S;; T = (T - 1) & S) {
                if (T == S) continue;
                double win = 1.0, lose = 1.0;
                REP(i, n) {
                    if ((S >> i & 1) == 0) continue;
                    win *= ((T >> i & 1) ? b[c][i] : b[(c + 2) % 3][i]);
                    lose *= ((T >> i & 1) ? b[(c) % 3][i] : b[(c + 1) % 3][i]);
                }
                acc += dfs(T) * win;
                draw -= win + lose;
                // acc += exp(dfs(T) + win);
                // draw -= exp(win) + exp(lose);
                if (T == 0) break;
            }
            if (ok) acc += draw;
            ret = max(ret, acc);
        }
        return dp[S] = ret;
    };
    int all = (1 << n) - 1;
    dfs(all);
    // REP(i, 1 << n) cout << i << " " << dp[i] << endl;
    cout << setprecision(20) << dp[all] << endl;
}
accuracy: 1
time_ms: 180
memory_kb: 3332
final_rank: 6

code_snippet: #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;
}
accuracy: 1
time_ms: 260
memory_kb: 3380
final_rank: 13

code_snippet: #include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


struct Info{
	void set(double arg_rock,double arg_paper,double arg_scissors){
		rock = arg_rock;
		paper = arg_paper;
		scissors = arg_scissors;
	}
	int rating;
	double rock,paper,scissors;
};



int POW[14];
int N,my_rating;
double* dp;
Info info[14];

double recursive(int state){

	if(dp[state] != -1.0)return dp[state];
	if(state == POW[N]-1)return 1.0;

	double ret_rock = 0,ret_paper = 0,ret_scissors = 0;
	int maximum,alive_num,new_loser;
	double calc_1,calc_2,win_rock,win_paper,win_scissors;
	double end_rock,end_paper,end_scissors,finish_rock,finish_paper,finish_scissors;
	vector<int> member;

	member.clear();
	maximum = my_rating;
	alive_num = 0;

	for(int loop = 0; loop < N; loop++){
		if(state & (1 << loop)){
			//Do nothing
		}else{
			member.push_back(loop);
			maximum = max(maximum,info[loop].rating);
			alive_num++;
		}
	}

	finish_rock = finish_paper = finish_scissors = 0.0;

	if(maximum == my_rating){

		end_rock = 0;

		calc_1 = 1.0;
		calc_2 = 1.0;

		for(int i = 0; i < alive_num; i++){
			calc_1 *= (info[member[i]].rock+info[member[i]].scissors);
			calc_2 *= info[member[i]].rock;
		}
		end_rock += calc_1-calc_2;

		calc_1 = 1.0;
		calc_2 = 1.0;

		for(int i = 0; i < alive_num; i++){
			calc_1 *= (info[member[i]].paper+info[member[i]].rock);
			calc_2 *= info[member[i]].rock;
		}
		end_rock += calc_1-calc_2;
		finish_rock = 1.0-end_rock;

		end_scissors = 0.0;

		calc_1 = 1.0;
		calc_2 = 1.0;

		for(int i = 0; i < alive_num; i++){
			calc_1 *= (info[member[i]].scissors+info[member[i]].paper);
			calc_2 *= info[member[i]].scissors;
		}
		end_scissors += calc_1-calc_2;

		calc_1 = 1.0;
		calc_2 = 1.0;

		for(int i = 0; i < alive_num; i++){
			calc_1 *= (info[member[i]].rock+info[member[i]].scissors);
			calc_2 *= info[member[i]].scissors;
		}
		end_scissors += calc_1-calc_2;
		finish_scissors = 1.0-end_scissors;

		end_paper = 0.0;

		calc_1 = 1.0;
		calc_2 = 1.0;

		for(int i = 0; i < alive_num; i++){
			calc_1 *= (info[member[i]].paper+info[member[i]].rock);
			calc_2 *= info[member[i]].paper;
		}
		end_paper += calc_1-calc_2;

		calc_1 = 1.0;
		calc_2 = 1.0;

		for(int i = 0; i < alive_num; i++){
			calc_1 *= (info[member[i]].scissors+info[member[i]].paper);
			calc_2 *= info[member[i]].paper;
		}
		end_paper += calc_1-calc_2;
		finish_paper = 1.0-end_paper;
	}

	for(int i = 0; i < POW[alive_num]; i++){

		new_loser = 0;
		win_rock = 1.0;
		win_paper = 1.0;
		win_scissors = 1.0;

		for(int loop = 0; loop < alive_num; loop++){
			if(i & (1 << loop)){
				win_rock *= info[member[loop]].rock;
				win_paper *= info[member[loop]].paper;
				win_scissors *= info[member[loop]].scissors;
			}else{
				win_rock *= info[member[loop]].scissors;
				win_paper *= info[member[loop]].rock;
				win_scissors *= info[member[loop]].paper;
				new_loser += POW[member[loop]];
			}
		}
		if(new_loser == 0)continue;

		if(state+new_loser == POW[N]-1){
			finish_rock += win_rock;
			finish_paper += win_paper;
			finish_scissors += win_scissors;
			continue;
		}

		ret_rock += win_rock*recursive(state+new_loser);
		ret_paper += win_paper*recursive(state+new_loser);
		ret_scissors += win_scissors*recursive(state+new_loser);
	}

	return dp[state] = max(ret_rock+finish_rock,max(ret_paper+finish_paper,ret_scissors+finish_scissors));
}


int main(){

	for(int i = 0; i < 14; i++)POW[i] = pow(2,i);

	scanf("%d",&N);
	N -= 1;

	scanf("%d",&my_rating);

	double r,p,s;
	for(int i = 0; i < N; i++){
		scanf("%d %lf %lf %lf",&info[i].rating,&r,&p,&s);
		info[i].set(r/100.0,p/100.0,s/100.0);
	}

	dp = new double[POW[N]];
	for(int i = 0; i < POW[N]; i++)dp[i] = -1.0;

	printf("%.10lf\n",recursive(0));
	return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 3484
final_rank: 1

code_snippet: #include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
int rate[1001];
double per[15][3];
double dp[15][1<<14][1<<3];
double dp2[1<<14];

double solve(int bit){
	if(dp2[bit]>=-0.1)return dp2[bit];
	if(bit==0)return 1.0;
	double res=0.0;
	for(int i=0;i<3;i++){
		double now=0.0;
		for(int j=1;j<8;j++){
			int nbit=j|(1<<i);
			if(nbit==1 || nbit==2 || nbit==4 || nbit==7){
				bool flag=true;
				for(int k=0;k<n-1;k++){
					if(rate[n-1]<rate[k] && (bit>>k & 1))flag=false;
				}
				if(flag)now+=dp[n-1][bit][j];
			}else{
				if(nbit==3 && i==0)continue;
				if(nbit==5 && i==2)continue;
				if(nbit==6 && i==1)continue;
				for(int k=(bit-1)&bit;k>=0;k=(k-1)&bit){
					double pr=1.0;
					int rest=3;
					if(nbit==3 && j==2)rest=2;
					if(nbit==3 && j==1)rest=1;
					if(nbit==5 && j==1)rest=2;
					if(nbit==5 && j==4)rest=1;
					if(nbit==6 && j==4)rest=2;
					if(nbit==6 && j==2)rest=1;

					for(int l=0;l<n-1;l++){
						if(!(bit>>l & 1))continue;
						if(nbit==3){
							if(k>>l & 1){
								if(j==1)pr=0.0;
								pr*=per[l][1];
								if(rest>=2)rest-=2;
							}
							else{
								if(j==2)pr=0.0;
								pr*=per[l][0];
								if(rest%2==1)rest-=1;
							}
						}
						if(nbit==5){
							if(k>>l & 1){
								if(j==4)pr=0.0;
								pr*=per[l][0];
								if(rest>=2)rest-=2;
							}else{
								if(j==1)pr=0.0;
								pr*=per[l][2];
								if(rest%2==1)rest-=1;
							}
						}
						if(nbit==6){
							if(k>>l & 1){
								if(j==2)pr=0.0;
								pr*=per[l][2];
								if(rest>=2)rest-=2;
							}else{
								if(j==4)pr=0.0;
								pr*=per[l][1];
								if(rest%2==1)rest-=1;
							}
						}
					}
					if(rest==0 && pr>1e-15)now+=pr*solve(k);
					if(k==0)break;
				}
			}
		}
		res=max(res,now);
	}
	dp2[bit]=res;
	return dp2[bit];
}

int main(void){
	scanf("%d",&n);
	scanf("%d",&rate[n-1]);
	for(int i=0;i<n-1;i++){
		scanf("%d",&rate[i]);
		for(int j=0;j<3;j++){
			scanf("%lf",&per[i][j]);
			per[i][j]/=100.0;
		}
	}
	for(int i=0;i<(1<<(n-1));i++){
		dp[0][i][0]=1.0;
	}
	for(int i=0;i<n-1;i++){
		for(int j=0;j<1<<(n-1);j++){
			for(int k=0;k<8;k++){
				if(dp[i][j][k]<1e-15)continue;
				if(j>>i & 1){
					for(int l=0;l<3;l++){
						dp[i+1][j][k|(1<<l)]+=dp[i][j][k]*per[i][l];
					}
				}else{
					dp[i+1][j][k]=dp[i][j][k];
				}
			}
		}
	}
	for(int i=0;i<(1<<n-1);i++){
		dp2[i]=-1.0;
	}
	printf("%.12f\n",solve((1<<n-1)-1));
	return 0;
}
accuracy: 1
time_ms: 450
memory_kb: 10544
final_rank: 20