Жишээ тэстүүд

Оролт
3 2 1000
3 1 2
Гаралт
8
Оролт
2 3 1000
2 2
Гаралт
24
Оролт
1 1 1000
5
Гаралт
0

Тэмдэглэл

In the first sample the following variants are possible: 121|1|12, 121|1|21, 121|2|12, 121|2|21, 212|1|12, 212|1|21, 212|2|12, 212|2|21. In the second sample the following variants are possible: 12|13, 12|23, 12|31, 12|32 and so on.

Figure for the first sample: