Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	io := NewIo()
	defer io.Flush()
	S, T, D := io.NextInt(), io.NextInt(), io.NextInt()
	w := make([]int, D)
	sum, min := 0, 0
	for i := 0; i < D; i++ {
		w[i] = io.NextInt()
		sum += w[i]
		min = intMin(sum, min)
		if S+sum <= T {
			io.Println(i + 1)
			return
		}
	}
	if sum >= 0 {
		io.Println(-1)
		return
	}
	ans := 0
	for ; S+min > T; ans += D {
		S += sum
	}
	for i := 0; i < D; i++ {
		S += w[i]
		if S <= T {
			io.Println(ans + i + 1)
			return
		}
	}
}

func intMin(a, b int) int {
	if a < b {
		return a
	}
	return b
}

// I/O template
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buff []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buff = append(buff, line...)
		if !isPrefix {
			break
		}
	}
	return string(buff)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	s := io.tokens[io.nextToken]
	io.nextToken++
	return s
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *Io) PrintIntSlice(a []int) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func (io *Io) PrintStringSlice(a []string) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func Log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}

func ExampleIo() {
	io := NewIo()
	defer io.Flush()
	a := make([]int, 0, 3)
	a[0], a[1], a[2] = io.NextInt(), io.NextInt(), io.NextInt()
	io.Println(a)
	io.PrintIntSlice(a)
	Log("io", a)
}

C++: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
ll w[100000];
//この状態から1周試す
//無理な場合は-1
int ty(ll s,ll t,int d)
{
	int ret=-1;
	for(int i=0;i<d;i++)
	{
		if(s<=t)
		{
			ret=i;
			break;
		}
		s+=w[i];
		if(s<=t)
		{
			ret=i+1;
			break;
		}
	}
	return ret;
}
int main()
{
	ll s,t;int d;
	ll ans=0;
	cin>>s>>t>>d;
	for(int i=0;i<d;i++)
		cin>>w[i];
	ll sum=0;
	ll tani=1e14-1;//変化量の中で最も小さいところ
	int taniind=-1;
	for(int i=0;i<d;i++)
	{
		sum+=w[i];
		if(sum<tani)
		{
			tani=sum;
			taniind=i;
		}
	}
	//cerr<<sum<<" "<<tani<<endl;
	if(sum>=0)
	{
		cout<<ty(s,t,d)<<endl;
		return 0;
	}
	ans=ty(s,t,d);
	if(ans!=-1)
	{
		cout<<ans<<endl;
		return 0;
	}
	sum*=-1;
	tani*=-1;
	ll cnt=ceill((double)max((s-t-tani),0LL)/(double)sum);
	s-=cnt*sum;
	ans=cnt*d+ty(s,t,d);
	cout<<ans<<endl;
	return 0;
}