Write a program that reads numbers from the input, and outputs the result of adding each digit multiplied by its position. We consider the most significant digit to be at position 1, the second most significant digit to be at position 2, and so on and so forth.
For example, given 785902, the program will print 86, which is the result of evaluating 1×7+2×8+3×5+4×9+5×0+6×2.
Input
The input has an arbitrary number of cases. Each one is a positive natural number in one line.
Output
For each case, the output contains a line with the corresponding result of adding digits multiplied by their positions.
Observation
Massive storage solutions are not accepted (like strings or vectors). Read numbers from the input into variables of type int; for instance, with cin >> a, and solve the problem operating with integers using +, -, *, /, and %.
Evaluation over 10 points:
We understand as fast solution one which is correct, has linear cost and passes the public and private tests. We understand as slow solution one which is not fast, but it is correct and passes the public tests.
Input
35102 785902 1010101 101010 1010101 10101 30219834 410938 99999999 999999 113311 13221 2 3 123456789
Output
26 86 16 9 16 9 159 105 324 189 35 26 2 3 285
Input
4289384 46930887 81692778 14636916 57747794 24238336 19885387 49760493 96516650 89641422 25202363 50490028 83368691 2520060 44897764 67513927 65180541 40383427 4089173 3455737 35005212 21595369 94702568 26956430 36465783 61021531 78722863 33665124 45174068 68703136 1513930 1979803 15634023 35723059 69133070 25898168 59961394 89018457 28175012 56478043 31176230 53377374 59484422 14544920 8413785 56898538 34575199 73594325 49798316 38664371
Output
159 215 229 178 228 155 230 178 141 119 112 131 194 54 223 178 117 154 132 148 73 212 184 136 198 80 176 128 171 133 89 137 99 164 103 224 192 185 97 149 99 182 141 128 149 232 220 156 192 156