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;

bool isin(int a,int c,int b){
	//c is in [a-b]
	return ((a < b) && (a <= c && c <= b)) || ((b < a)&&(a <= c||c <= b));
}

int main(){
	int a,b,c;
	cin >> a >> b >> c;
	int x=0;
	for(int i=0;i<60;i++){
		if(isin(x%60,c,(x+a)%60)){
			cout << (int)(x/60)*60+c << endl;
			return 0;
		}
		x+=a+b;
	}
	cout << -1 << endl;
	return 0;
}

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

using namespace std;

#define LOG(...) fprintf(stderr, __VA_ARGS__)
//#define LOG(...)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define RFOR(i, a, b) for (int i = (int)(b - 1); i >= (int)(a); --i)
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define RREP(i, n) for (int i = (int)(n - 1); i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(a) ((int)(a).size())
#define BIT(x, i) (((x) >> (i)) & 1)
#define SQ(x) ((x) * (x))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

    bool visited[60] = {0};
    int d = 0, e = 0;
    while (1) {
        if (visited[d]) break;
        visited[d] = true;
        if (d + a >= c) {
            cout << c - d + e << endl;
            return 0;
        }
        d = (d + a + b) % 60;
        e += a + b;
    }
    cout << -1 << endl;
}

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

int solve(int a, int b, int c) {
    if (60 % (a + b) == 0) return c % (a + b) <= a ? c : -1;
    for (int t = 0; ; ++t) if ((60 * t + c) % (a + b) <= a) return 60 * t + c;
}

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

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

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	int a, b, c; cin >> a >> b >> c;
	int t = 0;
	rep(i, 0, 120) {
		if (t % 60 + a >= c&&t % 60 <= c) {
			t += (c + 60 - t % 60) % 60;
			cout << t << endl;
			return 0;
		}
		t += a + b;
	}
	cout << -1 << endl;
	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 firsttime = 0;
	int lasttime = a;
	int nowc = c;
	if (c > a && a+b==60) {
		cout << -1 << endl;
		return 0;
	}
	while (1) {
		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;

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(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();}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a,b,c;
  cin >> a >> b >> c;
  bool vis[60];
  memset(vis,false,sizeof(vis));
  int p = 0;
  int t = 0;
  vis[0] = true;
  while(true){
    if(p+a <= 60){
      if(p <= c && c <= p+a){
        cout << t + (c-p) << endl;
        return 0;
      }
    }else{
      if(p <=  c){
        cout << t+(c-p) << endl;
        return 0;
      }
      else if((p+c) % 60 >= c){
        cout << t + (60-p) + c << endl;
        return 0;
      }
    }
    (p += a+b) %= 60;
    t += a+b;
    if(vis[p] == true){
      cout << -1 << endl;
      return 0;
    }
  }

  return 0;
}

C++: #include <iostream>

using namespace std;

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