#!/bin/python3

import sys
import math

input_file = sys.argv[1]
diffout = sys.argv[3]

with open(input_file, "r") as f, open(diffout + "/judgemessage.txt", "w") as f2:
    n = int(f.readline())
    try: 
        line = input()
    except EOFError:
        f2.write("No lines were provided.\n")
        sys.exit(43)
    try:
        input()
        f2.write("Too many lines were provided.\n")
        sys.exit(43)
    except EOFError:
        pass
    answers = line.split()
    
    if n % 4 == 2 or n % 4 == 3:
        if len(answers) != 1:
            f2.write("Input length was " + str(len(answers)) + ", while " + str(1) + " was expected.\n")
            sys.exit(43)
        elif answers[0] != "impossible":
            f2.write("Input was not \"impossible\".\n")
            sys.exit(43)
        if answers[0] == "impossible":
            sys.exit(42)
        f2.write("Unexpected error.\n")
        sys.exit(43)
    else:
        if len(answers) != n:
            f2.write("Input length was " + str(len(answers)) + ", while " + str(n) + " was expected.\n")
            sys.exit(43)
        try: 
            digits = [int(i) for i in answers]
        except:
            f2.write("Output has non-integer value.\n")
            sys.exit(43)
        if digits[0] != 1 or digits[n-1] != 1:
            f2.write("Cricket did not start and end at 1.\n")
            sys.exit(43)
        seen = [False] * n
        diss = [False] * n
        currp = 1
        for i in range(1, n):
            ps = digits[i]
            if ps <= 0 or ps > n:
                f2.write("Left range at index " + str(i) + ": " + str(ps) + ".\n")
                sys.exit(43)
            if seen[ps - 1]:
                f2.write("Position " + str(ps) + " reached multiple times.\n")
                sys.exit(43)
            seen[ps - 1] = True
            dst = abs(currp - ps)
            if dst <= 0 or dst >= n:
                f2.write("Jump too large at index " + str(i) + ": " + str(dst) + ".\n")
                sys.exit(43)
            if diss[dst]:
                f2.write("Jump of " + str(dst) + " seen multiple times.\n")
                sys.exit(43)
            diss[dst] = True
            currp = ps
        sys.exit(42)
    f2.write("Did not exit in time.\n")
    sys.exit(43)