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>

int main() {
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);

  int A[4096];
  for(int t = 0; t < 4000;) {
    for(int i = 0; i <= a; ++i) {
      A[t + i] = 1;
    }
    t += a;
    for(int i = 1; i < b; ++i) {
      A[t + i] = -1;
    }
    t += b;
  }
  int res = -1;
  for(int t = c; t < 4096; t += 60) {
    if( A[t] > 0 ) {
      res = t;
      break;
    }
  }

  printf("%d\n", res);  
  
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

	bool used[60][2];
	memset(used, 0, sizeof(used));

	int cnt = 0, ans = 0;
	bool flag = true;
	while(true) {
		if(cnt & 1) {
			ans += b;
			if(used[ans%60][1]) {
				flag = false;
				break;
			}
			used[ans%60][1] = true;
		} else {
			if(ans % 60 + a >= 60 && ans % 60 <= c) {
				ans += c - ans % 60;
				break;
			}
			else if((ans + a) % 60 >= c) {
				ans += c - ans % 60;
				break;
			} else {
				ans += a;
				if(used[ans%60][0]) {
					flag = false;
					break;
				}
				used[ans%60][0] = true;
			}
		}
		cnt++;
	}

	if(flag) cout << ans << endl;
	else 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<150000000;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>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<cstring>
#include<utility>
#include<set>
#include<stack>
#include<complex>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
#define bv vector<bool>
using namespace std;
typedef pair<int, int>PI;
using namespace std;
#define MAX  999999
int main(){
    int a,b,c; cin >> a>>b>>c;
    int sum = a+b; ll ans = 0;
    for(int i = 0;10000;i++){
        ans=i*60+c;
        if(ans % (a+b)<=a){cout << ans << endl; break;}
        if(((a+b == 60) && c > a )|| i>5000){cout << -1 << endl; break;}
    }
    
}

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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if( a + b == 60 ) cout << -1 << endl;
  else if( c <= a ) cout << c << endl;
  else if ( c > a ){
    if ( a + b < c ){
      cout << c << endl;
    }else if ( a + b > c ){
      int time = 0;
      int cnt = 0;
      while(1){
	time += a + b;
	cnt++;
	if( cnt == 10000 ){
	  cout << -1 << endl;
	  break;
	}
	if( time > 60 ){
	  int tmp = time -60;
	  int temp = c - tmp;
	  //  cout << "temp" << " " << temp << " " << "c" << " " << c << " " << "time" << " " << time << endl;
	  time += temp;
	  
	    cout << time << endl;
	    break;
	}
      }
    }
  }
  return 0;
}

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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int a, b, c;
  cin >> a >> b >> c;
  for (int t = 0; t < 100; ++t) {
    int n = 60 * t + c;
    n %= a + b;
    if (0 <= n and n <= a) {
      cout << 60 * t + c << '\n';
      return 0;
    }
  }
  cout << "-1\n";
}

C++: #include<bits/stdc++.h>
using namespace std;
 
#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
 
typedef long long ll;
typedef pair<int, int> ii;

int main() {
	
	ll a, b, c;
	cin >> a >> b >> c;
	
	ll ans = c;
	ll tmp = c - 60;
	rep(i, 61){
		tmp = (tmp + 60) % (a + b);
		if(a < tmp && tmp < a + b) ans += 60;
		else {
			cout << ans << endl;
			return 0;
		}
	}
	
	cout << -1 << endl;
	
	/*
	if(60 % (a + b) == 0){
		ll tmp = c % (a + b);
		if(a < tmp && tmp < a + b) cout << -1 << endl;
		else cout << c << endl;
	}else{
		ll ans = c;
		while(1){
			ll tmp = ans % (a + b);
			if(a < tmp && tmp < a + b) ans += 60;
			else{
				cout << ans << endl;
				break;
			}
		}
	}
	*/
	
	return 0;
}

C++: #import<iostream>
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>
using namespace std;

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

C++: #include <iostream>
#include <vector>
#include <cstdio>
#include <cstdlib>

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;
}