#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <string>
#include <vector>
#include <numeric>
#include <algorithm>

using namespace std;

[[noreturn]] void err(const char *msg) {
    cerr << "Judge Error\n";
    cerr << "ADMIN_MESSAGE: " << msg << "\n";
    exit(1);
}

[[noreturn]] void grade(float score, const char* msg, const char* admin_msg = nullptr) {
    cout << score;
    cerr << msg << "\n";
    if(admin_msg) cerr << "ADMIN_MESSAGE: " << admin_msg << "\n";
    exit(0);
}

int find_next(const vector<vector<int>>& b, const vector<int>& perm, int x) {
    int mini = -1;
    int maxi = b.size();
    while (maxi != mini + 1) {
        int mid = (maxi + mini) / 2;
        if (b[perm[mid]].back() > x) maxi = mid;
        else mini = mid;
    }
    return mini;
}

vector<vector<int>> simulate(int N, int M, vector<int> a) {
    vector<vector<int>> b(M);
    for (int i = 0; i < M; i++) {
        b[i].push_back(a[i]);
    }
    vector<int> perm(M);
    iota(perm.begin(), perm.end(), 0);
    sort(perm.begin(), perm.end(), [&](int x, int y){return b[x][0] < b[y][0];});

    for (int i = M; i < N; i++) {
        int ind = find_next(b, perm, a[i]);
        if (ind == -1) continue;
        b[perm[ind]].push_back(a[i]);
    }
    return b;
}

[[noreturn]] void yesnoCorrect(string reason) {
    grade(0.2, "translate:partial", reason.c_str());
}

[[noreturn]] void permutationValid(string reason) {
    grade(0.4, "translate:partial", reason.c_str());
}

[[noreturn]] void wrong(string reason) {
    grade(0.0, "translate:wrong", reason.c_str());
}

int main(int argc, char* argv[]) {
    ifstream input(argv[1]);
    ifstream master_output(argv[2]);
    ifstream contestant_output(argv[3]);

    if (!input.is_open())
        err("Cannot open input file!");
    if (!contestant_output.is_open())
        err("Cannot open output file!");
    if (!master_output.is_open())
        err("Cannot open correct output file!");

    int N, M;
    string S, T;

    input >> N >> M;

    master_output >> T;
    for (char& c : T) c = static_cast<char>(tolower(static_cast<unsigned char>(c)));

    vector<int> solution(N, -1);
    if (T == "yes") {
        for (int i = 0; i < N; i++) master_output >> solution[i];
    }

    if (!(contestant_output >> S)) wrong("no output");
    for (char& c : S) c = static_cast<char>(tolower(static_cast<unsigned char>(c)));

    if (S != T) wrong("wrong first line");

    std::string tmp;

    if (S == "no") {
        if (contestant_output >> tmp) {
            yesnoCorrect("no + garbage");
        }
        grade(1.0, "translate:success");
    }

    vector<int> a;
    int x;
    for (int i = 0; i < N; i++) {
        if (!(contestant_output >> x)) yesnoCorrect("failed to read permutation");
        a.push_back(x);
    }

    contestant_output >> std::ws;
    if (!contestant_output.eof()) yesnoCorrect("trailing garbage");

    vector<bool> perm(N, false);
    for (int i = 0; i < N; i++) {
        if (a[i] < 0 || a[i] >= N) yesnoCorrect("out-of-range");
        if (perm[a[i]]) yesnoCorrect("duplicate");
        perm[a[i]] = true;
    }

    if (solution == a) {
        grade(1.0, "translate:success");
    }

    // --- Valid permutation but not lex-smallest: simulate to verify correctness ---
    vector<vector<int>> binp(M);
    for (int i = 0; i < M; i++) {
        int L; input >> L;
        for (int j = 0; j < L; j++) {
            int v; input >> v;
            binp[i].push_back(v);
        }
    }

    vector<vector<int>> b = simulate(N, M, a);

    if (binp != b) {
        yesnoCorrect("perm fails");
    }

    if(a < solution) {
        err("contestant found better solution?");
    }

    permutationValid("ok, not smallest");
}
