PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#QHD0000087. Đếm cách thanh toán (Pay the Price)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Đếm cách thanh toán (Pay the Price)

Pay the Price

Source: UVa

Version: Phuoc Hung OJ Extended

Problem Statement

In a country, coin denominations are all integers from 11 to 300300, with unlimited availability of each denomination. To pay exactly nn units, choose a multiset of coins summing to nn. Two payment methods are the same if they use the same count of each denomination; changing the order of the coins does not make a new method. For example, paying 66 using exactly three coins has three methods: 1+1+41+1+4, 1+2+31+2+3, and 2+2+22+2+2.

The input specifies one of three possible restrictions on the number of coins:

  • Only nn: any number of coins is allowed, provided they sum to nn.
  • nn and UU: use at most UU coins.
  • n,L,Un,L,U: use at least LL and at most UU coins, with both endpoints included.

Count the distinct methods satisfying the specified limit. For n=0n=0, the empty payment is one method if zero coins are permitted. No valid payment of value nn can contain more than nn coins because all denominations are positive.

PHOJ adaptation: The original UVa input contains many independent query lines until end-of-file. This version takes one query and prints one answer; no EOF loop or sentinel is used.

Input

One line contains one, two, or three integers: n, n U, or n L U. The number of integers determines the query type.

Output

Print a 64-bit integer: the number of distinct payment methods. Do not take any modulus.

Subtasks

  • Subtask 1 (20 points): 0≤n≤400\le n\le40; supplied limits are in [0,40][0,40] and lower limit does not exceed upper.

  • Subtask 2 (30 points): 0≤n≤1500\le n\le150; supplied limits are in [0,150][0,150].

  • Subtask 3 (50 points): 0≤n≤3000\le n\le300; supplied limits may be between 00 and 10910^9, with L≤RL\le R when both are present.

Examples

Example 1

Input

6 2 5

Output

9

Explanation: Of the 11 unrestricted partitions of 6, remove the single-coin method and the six-coin method, leaving 9.

Example 2

Input

6

Output

11

Explanation: There are 11 integer partitions of 6, hence 11 payment methods.

Example 3

Input

6 3

Output

7

Explanation: Exactly seven partitions of 6 use at most three positive parts.