#!/usr/bin/python3
# -*- coding: utf-8 -*-
 
import sys
import os
 
EJUDGE = bool(os.environ.get("EJUDGE", "0") == "1")
VERBOSE = bool(os.environ.get("VERBOSE", "0") == "1")
YANDEX = False
 
if EJUDGE:
    OK = 0
    PE = 4
    WA = 5
    CF = 6
    AC = 8
else:
    OK = 0
    WA = 1
    PE = 2
    CF = 3
 
LOG = ""
# sys.stdout.reconfigure(encoding='utf-8')
# sys.stderr.reconfigure(encoding='utf-8')
 
def quit(status, log="", score=0):
    # Если задано значение параметра log, то выводится это значение, иначе выводится глобальная переменная LOG
    if EJUDGE and not VERBOSE and status != PE:
        log = "Полные протоколы проверки будут доступны после окончания олимпиады"
    sys.stderr.write(log if log else LOG)
    if EJUDGE:
        if status == WA or status == OK:
            sys.stdout.write(str(score) + "\n0\n" + str(AC) + "\n")
    elif YANDEX:
        if status == WA or status == OK:
            sys.stdout.write("$" + str(score) + "$\n")
            status = OK
    else:
        sys.stdout.write("Score: " + str(score) + "\n")
    sys.exit(status)
 
def is_increasing(a):
    for i in range(1, len(a)):
        if (a[i] <= a[i - 1]):
            return 0
    return 1
 
def is_sub(a, b):
    i = -1
    j = -1
    while i < len(a) - 1:
        i += 1
        j += 1
        while j < len(b) and b[j] != a[i]:
            j += 1
        if j >= len(b):
            return 0 
    return 1   
 
fin = open(sys.argv[2], "r")
ans = fin.read().strip().replace(',', ' ').replace(';', ' ')
 
if not ans:
    quit(PE, "Ответ пуст")
 
for char in ans:
    if char not in " 0123456789\n":
        quit(PE, "Ответ содержит недопустимый символ: ''" + char + "''" + "\n")
 
 
ans = ans.split('\n')
 
ans = [list(map(int, i.split())) for i in ans]
 
corr_ans = [2, 4, 5, 6]
s = [[5, 3, 4, 2, 3], [1, 6, 3, 2, 5, 8], [4, 6, 7, 5, 6, 7, 1, 2, 8], [2, 5, 3, 5, 3, 4, 7, 3, 8, 4, 9, 6, 7]]
scores   = [10, 20, 40, 30]
 
score = 0
e = ""
j = 0
 
for i in range(0, len(ans)):
    if ans[i] and j < 4: 
        if (not is_increasing(ans[i])):
            quit(PE, "Не все последовательности возрастают.")
        if (len(ans[i]) == corr_ans[j] and is_increasing(ans[i]) and is_sub(ans[i], s[j])):
            score += scores[j]
        j += 1
    elif ans[i] and j == 4:
        quit(PE, "Введено больше четырех последовательностей.")
        
if j < 4:
    quit(PE, "Введено меньше четырех последовательностей.")
 
if score == 100:
    quit(OK, "OK", score)
else:
    quit(WA, "Не все последовательности верны.", score)
