#!/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:
        m = int(line)
    except:
        f2.write("Output has non-integer value.\n")
        sys.exit(43)
    doubles = []
    try:
        for i in range(m):
            line = input()
            if line == "DOUBLE":
                doubles.append(True)
            elif line == "ADD":
                doubles.append(False)
            else:
                f2.write("Output incorrectly formatted.\n")
                sys.exit(43)
    except EOFError:
        f2.write("Too few lines were provided.\n")
        sys.exit(43)
    try:
        input()
        f2.write("Too many lines were provided.\n")
        sys.exit(43)
    except EOFError:
        pass
    opt = n.bit_length() + bin(n).count("1") - 2
    if m != opt:
        f2.write(f"Answer was {m}, expected {opt}.\n")
        sys.exit(43)
    val = 1
    for d in doubles:
        if d:
            val *= 2
        else:
            val += 1
    if val != n:
        f2.write(f"Resulting length was {val}, expected {n}.\n")
        sys.exit(43)
    sys.exit(42)
f2.write("Did not exit in time.\n")
sys.exit(43)