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 ;
	  cin >> a >> b >> c;

	  if( c % (a+b) <= a ){
			cout << c << endl;
			return 0;
	  }else{

			if( 60%(a+b) == 0 ) {
				  cout << -1 << endl;
				  return 0;
			}
			else{
				  int i;
				  for( i=1; (c+(60*i)) % (a+b) <= a ;i++){}
				  cout << c+(60*i)-60 << endl;
				  return 0;
			}
	  }

}

C++: #include<iostream>
int main(){
int n,m,b,c;
std::cin>>n>>m>>b;c=b;
for(int i=0;i<99;i++){
if(c%(n+m)<=n){goto a;}
c+=60;
}
c=-1;
a:
std::cout<<c<<"\n";
for(int i=0;i<20000;i++){
for(int j=0;j<20000;j++){
c+=1;
}
}
return 0;}

C++: #include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
typedef long long int ll;
using namespace std;
int main(){
	int a,b,c; cin >>a>>b>>c;
	int now=0;
	while(1){
		if(now%60<=c&&c<=(now%60+a)){
			cout << now+(c-now%60) << endl;
			return 0;
		}
		else if(now%60+a>=60&&c<=(now%60+a)%60){
			cout << now+(60-now%60+c%60) << endl;
			return 0;
		}
		now+=(a+b);
		if(now%60==0){
			cout << -1 << endl;
			return 0;
		}
	}
}

C++: #include <cstdio>

int main() {
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);
  int t = 0;
  while (true) {
    if (c <= t+a) {
      printf("%d\n", c);
      break;
    }
    t += a+b;
    if (t > c) {
      if ((a+b)%60 == 0) {
        puts("-1");
        break;
      }
      do c += 60; while (t > c);
    }
  }
  return 0;
}

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


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

C++: #include <cstdint>
#include <iostream>

using namespace std;

int32_t main() {
  while (true) {
    uint32_t a, b, c;
    cin >> a >> b >> c;
    if (a == 0) break;

    if (60 % (a + b) == 0) {
      if (c % (a + b) <= a) {
        cout << c << endl;
      } else {
        cout << -1 << endl;
      }
    } else {
      uint32_t n = 0;
      while (((60 * n + c) % (a + b)) > a) {
        n++;
      }
      cout << n * 60 + c << endl;
    }
  }

  return 0;
}

C++: #include<iostream>


#define FOR(i,a,b) for(int i = a;i < b;i++)
#define RFOR(i,a,b) for(int i = a;i >= b;i--)
#define IN cin >> 
#define OUT cout <<
#define E  << endl;

using namespace std;


int goal_time = 0;

int a, b, c;

void input() {
	IN a >> b >> c;
}

int main() {
	input();
	int memo = 0;
	if (a + b == 60 && c > a) {
		OUT - 1 E
			return 0;
	}
	bool flag = false;
	goal_time += c;
	while (true) {
		int n = memo;
		while (true){
			if ((a + b) * n <= goal_time && (a + b) * n + a >= goal_time) {
				OUT goal_time E
				flag = true;
				memo = n;
				break;
			}
			if ((a + b) * n > goal_time) {
				break;
			}
			n++;
		}
		if (flag)break;
		goal_time += 60;
	}

	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
#include<random>
#include<ctime>
#include<set>
using namespace std;


const long long int mod=1000000007;
const long long int INF=99999999999999999;

long long int a,b,c;

int main() {
    cin>>a>>b>>c;
	long long int t=0;
	while(t<=3600){
		if(t/60==(a+t)/60&&t%60<=c&&c<=(a+t)%60||t/60!=(a+t)/60&&t%60<=c&&c<=59){
			cout<<t/60*60+c<<endl;
			return 0;
		}else if(t/60!=(a+t)/60&&1<=c&&c<=(a+t)%60){
			cout<<(t+60)/60*60+c<<endl;
			return 0;
		}
		t+=a+b;
	}
	cout<<-1<<endl;
}