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;
  if(60%(a+b)==0&&c%(a+b)>a)cout<<-1<<endl;
  else{
    long long t=0;
    while(1){
      if((60*t+c)%(a+b)<=a){
        cout<<60*t+c<<endl;
        break;
      }
      t++;
    }
  }
  return 0;
}

C++: #import<iostream>
main(){int n,m,c,i;std::cin>>n>>m>>c;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;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<pll> vp;
typedef vector<ll> vll;

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

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

    int t = 0;
    rep(i, 10000) {
        rep(j, 100) {
            int ans = c + 60 * j;
            if (t <= ans && ans <= t + a) {
                cout << ans << endl;
                return 0;
            }
        }
        t += a + b;
    }
    cout << -1 << endl;
}

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

using namespace std;

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

	scanf("%d %d %d", &a, &b, &c);

	for (int t = 0; t <= 100; t++){
		if (1 <= (60 * t + c) % (a + b) && (60 * t + c) % (a + b) <= a){
			printf("%d\n", 60 * t + c);
			return (0);
		}
	}

	printf("-1\n");

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

	return 0;

}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c,i,j,s=0,s2=0,k=0;
	cin>>a>>b>>c;
	for(i=1;i<120;i++){
		s=0;
		for(j=1;j<=60;j++){
			s+=a+b;
			if(s-a-b<=c&&s-b>=c){k++;break;}
		}
		if(k==1)break;
		if(i==111){c=-1;break;}
		c+=60;
	}
	cout<<c<<endl;
}

C++: #include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<climits>
#include<ctime>
#include<cstring>
#include<sstream>
#define REP(i,p,n) for(int i=p;i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define ALL(c) (c).begin(), (c).end()
#define dump(a) cerr << #a << "=" << (a) << endl
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
#define MAX_SIZE 10000

using namespace std;

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

	int t=0;
	int back_time=0;
	bool is_break = false;
	int ans=0;
	while(true) {
		if (t > MAX_SIZE) { break; }
		if (is_break) { break; }
		int time = 60*t + c;

		for(int i=0; i<time; i+=(a+b)) {
			if (i <= time && time <= i+a) {
				ans = time;
				is_break = true;
				break;
			}
		}
		back_time = time;
		t++;
	}
	if (is_break) {
		cout << ans << endl;
	}
	else {
		cout << -1 << endl;
	}


	return EXIT_SUCCESS;
}

C++: #include <bits/stdc++.h>
using namespace std;
bool vis[120];
int main() {
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    int mod=c%(a+b);
    if(mod<=a) printf("%d\n",c);
    else {
        int ans=c;
        while(mod%(a+b)>a) {
            vis[mod]=1;
            mod=(mod+60)%(a+b);
            ans+=60;
            if(vis[mod]) break;
        }
        if(mod<=a) printf("%d\n",ans); else printf("-1\n");
    }
}

C++: #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < static_cast<int>(n); ++i)
#define REPR(i, n) for (int i = static_cast<int>(n) - 1; i >= 0; --i)
#define FOR(i, a, b) \
  for (int i = static_cast<int>(a); i < static_cast<int>(b); ++i)
#define FORR(i, a, b) \
  for (int i = static_cast<int>(b) - 1; i >= static_cast<int>(a); --i)
#define ALL(f, x, ...) \
  ([&](auto& y) { return (f)(begin(y), end(y), ##__VA_ARGS__); })(x)
auto INDEX = [](auto& x, auto& xs) { return &x - &xs[0]; };
void async_io() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}
const auto inf = INT_MAX / 3;
const auto pi = 2 * std::acos(0.0);
const auto eps = 1e-14;
using ll = signed long long;
using ull = unsigned long long;

signed main() {
  async_io();
  int a, b, c;
  cin >> a >> b >> c;
  // [0..a] + [a+b % 60 .. $0 + a % 60] ...
  bool seeked[60] = {};
  for (int i = 0, j = 0;;) {
    if (seeked[i]) {
      cout << "-1" << endl;
      return 0;
    }
    if (i <= c and c <= i + a) {
      cout << 60 * j + c << endl;
      return 0;
    }
    seeked[i] = true;
    if (i + a + b >= 60) j++;
    i = (i + a + b) % 60;
  }
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c,i,j,s=0,s2=0,k=0;
	cin>>a>>b>>c;
	for(i=1;i<120;i++){
		s=0;
		for(j=1;j<=i;j++){
			s+=a+b;
			if(s-b-b<c&&s-b>=c){k++;break;}
		}
		if(k==1)break;
		if(i==111){c=-1;break;}
		c+=60;
	}
	cout<<c<<endl;
}

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

bool check[64];

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	bool t = false;
	int now = 0;
	int ans = 0;
	while(1){
		if(t){
			now = (now + b) % 60;
			ans += b;
		}
		else{
			if(check[now]){
				cout << "-1" << endl;
				return 0;
			}
			check[now] = true;
			if(now > c){
				if(now <= c + 60 && c + 60 <= now + a){
					cout << ans + (c + 60 - now) << endl;
					return 0;
				}
			}
			else{
				if(now <= c && c <= now + a){
					cout << ans + (c - now) << endl;
					return 0;
				}
			}
			now = (now + a) % 60;
			ans += a;
		}
		t = !t;
	}
	return 0;
}