#jag2017summerday3b. [jag2017summer_day3_b]Slimming Plan
[jag2017summer_day3_b]Slimming Plan
MathJax.Hub.Config({ tex2jax: { inlineMath: [[""], ["\\(","\\)"]], processEscapes: true }}); blockquote { font-family: Menlo, Monaco, "Courier New", monospace; color: #333333; display: block; padding: 8.5px; margin: 0 0 9px; font-size: 16px; line-height: 18px; background-color: #f5f5f5; border: 1px solid #ccc; border: 1px solid rgba(0, 0, 0, 0.15); -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px; white-space: pre; white-space: pre-wrap; word-break: break-all; word-wrap: break-word; }
Problem Statement
Chokudai loves eating so much. However, his doctor Akensho told him that he was overweight, so he finally decided to lose his weight.
Chokudai made a slimming plan of a -day cycle. It is represented by integers . His weight is on the -th day of the plan and he aims to reduce it to . If his weight on the -th day of the plan is , it will be x + w\_{i \\% D} on the -th day. Note that is the remainder obtained by dividing by . If his weight successfully gets less than or equal to , he will stop slimming immediately.
If his slimming plan takes too many days or even does not end forever, he should reconsider it.
Determine whether it ends or not, and report how many days it takes if it ends.
Input
The input consists of a single test case formatted as follows.
The first line consists of three integers . The second line consists of integers ( for each ).
Output
If Chokudai's slimming plan ends on the -th day, print in one line. If it never ends, print .
Sample Input 1
65 60 3
-2 3 -4
Output for Sample Input 1
4
Chokudai's weight will change as follows: .
Sample Input 2
65 60 3
-2 10 -3
Output for Sample Input 2
-1
Chokudai's weight will change as follows: $65 \\to 63 \\to 73 \\to 70 \\to 68 \\to 78 \\to 75 \\to \\cdots$.
Sample Input 3
100000 1 1
-1
Output for Sample Input 3
99999
Sample Input 4
60 59 1
-123
Output for Sample Input 4
1