* DIFFICULTY: 40

The problem requires some observations but they are not hard
to figure out with some experimenting

* DISCUSSION

Observe that the coins can be resolved one at a time:

Let r(s) be the result of resolving sequence s. We have
that is s = s1 + s2 then r(s) = r(r(s1) + r(s2)) where
addition is componentwise (102 + 110 = 212).

With this, we can make sure that at every step there is
at most one 2 in the sequence that we are resolving.

Example:

  Supposed that we want to resolve 0111211210. We have
  that 0111211210 = 0111211110 + 0000000100. Thus

  r(0111211210) = r( r(0111211110) + r(0000000100) )

  We resolve the first part:
  r(0111211110) = 1111101111

  We resolve the second part:
  r(0000000100) = 0000000100

  We add the results:
  1111101111 + 0000000100 = 1111101211

  And finally we resolve the last:
  r(1111101211) = 1111111101

  Therefore r(0111211210) = 1111111101


Now we can focus on how to resolve a sequence with a single 2.
This will have the form 01...121...10 and will always end in 
1111...101...11 so all we need is to know the position of the final 0.

It is not hard to see that this position is:

pos_left_0 + pos_right_0 - pos_2

where

pos_left_0 = the position of the rightmost 0 to the left of the 2 
pos_rigth_0 = the position of the leftmost 0 to the right of the 2
pos_2 = the position of the 2

Example:

  0123456789  pos
  ------
  0111121110

  pos_left_0 + pos_right_0 - pos_2 = 0 + 9 - 5 = 4

  Hence r(0111121110) = 1111011111


* SOLUTION O(n log(n))

n = length(s)
Z = tree set with the positions of the 0's
T = list with the positions of the 2'é
for each t in T
  add -1 to Z
  add n to Z
  if t in Z then remove t from Z
  otherwie
    pos_left_0 = remove_lower(T, t)
    pos_right_0 = remove_higher(T, t)
    Z.add(pos_left_0 + pos_right_0 - t)
for i in [0, ..., n - 1]
  print('0' if i is in Z and '1' otherwise)

