QOJ.ac

QOJ

Limite de temps : 1 s Limite de mémoire : 256 MB Points totaux : 100

#555. Code

Statistiques

Background

JSOI has recently become interested in a new programming language called JS, and JYY wants to analyze some of its properties.

Description

The JS language is very simple. A JS program can be viewed as a string. It has no input and a single internal register, which is initially $0$ but can store any integer. It supports 5 different operations:

  • Operation 1 "+": Increment the register by 1.
  • Operation 2 "-": Decrement the register by 1.
  • Operation 3 "!x": Call a library function. There are $K$ different library functions available depending on the version of the library, where $x$ is an integer between $1$ and $K$. This operation does not affect the current register value. Note that "!123" is a string of length 4.
  • Operations 4 and 5 "[" and "]": Loops. In a valid program, "[" and "]" must be properly matched. When execution reaches "[", if the register is $0$, it jumps directly to the corresponding "]", otherwise it continues execution. When execution reaches "]", if the register is $0$, it continues execution, otherwise it jumps back to the corresponding "[".

A JS program is a string composed of the above operations. Except for loop operations, operations are executed in order from left to right.

After writing some programs, JYY discovered that some programs enter an infinite loop and never terminate, while others do not. Now, JYY wants to calculate how many JS programs of length $N$ do not enter an infinite loop, given $K$ library functions.

Input

The input contains two integers $N$ and $K$.

Output

Output a single integer representing the number of JS programs of length $N$ that do not enter an infinite loop when there are $K$ library functions, modulo $10^9+7$.

Examples

Input 1

3 1

Output 1

16

Note

In the first example, there is only one library function !1. The 16 programs that do not enter an infinite loop are: +++, -++, +-+, --+, []+, ++-, -+-, +--, ---, []-, [+], [-], !1+, !1-, +!1, -!1.

Input 2

5 9

Output 2

1010

Constraints

  • For 30% of the data, $N \le 10$.
  • For 50% of the data, $N \le 50$.
  • For 100% of the data, $1 \le N \le 100$, $1 \le K < 10^4$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.