// checker.cpp
#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;

static const string GRADER_SECRET = "7K4t9P2xL1m8Q5r";

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

    // Input format:
    // line 1: tc (1/2/3/4)
    // line 2: N
    // line 3: K
    // next K lines: L a1 a2 [a3]
    //
    // (혹은 한 줄에 tc N K로 두고 싶으면, 아래 readInt/readLong 순서만 그대로 두면 됨)

    int tc = inf.readInt(1, 4, "tc");
    int N = inf.readInt();
    long long K = inf.readLong(); 

    for (long long i = 0; i < K; i++) {
        int L = inf.readInt();
        for (int j = 0; j < L; j++) inf.readInt();
        inf.readEoln();
    }

    string secret = ouf.readToken();
    if (secret != GRADER_SECRET) {
        quitf(_wa, "Protocol violation: Grader secret mismatch (did you print to stdout?)");
    }

    long long x = ouf.readLong();
    long long Q = ouf.readLong();
    // ouf.skipBlanks(); ouf.readEof();

    // Protocol violation sentinel from grader => 0 points
    if (x == -1) {
        quitf(_wa, "Protocol violation (grader sentinel). Q=%lld", Q);
    }

    if (Q < 0 || Q > 3000) quitf(_wa, "Invalid query count Q=%lld", Q);
    if (x != K) quitf(_wa, "Wrong answer: got %lld, expected %lld", x, K);

    // Scoring
    double score = 0.0;
    if (tc == 1 || tc == 2) {
        score = 1.0;
    } else {
        if (Q <= 41) score = 1.0;
        else score = 0.5 +  41.0 / (2.0*Q);
        score = min(1.0, max(0.0, score));
    }

    if (score == 1.0) {
        quitf(_ok, "Correct. tc=%d, Q=%lld", tc, Q);
    } else {
        quitp(score, "Correct. tc=%d, Q=%lld, score=%.10f", tc, Q, score);
    }
}
