#!/usr/bin/python

# usage: python check.py {easy,hard} < contestants_output

optimal_dominating_sets = [1,1,2,2,4,7,12,16,32]

from sys import stdin, argv, exit

def string_reader():
    for x in stdin.read().split(): yield x
next_string = string_reader().next

def fail(message):
    print message
    exit(1)

def check_syntax(strategies):
    n = len(strategies)
    for x,strategy in enumerate(strategies):
        if len(strategy) != 2**(n-1): fail('Strategy for n=%d, player %d: incorrect length.' % (n,x+1))
        for c in strategy:
            if c!='H' and c!='T' and c!='P': fail('Strategy for n=%d, player %d: unexpected character.' % (n,x+1))

def evaluate_strategies(strategies):
    wins = 0
    n = len(strategies)
    for throws in range(2**n):
        results = ''
        for i in range(n):
            if throws & (1<<(n-1-i)): results += 'T'
            else: results += 'H'
        correct, wrong = False, False
        for person in range(n):
            sees, j = 0, n-2
            for i in range(n):
                if i != person:
                    if throws & (1<<(n-1-i)): sees += 1<<j
                    j -= 1
            guess = strategies[person][sees]
            if guess=='P': continue
            if guess==results[person]: correct = True
            else: wrong = True
        if correct and (not wrong): wins += 1
    return wins

if argv[1]=="easy":
    try:    strategies = [ next_string() for x in range(3) ]
    except: fail('Too few strings in your submission.')
    check_syntax(strategies)
    wins = evaluate_strategies(strategies)
    if wins < 4: fail('Winning probability for your strategy is less than 50%.')
    if wins == 4: fail('Winning probability for your strategy is 50% but more is possible.')
else:
    for n in range(1,9):
        try:    strategies = [ next_string() for x in range(n) ]
        except: fail('Too few strings in your submission.')

        check_syntax(strategies)
        wins = evaluate_strategies(strategies)
        losses = 2**n - wins
        if losses > optimal_dominating_sets[n]: fail('For some n, the strategy you submitted is not optimal.')

too_many = False
try: 
    junk = next_string()
    too_many = True
except: pass

if too_many: fail('Too many strings in your submission.')

print 'OK'
exit(0)
