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

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>

using namespace std;

#define INF 1010001000
#define EPS 1e-10
#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

typedef pair<int, int> i_i;
typedef long long int llong;
typedef pair<llong, llong> ll_ll;
typedef struct edge {int f, t;}Edge;


int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    int time = c;
    rep(i, 101000) {
        if (a * i + b * i <= time && time <= a * (i + 1) + b * i) {
            cout << time << endl;
            return 0;
        } else if (time < a * i + b * i) {
            time += 60;
            i--;
        }
    }
    cout << -1 << endl;

    return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  /*  (a+b)m<=60*t+c<=(a+b)*m+a
    0<=60*t+c-(a+b)*m<=a
    0 <= c-(a+b)*m<=a
    c-a<=(a+b)*m
(c-a)/(a+b)<=m


  */
  int a,b,c;
  cin>>a>>b>>c;
  rep(i,1e9){
    if(i==10000000){cout<<-1<<endl;break;}
    double m=(60*i+c-a)/(double)(a+b);
    if(m<0){cout<<c<<" "<<i<<endl;break;}
    int mm=(int)(m+0.99999999999999);
    if(0<=60*i+c-(a+b)*mm){cout<<60*i+c<<endl;break;}
  }
}

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

int a, b, c;
int solve() {
    int s = 0;
    int e = (a % 60);

    int cycle = 0;
    std::set<int> waked;
    while(true) {
        std::cout << s << "<-" << c << "->" << e << std::endl;
        if(waked.count(s) > 0) {
            return -1;
        }
        waked.insert(s);

        bool f = s <= e ? (s <= c && c <= e) : (s <= c || c <= e);
        if(f) break;

        s = (e + b) % 60;
        e = (s + a) % 60;
        ++cycle;
    }
    return (cycle-1)*60 + c;
}

int main() {
    std::cin >> a >> b >> c;
    std::cout << solve() << std::endl;
}

C++: #include<bits/stdc++.h>
using namespace std;

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  bool visited[60];
  int time = 0, cnt = 0;
  memset(visited, 0, sizeof(visited));
  for(int i = 0; !visited[time]; i++){
    if(time <= c && c <= time + a){
      cout << 60*cnt + c << endl;
      break;
    }
    time += b;
    if(time > 60){
      cnt++, time -= 60;
    }
    visited[time] = true;
  }
  if(visited[time])cout << -1 << endl;
}

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

int main(){
    int a, b, c;
    cin >> a >> b >> c;

    int time=0, time_=-1;
    for(int i=0; i<60; i++){
        if(time%60 != time_%60)
            break;
        time_ = time;
        
        while(time < (i+1)*60){
            if(time%60 <= c && c <= time%60+a){
                time += c - time%60;
                cout << time << endl;
                return 0;
            }else{
                time += a+b;
            }
        }
    }
    cout << -1 << endl;
    
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

using ll=long long;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)

int read(){
	int i;
	scanf("%lld",&i);
	return i;
}

signed main(){
	int A=read(),B=read(),C=read();
	int time=0;
	bool sleep=false;
	int t=0;
	while(true){
		time += A;
		if(time >= C) break;
		time += B;
		if(time > C) C += 60;
		
		if(time == 60){
			cout << -1 << endl;
			return 0;
		}
	}
	
	cout << C << endl;

}

C++: #include <bits/stdc++.h>
using namespace std;


int main(){
	int a,b,c;
	cin >> a >> b >> c;
	for(int i = 0 ; i < 1000000 ; i++){
		if( i % 60 == c && i % (a+b) <= a ){
			cout << i << endl;
			return 0;
		}
	}
	cout << -1 << endl;

}

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

using namespace std;

int getArriveTime(int a,int b,int c){
  bool visited[60][60][2];
  memset(visited,false,sizeof(visited));
  int d = 0,st = 1,e = 0;
  for(int i = 0 ; ; i++,d++){
    if(i >= 60){ i %= 60; e++; }
    if(c == i && st){ return c+e*60; }
    if(visited[i][d][st]){ return -1; }
    visited[i][d][st] = true;
    if(d >= a && st == 1){ d = 0; st = 0; }
    if(d >= b && st == 0){ d = 0; st = 1; }
  }
  return -1;
}

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  int res = getArriveTime(a,b,c);
  cout << (res >= 0 ? res : -1) << endl;
  return 0;
}