Under construction

Still being built. Things may change

Expressions

Time limit1sMemory limit128 MB

Summary
Count balanced parenthesis strings of a given total length that have exactly a given maximum nesting depth.
Level

Medium6 of 10

Topics
Dynamic programming, Combinatorics, Math
Solved
No attempts yet

Problem

Let XX be the smallest set defined by the following rules:

  • the empty string belongs to XX;
  • if AA and BB belong to XX, then both (A)(A) and ABAB belong to XX.

The elements of XX are called correctly built parenthesis expressions. For example, these strings are correctly built parenthesis expressions:

()(())()
(()(()))

while these are not:

(()))(()
())(()

Let EE be a correctly built parenthesis expression. The length of EE is the number of single parentheses in EE. The depth D(E)D(E) of EE is defined by:

D(E)={0if E is emptyD(A)+1if E=(A) with A∈Xmax⁡(D(A),D(B))if E=AB with A,B∈XD(E) = \begin{cases} 0 & \text{if } E \text{ is empty} \\ D(A) + 1 & \text{if } E = (A) \text{ with } A \in X \\ \max(D(A), D(B)) & \text{if } E = AB \text{ with } A, B \in X \end{cases}

Given two positive integers nn and dd, determine how many correctly built parenthesis expressions have length exactly nn and depth exactly dd.

Input

A single line containing two integers nn and dd separated by one space, with 2≤n≤382 \le n \le 38 and 1≤d≤191 \le d \le 19.

Output

Print a single integer: the number of correctly built parenthesis expressions of length nn and depth dd.

Hint

There are exactly three correctly built parenthesis expressions of length 66 and depth 22:

(())()
()(())
(()())

Examples4

  1. Example 1

    Input
    6 2
    
    Expected output
    3
    
  2. Example 2

    Input
    2 1
    
    Expected output
    1
    
  3. Example 3

    Input
    4 2
    
    Expected output
    1
    
  4. Example 4

    Input
    6 1
    
    Expected output
    1