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<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#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 all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e8;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	int s=0,g=a;
	while(g<1e8){
		if(s%60<=c&&c<=g%60)break;
		if(g%60<s%60&&(s%60<=c||c<=g%60))break;
		s+=a+b;
		g+=a+b;
	}
	if(g>=1e8)cout<<-1<<endl;
	else if(s%60<c)cout<<s+c-s%60<<endl;
	else cout<<g+c-g%60<<endl;
}

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);
        
        // std::cout << i << std::endl;
        // std::cout << "!" << s << ", " << t << std::endl;
        
        if((C - i) % g == 0){
            t *= (C - i) / g;
            // std::cout << t << std::endl;
            while(t < 0){
                t += (A + B) / abs(g);
            }
            while(t - (A + B) / abs(g) >= 0){
                t -= (A + B) / abs(g);
            }
            t = 60 * t + C;
            if(res == -1 || t < res){
                res = t;
            }
            // std::cout << t << std::endl;
        }
        // std::cout << "----------" << std::endl;
    }

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

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

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

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

int main() {
  int a, b, c; cin >> a >> b >> c;
  int res = -1;
  for (int iter = 0; iter < 100; ++iter) {
	int q = c % (a + b);
	if (q <= a) {
	  res = c; break;
	}
	c += 60;
  }
  cout << res << endl;
}

C++: #include<iostream>

using namespace std;

int main() {
  int w,s,c;
  cin >> w >> s >> c;
  if(c < w && (w+s) % 60 == 0) cout << "-1" << endl;
  else {
    int i = 0;
    while(1) {
      if(c < (w + s) * i) c += 60;
      if(c <= (w + s) * i + w) break;
      else i++;
    }
    cout << c << endl;
  }
  
  return 0;
}

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

using namespace std;

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

  int ans;
  int ab = a + b;
  int s = 0;
  int g = c;

  while(1){
    if(s <= g && g <= s + a){
      ans = g; 
      break;
    }
    else{
      if(s % 60 == 0 && s != 0){
        ans = -1;
        break;
      }

      if(g < s + ab){
        g = g + 60;
      }
    s += ab;
    }
  }

  cout<<ans<<endl;

  return 0;
}

C++: #include <iostream>

using namespace std;
const int LIMIT = 1e4;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
	int a,b,c;
	cin >> a >> b >> c;
	int ct = 0,t = 0,time =0;
	while(true){
		if((c + 60 - t)%60 <= a){
			time += (c + 60 - t) % 60;
			break;
		}else{
			t = a + b % 60;
			time += a+b;
		}
		if(time > LIMIT){
			time = -1;
			break;
		}
	}
	cout << time << endl;
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <ctime>
#define INF 999999999
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define MOD(x) (x%(mod))
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;
/*---------------------------------------------------*/

int a,b,c;

void solve(){
  int t=0,now=0;
  bool ok=false;
  while(1){
    if(now>=100000)break;
    if(now<=60*t+c&&60*t+c<=now+b){
      cout<<60*t+c<<endl;
      ok=true;break;
    }else{
      now+=(a+b);
      t++;
    }
  }
  if(!ok)cout<<-1<<endl;
}

int main(){
  cin>>a>>b>>c;
  solve();
  return 0;
}

C++: #include <iostream>

using namespace std;

int main(){

	int a,b,c;

	cin>>a>>b>>c;

	int now=0;
	int goal = c;

	while(1){
		if(now<=goal && goal<=now+a){
			cout<<goal<<endl;
			break;
		}
		now+= (a+b);

		if(goal<now){
			goal+=60;
			if(60%(a+b)==0){
				cout<<-1<<endl;
				return 0;
			}
		}
		if(now%60==0){
			cout<<-1<<endl;
			return 0;
		}
	}

	return 0;

}