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;

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

C++: #include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
int a,b,c;



int main(){
    cin >> a>>b>>c;
    int round = a+b;
    int cnt=0;
    while(1){
        if((60*cnt+60)%(a+b)==0){
            if(c%(a+b)<=a)break;
            cnt = -1;
            break;   
        }
        if(c%(a+b)<=a)break;
        c+=60;
        cnt++;
    }
    if(cnt==-1){
        cout << cnt << endl;
    }else{
        cout << c << endl;
    }


}

C++: #include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int A,B,C;
    cin >> A >> B >> C;
    if(A + B == 60 && A < C){
        cout << -1 << endl;
        return 0;
    }
    int time = 0;
    while(1){
        int l = time % 60;
        int r = (time + A) % 60;
        /*
        int next = time + C;
        if(next >= l && next <= r){
            cout << next << endl;
            return 0;
        }
        */
        
        if  (l < r && C >= l && C <= r || 
             l > r && ( (C >= l && C <= 60) || (C >= 0 && C <= r)) ){
            cout << time + C - time % 60 << endl;
            //cout << time << endl;
            return 0;
        }
        
        time += A + B;
        if(time > 60 * 60 * 60){
            cout << -1 << endl;
            return 0;
        }
    }
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;


int main(){
    ll a,b,c;
    cin>>a>>b>>c;
    vector<vector<bool> > dp( 63, vector<bool> (60,false) );
    ll now = 0;
    while( now <= 60*60){
	for(ll i=0;i<a;i++){
	    dp[ now/60 ][now%60] = true;
	    now++;
	}
	now += b;
    }
    ll res = -1;
    for(ll i=0;i<60;i++){
	if( dp[i][c-1] ) {
	    cout<<i*60 + c<<endl;
	    return 0;
	}
    }
    cout<<res<<endl;
    return 0;
}

C++: #include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++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((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

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 pair<int, int> pii;
typedef pair<ll, ll> pll;

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

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	int memo[60];
	REP(i, 60)
		memo[i] = 999;
	int mi=0;
	int count = 0;
	REP(i, 60){
		REP(j, a){
			memo[mi] = min(count, memo[mi]);
			mi++;
			if (mi >= 60){
				mi %= 60;
				count++;
			}
		}
			memo[mi] = min(count, memo[mi]);
		REP(j, b){
			mi++;
			if (mi >= 60){
				mi %= 60;
				count++;
			}
			//memo[mi] = min(i, memo[mi]);
		}
		if (mi == 0)break;
	}
	if (memo[c] != 999)
		cout << 60 * memo[c] + c << endl;
	else
		cout << -1 << endl;
}

C++: #include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define REP(i, n) for ( int i = 0; i < (n); i++ )
 
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);

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

  int now = 0, sum = 0;
  for ( int i = 0; i < 100; i++ ) {
    if ( now <= c && c <= now+a ) {
      for ( int j = 0; j < 60; j++ ) {
	if ( now+j == c ) {
	  cout << sum+j << endl;
	  return 0;
	}
      }
    }
    sum += a+b;
    now += a+b;
    now %= 60;
  }

  cout << -1 << endl;

  return 0;
}

C++: #include<bits/stdc++.h>
#include<math.h>
using namespace std;
int main(void){
    int a,b,c;
    cin>>a>>b>>c;
    int ts,te,cnt=0,ans;
    while(1){
        ts=(a+b)*cnt;
        te=a*(cnt+1)+b*cnt;
        if(ts%60<=c&&c-ts%60<=a){
            ans=60*(ts/60)+c;
            break;
        }
        if(ts!=0&&ts%60==0){
            ans=-1;
            break;
        }
        cnt++;
    }
    cout<<ans<<endl;
}

C++: #include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <sstream>
#include <numeric>
#include <set>
#include <map>
//#include <bits/stdc++.h>

#define rep(i, j) for(int i = 0; i < j; i++)
#define all(i) i.begin(), i.end()
#define ll long long
#define bl bool
#define nn printf("\n");
#define mod 1000000007

using namespace std;

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

	int a, b, c; cin >> a >> b >> c;
	int t = 1, t_ans = 0;
	int i = 1, cri = 0;
	while (1)
	{
		if (a + b == 60 && t_ans > 5) 
		{
			printf("-1\n"); 
			break;
		}
		if (t == 60){ t = 0; t_ans++; }
		t++;
		if (i == a && cri == 0){ i = 0; cri = 1; }
		else if (i == b && cri == 1){ i = 0; cri = 0; }
		else if (cri == 0 && t == c)
		{ 
			printf("%d\n", (60 * t_ans) + c); 
			break;
		}
		i++;
	}
	return 0;
}