IOI Farm is an agricultural farm growing apples. It is famous for being located around a large circular lake.
In IOI Farm, there are employees, numbered from
to
. There are
apple trees, numbered from
to
.
The perimeter of the lake is
meters.
In the beginning, the employee
is waiting at the distance of
meters from the northernmost point
of the lake, in the clockwise direction. The values of
are distinct. The apple tree
is grown up at the distance of
meter from the northernmost point of the lake, in the clockwise direction. The
values of
are distinct. Moreover, there is no apple tree at the initial position of any employee.
Due to a special breed improvement of the apple trees in IOI Farm, every apple tree can have at most one
apple at the same time. Moreover, if an apple is harvested from the apple tree, it will have a new apple exactly
after seconds. At time
, every apple tree has an apple, and every employee starts walking around the lake
in the clockwise direction. The speed of every employee is
meter per second. If an employee arrives at an
apple tree with an apple, then the employee will always harvest it (If an apple tree has a new apple at the same
time when an employee arrives there, then the employee will harvest it too). We ignore the time it takes for an
employee to harvest an apple.
President K is a stockholder of IOI Farm. Since you are a manager of IOI Farm, President K asked you to
report on the efficiency of the employees. More precisely, President K wants to know the following values.
For each
![]()
, the number of apples harvested by the employee
until time
(including an apple harvested exactly at time
if it exists).
Write a program which, given the number of employees, the number of apple trees, the perimeter of
the lake, the time it takes for an apple tree to have a new apple, the positions of the employees and the apple
trees, and information on queries, calculates the number of harvested apples for each query.
Input Specification
Output Specification
Write lines to the standard output. In the
-th line
, output the answer to the
-th query.
Constraints
.
.
.
.
.
.
.
.
.
.
.
.
Subtasks
- (5 points)
,
,
.
- (20 points)
.
- (75 points) No additional constraints.
Sample Input 1
3 2 7 3
1 4 6
0 5
3
1 7
2 3
3 8
Sample Output 1
2
1
1
Explanation for Sample 1
- At time
, the employee
harvests an apple from the apple tree
, and the employee
harvests an apple from the apple tree
.
- At time
, the employee
arrives at the apple tree
. Since it has no apple at that time, the employee does not harvest an apple.
- At time
, the employee
harvests an apple from the apple tree
.
- At time
, the employee
harvests an apple from the apple tree
. The employee
arrives at the apple tree
, but does not harvest an apple since the apple tree has no apple at that time.
- At time
, the employee
harvests an apple from the apple tree
. The employee
arrives at the apple tree
, but does not harvest an apple since the apple tree has no apple at that time.
As the number of apples harvested by the employee until time
(including an apple harvested at time
) is
, output
in the first line.
Sample Input 2
5 3 20 6
0 4 8 12 16
2 11 14
9
4 1932
2 93787
1 89
5 98124798
1 2684
1 137598
3 2
3 8375
4 237
Sample Output 2
146
7035
7
7359360
202
10320
0
628
18
Sample Input 3
8 15 217 33608
0 12 71 96 111 128 152 206
4 34 42 67 76 81 85 104 110 117 122 148 166 170 212
14
2 223544052420046341
3 86357593875941375
4 892813012303440034
1 517156961659770735
7 415536186438473633
6 322175014520330760
7 557706040951533058
6 640041274241532527
5 286263974600593111
8 349405886653104871
1 987277313830536091
5 989137777159975413
2 50689028127994215
7 445686748471896881
Sample Output 3
33230868503053
3
5
1
123542793648997
8
165811220737767
8
7
1
1
7
7535161012043
132506837660717
Comments