Ուղարկել | Բոլոր լուծումները | Լավագույն լուծումները | Վերադառնալ ցուցակին |
ACM_0184 - DICE |
Along with other things, Feadagor is fond of playing tabletop role playing games. He has just discovered a new game and he’d like to play it with his friends. Unluckily, he cannot call his friends right now, as the game requires quite an unusual set of dice. The description of the game says that there must be n dice, and i-th die must have ai faces. Each die must be shaped so its faces fall equiprobably.
According to the game manual, the numbers from 1 to m, where m = a1+a2+...+an, must be written on the faces, and each number from the interval must be used exactly once. The numbers arrangement must be chosen so that if you throw all the dice simultaneously, then the mathematical expectation E of the total value in such experiment will be maximal.
The manual says that only Maiar have enough wisdom to arrange the numbers properly (and therefore your only choice is to buy the dice just for 133 dollars, telepathy is quite expensive now). But maybe there is a simpler way to make the proper arrangement?
Input
The first line of the input file contains a single integer number n (1 ≤ n ≤ 1000). The following line contains n integer numbers a1, a2 ... an (1 ≤ ai ≤ 100).
Output
The first line of the output file must contain maximal possible expectation E — a floating-point number precise up to 5 digits after the decimal point.
The following n lines must contain the numbers arrangement: i-th line must contain ai integer numbers — the numbers to be written on the faces of i-th die.
Example
№ |
stdin |
stdout |
1 |
2 1 4 |
7.50000 5 1 2 3 4 |
Ավելացրեց. | Հրանտ Հովհաննիսյան |
Ամսաթիվ. | 2014-04-09 |
Ժամանակի սահմանափակումը. | 1s |
Ծրագրի տեքստի սահմանափակումը. | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Լեզուներ. | Բոլորը բացի ASM32 ASM64 GAWK CLPS CLOJURE D ERL FSHARP FORTRAN GOSU HASK ICON ICK NEM NIM OBJC-CLANG PICO PIKE PYPY PYPY3 PY_NBC RUST SCM guile CHICKEN SED TCL WHITESPACE |
Աղբյուրը. | Northern QF 2011.D |