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 <iostream>
using namespace	std;
int 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 <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


struct Info{
	Info(int arg_minus_value,int arg_loc){
		minus_value = arg_minus_value;
		loc = arg_loc;
	}
	int minus_value,loc;
};


int main(){

	int S,T,D;
	scanf("%d %d %d",&S,&T,&D);

	int* table = new int[D];
	for(int i = 0; i < D; i++)scanf("%d",&table[i]);

	vector<Info> V;
	if(table[0] < 0){
		V.push_back(Info(abs(table[0]),0));
	}

	for(int i = 1; i <= D-1; i++){
		table[i] += table[i-1];
		if(table[i] < 0){
			V.push_back(Info(abs(table[i]),i));
		}
	}

	int tmp = S;

	for(int day = 1; day <= D; day++){
		tmp = S+table[day-1];
		if(tmp <= T){
			printf("%d\n",day);
			return 0;
		}
	}

	if(tmp >= S){
		printf("-1\n");
		return 0;
	}

	int pre_loc = -1;
	ll ans = D;

	while(true){

		for(int i = 0; i < V.size(); i++){

			tmp -= V[i].minus_value;

			if(V[i].loc <= pre_loc){
				ans += (V[i].loc+D)-pre_loc;
			}else{
				ans += V[i].loc-pre_loc;
			}
			if(tmp <= T){
				printf("%d\n",ans);
				return 0;
			}
			pre_loc = V[i].loc;
		}
	}

	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;
 
int w[100001];
int main(){
    int s,t,d;
    cin>>s>>t>>d;
    ll sum=0;
    ll mn=1000100010;
    rep(i,d){
        cin>>w[i];
        sum+=w[i];
        mn=min(mn,sum);
        if(-sum>=s-t){
            cout<<i+1<<endl;
            return 0;
        }
    }
    if(sum>=0){
        cout<<-1<<endl;
        return 0;
    }
    ll ans=0;
    ll sub=s-t+mn;
    ans+=(sub/(-sum)+1)*d;
    sub=s-t-(sub/(-sum)+1)*(-sum);
    rep(i,d){
        if(sub<=0){
            cout<<ans<<endl;
            return 0;
        }
        sub+=w[i];
        ++ans;
    }
    cout<<ans<<endl;
    return 0;
}

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

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<bits/stdc++.h>
 
using namespace std;
 
typedef long long int64;
 
int main()
{
  int64 S, T, D, W[100000];
 
  cin >> S >> T >> D;
  int64 sum = 0, minimum = 0;
  for(int i = 0; i < D; i++) {
    cin >> W[i];
    sum += W[i];
    minimum = min(minimum, sum);
  }
 
  if(sum > 0 && S + minimum > T) {
    cout << -1 << endl;
  } else {
    sum *= -1;
    int64 ret = 0;
 
    if(S + minimum > T) {
      int64 add = (S + minimum - T) / sum;
      ret += add * D;
      S -= add * sum;
    }
    int idx = 0;
    while(S > T) {
      S += W[idx++ % D];
      ++ret;
    }
    cout << ret << endl;
  }
}

C++: #include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int w[100001];
int main(){
    int s,t,d;
    cin>>s>>t>>d;
    ll sum=0;
    rep(i,d){
        cin>>w[i];
        sum+=w[i];
        if(-sum>=s-t){
            cout<<i+1<<endl;
            return 0;
        }
    }
    if(sum>=0){
        cout<<-1<<endl;
        return 0;
    }
    ll ans=0;
    ll sub=s-t;
    ans+=sub/(-sum)*d;
    sub-=sub/(-sum)*(-sum);
    rep(i,d){
        if(sub<=0){
            cout<<ans<<endl;
            return 0;
        }
        sub+=w[i];
        ++ans;
    }
    cout<<ans<<endl;
    return 0;
}