eolymp
bolt
Try our new interface for solving problems
Problems

Number of inversions

Number of inversions

The permutation is a sequence of \textbf{n }different integers from \textbf{1} to \textbf{n}. For example (\textbf{5}, \textbf{3}, \textbf{2}, \textbf{1}, \textbf{4}) is a permutation. The inversion of a permutation \textbf{p} is such ordered pair of indexes (\textbf{i}, \textbf{j}) that \textbf{i} < \textbf{j} and \textbf{p_i} > \textbf{p_j}. In the sample above the pair of indexes (\textbf{2}, \textbf{4}) forms an inversion because \textbf{2} < \textbf{4} and \textbf{3} > \textbf{1}. You are given the pair of numbers \textbf{n} and \textbf{t}. Find the number of permutations from \textbf{n} elements, that contains exactly \textbf{t} inversions. Print the lexicographically smallest permutation with \textbf{t} inversions. \InputFile Two integers \textbf{n} and \textbf{t} (\textbf{1} ≤ \textbf{n} ≤ \textbf{18}; \textbf{0} ≤ \textbf{t} ≤ \textbf{200}). \OutputFile In the first line print the number of permutations of \textbf{n} elements with exactly \textbf{t} inversions. In the second line print the lexicographically smallest permutation with \textbf{t} inversions. If such permutation does not exist, print "\textbf{0}" in the first line, and symbol "\textbf{-}" in the second. \InputFile Два целых числа \textbf{n} и \textbf{t} (\textbf{1} ≤ \textbf{n} ≤ \textbf{18}; \textbf{0} ≤ \textbf{t} ≤ \textbf{200}). \OutputFile В первую строку выведите количество перестановок из \textbf{n} элементов, которые имеют ровно \textbf{t} инверсий. Во вторую строку выведите наименьшую в лексикографическом порядке перестановку с заданным числом инверсий \textbf{t}. Если такой перестановки не существует, выведите в первую строку "\textbf{0}", а во вторую -- символ "\textbf{-}".
Time limit 4 seconds
Memory limit 64 MiB
Input example #1
3 0
Output example #1
1
1 2 3