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>
 
using namespace std;
 
int main(){
    int a,b,c;
    int i;
    cin >> a >> b >> c;
    i=0;
    while(i<60){
        if((c+60*i)%(a+b)<=a){
            cout << (i*60+c) << '\n';
            break;
        }
        i++;
    }
    if(i==60){
        cout <<-1<< '\n';
    }
}

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

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) {
        ll d = euclid(b, a % b, y, x);
        return y -= a / b * x, d;
    }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1)
            ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1);
        return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e)
            return Mod(1);
        Mod r = *this ^ (e / 2);
        r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

char cc(char x) {
    if (x == 'a')
        return 'Z';
    if (x == 'A')
        return 'z';
    return --x;
}

int main() {
    cin.sync_with_stdio(0);
    cin.tie(0);
    cin.exceptions(cin.failbit);

    cin >> skipws;

    int a, b, c;
    cin >> a >> b >> c;
    int mins = 0;
    for (int q = 0; q < 120; q++) {
        if (mins % 60 == c) {
            cout << mins << endl;
            return 0;
        }
        for (int i = 0; i < a; i++) {
            ++mins;
            if (mins % 60 == c) {
                cout << mins << endl;
                return 0;
            }
        }
        for (int j = 0; j < b; j++) {
            ++mins;
        }
    }
    cout << -1 << endl;
}

C++: #include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <list>
#include <tuple>
#include <bitset>
#include <ciso646>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;

inline bool cheak(ll x, ll y, ll xMax, ll yMax){ return x >= 0 && y >= 0 && xMax > x && yMax > y; }
inline ll toInt(string s) { ll v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
template<class T> inline T sqr(T x) { return x*x; }

#define For(i,a,b)	for(ll (i) = (a);i < (b);(i)++)
#define rep(i,n)	For(i,0,n)
#define rFor(i,a,b)	for(ll (i) = (a-1);i >= (b);(i)--)
#define rrep(i,n)	rFor(i,n,0)
#define clr(a)		memset((a), 0 ,sizeof(a))
#define mclr(a)		memset((a), -1 ,sizeof(a))
#define all(a)		(a).begin(),(a).end()
#define sz(a)		(sizeof(a))

const ll dx[8] = { 1, 0, -1, 0, 1, 1, -1, -1 }, dy[8] = { 0, -1, 0, 1, -1, 1, -1, 1 };
const ll mod = 1e9 + 7;
const ll INF = 1e9 + 9;

int main(){

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

	for (int cnt = 0; cnt <= 1e7; cnt++){
		int t = cnt % (a + b);
		if (cnt % 60 == c){
			if (t <= a){
				cout << cnt << endl;
				return 0;
			}
		}
	}
	
	cout << -1 << endl;

	return 0;
}

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

int a, b, c;
int solve() {
    int s = 0, t = 0;

    std::vector<bool> waked(61, false);
    while(true) {
        if(waked[s]) {
            return -1;
        }
        waked[s] = true;

        if(s <= c && c <= s+a) {
            break;
        }

        t += (a + b);
        s = (a+b+s)%60;
    }
    return t + c - s;
}

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

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

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

C++: #include<iostream>
using namespace std;
int main(){
    int n,m,b,d;
long long c;
    bool a=false;
    cin>>n>>m>>b;c=b;
    for(int i=0;i<357000000;i++){
        if(c%(n+m)<=n && a==false){
            a=true;
            d=i;
        }
        c+=60;
    }
    if(a==false){
        cout<<"-1"<<endl;
    }
    else{
        c=b+d*60;
        cout<<c<<endl;
    }
    return 0;
}

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

int main()
{
  int a,b,c,sleep[10000]={0};

  cin>>a>>b>>c;
  if(a+b==60&&a<c){
    cout<<"-1"<<endl; return 0;
  }
  for(int i=0;i<9000;i+=(a+b))
    for(int j=i;j<=(i+a);j++)
      sleep[j]=1;
  for(int i=c;i<10000;i+=60)
    if(sleep[i]){
      cout<<i<<endl; return 0;
    }
  cout<<"-1"<<endl;
}

C++: #include<iostream>
#include<climits>
#define ll long long 
using namespace std;

int main(){
  int a,b;
  ll c,time=0;

  cin>>a>>b>>c;

  while(1){
    if(c>=INT_MAX){
      c=-1;
      break;
    }
    time+=a;
    if(time>=c) break;
    time+=b;
    if(time>=60)  c+=60;

  }

  cout<<c<<endl;
  
  return 0;
}