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)
}

Python: S, T, D = map(int, input().split())
S -= T
*W, = map(int, input().split())
F = sum(W)
if F >= 0:
    su = S
    for i, w in enumerate(W):
        su += w
        if su <= 0:
            print(i+1)
            break
    else:
        print(-1)
    exit(0)
su = 0
mi = 0
for d in W:
    su += d
    mi = min(mi, su)

k = max((S+mi-F-1) // -F, 0)
S += k*F
for i, w in enumerate(W):
    S += w
    if S <= 0:
        print(i+1+k*D)
        break
else:
    assert 0

Python: #!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    s,t,d = LI()
    w = LI()
    W = -sum(w)
    if W <= 0:
        for i in range(d):
            s += w[i]
            if s <= t:
                print(i+1)
                return
        print(-1)
    else:
        S = [s]
        for i in range(d):
            S.append(S[-1]+w[i])
            if S[-1] <= t:
                print(i+1)
                return
        m = min(S)
        for j in range(d+1):
            if S[j] == m:
                break
        s = S[j]
        w = w[j:]+w[:j]
        k = (s-t)//W
        s -= k*W
        if s <= t:
            print(k*d+j)
            return
        for i in range(d):
            s += w[i]
            if s <= t:
                print(k*d+i+1+j)
                return
    return

#Solve
if __name__ == "__main__":
    solve()

Python: #!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    s, t, d = LI()
    w = LI()
    sumw = sum(w)
    sb = s
    mins = s
    for i in range(d):
        sb += w[i]
        mins = min(mins, sb)
        if sb <= t:
            print(i + 1)
            return
    if sumw >= 0:
        print(-1)
    else:
        ans = ((mins - t) // abs(sumw)) * d
        #print(ans, s, d, t, sumw)
        s += ans // d * sumw
        i = 0
        while 1:
            if s <= t:
                print(ans + i)
                return
            s += w[i%d]
            i += 1
        print(ans+i+1)
    return

#B
def B():
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    A()

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

C++: #include <bits/stdc++.h>

using namespace std;

int main(){
    long long s,t,d;
    cin>>s>>t>>d;
    long long moku=t-s;
    map<long long,long long> mp;
    long long dif=0;
    long long mx=-1,mn=200000;
    for (int i = 1; i <= d; ++i) {
        long long w;
        cin>>w;
        dif+=w;
        if(dif<=moku){
            cout<<i<<endl;
            return 0;
        }
        if(mp.find(dif)==mp.end())mp[dif]=i;
        mx=max(mx,dif);mn=min(mn,dif);
    }

    for (long long yaru = 1; yaru <= 200000; ++yaru) {
        moku-=dif;
        if(moku>=0){
            cout<<d*yaru<<endl;
            return 0;
        }
        auto it=mp.upper_bound(moku);
        if(it!=mp.begin()){
            long long ans=200000;
            for(auto jt:mp){
                if(jt.first<=moku)ans=min(ans,jt.second);
            }
            cout<<d*yaru+ans<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
    return 0;
}