#P11465. Banana Card Usage

    ID: 13547 Type: Default 1000ms 256MiB

Banana Card Usage

Banana Card Usage

You are playing a card game with a special interaction. You have k copies of the card Water Dancer Sonia on the field, and one card in hand called Bunch of Bananas with remaining n bananas and a mana cost of 1.

You have unlimited mana and an unlimited hand size. When you play a Bunch of Bananas card, the following occurs:

  • When you use a cost \(1\) card with \(x\) bananas remaining, you gain:
    • \(k\) cards with cost \(0\) (each with \(x\) bananas remaining), and
    • 1 card with cost \(1\) (with \(x-1\) bananas remaining), provided that \(x > 1\).
  • When you use a cost \(0\) card with \(x\) bananas remaining, you gain:
    • 1 card with cost \(1\) (with \(x-1\) bananas remaining), provided that \(x > 1\).

The process stops when a card with \(x = 1\) is used and no new card is generated from the \(x-1\) part. Each time you play a card (regardless of its cost), you count it as one usage.

It can be shown that if you start with a cost \(1\) card with \(n\) bananas remaining, the total number of times you use a card is given by:

[ f_1(n) = \sum_{i=1}^{n} (1+k)^i. ]

Since the answer might be very large, output the result modulo \(10^9+7\).

inputFormat

The input consists of a single line containing two integers k and n, where:

  • k is the number of Water Dancer Sonia cards on the field.
  • n is the number of bananas remaining on the single Bunch of Bananas card in hand.

outputFormat

Output a single integer, which is the total number of times you can use a banana card, modulo \(10^9+7\).

sample

0 5
5