Under construction

Still being built. Things may change

Numerically Speaking

Time limit1sMemory limit128 MB

Summary
Translate between lowercase words of length 1 to 20 and their bijective base-26 numbers, printing output in a padded two-column format.
Level

Medium4 of 10

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

Problem

Every lowercase word whose length is between 1 and 20 is assigned a distinct positive integer. Words are ordered first by length, and within the same length alphabetically, then numbered consecutively starting from 1. The beginning of the list looks like this:

a           1
b           2
...
z          26
aa         27
ab         28
...
snowfall   157,118,051,752
...

This is exactly bijective base-26 numbering: read the word from left to right using a = 1, b = 2, …, z = 26 as digits, and the number of a word of length kk with digit values d1d2…dkd_1 d_2 \dots d_k is ∑i=1kdi⋅26 k−i\sum_{i=1}^{k} d_i \cdot 26^{\,k-i}.

Write a program that translates in both directions: given a word, print its number; given a number, print its word.

Input

The input lists one item per line, each starting in column one. A line whose column one contains a single asterisk (*) marks the end of the input.

Each item is either a number or a word:

  • A number consists only of the decimal digits 0–9 (there are no commas in the input) and corresponds to some word of length 1 to 20.
  • A word consists of 1 to 20 lowercase letters a–z.

Output

Print one line for each input item. The word begins in column one and its number begins in column 23; fill the space between them with blanks (that is, place the word in a left-justified field 22 characters wide, immediately followed by the number). Group the digits of the number with commas every three digits from the right (thousands, millions, and so on).

Examples3

  1. Example 1

    Input
    29697684282993
    transcendental
    28011622636823854456520
    computationally
    zzzzzzzzzzzzzzzzzzzz
    *
    
    Expected output
    elementary            29,697,684,282,993
    transcendental        51,346,529,199,396,181,750
    prestidigitation      28,011,622,636,823,854,456,520
    computationally       232,049,592,627,851,629,097
    zzzzzzzzzzzzzzzzzzzz  20,725,274,851,017,785,518,433,805,270
    
  2. Example 2

    Input
    1
    a
    26
    z
    *
    
    Expected output
    a                     1
    a                     1
    z                     26
    z                     26
    
  3. Example 3

    Input
    cat
    dog
    hello
    *
    
    Expected output
    cat                   2,074
    dog                   3,101
    hello                 3,752,127