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>
using namespace std;
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define ll long long
#define pii pair<int,int> 
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
const int INF = 1001001001;
//int 2×10の9乗
//vector<vector<int>> a(n, vector<int>(m));
  //rep(i,n) rep(j,m) cin >> a[i][j]; 
//cout << fixed << setprecision(10);
//int gcd(int x, int y){
  //if(y==0) return x;
  //return gcd(y, x%y);
//}
//sort小さい順(昇順)
//g++ code.cpp   ./a.out 
int main(){
  ll a,b,c;
  cin >> a >> b >> c;
  if(a>=c){
    cout << c << endl;
    return 0;
  }
  else if(a+b==60){
    cout << "-1" << endl;
    return 0;
  } 
  else{
    rep(i,1000){
      rep(j,1000){
        if((i+1)*a+(i+1)*b<=c+60*j && c+60*j<=(i+2)*a+(i+1)*b){
          cout << c+60*j << endl;
          return 0;
        }  
      }
    }
    cout << -1 << endl;
  }
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)

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

	int v[100100];
	rep(i, 100000) v[i] = 0;

	for (int i = 0; i < 10000; i += (a + b)){
		reps(j, i, i + a) v[j] = 1;
	}

	int cnt = 0;
	for (int i = c - 1; i <= 10000; i += 60){
		cnt++;
		if(v[i] == 1){
			printf("%d\n", c + ((cnt - 1) * 60));
			return 0;
		}
	}

	printf("-1\n");
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <sstream>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <complex>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cmath>
#include <time.h>
#include <tuple>
#define all(c) ((c).begin(),(c).end())
#define rall(c) ((c).rbegin(),(c).rend())
//#define sort(v,n) sort(v,v+n)
#define ll long long
#define fi first
#define se second
#define inf 999999999
using namespace std;
const ll MOD = 1e9 + 7;
const double PI = acos(-1.0);
//---------------------------------------------------------------------------------------------//
int a, b, c;

int main() {
	cin >> a >> b >> c;
	int cont = 0;
	int firsttime = 0;
	int lasttime = a;
	int nowc = c;
	if (c > a && a+b==60) {
		cout << -1 << endl;
		return 0;
	}
	while (1) {
		cont++;
		if (cont > 1000000) {
			cout << -1 << endl;
			return 0;
		}
		if (firsttime <= nowc && lasttime >= nowc) {
			cout << nowc << endl;
			break;
		}
		else {
			firsttime = lasttime + b;
			lasttime = firsttime + a;
			if (firsttime > nowc) {
				nowc += 60;
			}
		}
	}
	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<10000000){
    if(n%60<=c&&c<=n%60+a){cout<<n/60*60+c<<endl;return 0;}
    n+=a+b;
  }
  cout<<-1<<endl;
  return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	for(int x=c;x<1000000;x+=60){
		if(x%(a+b)<=a){
			cout<<x<<endl;
			return 0;
		}
	}
	puts("-1");
}

C++: #include <algorithm>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string>
#include <vector>

#define el endl
#define fd fixed
#define INF INT_MAX/2-1
#define pb push_back

using namespace std;

int main() {
  int a, b, c, wakingtime, t;
  bool flag;
  while (cin >> a >> b >> c, a | b | c) {
    wakingtime = 0;
    flag = false;
    for (t = 0; t < 60; t++) {
      if (wakingtime <= 60*t+c && 60*t+c <= wakingtime + a) {
        flag = true;
        break;
      } else if (wakingtime < 60*t+c){
        while (wakingtime < 60*t+c)
        wakingtime += a+b;
      }
    }
    if (flag) cout << 60*t+c << el;
    else cout << "-1" << el;
  }
}

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

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(60%(a+b)==0){
        //???????????????????????§??¢???
        int T=0;
        while(T<=60){
            T+=a;
            if(c<=T){
                cout<<c<<endl;
                return 0;
            }
            T+=b;
            if(c<T){
                cout<<-1<<endl;
                return 0;
            }
        }
    }else{
        int T=0;
        while(true){
            T+=a;
            if(c<=T){
                cout<<c<<endl;
                return 0;
            }
            T+=b;
            if(c<T) c+=60;
        }
    }

    return 0;
}