Parse a list of signed unary numbers Unary numbers typically only represent nonnegative integers, but we can extend them to represent all integers as follows:


A positive integer N is represented as N 1's: 5 -&gt; 11111
A negative integer -N is represented as a 0 followed by N 1's: -5 -&gt; 011111
Zero is represented as 0


We can then represent a list of these numbers unambiguously if we use 0 as the separator:

3,-2,0,1
111,011,0,1
111 0 011 0 0 0 1
11100110001


Your task: take a string representing such a list of signed unary numbers, and translate it into a list of decimal numbers.

Details

You may assume that the input is a complete list of signed unary numbers. In particular, your program will not have to handle 1) empty input or 2) input that ends with a separator.

You may assume that the magnitude of each number will not exceed 127. For languages with maximum sizes of strings or lists, you may assume that the input and output will fit in your language's data structures, but your algorithm should theoretically work for a list of any size.

Your program or function may perform I/O in any of the standard ways. Input may be a string or a list of characters, single-character strings, integers, or booleans. You may use any two characters to represent 1 and 0; if you don't use 1 and 0, please specify which characters you're using.

Output must be decimal numbers in any reasonable list format (in particular, there must be some kind of a separator between numbers). Negative numbers should be indicated with a minus sign, although if your language has a different format for negative integers I will also accept that. Zero may be represented in the output as 0 or -0.

Test cases

1 -&gt; 1
0 -&gt; 0 (or -0, and similarly for the other test cases)
011 -&gt; -2
1101 -&gt; 2,1
1100 -&gt; 2,0
11001 -&gt; 2,-1
110001 -&gt; 2,0,1
11100110001 -&gt; 3,-2,0,1
00000001 -&gt; 0,0,0,-1
01111011111111001111111111111110111111111111111100111111111111111111111110111111111111111111111111111111111111111111 -&gt; -4,8,-15,16,-23,42
01111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111 -&gt; -127
Python 2, 73 70 bytes

A function that takes a string as input and returns a string representation of a Python list. Zero can be represented both by 0 and -0 (when it comes last):



lambda s:`map(len,s.split('0'))`.replace('0, ','-').replace('--','0,')


Explanation


split the input string s on zeroes.
Take the length of each string in the resulting list (using map).


That takes us a long way. Zeroes were separators after all. And the numbers were unary, so len conveniently converts those to decimal. But now we've messed up all the non-separator uses of 0. Luckily, all non-separator uses were leading zeroes so they came after a separator-zero and gave us zero-length strings ('00'.split('0') == ['', '', '']). Those zero-length strings then also became 0 because of the len.


Turn the list into a string (using "reverse quotes"), so we can fix up the mess more easily.
replace each zero that precedes another number by a negative sign on that number instead. That fixes the use of 0 as a sign but it breaks the literal zeroes. Literal zeroes were also preceded by a separator, so they've now become pairs of extra dashes on the next number.
replace each -- back into a 0 element in the "list".