Slimming Plan

Interview

Time limit2sMemory limit512 MB

Summary
Simulate daily weight changes from the repeating D-day plan and report the day the weight reaches T, or output -1 if it never does.
Level

Easy3 of 10

Topics
Simulation, Array, Implementation
Solved
No attempts yet

Problem

Chokudai loves eating so much. However, his doctor Akensho told him that he was overweight, so he finally decided to lose weight.

Chokudai made a slimming plan with a cycle of DD days. It is represented by DD integers w0,…,wD−1w_0, \ldots, w_{D-1}. His weight is SS on day 0 of the plan, and he aims to reduce it to T (S>T)T \ (S > T). If his weight on day ii of the plan is xx, it will be x+wi%Dx + w_{i \% D} on day (i+1)(i+1). Here i%Di \% D is the remainder obtained by dividing ii by DD. If his weight gets less than or equal to TT, he stops slimming immediately.

If his slimming plan takes too many days or never ends, he should reconsider it.

Determine whether it ends, and report how many days it takes if it ends.

Input

The input consists of a single test case formatted as follows.

S T D
w0⋯wD−1

The first line consists of three integers S,T,D (1≤S,T,D≤100,000, S>T)S, T, D \ (1 \le S,T,D \le 100{,}000, \ S > T). The second line consists of DD integers w0,…,wD−1w_0, \ldots, w_{D-1} (−100,000≤wi≤100,000-100{,}000 \le w_i \le 100{,}000 for each ii).

Output

If Chokudai's slimming plan ends on the dd-th day, print dd in one line. If it never ends, print −1-1.

Examples4

  1. Example 1

    Input
    65 60 3
    -2 3 -4
    
    Expected output
    4
    
  2. Example 2

    Input
    65 60 3
    -2 10 -3
    
    Expected output
    -1
    
  3. Example 3

    Input
    100000 1 1
    -1
    
    Expected output
    99999
    
  4. Example 4

    Input
    60 59 1
    -123
    
    Expected output
    1