13370 - Bender and the Haunted Mansion   

Description

After the death of his uncle, Bender inherited the his large mansion but what he does not know is that the mansion is haunted by robot ghosts. While he was staying a night with his friends, he saw the scariest image imaginable:

Once he saw that horrific sight he knew that he must use the power of programming to reprogram his machine brain to understand what it meant. 

When reading a set of numbers, Bender will know that the base of that number is. The set of numbers also only come in 8 digits and the numbers can range from 0 to 15, with A equal to 10, B equal to 11, and so on. The base of the number on the other hand can range from 2 to 16 (binary and hexadecimal).

In the set of digits, no number will exceed the base, so when the base is 8, the highest possible number is 7 but when the base is 16, the highest possible number is 15.

All the program has to do is convert all the given digits to a decimal number.

For an example, the number  set, 10111001, with a base of 2 is calculated like this:

2^7 * 1 + 2^6 * 0 + 2^5 * 1 + 2^4 * 1 + 2^3 * 1 + 2^2 * 0 + 2^1 * 0 + 2^0 * 1 = 185

Input

integer M which represents the number's base 

a string of exactly 8 integers

Output

the value of the 8 decimal in base 10 form followed by a newline

Sample Input  Download

Sample Output  Download

Tags




Discuss