P = int(input()) Q = int(input()) N = int(input()) R = [list(map(int,input().split())) for _ in range(N)] s = 0 for i in range(N-1): if R[i] == R[i+1]: s += 1 print((P+Q)*s)