A foundry runs a line of n metal stamps past a die press. Each stamp already carries a positive whole-number rating painted on it, but the press's imprinting head is worn and simply refuses to strike the digit 0 -- every other digit still gets imprinted normally, in its original left-to-right order, onto the stamp's fresh face. Reading the stamps in line order and writing down each stamp's imprinted digits one after another (each stamp's own digits stay in their original left-to-right order), you get one long number for the whole batch: the batch serial. Because no stamp's rating is ever written with a leading zero, its very first digit always survives the press, so the batch serial is guaranteed to be non-empty and to never start with a zero.
The foreman also wants a quality-control figure. Before any digits were dropped, add up the ORIGINAL ratings of every stamp on the line to get the line weight. The plant's final batch code is the batch serial, read as an ordinary integer, multiplied by the line weight.
Given the stamps' ratings in line order, compute the batch code.
Example 1
Input
3 12 34 5
Expected
629595
Explanation
Stamp ratings are 12, 34, 5. None of their digits are 0, so the imprinted digits are '12', '34', '5', concatenated into the batch serial 12345. The line weight is 12+34+5=51. The batch code is 12345 * 51 = 629595.
Example 2
Input
2 100 205
Expected
38125
Explanation
Stamp ratings are 100 and 205. 100's digits are 1,0,0, so only the leading '1' survives the press, giving '1'. 205's digits are 2,0,5, so the surviving digits give '25'. Concatenating in line order gives batch serial '1'+'25' = '125'. The line weight is 100+205=305. The batch code is 125 * 305 = 38125.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →