Balance a set of weights on a seesaw Balancing Act

Overview

Given an input of 3 single-digit positive integers representing a set of weights, output an ASCII representation of a seesaw with the weights placed on it so that it is in balance around a central pivot, taking lever effects into account.

Each number has a weight equal to its value. The torque of each number is the weight multiplied its the distance from the center in characters. For the seesaw to be in balance, the sum torque of the weights on the left of the seesaw must equal that of those on the right, like this.

Input

3 integers in the range of 1-9. You can input the integers however is convenient, e.g. a tuple, 3 comma-separated values etc. However your program must be able to handle numbers input in any order (i.e. no assuming the values will be sorted). Duplicate numbers may be input (e.g. 2,3,2).

The inputs will always mathematically allow for a valid output, otherwise the input is not valid.

Output

The output should be a 2-line ASCII representation of the seesaw with the weights placed on it. On the first line are the digits, spaced in order to balance them on the seesaw.

Numbers may not be placed in the very center of the scale, where the distance and therefore the torque would be zero. Valid distances from the center range from 1-10 characters inclusive to the left or right of the pivot.

In the spaces unoccupied by the numbers are 18 underscore characters (a center underscore and 10 on each side, minus the 3 positions occupied by the numbers). On the last line is a single caret character aligned with the center of the scale, representing the pivot.

Examples

Input:

4,7,2


Output:

________7___42_______
          ^


7*2 = 4*2 + 2*3

Numbers can be output on either side, for example this would also be valid:

_______24___7________
          ^


2*3 + 4*2 = 7*2

Numbers can be placed anywhere on the scale as long as they balance, e.g:

Input:

3,1,5


Output:

_____5________1__3___
          ^


5*5 = 1*4 + 3*7

or

____5________1_____3_
          ^


5*6 = 1*3 + 3*9

or

____5___________1_3__
          ^


5*6 = 1*6 + 3*8

etc

Your program only has to output one of the valid outputs. It does not have to output an error if the input is not valid.

Notes


This is code-golf so the shortest program in bytes wins
Program may be a stand-alone or a function that accepts the numbers as input and returns a string.
Trailing newline and white-space on last line is optional
If you don't know what a seesaw is, it's also known as a teeter-totter or a teeterboard.
CJam, 40 39 38 bytes

q~21Ue]e!{21,Af-Aest.*:+!}=0'_erNAS*'^


Try it online.

How it works

q~                                     e# Read and evaluate the input.
  21Ue]                                e# Append zeroes to achieve a length of 21.
       e!                              e# Push all unique permutations.
         {               }=            e# Find the first permutation such that:
          21,                          e#  Push [0 ... 20].
             Af-                       e#  Subtract 10 from each.
                Aest                   e#  Replace the element at index 10 with the
                                       e#  current time (ms since epoch) to push
                                       e#  [-10 ... -1 &lt;big number&gt; 1 ... 10].
                    .*                 e#  Multiply each number of the permutation
                                       e#  by the corresponding distance.
                      :+               e#  Add the products.
                                       e#  The timestamp makes sure that this sum
                                       e#  is non-zero for a non-zero element in
                                       e#  the middle of the permutation.    
                        !              e#  Push the logical NOT of the sum.
                           0'_er       e# Replace zeroes with underscores.
                                NAS*'^ e# Push a linefeed, ten spaces and a caret.