import std.algorithm, std.conv, std.range, std.stdio, std.string; void main() { auto p1 = readln.chomp.to!int; auto p2 = readln.chomp.to!int; auto n = readln.chomp.to!int; auto r = new int[](n); foreach (i; 0..n) r[i] = readln.chomp.to!int; auto t = new int[](1000); foreach (ri; r) ++t[ri]; auto ans = 0; foreach (ti; t) if (ti >= 2) ans += (ti-1)*(p1+p2); writeln(ans); }