Problem: cf1578_m
Difficulty: hard
Categories: game, math
Time limit: 2000 ms, memory limit: 1024 MB

This is an interactive problem.

In this problem, you need to come up with a strategy for a cooperative game. This game is played by two players. Each player receives 5 cards. Each card has a random integer between 1 and 100 on it. It is guaranteed that all numbers on cards are distinct.

The goal of the game is to play a card with a minimal number on it out of all 10 cards dealt to the players before any other card. The problem is that each player can only see their own cards and cannot communicate with another player in any way.

The game consists of 5 turns. During each turn, players simultaneously make a move. Each player can either play their smallest card or do nothing. If on some turn the smallest card is played, and no other card is played on or before that turn, players win. If two cards are played at the same turn or if after all 5 turns, no card is still played, players lose.

Players cannot communicate, so a strategy for the game should only be based on 5 cards that the player has. You can describe a strategy as five numbers $0.0 \le p_i \le 1.0, \sum_{i=1}^{5}p_i \le 1$, where $p_i$ — the probability of playing the player's smallest card in their hand on $i$-th turn. If you know the cards dealt to the players, and the strategies that players choose, you can compute the probability of winning by a simple formula.

You will be given $n=1000$ randomly generated hands of 5 cards. You need to generate a strategy for each of the hands to maximize the probability of winning. After the judge program receives all $n$ strategies, it generates all possible valid pairs of those hands (pairs which have the same numbers are discarded), and computes a probability of winning based on two strategies provided by your program.

To ensure that answers for different hands are independent, you must output a strategy for a hand and flush the standard output before reading information about the next hand.

If the average probability of winning a game is more than 85% over all valid pairs of hands, the test is considered passed. This problem contains the sample test and $20$ randomly generated tests with $n = 1000$.

Input

The first line contains one integer $n$ — the number of hands. It is guaranteed that $n = 1000$ for all cases except the first sample case.

Each of the next $n$ lines contains 5 numbers $a_i$ ($1 \le a_i \le 100, a_i < a_{i+1}$) — the cards in the hand. It is guaranteed that each possible set of 5 cards has an equal probability of being chosen.

Output

For each of the $n$ hands you need to output 5 numbers $0.0 \le p_i \le 1.0, \sum_{i=1}^{5}p_i \le 1$, where $p_i$ — probability of playing the smallest card on $i$-th turn.

Example

Input

```
2
2 12 27 71 100

22 29 39 68 90
```

Output

```
0.8 0.2 0.0 0.0 0.0 

0.0 0.2 0.2 0.2 0.3
```

Note

In the example test there is only one valid pair of hands. The winning probability for the example output is equal to $0.8 + 0.2 \cdot (1 - 0.2) = 0.96$. Also note that the second player will not play a card at all with probability 0.1.

Non-adaptive interactor (C++):
#include "testlib.h"
#include <bits/stdc++.h>

using namespace std;


static long long queries = 0;
static long long query_limit = 0;



static void log_metrics() {
    try {
        tout << "queries=" << queries << endl;
        tout << "query_limit=" << query_limit << endl;
    } catch (...) {
        
    }
}


static void finish(TResult verdict, const string& msg) {
    log_metrics();
    quitf(verdict, "%s", msg.c_str());
}


static string fmt_double(double x) {
    char buf[64];
    sprintf(buf, "%.5f", x);
    return string(buf);
}

struct Hand {
    vector<int> cards;
    vector<double> probs;
};

int main(int argc, char** argv) {
    
    registerInteraction(argc, argv);
    
    
    atexit(log_metrics);

    
    
    int n = inf.readInt();
    query_limit = n;
    
    
    log_metrics();

    
    cout << n << endl;

    vector<Hand> hands(n);
    
    
    for (int i = 0; i < n; ++i) {
        hands[i].cards.resize(5);
        for (int j = 0; j < 5; ++j) {
            hands[i].cards[j] = inf.readInt();
        }

        
        for (int j = 0; j < 5; ++j) {
            cout << hands[i].cards[j] << (j == 4 ? "" : " ");
        }
        cout << endl; 

        
        hands[i].probs.resize(5);
        double sum_p = 0.0;
        for (int j = 0; j < 5; ++j) {
            
            if (!(cin >> hands[i].probs[j])) {
                finish(_pe, "Failed to read probability " + to_string(j+1) + " for hand " + to_string(i+1));
            }
            
            if (hands[i].probs[j] < -1e-9 || hands[i].probs[j] > 1.0 + 1e-9) {
                finish(_wa, "Probability must be in [0, 1] for hand " + to_string(i+1));
            }
            
            if (hands[i].probs[j] < 0) hands[i].probs[j] = 0;
            if (hands[i].probs[j] > 1) hands[i].probs[j] = 1;
            
            sum_p += hands[i].probs[j];
        }
        
        
        if (sum_p > 1.0 + 1e-7) {
            finish(_wa, "Sum of probabilities exceeds 1.0 for hand " + to_string(i+1));
        }
        
        queries++;
        
        if (queries % 10 == 0) {
            log_metrics();
        }
    }
    
    
    double total_win_prob = 0.0;
    long long valid_pairs = 0;
    
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            
            bool disjoint = true;
            int p1 = 0, p2 = 0;
            const vector<int>& c1 = hands[i].cards;
            const vector<int>& c2 = hands[j].cards;
            
            while (p1 < 5 && p2 < 5) {
                if (c1[p1] == c2[p2]) {
                    disjoint = false; 
                    break;
                }
                if (c1[p1] < c2[p2]) p1++;
                else p2++;
            }
            
            if (disjoint) {
                valid_pairs++;
                
                
                int min_i = c1[0];
                int min_j = c2[0];
                
                const Hand* winner = (min_i < min_j) ? &hands[i] : &hands[j];
                const Hand* loser  = (min_i < min_j) ? &hands[j] : &hands[i];
                
                
                
                
                
                
                double prob = 0.0;
                double loser_cum = 0.0; 
                for (int k = 0; k < 5; ++k) {
                    loser_cum += loser->probs[k];
                    if (loser_cum > 1.0) loser_cum = 1.0; 
                    
                    prob += winner->probs[k] * (1.0 - loser_cum);
                }
                total_win_prob += prob;
            }
        }
    }
    
    
    if (valid_pairs == 0) {
        
        
        finish(_wa, "No valid disjoint pairs found (unexpected)");
    }
    
    double avg = total_win_prob / valid_pairs;
    
    if (avg > 0.85) {
        finish(_ok, "Passed, average winning probability = " + fmt_double(avg));
    } else {
        finish(_wa, "Average winning probability too low: " + fmt_double(avg) + " <= 0.85");
    }

    return 0;
}


Adaptive interactor (C++):

Test generator (C++):
#include "testlib.h"
#include <bits/stdc++.h>

using namespace std;

int main(int argc, char* argv[]) {
    
    registerGen(argc, argv, 1);

    
    
    
    string mode = opt<string>("mode", "non");
    int n = opt<int>("n", 1000);

    
    
    if (string(argv[1]) == "1") {
        cout << "2\n";
        cout << "2 12 27 71 100\n";
        cout << "22 29 39 68 90\n";
        return 0;
    }

    
    
    
    
    
    
    cout << n << "\n";
    for (int i = 0; i < n; ++i) {
        
        
        vector<int> hand = rnd.distinct(5, 100);

        
        for (int &card : hand) {
            card++;
        }

        
        sort(hand.begin(), hand.end());

        
        for (int j = 0; j < 5; ++j) {
            cout << hand[j] << (j == 4 ? "" : " ");
        }
        cout << "\n";
    }

    return 0;
}