from collections import defaultdict, deque from itertools import groupby, permutations from sys import stdin edges = defaultdict(list) for line in stdin.read().strip().split(): for key, value in permutations(line.split('-')): if key != 'end' and value != 'start': edges[key].append(value) paths = set() queue = deque([('start',)]) while queue: if (head := queue.popleft()) in paths: continue paths.add(head) if (chin := head[-1]) == 'end': continue for neck in edges[chin]: top = head + (neck,) if sum(len(tuple(group)) - 1 for cave, group in groupby(sorted(top)) if cave.islower()) > 1: continue queue.append(top) print(sum(path[-1] == 'end' for path in paths))