logo AlgoBeat OnlineJudge
登录 注册

#212506. [NERC2023] Joy of Pokémon Observation

内存限制:1024 MiB 时间限制:3000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

The Pokémon Conservation Society protects Pokémon and their habitats all around the globe. In recent research, data about habitats was collected.

Each habitat may be inhabited by several Pokémon species. Researchers know how many limbs each species has. Pokémon are swift and extremely good at hiding, so researchers were only able to detect the total number of limbs in each of the habitats.

Researchers understand that it might not be possible to find the population of each species, but would like to understand how much uncertainty is left. How many different combinations of Pokémon would have the observed number of limbs?

输入格式

The first line contains a single integer () --- the number of habitats. The next lines contain the description of each habitat.

Each line starts with two integers and (, ), where is the total number of limbs, and is the number of species in the habitat. They are followed by integers () --- the number of limbs for each species.

输出格式

Output the number of possible combinations of Pokémon in each habitat. Output should contain lines with a single integer.

样例

样例输入 1

3
6 1 3
6 2 2 3
6 3 1 2 3

样例输出 1

1
2
7

样例输入 2

4
1000000000 3 1 1 1
0 3 2 4 5
17 2 2 4
34 3 5 3 2

样例输出 2

500000001500000001
1
0
25

数据范围与提示

For the sake of example we will use Pokémon: has one limb, has two limbs, has three limbs. In the first example all three habitats have limbs.

In the first example the first habitat has only one Pokémon species --- . So it is likely the young family containing .

In the second habitat there are two Pokémon species: and . So it is either or .

The third habitat may contain any of the three Pokémon species: , and . There are seven possible combinations: , , , , , , .

In the second example the first habitat has three Pokémon species, but all of them have only one limb: , and . There are limbs and combinations.

In the second habitat no limbs were detected. So there are unfortunately no Pokémon left in the area.

In the third habitat all Pokémon have an even number of limbs, so it is not possible to have 17 limbs.