#P16791. [蓝桥杯 2026 国 A] 神秘排列

    ID: 19132 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 显示难度普及+/提高− 上传者: 标签>数学组合数学2026蓝桥杯国赛

[蓝桥杯 2026 国 A] 神秘排列

Problem Description

While studying combinatorics, Xiao Lan proposed the concept of a "balanced position".

For a permutation a1,a2,…,ana_1, a_2, \ldots, a_n of 11 to nn, if position ii satisfies the following condition, then position ii is called a balanced position:

  • The "number of elements on the left of position ii whose values are less than aia_i" is exactly equal to the "number of elements on the right of position ii whose values are greater than aia_i".

Here, the left side of position ii refers to positions 1,2,…,i−11, 2, \ldots, i-1, and the right side refers to positions i+1,i+2,…,ni+1, i+2, \ldots, n. Neither side includes position ii itself.

Xiao Lan believes that if a permutation has at least ⌈n/2⌉\lceil n/2 \rceil balanced positions (where ⌈x⌉\lceil x \rceil denotes the ceiling function), then this permutation is called a "good permutation".

Now, given the number nn, please compute the number of good permutations among all permutations of 11 to nn. Since the answer may be very large, output it modulo 109+710^9 + 7.

Input Format

Input one line containing one positive integer nn.

Output Format

Output one line containing one integer, representing the number of good permutations modulo 109+710^9 + 7.

4
7

Hint

Sample Explanation

When n=4n = 4, a good permutation needs at least ⌈4/2⌉=2\lceil 4/2 \rceil = 2 balanced positions.

Take the permutation 4 3 2 14\ 3\ 2\ 1 as an example: on the left of every position, there is no number smaller than the element at the current position, and on the right there is also no number greater than the element at the current position. Therefore, all four positions are balanced positions. This permutation is a good permutation.

Among all permutations of length 44, there are 77 good permutations in total, so the output is 77.

Constraints

For 30%30\% of the testdata, 1≤n≤101 \le n \le 10.

For 60%60\% of the testdata, 1≤n≤50001 \le n \le 5000.

For all testdata, 1≤n≤1071 \le n \le 10^7.

Translated by ChatGPT 5