/* the checker has three arguments:
    - first - name of the input file
    - second - name of the correct output file
    - third - name of the contestant output file */
#include<iostream>
#include<fstream>
#include<math.h>
#define MAXN 500
#define MAXM 500
using namespace std;
void output_message (double points, const char message[]) {
    cout << points << endl ;
    cerr << message << endl ;
    exit(0);
}
const long long int base=37159,mod=82651;
int main (int argc, char** argv) {
    ifstream inp,ans,out;
    if (argc<4) output_message(0,"The checker needs input file, correct output and contestant output!");
    inp.open(argv[1]);
    if (inp.is_open()==false) output_message(0,"Could not open input file!");
    ans.open(argv[2]);
    if (ans.is_open()==false) output_message(0,"Could not open correct output file!");
    out.open(argv[3]);
    if (out.is_open()==false) output_message(0,"Could not open contestant output file!");

    int n,m;
    long long int hash1=0;
    if (!(inp >> n >> m )) output_message(0,"Error reading input file!");
    hash1*=base; hash1+=n;
    hash1*=base; hash1+=m;
    for (int i=0; i<n; i++) {
        for (int j=0; j<m; j++) {
            int num;
            if (!(inp >> num)) output_message(0,"Error reading input file!");
            hash1*=base; hash1+=num;
            hash1%=mod;
        }
    }
    int hash2;
    if (!(out >> hash2 )) output_message(0,"Error reading output file!");
    if (hash1!=hash2) output_message(0,"Invalid output file!");
    int status;
    if (!(out >> status )) output_message(0,"Error reading output file!");
    if (status==-1) output_message(0,"Invalid row or column number in question!");
    if (status==-2) output_message(0,"Too many questions!");
    if (status==-3) output_message(0,"Invalid row or column in answer!");
    if (status==-4) output_message(0,"Wrong answer!");
    if (status!=0) output_message(0,"Invalid output file!");
    int cnt;
    if (!(out >> cnt )) output_message(0,"Error reading output file!");
    char tmp;
    if (out >> tmp ) output_message(0,"Extra output!");
    if (n==1) {
        if (cnt<30) output_message(1,"OK!");
        else if (cnt<300) output_message(min(1.0,30./cnt),"OK!");
        else output_message(0.1,"OK!");
    }
    else {
        if (cnt<2026) output_message(1,"OK!");
        else if (cnt<5000) output_message(min(1.0,pow(2026./cnt,max(1.0,4000./cnt))),"OK!");
        else if (cnt<10000) output_message(min(0.4,pow(2026./cnt,1.2)),"OK!");
        else output_message(0.1,"OK!");
    }
    return 0;
}
