1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | import sys n = int(sys.stdin.readline().rstrip()) dic = dict() for _ in range(n): arr = list(sys.stdin.readline().rstrip()) length = len(arr) key = str(length) + arr[0] + arr[length – 1] + ”.join(sorted(arr[1:–1])) if dic.get(key) is not None: dic[key] += 1 else: dic[key] = 1 m = int(sys.stdin.readline().rstrip()) for _ in range(m): arr = list(sys.stdin.readline().rstrip().split()) result = 1 check = 0 for i in arr: length = len(i) key = str(length) + i[0] + i[length – 1] + ”.join(sorted(i[1:–1])) if dic.get(key) is not None: result *= dic[key] check += 1 if not check: print(0) else: print(result) | cs |