Message Passing

Count the telephone calls made at time t when each informed employee calls d new people over the next d time units, modulo 31991.

Medium6Dynamic programmingCombinatoricsMathNo attempts yetTime limit1sMemory limit512 MB

Problem

At International Computer Products Company (ICPC), the employer often has to pass an important message to every employee. The message spreads along the organizational reporting lines as a chain of telephone calls. Kim, the employer of ICPC, is rebuilding the message passing system so that no employee calls other employees more than dd times. Kim wants to know how many telephone calls are made at time tt after the message passing starts. The rules are these.

  1. Each call involves exactly two employees.
  2. Each call takes one unit of time.
  3. An employee takes part in at most one call per unit of time.
  4. During the dd consecutive time units right after an employee is informed, that employee calls one uninformed employee per unit of time, so dd employees in total.

Kim calls exactly one employee at the moment the message passing starts, and Kim makes no other call. The case d=2d = 2 looks like this.

Time ttTelephone callsNumber of calls at time tt
0Kim starts the message passing by calling A.1
1A calls B.1
2A calls C, and B calls D.2
3B, C, and D call E, F, and G.3

Kim starts the message passing by calling A at time 0, and that call takes one unit of time. At time 1, A is the only employee who knows the message, so A calls the uninformed employee B. At time 2, both A and B know the message, and they call the uninformed employees C and D. No employee makes more than two calls here, so A stops calling after time 2. Three telephone calls are made at time 3.

Given dd and tt, compute the number of telephone calls made at time tt after Kim started the message passing. Assume the company always has enough uninformed employees.

Input

The first line contains two integers dd and tt (2d502 \le d \le 50, 1t2×1091 \le t \le 2 \times 10^9). dd is the number of employees that one employee calls, and tt is the time that has passed since the message passing started.

Output

Let mm be the number of telephone calls made at time tt. Print mmod31991m \bmod 31991 on one line. For example, if m=32000m = 32000, print 9.