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 all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<ll,ll> P;
const ll MOD=1000000007LL;
const double INF=1000000000;
const int MAX=100001;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    int aa=0;int bb=0;bool f=true;
    if(a==30&&b==30&&c!=30){
        cout<<-1<<endl;
        return 0;
    }
    for(int i=0;i<=3600+c;i++){
        if((i-c+60)%60==0){
            if(f){
                cout<<i<<endl;
                return 0;
            }
        }
        if(f){
            aa++;
            if(aa>a){
                f=false;
                aa=0;
                continue;
            }
        }else{
            bb++;
            if(bb>b){
                bb=0;
                f=true;
                continue;
            }
        }
    }
    return 0;
}

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

#define CH(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)

using namespace std;

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

  REP(k,1,10000){
    REP(i,1,10000){
      if((a + b)*i - 60*k <= c && c <= (a + b)*i + a - 60*k){
        cout<<c + 60*k<<endl;
        return 0;
      }
    }
  }

  return 0;
}

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

int main(){

	  int a,b,c ;
	  cin >> a >> b >> c;

	  if( c % (a+b) <= a ){
			cout << c << endl;
			return 0;
	  }else{

			if( 60%(a+b) == 0 ) {
				  cout << -1 << endl;
				  return 0;
			}
			else{
				  int t=0;
				  while( c % (a+b) > a ) {
						c = c%(a+b);
						c += 60; t++;
				  }
				  cout << c+(60*t)-60 << endl;
				  return 0;
			}
	  }

}

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

using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) reep((i),0,(n))

typedef long long ll;

int main(){
	ll a,b,c;
	cin>>a>>b>>c;
	ll t=0;
	while(1){
		if(c<(a+b)*t){
			c+=60;
		}
		else if(c<=(a+b)*t+a){
			cout<<c<<endl;
			return 0;
		}
		else{
			t++;
		}
		if(t>1000) break;
	}
	cout<<-1<<endl;
}

C++: //#include <bits/stdc++.h>
//#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <bitset>
#include <algorithm>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <string>
#include <string.h>
#include <cmath>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <cctype>
#include <fstream>

#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define LFOR(i, a, b) for (long long int i = (a); i <= (b); i++)
#define LRFOR(i, a, b) for (long long int i = (a); i >= (b); i--)
#define MOD 1000000007
#define INF 1000000000			 //2000000000
#define LINF 1000000000000000000 //9000000000000000000
#define DINF 1000000000000000.0
#define PI 3.14159265358979
#define MAXI 7500000

//.size()はunsigned int　0-1をするとオーバーフローする

using namespace std;
typedef long long int ll;
typedef pair<long long int  ,long long int> P;

//int dy[5] = { 0,0,1,-1,0 };
//int dx[5] = { 1,-1,0,0,0 };

int dy[5] = {-1, 0, 1, 0, 0};
int dx[5] = {0, -1, 0, 1, 0};


int main(void)
{
	int a, b, c;
	int time;
	int now = 0;
	int res = -1;

	cin >> a >> b >> c;

	FOR(t,0,60){
		time = 60 * t + c;
		now = 0;
		while (1)
		{
			if (now + a >= time)
			{
				res = time;
				break;
			}
			now += a + b;
			if(now>=time){
				break;
			}
		}
		if(res!=-1){
			break;
		}
	}
	cout << res << endl;
}

C++: #define  _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
#pragma comment (linker, "/STACK:526000000")

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144*2LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

unsigned long xor128() {
	static unsigned long x = 123456789, y = 362436069, z = 521288629, w = time(NULL);
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(10);
}

#define int ll

void solve() {
	int a, b, c;
	cin >> a >> b >> c;
	for (int t = 0; t <= 300; ++t) {
		int hoge = c + t * 60;
		if (hoge % (a + b) <= a) {
			cout << hoge << endl;
			return;
		}
	}
	cout << -1 << endl;
}
#undef int

int main() {
	init();
	solve();
}

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

vector<vector<bool>> list(1000);

bool check(){
	bool p = true;
	for(int i=0; i < list.size(); i++){
		for(int j=i+1; j < list.size(); j++){
			p = true;
			for(int k = 0; k < list[i].size(); k++) if(list[i] != list[j]){p = false; break;}
			if(p){cout << -1 << endl; return true;}
		}
	}
	return false;
}

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

	int n = 0;
	list[0].push_back(20);
	while(true){
		for(int i=0; i< a; i++){
			if(list[n].size() <= 60) list[n].push_back(true);
			else {
				if(list[n][c]){
					cout << n*60+c << endl; return 0;
				}
				n++;
				list[n].push_back(true);
				list[n].push_back(true);
			}
		}
		if(c <= list[n].size() && list[n][c]){
			cout << (n == 0 ? 0 : (n-1))*60+c << endl; return 0;
		}

		if(1 < n && check()) return 0;

		for(int i=0; i< b; i++){
			if(list[n].size() <= 60) list[n].push_back(false);
			else {
				n++;
				list[n].push_back(true);
				list[n].push_back(false);
			}
		}
	}
}