#Lutece2700. Squad 404
Squad 404
Migrated from Lutece 2700 Squad 404
All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.
Description
In a war-torn world, the order of human society has been severely disrupted. As a commander of Squad 404, which specializes in covert operations and electronic warfare, you need to make combat preparations.
The battlefield can be seen as a grid with rows and columns of cells. The rows are numbered from to , and the columns are numbered from to . We can use to indicate a cell in row and column .
The rule of moving on the battlefield is special. If someone passes through the left border, he will be teleported to the right border, and vice versa, as well as the top and bottom borders. Squad 404 moves a fixed distance in each step. Formally, they can make four kinds of moves in each step:
- Move upper-left: from to
- Move upper-right: from to
- Move lower-left: from to
- Move lower-right: from to
Here means the remainder of divided by . For example, , since .
If Squad 404 starts from , please calculate how many different cells they can reach.
Input
The first line contains two integers (), indicating the number of rows and columns of the grid.
The second line contains two integers (, , ), indicating the fixed distance in each step.
Output
Print an integer, indicating the number of different cells they can reach.
Samples
10 1
6 0
5
4 4
1 3
8
6 2
4 1
6
Note
For the first example, they can reach a total of cells .
For the second example, they can reach a total of cells .
For the third example, they can reach a total of cells .
Resources
电子科技大学第十二届 ACM 趣味程序设计竞赛