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 <bits/stdc++.h>
 
#define loop(n, i) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;

using namespace std;
typedef long long ll;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    int loop = 0;
    int time = 0;
    for(;;) {
        time += a;
        if (time >= c) {
            cout << 60 * loop + c << endl;
            break;
        } 
        if (time + b >= 60) loop++;

        time = (time + b) % 60;
        if (time == 0) {
            cout << -1 << endl;
            break;
        }
    }
}

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

int main(void){
    int awake, asleep, destination;
    cin >> awake >> asleep >> destination;

    int now = 0;
    int a = awake, b = 0;

    while(1){
        if( now!=0 && now%60==0 && a==awake ){
            cout << -1 << endl;
            return 0;
        }
        if( now%60==destination && (a!=0 || (a==0 && b==asleep))){
            cout << now << endl;
            return 0;
        }

        if(a){
            a--;
            now++;
            if(a == 0){
                b = asleep;
            }
        }else if(b){
            b--;
            now++;
            if(b == 0){
                a = asleep;
            }
        }
    }

    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  int n=0;
  while(n<1000000){
    if(n%60<c&&c<=n%60+a)cout<<n/60*60+c<<endl,n=10000000;
    n+=a+b;

  }
  return 0;
}

C++: #include<iostream>
#include<string.h>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#define ll long long int
#define ld long double
#define INF 1000000000
#define EPS 0.0000000001
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;
typedef pair<int, int> pii;

int main()
{
  int a,b,c;
  int i,j;

  cin>>a>>b>>c;
  int max=(a+b)*c;
  int x=a+b;
  for(i=c;i<=max;i=i+60){
    // cout<<i<<endl;
    if(i%x<=a){
      cout<<i<<endl;
      return 0;
    }
  } 

  cout<<"-1"<<endl;
}

C++: #include <cstdint>
#include <iostream>

using namespace std;

int32_t main() {
  uint32_t a, b, c;
  cin >> a >> b >> c;

  int32_t time = -1;
  for (uint32_t i = c; i <= (a + b) * 60; i += 60) {
    if (i % (a + b) <= a) {
      time = i;
      break;
    }
  }

  cout << time << endl;

  return 0;
}

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

using namespace std;

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

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

typedef pair<int,int> pii;

int main(){
  int a,b,c;
  scanf("%d %d %d",&a,&b,&c);
  
  set <pii> s;
  int t=0;

  for(;;){
    int r = t*(a+b)/60;
    if( s.count( pii( (t*(a+b))%60 , ((t+1)*a)%60 ) ) ){
      puts("-1");
      break;
    }
    s.insert( pii( (t*(a+b))%60,((t+1)*a)%60 ) );

    if ( t*(a+b) <= 60*r+c && 60*r+c <= t*(a+b)+a ){
      printf("%d\n",r*60+c);
      break;
    }
    t++;
  }
}

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) {
        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*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,i,j,s=0,s2=0,k=0;
	cin>>a>>b>>c;
	for(i=1;i<120;i++){
		s=0;
		for(j=1;j<=60;j++){
			s+=a+b;
			if(s-b-b<=c&&s-b>=c){k++;break;}
		}
		if(k==1)break;
		if(i==111){c=-1;break;}
		c+=60;
	}
	cout<<c<<endl;
}