This page is still under construction.

Parts of this page are still being built. What you see may change.

Death to Binary?

Time limit1sMemory limit128 MB

Summary
Add two numbers written in the Fibonacci base and print the sum in canonical Zeckendorf form, aligned for display.
Level

Medium6 of 10

Topics
Math, Greedy, Implementation, Simulation
Solved
No attempts yet

Problem

A group of eccentric calculation enthusiasts has found a wonderful new way to count. Instead of ordinary decimal numbers, they use the Fibonacci base. A number in this base is written as a string of 00s and 11s, just like a binary number, but the weight of each digit is not a power of two — it is an element of the Fibonacci progression. This progression starts with F0=1F_0 = 1 and F1=2F_1 = 2, and for n≥2n \ge 2 it satisfies Fn=Fn−1+Fn−2F_n = F_{n-1} + F_{n-2} (that is, 1,2,3,5,8,…1, 2, 3, 5, 8, \dots).

In a representation, the rightmost digit has weight F0F_0, and each digit further to the left carries the next Fibonacci weight. For example,

1101001Fib=F0+F3+F5+F6=1+5+13+21=40.1101001_{\mathrm{Fib}} = F_0 + F_3 + F_5 + F_6 = 1 + 5 + 13 + 21 = 40.

Every integer can be expressed in this base, but not necessarily uniquely — for instance, 4040 can also be written as 10001001Fib10001001_{\mathrm{Fib}}. However, for every integer there is a unique representation that contains no two adjacent 11s; we call it the canonical representation. For example, the canonical representation of 4040 is 10001001Fib10001001_{\mathrm{Fib}}.

To build a computer that calculates in the Fibonacci base, write a program that adds two numbers given in the Fibonacci base (not necessarily in canonical form).

Input

The input consists of several test cases, each on a single line. Each line contains two numbers XX and YY in the Fibonacci base, separated by a single space. Each number has at most 4040 digits. The end of the input is marked only by the end of file; there is no special terminator.

Output

For each test case, print the following four lines:

  1. Line 1: the canonical representation of XX, left-padded with spaces.
  2. Line 2: a plus sign + followed by the canonical representation of YY, left-padded with spaces.
  3. Line 3: two spaces followed by a row of minus signs - whose length equals the length of the canonical representation of the sum.
  4. Line 4: two spaces followed by the canonical representation of X+YX + Y.

Left-pad XX and YY with spaces so that the least significant (rightmost) digits of XX, YY, and X+YX + Y line up in the same column. Put a single blank line between the outputs of consecutive test cases.

Examples2

  1. Example 1

    Input
    11101 1101
    1 1
    
    Expected output
       100101
    +   10001
      -------
      1001000
    
       1
    +  1
      --
      10
    
  2. Example 2

    Input
    1101001 10001001
    
    Expected output
       10001001
    +  10001001
      ---------
      101000101