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>

# define x first
# define y second
# define mp make_pair
// everything goes according to my plan
# define pb push_back
# define sz(a) (int)(a.size())
# define vec vector
// shimkenttin kyzdary, dzyn, dzyn, dzyn...
# define y1    Y_U_NO_y1
# define left  Y_U_NO_left
# define right Y_U_NO_right

# ifdef Local
# define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
# else
# define debug(...) (__VA_ARGS__)
# define cerr if(0)cout
# endif

using namespace std;

typedef pair <int, int> pii;
typedef long long ll;
typedef long double ld;

const int Mod = (int)1e9 + 7;
const int MX = 1073741822;
const ll MXLL = 4e18;
const int Sz = 1110111;
// a pinch of soul
inline void Read_rap () {
  ios_base :: sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}
inline void randomizer3000 () {
  unsigned int seed;
  asm ("rdtsc" : "=A"(seed));
  srand (seed);
}
void files (string problem) {
  if (fopen ((problem + ".in").c_str(),"r")) {
    freopen ((problem + ".in").c_str(),"r",stdin);
    freopen ((problem + ".out").c_str(),"w",stdout);
  }
}
void localInput(const char in[] = "s") {
  if (fopen (in, "r")) {
    freopen (in, "r", stdin);
  }
  else
    cerr << "Warning: Input file not found" << endl;
}

int main()
{
  # ifdef Local
    //localInput();
  # endif
  Read_rap();

  ll s, t, d;

  cin >> s >> t >> d;

  ll lmin = 0, sum = 0;
  int a[d + 1];
  for (int i = 0; i < d; i++) {
    int x;
    cin >> x;
    a[i] = x;
    sum += x;
    lmin = min (lmin, sum);
  }
  ll days = 0;
  while (s + lmin > t && sum < 0)
    days += d, s += sum;
  for (int i = 0; i < d; i++) {
    s += a[i];
    if (s <= t) {
      cout << days + i + 1 << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  


  return 0;
}






// Coded by Z..e

C++: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll s,t,d,w[100000],c=0,ans=1e11;
  cin>>s>>t>>d;
  for(ll i=0;i<d;i++)cin>>w[i],c-=w[i];
  s-=t;
  for(ll i=0;i<d;i++){
    s+=w[i];
    if(s<=0)ans=min(ans,i+1);
    else if(c>0)ans=min(ans,i+(s+c-1)/c*d+1);
  }
  if(ans==1e11)ans=-1;
  cout<<ans<<endl;
  return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;
typedef long long ll;

int main(){
    int s, t, d;
    cin >> s >> t >> d;
    vector<ll> v(d);
    for(int i = 0; i < d; i++)  cin >> v[i], v[i] *= -1;
    ll target = s-t;
    ll sum = 0, ma = 0;
    for(int i = 0; i < d; i++){
        sum += v[i];
        if(sum >= target){
            cout << i+1 << endl;
            return 0;
        }
        ma = max(ma, sum);
    }
    if(sum <= 0){
        cout << -1 << endl;
        return 0;
    }
    ll ans = (target-ma+sum-1)/sum*d;
    target -= (target-ma+sum-1)/sum*sum;
    for(int i = 0; i <= d; i++){
        if(target <= 0){
            cout << ans+i << endl;
            return 0;
        }
        if(i < d)   target -= v[i];
    }
}

C++: #include <iostream>
using namespace	std;
#define	int long long
main(){

  int s,t,d,w[100000];
  cin>>s>>t>>d;
  for(int i=0,tmp;i<d;i++){
    cin>>tmp;
    if(i) w[i]=w[i-1]+tmp;
    else w[i]=tmp;
  }
  for(int i=0;i<d;i++){
    if(s+w[i]<=t){
      cout<<i+1<<endl;
      return 0;
    }
  }
  if(w[d-1]>=0){
    cout<<-1<<endl;
    return 0;
  }
  long long r=114514191911451419;
  for(int i=0;i<d;i++){
    r=min(r,(long long)(s-t+w[i]-w[d-1]-1)/-w[d-1]*d+i+1);
    //   cout<<r<<endl;                                                                                                        
  }
  cout<<r<<endl;
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;

const long double PI = acos(-1);
constexpr long double EPS = 1e-15;
constexpr int inf = 2e9;
constexpr ll INF = 2e18;
constexpr ll MOD = 1e9+7;
constexpr ll MOD1 = 998244353;
typedef pair<ll,ll> P;

#define int long long

//#define all(v) (v).begin(), (v).end()
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
//#define mp make_pair

int s, t, d, w[112345], sum, mn, mnd;

signed main(){
    cin >> s >> t >> d;
    REP(i, d) cin >> w[i];
    REP(i, d){
        sum += w[i];
        if(mn > sum){
            mn = sum;
            mnd = i;
        }
    }

        int st = s;
        for(int i = 0; i < d; ++i){
            st += w[i];
            if(st <= t){
                cout << i + 1 << endl;
                return 0;
            }
        }
    if(sum >= 0){
        cout << -1 << endl;
        return 0;
    }

    // cout << sum << endl;
    // cout << mn << " " << mnd << endl;
    int ans = (s - t + mn - 1) / (- sum) + 1;
    st = s + ans * sum;
    ans *= d;
    if(st > t)
    for(int i = 0; i < d; ++i){
        st += w[i];
        if(st <= t){
            ans += i + 1;
            break;
        }
    }
    cout << ans << endl;
}