House Plates
Time limit2sMemory limit1024 MB
Given house numbers on each street, find the total cost of plates when each binary 0 digit costs a rubles and each binary 1 digit costs b rubles.
- Level
Easy2 of 10
- Topics
- Implementation, Math
- Solved
- No attempts yet
Problem
A country plans to build a programmer city called Oskolkovo. The city will be large. It will have streets, and each street has houses. The government decided to use an innovation: instead of ordinary house number plates, the plates will show house numbers written in binary.
After the numbering plan was approved, a tender was held for making plates with the digits 0 and 1. The winning company makes a plate with the digit 0 for rubles and a plate with the digit 1 for rubles. The government wants to know the cost of making the plates for the houses.
Input
The first line contains a natural number () and , (). is the number of streets, and and are the costs of making the digits 0 and 1.
Each of the next lines contains a natural number (), the number of houses on that street. After that, the line contains natural numbers (), the house numbers on that street that need plates. A house may need more than one plate.
Output
Output one natural number: the cost of making the plates.