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++: // clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int a, b, c;
  cin >> a >> b >> c;
  int b += a;
  for (int i = c; i <= b * c; i += 60) {
    if (i % b <= a) {
      cout << i << endl;
      return;
    }
  }
  cout << -1 << endl;
}

C++: #include <iostream>

using namespace std;
const int LIMIT = 1e4;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
	int a,b,c;
	cin >> a >> b >> c;
	int ct = 0,t = 0,time =0;
	while(true){
		int minute = time % 60;
		if(minute <= c && c <= a + minute){
			time += c - minute;
			break;
		}else{
			time += a+b;
		}
		if(time > LIMIT){
			time = -1;
			break;
		}
	}
	cout << time << endl;
  return 0;
}

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

int main()
{
    int a, b, c;
    while (cin>>a>>b>>c) {
        int res=-1, x=0;
        for(int t=0; t<1000000; ++t) {
            if (x<=a and t%60==c) {
                res=t;
                break;
            }
            if (++x==a+b) x=0;
        }
        cout<<res<<endl;
    }
}

C++: #include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
const int INF = 100000000;
using namespace std;
int solve(int a, int b, int c) {
    int now = 0;
    rep(i,1000000){
        rep(j,a){
            now++;
            if(now % 60 == c){
                return now;
            }
        }
        rep(j,b){
            now++;
        }
    }
    return -1;
}

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

    cout << solve(a,b,c) << endl; 
}

C++: #include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <functional>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define SQ(x) ((x)*(x))
#define Mod(x, mod) (((x)+(mod)%(mod))
#define MP make_pair
#define PB push_back
#define Fi first
#define Se second
#define INF (1<<29)
#define EPS 1e-10
#define MOD 1000000007

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int main()
{
  int a, b, c;
  int t[60]; memset(t, 0, sizeof(t));
  cin >> a >> b >> c;
  int n = 0;
  while(1){
    //    cout << n%60 << " " << (n%60) + a << endl;
    if(((n%60) <= c && c <= ((n%60)+a) || (n%60)+a > 60 && 0 <= c && c <= ((n+a)%60))){
      cout << n  + (c-(n%60)) << endl;
      break;
    }
    n += a;
    if(t[n%60]){
      cout << -1 << endl;
      break;
    }
    t[n%60] = 1;
    n += b;
  }
  return 0;
}

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

int a, b, c;

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	cin >> a >> b >> c;
	for(int i=1; i<=4000; ++i){
		if(i % 60 == c && i % (a+b) <= a){
			cout << i << "\n";
			return 0;
		}
	}
	cout << "-1\n";
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;

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

    rep(i,61){
        if(t%60<=c && c<=t%60+a){
            cout<<t-t%60+c<<endl;
            return 0;
        }
        t+=(a+b);
    }

    cout<<-1<<endl;

    return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;
#define rep(i,a) for(int i = 0 ; i < a ; i ++)

int main(void){
  int a,b,c;
  cin>>a>>b>>c;
  if(a>=c){
    cout<<c<<endl;
    return 0;
  }
  int n = 60;
  int sum = c;
  int tm = a;
  int t = 1;
  while(n--){
    // cout<<t<<" "<<tm<<" "<<sum<<" "<<tm+b<<endl;
    if(t){ // turn a
      t = 0;
      tm += a;
    } else { // turn b
      t ++;
      tm += b;
    } 
    if(tm > sum)
      sum += 60;
    //cout<<t<<" "<<tm<<" "<<sum<<" "<<tm+b<<endl;
    if(tm < sum && sum < tm + b && t == 0) {
      cout<<sum<<endl;
      break;
    }//*/else {
    
  }
  cout<<"move"<<n<<endl;
  if(n == 0)
    cout<<-1<<endl;
}