#!/usr/bin/env python3

import emoji
import sys


CORRECT = 42
WRONG_ANSWER = 43
JUDGE_ERROR = 1

LEG = 0
REST = 1
ARM = 2

"""
Data sources:
 - https://www.unicode.org/reports/tr51/#emoji_data
 - https://www.compart.com/en/unicode/plane/U+10000
   - https://www.compart.com/en/unicode/block/U+1F300 Miscellaneous symbols & pictographs
   - https://www.compart.com/en/unicode/block/U+1F600 Emoticons
   - https://www.compart.com/en/unicode/block/U+1F900 Supplemental symbols & pictographs
"""
def main(data, jury, team):
  workouts = []
  workout_days = int(data.readline())
  for i in range(workout_days):
    workout = data.readline().strip()
    if 'rest' in workout:
      workouts += [REST]
    elif 'leg' in workout:
      workouts += [LEG]
    elif 'arm' in workout or True:
      workouts += [ARM]
#   else:
#     print('Unknown kind of exercise: {}'.format(workout))
#     return JUDGE_ERROR

  days = []
  for i in range(5):
    try:
      l = team.readline()
    except:
      print('Team output was unreadable (bad unicode encoding?)')
      return WRONG_ANSWER
    if not l:
      print('Team output ended before 5 lines')
      return WRONG_ANSWER

    # Consider emojis with different Fitzpatrick types as the same
    l = l.strip().translate({ord(c): None for c in '🏻🏼🏽🏾🏿'})

    expect_len = (7 if i<4 else 3) + 2
    if len(l) != expect_len:
      print('Wrong line length: got {} but expected {}'.format(len(l), expect_len))
      return WRONG_ANSWER
    for j in l[2:]:
      days += [emoji.demojize(j)]

  symbols = dict()
  for i in range(31):
    expect = workouts[i % workout_days]
    plan = days[i]

    if expect == LEG and not ('leg' in plan):
      print('No leg in leg day {}: {}'.format(i+1, plan))
      return WRONG_ANSWER
    elif expect == REST and not ('face' or 'robot' in plan):
      print('No face in rest day {}: {}'.format(i+1, plan))
      return WRONG_ANSWER
    elif expect == ARM and not ('arm' in plan or 'biceps' in plan):
      print('No arm/biceps in arm day {}: {}'.format(i+1, plan))
      return WRONG_ANSWER

    if expect not in symbols:
      symbols[expect] = plan
    else:
      if symbols[expect] != plan:
        print('Used multiple emojis for same exercise: {} and {}'.format(symbols[expect], plan))
        return WRONG_ANSWER

  return CORRECT
  

if __name__ == '__main__':
  data = open(sys.argv[1], "r")
  jury = open(sys.argv[2], "r")
  team = sys.stdin 
  try:
    sys.exit(main(data, jury, team))
  finally:
    team.close()
    jury.close()
    data.close()
