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<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<cstring>
#include<utility>
#include<set>
#include<stack>
#include<complex>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
#define bv vector<bool>
using namespace std;
typedef pair<int, int>PI;
using namespace std;
#define MAX  999999
int main(){
    int a,b,c; cin >> a>>b>>c;
    int sum = a+b; int ans = 0;
    for(int i = 0;10000;i++){
        ans=i*60+c;
        if(ans % (a+b)<=a){cout << ans << endl; break;}
        if((a+b == 60) && c > a){cout << -1 << endl; break;}
    }
    
}

C++: #include <bits/stdc++.h>
 
using namespace std;
 
int getArriveTime(int a,int b,int c){
    bool visited[60][60][2];
    memset(visited,false,sizeof(visited));
    int d = 0,st = 1,e = 0;
    for(int i = 0 ; ; i++,d++){
	if(i >= 60){ i %= 60; e++; }
	if(c == i && st) return c+e*60;
	if(visited[i][d][st]) return -1;
	visited[i][d][st] = true;
	if(d >= a && st == 1){ d = 0; st = 0; }
	if(d >= b && st == 0){ d = 0; st = 1; }
    }
    return -1;
}
 
int main(){
    int a,b,c;
    cin >> a >> b >> c;
    int res = getArriveTime(a,b,c);
    cout << (res >= 0 ? res : -1) << endl;
    return 0;
}

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



int main(void) {
    int a, b, c;
    cin >> a >> b >> c;
    int t[60] = {0};
    int now_time=0;
    while(1) {
        if (t[now_time%60]==1) {
            cout << -1 << endl;
            exit(0);
        }
        t[now_time%60] = 1;
        if ( (now_time%60 < c && c <= now_time%60+a) ) {
            cout << now_time + (c - now_time%60) << endl;
            exit(0);
        }
        now_time += a;
        now_time += b;
    }
    return 0;
}

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

int main(){
  int a, b, c, t = 0, e = 0, temp;
  int i, j, k;
  cin>>a>>b>>c;


  if(60%(a+b) != 0 ){ 
    while(1){//cout<<t<<endl;
      if(t%60 <= c && c <= t%60 + a){
      t = e * 60 + c ;
      break;
      }
      t += a + b;
      e++;
    }

  } else{
     if(t <= c && c <= t + a){
      t = c;
     } else t = -1;
  }

  
  cout<<t<<endl;
  return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	int l=1;
	if(a+b==60) l=60;
	for(int i=2;i<=30;i++){
		if(l%i==0&&(a+b)%i==0) l=i;
	}
	int shu=-1;
	for(int i=0;i<=60/l;i++){
		if((60*i+c)%(a+b)>0&&(60*i+c)%(a+b)<=a){
			shu=i;
			break;
		}
	}
	if(shu==-1) cout<<-1<<endl;
	else cout<<60*shu+c<<endl;
    return 0;
}

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

int a, b, c;

int solve() {
    int s = 0;
    int e = a % 60;

    int cycle = 0;
    std::set<int> waked;
    while(true) {
        if(waked.count(s) > 0) {
            return -1;
        }
        waked.insert(s);

        bool f = s < e ? (s <= c && c <= e) : (s <= c || c <= e);
        if(f) break;

        s = (e + b) % 60;
        e = (s + a) % 60;
        ++cycle;
    }
    return cycle*60 + c;
}

int main() {
    std::cin >> a >> b >> c;
    std::cout << solve() << std::endl;
}

C++: #include <cstdio>
int main(){int a,b,c,d;scanf("%d%d%d", &a, &b, &c);c-=60;d=a+b;
while((c+=60)<3600)
if(0<=c%d&&c%d<=a)
break;
printf("%d\n",c>3599?-1:c);return 0;}

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

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

  cin >> a >> b >> c;
  if ((a+b==30||a+b==60)&&a<c) {
    cout << -1 << endl;
    return 0;
  }
  i=a;
  j=c;
  while (1){
    //cout << i << " " << j << endl;
    if (i>=j){
      cout << j << endl;
      break;
    }
    if (j-i>60){
    i+=a+b;
    continue;
    }
    i+=a+b;
    j+=60;
  }
  return 0;
}

C++: #include <iostream>

using namespace std;

int main() {
	int a, b, c; cin >> a >> b >> c;
	int ans = -1;
	for (int i = 0; i < 60; ++i) {
		int tmp = ((a + b) * i) % 60;
		if (tmp <= c && c <= tmp + a) {
			ans = (a + b) * i + c - tmp;
			break;
		}
	}
	cout << ans << endl;

	return 0;
}

C++: #include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
using namespace std;
int main() {
	int a, b, c;
	while (cin >> a >> b >> c) {
		long long i = 0;
		while (true) {
			int sum = (a + b)*i;
			if (c >= sum % 60 && c <= sum % 60 + a) {
				sum = ceil(sum / 60) * 60 + c;
				if (sum > (a + b)*i+a) {
					sum -= 60;
				}
				cout << sum << endl;
				break;
			}
			if (i >= 1000000) {
				cout << -1 << endl;
				break;
			}
			i++;
		}
	}
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<cstring>
#include<utility>
#include<set>
#include<stack>
#include<complex>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
#define bv vector<bool>
using namespace std;
typedef pair<int, int>PI;
using namespace std;
#define MAX  999999
int main(){
    int a,b,c; cin >> a>>b>>c;
    int sum = a+b; int ans = 0;
    for(int i = 0;10000;i++){
        ans=i*60+c;
        if(ans % (a+b)<=a){cout << ans << endl; break;}
        if(a == b &&c>a){cout << -1 << endl; break;}
    }
    
}