Problem D
The Base-1 Number System

Input: Standard Input

Output: Standard Output

 

 

As we know, in an n-based number system, there are n different types of digits. In this way, a 1-based number system has only 1 type of digit, the ‘0’. Here are the rules to interpret 1-based numbers. Each number consists of some space separated blocks of 0. A block may have 1, 2 or more 0s. There is a ‘flag’ variable associated with each number

Note that, the first block of every number will have at most 2 0s. For example, the 1-base number 0 0000 00 000 0 0000 is equivalent to binary 11011.

 

The final binary number won’t have more than 30 digits. Once, you’ve completed the process, convert the binary value to decimal & print, you’re done!

 

Input

Input will have at most 100 test cases. Each case consists of a 1-based number as described above. A number may be spanned to multiple lines but a single block will always be in a single line. Termination of a case will be indicated by a single ‘#’ char which will be space-separated from the last digit of your input number. The last case in the input is followed by a ‘~’ character indicating, end of input.

 

Output

 

For each test case, output a single line with the decimal equivalent value of your given 1-based number.

 

Sample Input                                                  Output for Sample Input

0 0000 00 000 0 0000 #

0 000 #

~

27

1

 


Problemsetter: Mohammad Mahmudur Rahman