#P6386. Agitated Dogs
Agitated Dogs
Agitated Dogs
In a small village, a postman, a milkman, and a garbage collector face the same problem every morning at house number 18: two guard dogs. What they do not know is that the dogs' behavior is predictable.
At the start of each day, one dog becomes agitated for \(a\) minutes and then calm for \(b\) minutes, repeating this cycle indefinitely. The other dog becomes agitated for \(c\) minutes and then calm for \(d\) minutes, and then repeats its cycle indefinitely.
You are given the arrival times of the three persons at house number 18. For each arrival time, determine how many dogs are agitated (i.e. in their "agitated" phase) at that exact moment. Note that time is measured in minutes from the beginning of the day and the cycles start at time 0.
Behavior Details:
- For the first dog, its cycle period is \(a+b\). It is agitated when \(t \bmod (a+b) < a\) and calm otherwise.
- For the second dog, its cycle period is \(c+d\). It is agitated when \(t \bmod (c+d) < c\) and calm otherwise.
Output one integer per arrival time indicating how many dogs are agitated at that moment.
inputFormat
The input consists of two lines:
- The first line contains four positive integers \(a\), \(b\), \(c\), and \(d\) separated by spaces.
- The second line contains three non-negative integers representing the arrival times of the postman, milkman, and garbage collector.
It is guaranteed that all integers are space separated.
outputFormat
For each arrival time given in the input, output a single integer on a new line indicating the number of dogs that are agitated at that moment.
sample
2 3 1 2
1 5 6
1
1
2
</p>