yhm = input() ohm = input() N = input() r = [] for i in range(N): r.append(input()) s = 0 x = 0 N -= 1 while x < N: t = r[x] k = 0 n = x + 1 last = len(r) while n < last: if t == r[n]: k += 1 n += 1 s += k if k == 0: x += 1 else: x += k f = (yhm + ohm) * s print f