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 <vector>

using namespace std;


int a,b,c;

int main(){

	int flag = 0;
	int t=0;
	int i = 0;



	while(scanf("%d %d %d",&a,&b,&c) != EOF){


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

			if(flag == 0){
				t += a;
				flag = 1;
			}
			else if(flag == 1){
				t += b;
				flag = 0;
				i++;

			}

			if(flag == 1){
				if(t >= c + 60 * i){
					cout << c + 60*i << endl;
					return 0;
				}
			}
		}
	}

	return 0;
}

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

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

int main(){
    int a,b,c;
    while(cin >> a >> b >> c){
        int ans = -1;
        rep(i,(a+b)*60){
            if(i%60==c){
                if(i%(a+b) <= a){
                    ans = i;
                    break;
                }
            }
        }
        cout << ans << endl;
    }
}

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

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

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

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

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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

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

// extgcd(a, b) = (g, s, t)
// g: GCD of a and b, s, t: a solution of sa + tb = g
template <typename T>
std::tuple<T, T, T> extgcd(T a, T b){
    if(b == 0){
        return std::make_tuple(a, 1, 0);
    }
    T g, _s, _t;
    std::tie(g, _s, _t) = extgcd(b, a % b);
    return std::make_tuple(g, _t, _s - (a/b) * _t);
}

int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    int A, B, C;
    std::cin >> A >> B >> C;

    int res = -1;
    for(int i=0;i<=A;++i){
        int g, s, t;
        tie(g, s, t) = extgcd(A + B, -60);
        
        if((C - i) % g == 0){
            t *= (C - i) / g;
            while(t < 0){
                t += A + B;
            }
            t = 60 * t + C;
            if(res == -1 || t < res){
                res = t;
            }
        }   
    }

    std::cout << res << std::endl;
}

C++: #include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
using namespace std;
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	int i = 0;
	while (true) {
		int sum = (a + b)*i;
		if (c >= sum % 60 && c <= sum % 60+a) {
			sum = ceil(sum / c)*c;
			cout << sum << endl;
			break;
		}
		if (i >= 1000000) {
			cout << -1 << endl;
			break;
		}
	}
}

C++: #include<iostream>
int n,m,c,i;main(){std::cin>>n>>m>>c;for(i=0;i<99;i++){if(c%(n+m)<=n)goto a;c+=60;}c=-1;a:printf("%d\n",c);}

C++: #include "bits/stdc++.h"
#define pb push_back
#define mt make_tuple
#define all(a) (a).begin(),(a).end()
#define frep(i,a,n) for(int i=(a);i<(n);++i)
#define rep(i, n) for(int i=0;i<(n);++i)
#define rrep(i, n) for(int i=n-1;i>=0;--i)
#define debug(x) cout << #x << " : " << x << " ------------ " << endl;

using namespace std;

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

C++: #include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(i, (v).size()) { cout << v[i]; if (i != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
///(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)///
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, b, c;
	cin >> a >> b >> c;
	if ((a + b) % 60 == 0) {
		if (a >= c)cout << c << endl;
		else cout << -1 << endl;
	}
	else {
		int t = 0;
		while (1) {
			REP(i, a) {
				if (t % 60 == c) {
					cout << t << endl;
					return 0;
				}
				t++;
			}
			if (t % 60 == c) {
				cout << t << endl;
				return 0;
			}
			t += b;
		}
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

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