#!/usr/bin/env python3
'''
'''
import re

Cls, L = {}, {}

def merge(mros):
    if not mros:
        return
    S = [L.setdefault(c, [c, *merge(Cls[c])]).copy() for c in mros] + [mros]
    while S:
        for s in S:
            if not s: continue
            e = s[0]
            if all(e==ss[0] or e not in ss for ss in S):
                yield e
                for ss in S:
                    if ss and ss[0] == e:
                        del ss[0]
                S = list(filter(len, S))
                break
        else:
            raise TypeError

reClass = re.compile(r"class\s+(\w+)\s*(?:\((.*)\))?\s*:")
s = input().rstrip()
while s:
    res = reClass.match(s)
    if res:
        Nam, Par = res.groups()
        Cls[Nam] = [c.strip() for c in Par.split(",")] if Par else []
        try:
            L[Nam] = [Nam, *merge(Cls[Nam])]
        except TypeError:
            print("No")
            break
    s = input().rstrip()
else:
    print("Yes")

