Problem list
Log in
#coci00722 · COCI 2025/2026 Contest 5

Struktura

Unrated 1.0 s 256 MB

Petar and Ivana are bored during a long winter afternoon, so they decided to invent a game with numbers. Petar takes a sheet of paper and randomly writes down $n$ numbers. Each number is chosen completely at random and independently among the integers from 1 to $k$. Using this procedure, Petar creates an array $a$ of $n$ numbers. Ivana says that she especially likes some arrays because they have a “hidden balance”, and she calls them structures. An array is a structure if the following conditions are satisfied:

  • Every number from 1 to $n$ appears in the array exactly once.
  • For every index $i$ ($1 \le i \le n$), it holds that |$a_{i} + i - n - 1$| ≤1. Ivana is interested in the probability that Petar, choosing the numbers completely at random, constructs an array that is a structure. It can be proven that the answer can always be represented as a fraction ^{P} _{Q}^{,} ^{where} ^{P} ^{is} ^{an} ^{integer} ^{and} ^{Q} is a positive integer not divisible by $10^{9} + 7$. In that case, output $P \cdot Q^{−1}$ (mod $10^{9} + 7$).

Input

The first line contains the natural numbers $n$ and $k$ ($1 \le n$, $k \le 10^{9}$), the numbers from the problem statement.

Output

Output a single number, the answer to the question from the problem statement.

Example 1

Input
2 1
Output
0

Example 2

Input
2 2
Output
500000004

Example 3

Input
7 94
Output
100976822

Clarification of the second example: The arrays a that Petar can construct are: (1, 1), (1, 2), (2, 1), (2, 2). The arrays that are structures are (1, 2) and (2, 1). The probability that Petar completely at

random obtains an array that is a structure is 2 4, i.e. 500000004 (mod 109 + 7).

Source
COCI 2025/2026 Contest 5
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code