function Main (input) { var line = input.split("\n").map(Number); var P1 = line[0]; var P2 = line[1]; var N = line[2]; var reservedList = [] ; var C = 0; for (var i = 3 ; i < line.length ; i ++) { if( reservedList.indexOf( line[i] ) == -1){ reservedList.push( line[i] ); } else { C += P1 + P2; } } console.log( C ); } Main(require("fs").readFileSync("/dev/stdin","utf8"));