#include <cstdlib>
#include <cstring>
#include <iostream>

using namespace std;

#define NUM_REGISTERS 64
#define MAX_PROGRAM_LENGTH 100
#define MAX_ITERATIONS 50000000

#define INCREMENT 0
#define DECREMENT 1
#define HALT 2

void program_machine(int N);
void add_increment(int x, int i);
void add_decrement(int x, int i, int j);
void add_halt();

struct instruction {
    int type;
    int x; int i; int j;
} instructions[MAX_PROGRAM_LENGTH];

int registers[NUM_REGISTERS];

int instruction_count = 0;

[[noreturn]] static void wa(const string& message) {
    cerr << "WA " << message << '\n';
    exit(0);
}

void add_increment(int x, int i) {
    if (instruction_count == MAX_PROGRAM_LENGTH) {
        cout << "Program too long." << endl;
        exit(0);
    }
    if (x < 0 || x >= NUM_REGISTERS) {
        cout << "Invalid register." << endl;
        exit(0);
    }
    instructions[instruction_count] = {INCREMENT, x, i};
    instruction_count++;
}

void add_decrement(int x, int i, int j) {
    if (instruction_count == MAX_PROGRAM_LENGTH) {
        cout << "Program too long." << endl;
        exit(0);
    }
    if (x < 0 || x >= NUM_REGISTERS) {
        cout << "Invalid register." << endl;
        exit(0);
    }
    instructions[instruction_count] = {DECREMENT, x, i, j};
    instruction_count++;
}

void add_halt() {
    if (instruction_count == MAX_PROGRAM_LENGTH) {
        cout << "Program too long." << endl;
        exit(0);
    }
    instructions[instruction_count] = {HALT};
    instruction_count++;
}

int main() {
    int N;
    cin >> N;

    program_machine(N);

    memset(registers, 0, sizeof(registers));
    int ip = 0; // instruction pointer
    for (int cnt = 0; cnt < MAX_ITERATIONS; cnt++) {
        if (instructions[ip].type == HALT) {
            if (registers[0] != N) {
                wa("Register 0 does not contain the correct value at halt.");
            }
            cout << "OK " << instruction_count << endl;
            return 0;
        }
        if (instructions[ip].type == INCREMENT) {
            registers[instructions[ip].x]++;
            if (instructions[ip].i < 0 || instructions[ip].i >= instruction_count) {
                wa("Invalid instruction index in increment.");
            }
            ip = instructions[ip].i;
        } else {
            if (registers[instructions[ip].x] == 0) {
                if (instructions[ip].i < 0 || instructions[ip].i >= instruction_count) {
                    wa("Invalid instruction index in decrement.");
                }
                ip = instructions[ip].i;
            } else {
                registers[instructions[ip].x]--;
                if (instructions[ip].j < 0 || instructions[ip].j >= instruction_count) {
                    wa("Invalid instruction index in decrement.");
                }
                ip = instructions[ip].j;
            }
        }
    }
    wa("Too many iterations without halting.");
    return 0;
}
