Backgammon Array Mapping#4270

Backgammon Array Mapping

1 second
64 megabytes
Easy

A friend of yours is working on an AI program to play backgammon, and she has a small problem. At the end of the game, each player's pieces are moved onto a set of board positions called points, numbered through . The pieces can be distributed in any manner across these points: all could be on point ; could be on point , on point , on point and on point ; etc. Your friend wants to store all these possible configurations (of which there are ) into a linear array, but she needs a mapping from configuration to array location. It seems logical that the configuration with all pieces on point should correspond to array location , and the configuration of all pieces on point should correspond to the last array location. It's the ones in between that are giving her problems. That's why she has come to you.

You decide to specify a configuration by listing the number of pieces on each point, starting with point . For example, the two configurations described above could be represented by (0, 0, 0, 15, 0, 0) and (5, 2, 3, 0, 5, 0). Then you can order the configurations in lexicographic ordering, starting with (0, 0, 0, 0, 0, 15), then (0, 0, 0, 0, 1, 14), (0, 0, 0, 0, 2, 13), ..., (0, 0, 0, 0, 14, 1), (0, 0, 0, 0, 15, 0), (0, 0, 0, 1, 0, 14), (0, 0, 0, 1, 1, 13) etc., ending with (15, 0, 0, 0, 0, 0). Now all you need is a way to map these orderings to array indices. Literally, that's all you need, because that's what this problem is all about.

Input

Each test case will consist of one line, starting with a single character, either or . If it is an it will be followed by a configuration and you must determine what array index it gets mapped to. If it is a then it will be followed by an integer array index , 0 \leq i < 15504, and you must determine what configuration gets mapped to it. A line containing the single character will end input.

Output

For each test case, output the requested answer — either an array index or a configuration. Follow the format in the examples below.

Examples

Example 1

Loading
Loading