Codeforces #704 Div.2 A. Three swimmers

Problem - A - Codeforces
Codeforces. Programming competitions and contests, programming community

Three Swimmers is a Very Simple Problem.
First of all the main subject of this problem is that we need to find the require timing for the first person to wait until any other swimmers to arrives to the left side of the pool.

and as we all know every swimmers have a sequence of

0 p 2p 3p …
0 a 2a 3a …
0 b 2b 3b …
0 c 2c 3c …

from the example case of

4
9 5 4 8
2 6 10 9
10 2 5 10
10 9 9 9

from the first case 9 5 4 8
we can fine the answer like

0 9
0 5 10
0 4 8 12
0 8 16

which makes the minimum waiting time to 1

so if we made this rule to an equation

min(a-p%a, b-p%b, c-p%c)

this equation would be a possible outcome, but in this case I don’t know why but when a-p==0
the % calculation get screwed up and throw some weird value

so to avoid that

min(a-1-(p-1)%a, (b-1-(p-1)%b, c-1-(p-1)%c)

I have done that to the equation