#P13607. [NWRRC 2022] Joking?

[NWRRC 2022] Joking?

题目描述

Julia wants to create a new board game for nn players. As part of the game, players decide the order of their turns. The game should be fair: every possible permutation of players should be chosen with the same probability.

To help players determine this permutation, Julia wants to create nn different kk-sided dice. Each player will throw their own dice and look at the number. The player with the smallest number will go first, the player with the second smallest number will go second, and so on. To make sure no ties could happen, all numbers used on all dice should be distinct.

That could be a good math problem, but this is a programming contest, so we allow some imprecision. We ask you to create the dice for this game, but the probabilities of obtaining the permutations may differ slightly. Your solution will be accepted if the relative difference of probabilities of any two permutations is no more than 0.2%.

Formally, there are knk^n different outcomes of throwing all nn dice. For each permutation PP, we can compute the number of scenarios f(P)f(P) that lead to this permutation. For any two permutations PP and QQ, the following should be true: f(P)f(Q)max(f(P),f(Q))0.002\frac{|f(P) - f(Q)|}{max(f(P), f(Q))} \le 0.002.

You may choose any kk, but it may not exceed 120120.

输入格式

The only line contains a single integer nn~--- the number of players (2n52 \le n \le 5).

输出格式

In the first line, print a single integer kk~--- the number of sides on each dice (1k1201 \le k \le 120).

Each of the next nn lines should describe one dice. For each dice, print kk integers from 11 to knk \cdot n. All integers used on all dice should be distinct.

2
2
1 4
2 3
3
16
3 7 9 10 12 17 18 19 28 32 33 35 38 40 43 48
1 2 6 13 14 20 22 26 27 29 30 36 37 39 44 46
4 5 8 11 15 16 21 23 24 25 31 34 41 42 45 47

提示

In the first example test, both permutations of players have the probability of 12\frac{1}{2}.

In the second example test, there are 163=409616^3=4096 possible scenarios. Permutations [2,1,3][2, 1, 3] and [3,1,2][3, 1, 2] arise in 682682 scenarios each, while every other permutation arises in 683683 scenarios. Thus, the relative difference between the most and the least probable permutations is 6836826830.146%\frac{683-682}{683} \approx 0.146\%.