eolymp
bolt
Try our new interface for solving problems
Məsələlər

I`ve Got Your Back(gammon)

I`ve Got Your Back(gammon)

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 \textbf{15} pieces are moved onto a set of \textbf{6} board positions called points, numbered \textbf{1} through \textbf{6}. The pieces can be distributed in any manner across these points: all \textbf{15} could be on point \textbf{3}; \textbf{5} could be on point \textbf{6}, \textbf{2} on point \textbf{5}, \textbf{3} on point \textbf{4} and \textbf{5} on point \textbf{2}; etc. Your friend wants to store all these possible con gurations (of which there are 15504) into a linear array, but she needs a mapping from con guration to array location. It seems logical that the con guration with all \textbf{15} pieces on point 1 should correspond to array location \textbf{0}, and the con guration of all \textbf{15} pieces on point 6 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 con guration by listing the number of pieces on each point, starting with point \textbf{6}. For example, the two con gurations described above could be represented by (\textbf{0}, \textbf{0}, \textbf{0}, \textbf{15}, \textbf{0}, \textbf{0}) and (\textbf{5}, \textbf{2}, \textbf{3}, \textbf{0}, \textbf{5}, \textbf{0}). Then you can order the con gurations in lexicographic ordering, starting with (\textbf{0}, \textbf{0}, \textbf{0}, \textbf{0}, \textbf{0}, \textbf{15}), then (\textbf{0}, \textbf{0}, \textbf{0}, \textbf{0}, \textbf{1}, \textbf{14}), (\textbf{0}, \textbf{0}, \textbf{0}, \textbf{0}, \textbf{2}, \textbf{13}), ..., (\textbf{0}, \textbf{0}, \textbf{0}, \textbf{0}, \textbf{14}, \textbf{1}), (\textbf{0}, \textbf{0}, \textbf{0}, \textbf{0}, \textbf{15}, \textbf{0}), (\textbf{0}, \textbf{0}, \textbf{0}, \textbf{1}, \textbf{0}, \textbf{14}), (\textbf{0}, \textbf{0}, \textbf{0}, \textbf{1}, \textbf{1}, \textbf{13}), etc., ending with (\textbf{15}, \textbf{0}, \textbf{0}, \textbf{0}, \textbf{0}, \textbf{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. \InputFile Each test case will consist of one line, starting with a single character, either '\textbf{m}' or '\textbf{u}'. If it is an '\textbf{m}' it will be followed by a con guration and you must determine what array index it gets mapped to. If it is a '\textbf{u}' then it will be followed by an integer array index \textbf{i}, \textbf{0} ≤ \textbf{i} < \textbf{15504}, and you must determine what con guration gets mapped to it. A line containing the single character '\textbf{e}' will end input. \OutputFile For each test case, output the requested answer - either an array index or a con guration. Follow the format in the examples below.
Zaman məhdudiyyəti 1 saniyə
Yaddaşı istafadə məhdudiyyəti 64 MiB
Giriş verilənləri #1
m 0 0 0 0 0 15
u 15503
e
Çıxış verilənləri #1
Case 1: 0
Case 2: 15 0 0 0 0 0
Mənbə ACM ICPC East Central Regional Contest 2012 (ECNA 2012)