import strutils, sequtils, tables proc getInt: int = stdin.readLine.parseInt # Yuki/振替先ホテルの料金, 予約の件数 let P1, P2, N = getInt() var R = initCountTable[int]() #予約された部屋番号 cost = 0 for n in 0 ..< N: R.inc getInt() while R.largest.val > 1: let maxR = R.largest cost += (P1 + P2) * (maxR.val - 1) R[maxR.key] = 0 echo cost