Go: package main

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

func main() {
	io := NewIo()
	defer io.Flush()
	a, b, c := io.NextInt(), io.NextInt(), io.NextInt()
	for i := 0; i < 61; i++ {
		for j := 0; j < 61; j++ {
			if (a+b)*i-60*j <= c && c <= (a+b)*i-60*j+a {
				io.Println(60*j + c)
				return
			}
		}
	}
	io.Println(-1)
}

// 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 := make([]interface{}, 0, len(a))
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func (io *Io) PrintStringSlice(a []string) {
	b := make([]interface{}, 0, len(a))
	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: import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    while True:
        a,b,c = LI()
        s = set()
        s.add(0)
        t = 0
        r = -1
        for i in range(60):
            while t > c:
                c += 60
            if t <= c <= t+a:
                r = c
                break
            t += a + b

        rr.append(r)
        break

    return '\n'.join(map(str, rr))


print(main())

Python: from itertools import count
a,b,c=map(int,input().split())
for n in count(0):
    if (a+b)*n<=c+60*n<=(a+b)*n+a:break
    if n>0 and a+b<=60 and c>a:
        n=-1
        break
print(c+60*n)

Python: "山手線"
a, b, c = map(int, input().split())

flag = True
if a+b == 60 and c > a:  # 必ず辿りつけない
    print(-1)
else:
    right = 0
    left = a
    i = 0
    while True:
        # print('left : ', left)
        # print('right : ', right)
        # print('c : ', c)
        if left >= c and c >= right:
            print(c)
            break
        if left+b > c and c > right+a:
            c += 60
        left += (b+a)
        right += (a+b)
        i += 1
        if i > 60:
            print(-1)
            break

Python: a, b, c = map(int, input().split())
now = 0
while True:
    sleep_start = now + a
    if now % 60 < sleep_start % 60:
        if now % 60 <= c <= sleep_start % 60:
            print(now // 60 * 60 + c)
            break
        now += sleep_start + b
    else:
        if now % 60 <= c < 60:
            print(now // 60 * 60 + c)
            break
        now += sleep_start + b
    if now % 60 == 0:
        print(-1)
        break

Python: def solve(a, b, c):
    l = 0; r = a;
    for i in range(80):
        t = l // 60
        p = 60*t + c
        if l <= p <= r:
            print(p)
            exit()

        l = r + b
        r = l + a

    print(-1)

a, b, c = map(int, input().split())
solve(a,b,c)

Python: a,b,c = map(int,input().split())
lst = []
ans = 0
cnt = 0
while True:
	s = (60*cnt+c) % (a+b) 
	if s in lst:
		ans = -1
		break
	lst.append(s)
	if 0 <= s <= a:
		ans = 60 * cnt + c
		break
	cnt += 1
	
print(ans)

Python: a, b, c = map(int, input().split())
passed = set()
time = 0
while True:
    if time % 60 <= c <= time % 60 + a:
        print(c + time // 60 * 60)
        break
    else:
        time += a + b
        if time % 60 in passed:
            print(-1)
            break
        else:
            passed.add(time % 60)

Python: from itertools import count
a,b,c=map(int,input().split())
for n in count(0):
    if (a+b)*n<=c+60*n<=(a+b)*n+a:break
    if n>0 and a+b<=60 and c>a:
        n=-1
        break
if n>=0:
    print(c+60*n)
else:
    print(n)

Python: def solve(a, b, c):
    l = 0; r = a;
    for t in range(514):
        t = l // 60
        p = 60*t + c
        if l <= p <= r:
            print(p)
            exit()

        l = r + b
        r = l + a

    print(-1)

a, b, c = map(int, input().split())
solve(a,b,c)

Python: def horizontal_input(T=str):
    return list(map(T,input().split()))

def vertical_input(n,T=str,sep=False,septype=tuple):
    data=[]
    if sep:
        for i in range(n):
            data.append(septype(map(T,input().split())))
    else:
        for i in range(n):
            data.append(T(input()))
    return data

a,b,c=horizontal_input(int)
count=0
time=0
f=True
past=0
alltime=0
while count<70:
    if f:
        time=(time+a)%60
    else:
        time=(time+b)%60
    if f and (past<=c<=time or (past>=time and (0<c<=time or past<=c<60))):
        print(alltime+(c-past if past<=c<60 else 60-past+c))
        break
    elif f:
        alltime+=a
    else:
        alltime+=b
    if past>=time:
        count+=1
    past=time
    f=not f
else:
    print(-1)

Python: a, b, c = map(int, input().split())
now = 0
while True:
    sleep_start = now + a
    if now % 60 < sleep_start % 60:
        if now % 60 <= c <= sleep_start % 60:
            print(now // 60 * 60 + c)
            break
        now += sleep_start + b
    else:
        if now % 60 <= c or c <= sleep_start % 60:
            print(now // 60 * 60 + c)
            break
        now += sleep_start + b
    if now % 60 == 0:
        print(-1)
        break

Python: import math
a, b, c = map(int, input().split())
for k in range(60):
  t = math.ceil((k * (a + b) - c) / 60)
  if t <= (k * (a + b) + a - c) / 60:
    print(t * 60 + c)
    break
else:
  print(-1)

C++: #include <iostream>
using namespace std;

int main() {
    int ot, nt, ct, dt;
    cin >> ot >> nt >> ct;
    dt = ct;
    if((ot + nt) % 60 == 0) {
        cout << -1  << endl;
        return 0;
    }
    while(true) {
        if(dt % (ot + nt) <= ot) {
            cout << dt << endl;
            return 0;
        } else {
            dt += 60;
        }
    }
}