#include <fstream>
#include <iostream>
#include <string>

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);
}

string to_lower(string s) {
  for (char &c : s)
    c = static_cast<char>(tolower(static_cast<unsigned char>(c)));
  return s;
}

int main(int argc, char *argv[]) {
  if (argc < 4)
    err("Insufficient arguments. Usage: checker <input> <master-output> "
        "<contestant-output>");

  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, Q;
  if (!(input >> N >> Q))
    err("Cannot read N and Q from input");

  string S, T;
  for (int i = 0; i < Q; i++) {
    if (!(master_output >> T))
      err("Master output shorter than expected");
    if (!(contestant_output >> S)) {
      grade(0.0, "translate:wrong", "Contestant output shorter than expected");
    }

    if (to_lower(S) != to_lower(T)) {
      string msg = "Wrong answer at query " + to_string(i + 1);
      grade(0.0, "translate:wrong", msg.c_str());
    }
  }

  if (contestant_output >> S) {
    grade(0.0, "translate:wrong", "Contestant output longer than expected");
  }

  grade(1.0, "translate:success");
}
