atcoder#ARC101D. [ARC101F] Robots and Exits
[ARC101F] Robots and Exits
Score : points
Problem Statement
There are robots and exits on a number line. The coordinates of these are all integers and all distinct. For each (), the coordinate of the -th robot from the left is . Also, for each (), the coordinate of the -th exit from the left is .
Snuke can repeatedly perform the following two kinds of operations in any order to move all the robots simultaneously:
- Increment the coordinates of all the robots on the number line by .
- Decrement the coordinates of all the robots on the number line by .
Each robot will disappear from the number line when its position coincides with that of an exit, going through that exit. Snuke will continue performing operations until all the robots disappear.
When all the robots disappear, how many combinations of exits can be used by the robots? Find the count modulo . Here, two combinations of exits are considered different when there is a robot that used different exits in those two combinations.
Constraints
- All given coordinates are integers.
- All given coordinates are distinct.
Input
Input is given from Standard Input in the following format:
Output
Print the number of the combinations of exits that can be used by the robots when all the robots disappear, modulo .
2 2
2 3
1 4
3
The -th robot from the left will be called Robot , and the -th exit from the left will be called Exit . There are three possible combinations of exits (the exit used by Robot , the exit used by Robot ) as follows:
- Exit Exit
- Exit Exit
- Exit Exit
3 4
2 5 10
1 3 7 13
8
The exit for each robot can be chosen independently, so there are possible combinations of exits.
4 1
1 2 4 5
3
1
Every robot uses Exit .
4 5
2 5 7 11
1 3 6 9 13
6
10 10
4 13 15 18 19 20 21 22 25 27
1 5 11 12 14 16 23 26 29 30
22