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++: #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const double PI = acos(-1);
const ll MOD = 1000000007;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////////////////////

bool A[100000];
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr); //入出力高速化
	int a,b,c; cin >> a >> b >> c;
	rep(i,100000) {
		if (i % (a+b) <= a) A[i] = true;
		else A[i] = false; 
	}
	int k = 0;
	int ans = -1;
	while (c + 60*k < 100000) {
		if (A[c + 60*k]) {
			ans = c + 60*k;
			break;
		} else k++;  
	}

	cout << ans << endl;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main() {
    int a, b, c, res = -1;
    cin >> a >> b >> c;
    for (int i=0; i<=a+b; ++i) {
        if ((c+i*60) % (a+b) <= a) {
            res = c+i*60;
            break;
        }
    }
    cout << res << 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>
#include<algorithm>
using namespace std;
int main(){

  int a,b,c;
  int i;
  cin >>a>>b>>c;
  
  int x=0,x2=a;
  bool flag=false;
  bool flag2=false;
  if((60%(a+b)) == 0)flag=true;
  for(i=0 ; i < 3; i++){
    while(x <= (i+1)*60){
      if((60*i+c) >= x && (60*i+c) <= x2){
	cout <<(60*i+c)<<endl;
	flag2=true;
	break;
      }else{
	x=x2+b;
	x2=x+a;
      }
    }
    if(flag2)break;
    if(flag){
      cout <<"-1"<<endl;
      break;
    }
  }
  
  return 0;
}

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

int func_J(int a,int b,int time){
  if(time<=a) return 1;
 
  time=time-(a+b);
  if(time>0) return func_J(a,b,time);
  else if(time<0) return 0;
  else return 1;

}

int func(int a,int b,int c,int d){
  int time;
   
  time=60-b+c-a;
  d+=60;
  if(time<=a||func_J(a,b,time)==1)return d;
  else  func(a,b,time,d);

  return 0;
}

int main(){
  int a,b,c;
  int rel=0;

  cin>>a>>b>>c;

  if(a>=c) rel=c;
  else if((a==b&&a<c)||(a<c&&a<b)) rel=-1;
  else if(c>a+b){
    if(func_J(a,b,c)==1)rel=c;
    else rel+=func(a,b,c,c); 
  } else rel+=func(a,b,c,c);

  cout<<rel<<endl;

  return 0;
}

C++: #include <bits/stdc++.h>
#define REP(i,n)for (int i=0;i<(n);i++)
#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define ll long long
using namespace std;
int main(){
    ll a,b,c;
    cin>>a>>b>>c;
    for(int i=0;i<10000000;i++){
        if(c%(a+b)<=a){
            cout<<c<<endl;
            return 0;
        }
        c+=60;
    }
    cout<<-1<<endl;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main(){

  int a,b,c;

  cin >>a>>b>>c;
  
  int x=0,x2=a;
  bool flag=false;
  if((60%(a+b)) == 0)flag=true;
  for(int i=0 ;; i++){
    if(flag && x > 60){
      cout <<"-1"<<endl;
      break;
    }
    if((60*i+c) >= x && (60*i+c) <= x2){
      cout <<(60*i+c)<<endl;
      break;
    }else{
      x=x2+b;
      x2=x+a;
    }
  }
  
  return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 30;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  int a, b, c; cin >> a >> b >> c;

  int k = 0;
  int ans = -1;
  while(1) {
    bool ok = false;
    REP(i, a+1) {
      if((k+i-c) % 60 == 0) {
        ok = true;
        ans = k+i;
        break;
      }
    }
    if(ok) break;
    k += a+b;
    if(k%60 == 0) break;
  }
  cout << ans << 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 "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;
    d += now / 60;
    now %= 60;
  }
}

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

C++: #include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<numeric>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

using namespace std;

int main() {
	int A, B, C;
	cin >> A >> B >> C;
	int time = 0, t = 0;	
	bool is_clear = false;	
	rep(i, 1000) {
		if(time > 60) {
			time -= 60; ++t;		
		}
		if(time <= C && C <= time + A) { 
			is_clear = true;	
		}
		if(is_clear) break;
		time += A+B;
	}

	cout << ((is_clear) ? 60*t + C : -1) << endl;
	return 0;
}