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 <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
//typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
    int a,b,c; cin >> a >> b >> c;
    int now = 0;
    while(1){
        if(now >= 10000){
            puts("-1");
            return 0;
        }
        if(now%60 < (now+a)%60){
            if(now%60 <= c && c <= (now+a)%60){
                cout << now+c-now%60 << endl;
                return 0;
            }
        }else{
            if(c >= now%60 || c <= (now+a)%60){
                if(c >= now%60){
                    cout << now+c-now%60 << endl;
                }else{
                    cout << now+c+60-now%60 << endl;
                }
                return 0;
            }
        }
        now += a+b;
    }
}

C++: #include <iostream>

using namespace std;

int gcd( int m, int n )
{
  if ( ( 0 == m ) || ( 0 == n ) )
    return 0;
  while( m != n )
  {
    if ( m > n ) m = m - n;
    else         n = n - m;
  }
  return m;
}

int lcm( int m, int n )
{
  if ( ( 0 == m ) || ( 0 == n ) )
    return 0;
  return ((m / gcd(m, n)) * n);
}

int solve(int a, int b, int c){
  int max, destination;
  destination = c;
  max = lcm(a+b, 60);
  while(max > destination){
    if ((destination % (a+b) ) <= a){
      return destination;
    }
    destination += 60;
  }
  return -1;
}

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

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++<10000000){ 
    if(sum%60+a<c||sum%60>c)sum+=a+b;
    else ans=sum+(c-sum%60);

  }
  cout <<ans<<endl;
  return 0;
}

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

#define REP(i, n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

using namespace std;

template <typename T> T &chmin(T &a, const T &b) {return a = min(a, b);}
template <typename T> T &chmax(T &a, const T &b) {return a = max(a, b);}

int A, B, C;

int main(){
	cin >> A >> B >> C;
	REP(i, 1000){
		int t = 60 * i + C;
		if(t % (A + B) <= A){
			cout << t << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;
}

C++: #include <iostream>

using namespace std;

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

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

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

C++: #include "bits/stdc++.h"

using namespace std;

static void solve()
{
  int a, b, c;
  set<int> s;
  cin >> a >> b >> c;
  int now = 0;
  int d = 0;
  while (true) {
    if(now <= c && c <= now + a) {
      cout << d * 60 + c << "\n";
      return;
    }
    if(s.count(now)) {
      cout << -1 << "\n";
      return;
    }
    s.insert(now);
    now += a + b;
    now %= 60;
    d++;
  }
}

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

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  /*  (a+b)m<=60*t+c<=(a+b)*m+a
    0<=60*t+c-(a+b)*m<=a
    0 <= c-(a+b)*m<=a
    c-a<=(a+b)*m
(c-a)/(a+b)<=m


  */
  int a,b,c;
  cin>>a>>b>>c;
  rep(i,1e9){
    if(i==10000000){cout<<-1<<endl;break;}
    double m=(60*i+c-a)/(double)(a+b);
    if(m<0){cout<<c<<endl;break;}
    int mm=(int)(m+0.99999999999999);
    if(0<=60*i+c-(a+b)*mm){cout<<60*i+c<<endl;break;}
  }
}

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

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

	int start = 0, end;
	bool flag = false;
	while (start <= 3600+c) {
		end = start + a;
		if (start <= c && c <= end) {
			flag = true;
			break;
		}

		start += end + b;
		c += 60;
	}
	if(flag) cout << c << endl;
	else cout << -1 << endl;

    return 0;
}