PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#QHD0000045. Tổ hợp tiền xu I (Coin Combinations I)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Tổ hợp tiền xu I (Coin Combinations I)
Coin Combinations I
Source: CSES
Version: Phuoc Hung OJ Extended
Problem Statement
A currency system provides distinct positive denominations . You have an unlimited supply of each denomination. Count the number of ordered coin sequences with total exactly : sequences with different orders are considered different. Print the result modulo .
Input
The first line contains and , followed by distinct denominations .
Output
Print the number of ordered sequences modulo .
Subtasks
The independent scoring groups have the following complete constraints:
- Subtask 1 (20%): , , , all distinct.
- Subtask 2 (30%): , , , all distinct.
- Subtask 3 (50%): , , , all distinct.
Examples
Input
3 9
2 3 5
Output
8
Explanation
There are ordered sequences summing to : gives permutations; gives ; and gives . Thus .