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

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 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;
    input >> N;
    string R, S, T;
    input >> R;

    if (!(contestant_output >> S)) {
        grade(0, "translate:wrong", "no output");
    }
    for (char& c : S) c = static_cast<char>(tolower(static_cast<unsigned char>(c)));
    bool ans_contestant = 0;
    if(S == "yes") ans_contestant = 1;
    else if(S == "no") ans_contestant = 0;
    else {
        grade(0, "translate:wrong", "not yes/no");
    }


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

    bool ans_correct;
    if(T.length() == 3){
        ans_correct = 1;
    } else {
        ans_correct = 0;
    }

    if(ans_contestant){
        if(!ans_correct){
            grade(0, "translate:wrong", "got yes; expected no");
        }
 
        vector<int> a;

        int value;
        while (contestant_output >> value) {
            if(value < 0 || value > N-1) {
                grade(0, "translate:wrong", "out of range");
            }
            a.push_back(value);
        }

        if (a.size() != N) {
            grade(0, "translate:wrong",
              ("wrong length " + to_string(a.size()) + " != " + to_string(N)).c_str());
        }

        vector<bool> w(N,0); //taken or not
        vector<int> pos(N+1); //inverse permutation
        for(int i=0; i<N; ++i){
            w[a[i]]=1;
            pos[a[i]]=i;
        }

        //checks if ans is a permutation
        bool check_permutation = 1;
        for(int i=0; i<N; ++i){
            check_permutation &= w[i];
        }
        if(!check_permutation){
            grade(0, "translate:wrong", "not perm");
        }

        //checks the construction
        for(int i=0; i<N; ++i){
            if(R[i] == '+' && a[(pos[i]+1)%N] < i) grade(0, "translate:wrong", "invalid construction");
            if(R[i] == '-' && a[(pos[i]+1)%N] > i) grade(0, "translate:wrong", "invalid construction");
        }
        grade(1, "translate:success");

    } else{
        //contestant's answer is NO
        if(!ans_correct){ //solution's answer is NO
            string garbage;
            if(contestant_output>>garbage)
                grade(0, "translate:wrong", "no + garbage");
            grade(1, "translate:success");
        } else{ //solution's answer is YES
            grade(0, "translate:wrong", "got no; expected yes");
        }
    }
}
