#!/usr/bin/env python3 import sys import re from collections import defaultdict E = defaultdict(list) # Parse in edges for l in sys.stdin: a, b = l.strip().split('-') E[a].append(b) E[b].append(a) smallre = re.compile('[a-z]+') def issmall(n): return smallre.match(n) paths = 0 def search(n, path): global paths if n == 'end': paths += 1 return if issmall(n) and n in path: return for c in E[n]: search(c, path + n) search("start", "") print(paths)