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<bits/stdc++.h>
using namespace std;

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  bool flag = true;
  int time = 0, cnt = 0;
  for(int i = 0; i < 100; i++){
    if(time <= c && c <= time + a){
      cout << 60*cnt + c << endl;
      flag = false;
      break;
    }
    time += a + b;
    if(time > 60){
      cnt++, time -= 60;
    }
  }
  if(flag)cout << -1 << endl;
}

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

int main(){
  int a,b,c;
  int i,j,k;

  cin >> a >> b >> c;
  i=0;
  j=a;
  k=c;
  if (60%(a+b)==0&&a<c){
    cout << -1 << endl;
    return 0 ;
  }
  while (1){
    if (i<=k&&k<=j){
      cout << k << endl;
      break;
    }
    i+=a+b;
    j+=a+b;
    if (k<i){
      k+=60;
    }
  }
  return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
    int a,b,c;
    cin >> a >> b >> c;
    vector<int> v(60*60+1,0);
    for(int i = 0; i*(a+b) < 60*60; i++){
        v[i*(a+b)]++;
        v[min(60*60-1, i*(a+b)+a)+1]--;
    }
    for(int i = 0; i < 60*60; i++) v[i+1] += v[i];
    for(int i = 0; i < 60; i++){
        if(v[i*60+c]){
            cout << i*60+c << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

C++: #include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b, c; cin >> a >> b >> c;
  int st = 0;
  st += c / (a + b) * (a + b);
  c -= st;
  if((a + b) % 60 == 0) {
    cout << -1 << endl;
    return 0;
  }
  int up = 0;
  while(1) {
    if(up + a >= c) {
      cout << st + c << endl;
      return 0;
    }
    if(up + a < c && up + a + b > c) c += 60;
    up += a + b;
  }
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  int n=0;
  while(n<10000000){
    if(n%60<=c&&c<=n%60+a)cout<<n/60*60+c<<endl,n=10000000;
    n+=a+b;
  }
  return 0;
}

C++: #include <iostream>

using namespace std;

int main()
{
    int a, b, c;
    bool ok=true;
    cin>>a>>b>>c;
    for (int i=1; i<=3600 && ok; i++)
    {
        if (i%60==c && i%(a+b)<=a) { cout<<i<<'\n'; ok=false; }
    }
    if (ok) cout<<"-1\n";
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  int n=0;
  while(n<10000000){
    if(n%60<=c&&c<=n%60+a)cout<<n/60*60+c<<endl,n=1000000000;
    n+=a+b;
  }
  return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <bitset>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef long long LL;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	vector<bool> visited(100);


	for (int i = 0; true; i++) {
		int x = i * (a + b);
		int y = x + a;
		int z = x / 60 * 60 + c;
		if (visited[x % 60]) { puts("-1"); return 0; }
		if (x <= z && z <= y) { cout << z << endl; return 0; }
		visited[x % 60] = true;
	}
}

C++: #include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
  
using namespace std;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    int ans = 0;
    if((a + b) % 60 == 0) ans = -1;
    else {
        int cnt = 0, t = c;
        while(t < cnt * (a + b) || t > cnt * (a + b) + a){
            if(t < cnt * (a + b)) t += 60;
            else cnt++;
        }
        ans = t;
    }
    cout << ans << endl;
}

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

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

	for(int t = 0; t <= 3600; t += a + b) {
		while(c < t) c += 60;
		if(t <= c && c <= t + a) return c;
	}
	return -1;
}

int main() {
	cout << solve() << endl;
	return EXIT_SUCCESS;
}

C++: #include <bits/stdc++.h>
 
#define loop(n, i) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;

using namespace std;
typedef long long ll;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    int loop = 0;
    int time = 0;
    bool pass = false;
    for(;;) {
        time += a;
        //cout << "time: " << time << endl;
        if (time >= c && !pass) {
            cout << 60 * loop + c << endl;
            break;
        } 
        time += b;
        if (time == 60) {
            cout << -1 << endl;
            break;
        }
        if (time > 60) {
            pass = false;
            loop++;
            time %= 60;
        }
        if (time >= c) {
            pass = true;
        }
    }
}