atcoder#CF17FINALG. Mancala

Mancala

Score : 10001000 points

Problem Statement

Consider the following game:

  • The game is played using a row of NN squares and many stones.
  • First, aia_i stones are put in Square i (1iN)i\ (1 \leq i \leq N).
  • A player can perform the following operation as many time as desired: "Select an integer ii such that Square ii contains exactly ii stones. Remove all the stones from Square ii, and add one stone to each of the i1i-1 squares from Square 11 to Square i1i-1."
  • The final score of the player is the total number of the stones remaining in the squares.

For a sequence aa of length NN, let f(a)f(a) be the minimum score that can be obtained when the game is played on aa.

Find the sum of f(a)f(a) over all sequences aa of length NN where each element is between 00 and KK (inclusive). Since it can be extremely large, find the answer modulo 1000000007(=109+7)1000000007 (= 10^9+7).

Constraints

  • 1N1001 \leq N \leq 100
  • 1KN1 \leq K \leq N

Input

Input is given from Standard Input in the following format:

NN KK

Output

Print the sum of f(a)f(a) modulo 1000000007(=109+7)1000000007 (= 10^9+7).

2 2
10

There are nine sequences of length 22 where each element is between 00 and 22. For each of them, the value of f(a)f(a) and how to achieve it is as follows:

  • f({0,0})f(\{0,0\}): 00 (Nothing can be done)
  • f({0,1})f(\{0,1\}): 11 (Nothing can be done)
  • f({0,2})f(\{0,2\}): 00 (Select Square 22, then Square 11)
  • f({1,0})f(\{1,0\}): 00 (Select Square 11)
  • f({1,1})f(\{1,1\}): 11 (Select Square 11)
  • f({1,2})f(\{1,2\}): 00 (Select Square 11, Square 22, then Square 11)
  • f({2,0})f(\{2,0\}): 22 (Nothing can be done)
  • f({2,1})f(\{2,1\}): 33 (Nothing can be done)
  • f({2,2})f(\{2,2\}): 33 (Select Square 22)
20 17
983853488