Petr’s problem

A permutation p₁, …, p_(n) is a sequence of numbers between 1 and n such
that each number appears exactly once. An inversion in a permutation is
a pair of indices (i, j) such that i < j but p_(i) > p_(j). The weight
of an inversion (i, j) is j − i.

How many permutations of n elements exist where the sum of weights of
all inversions is equal to x? For instance, there are exactly two such
permutations for n = 4 and x = 4: 3, 2, 1, 4 and 1, 4, 3, 2.

Input

Input consists of several cases, each one with n and x. You can assume
1 ≤ n ≤ 14 and 0 ≤ x ≤ (n + 1)n(n − 1)/6.

Output

For every case, print the number of permutations of n elements such that
the sum of weights of all inversions is x.

Problem information

Author: Petr Mitrichev

Generation: 2026-01-25T12:00:00.215Z

© Jutge.org, 2006–2026.
https://jutge.org
