Under construction

Still being built. Things may change

Unlucky Numbers

Time limit1sMemory limit512 MB

Summary
Count the n-digit numbers made of digits 0 to k whose digits cannot be split into two groups with equal sums.
Level

Medium7 of 10

Topics
Dynamic programming, Combinatorics, Math
Solved
No attempts yet

Problem

A six-digit bus ticket is usually called lucky if the sum of its first three digits equals the sum of its last three. Vasya, a schoolboy, loved getting lucky tickets, but they came up rarely. So he changed the definition of a lucky ticket.

In his definition, a number is lucky if the sum of some of its digits equals the sum of the remaining digits. Ticket 561743 is lucky because 5+1+4+3=6+75+1+4+3=6+7.

Vasya has grown up, but out of habit he still looks for signs of luck in document numbers. He extended his definition to nn-digit account numbers and other document numbers made of digits from 0 to kk, where 1≤k≤91 \le k \le 9. A number is lucky if the sum of some of its digits equals the sum of the rest. All other numbers are unlucky. Even with the wider definition, many unlucky numbers remain.

Count the unlucky nn-digit numbers that can be formed from the digits 0 to kk. Numbers may have any number of leading zeros.

The input file unlucky.in is provided as tests.txt. Create the matching output file for this input and submit it for judging.

Input

The input file contains several pairs of values nn and kk, each on its own line.

Output

For each pair of nn and kk in the input file, print the count of unlucky numbers on the corresponding line of the output file, or 0 if you cannot obtain the count. The input and output files must have the same number of lines.

Examples1

  1. Example 1

    Input
    1 1
    
    Expected output
    1