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>
using namespace std;

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

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

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

using namespace std;

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

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

using namespace std;

int32_t main() {
  uint32_t a, b, c;
  cin >> a >> b >> c;

  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>

using namespace std;

//ユークリッドの互除法で最大公約数を求める
int gcd( int p, int q ) {
	if( q == 0 ) return p;
	return gcd( q, p % q );
}

int main(void){

	/*
		睡眠の周期はa+b分
		睡眠と山手線の周期はlcm( a+b, 60 )
		0からlcm( a + b, 60 )までを調べれば十分？
	*/

	int a, b, c, lcm;
	int ans = -1;

	cin >> a >> b >> c;
	lcm = ( a + b ) * 60 / gcd( ( a + b ) , 60 );

	for( int t = 0; t <= lcm; t += ( a + b ) ) {
		for( int i = 0; i <= a; i++ )
			if( ( t + i ) % 60 == c ) 
				ans = t + i;
		if( ans > 0 ) break;
	}

	cout << ans << endl;

    return 0;
}

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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

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

// extgcd(a, b) = (g, s, t)
// g: GCD of a and b, s, t: a solution of sa + tb = g
template <typename T>
std::tuple<T, T, T> extgcd(T a, T b){
    if(b == 0){
        return std::make_tuple(a, 1, 0);
    }
    T g, _s, _t;
    std::tie(g, _s, _t) = extgcd(b, a % b);
    return std::make_tuple(g, _t, _s - (a/b) * _t);
}

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

    int A, B, C;
    std::cin >> A >> B >> C;

    int res = -1;
    for(int i=0;i<=A;++i){
        int g, s, t;
        tie(g, s, t) = extgcd(A + B, -60);
        
        if((C - i) % g == 0){
            t *= (C - i) / g;
            while(t < 0){
                t += (A + B) * abs((C - i) / g);
            }
            t = 60 * t + C;
            if(res == -1 || t < res){
                res = t;
            }
        }   
    }

    std::cout << res << std::endl;
}

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

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

int main()
{
  int a, b, c;
  cin >> a >> b >> c;
  int st, et, r;
  int d[60] = {};
  for(st = r = 0, et = a;; d[st] = et, st = et + b, et = st + a){
    if(st >= 60){
      st -= 60;
      et -= 60;
      r++;
    }
    if(c >= st && c <= et){
      cout << r*60+c << endl;
      break;
    }
    if(d[st] == et){
      cout << "-1" << endl;
      break;
    }
  }
}

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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  int start_a = 0,start_b = b,end_b;
  while(1){
    if( start_a <= c && c <= start_b ){
      cout << c << endl;
      break;
    }
    end_b = start_b + b;
    int check = c - b;
    start_a = a + b;
    start_b = start_a + b;
    end_b += end_b;
    if( c < start_a ){
      c += 60;
      if( c - start_b == check ){
	cout << -1 << endl;
	break;
      }
    }
  }
  return 0;
}

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

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

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;
	
	if(60 % (a + b) == 0){
		int 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;
}