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"
#include<unordered_map>
#pragma warning(disable:4996)
using namespace std;

const int My_Inf=2147483647;
const long long int My_LInf=9223372036854775807;
struct action {
	int ac;
	int time;
};
int main() {
	int a, b, c; cin >> a >> b >> c;
	vector<action>acs;
	int atime = 0;
	while (atime<10000) {
		atime += a;
		acs.push_back(action{ 2, atime });
		atime += b;
		acs.push_back(action{0,atime });
	}
	atime = c;
	while (atime<10000) {
		acs.push_back(action{ 1, atime });
		atime += 60;
		
	}
	sort(acs.begin(), acs.end(), [](const action&l, const action&r) {return l.time == r.time ? l.ac < r.ac : l.time < r.time; });
	bool awake = true;
	for (int i = 0; i < acs.size(); ++i) {
		int type = acs[i].ac;
		int atime = acs[i].time;
		if (type == 2) {
			awake = false;
		}
		else if (type == 1) {
			if (awake) {
				cout << atime << endl;
				return 0;
			}
		}
		else {
			awake = true;
		}
	}
	cout << -1 << endl;
	return 0;
}

C++: //	created : 16/01/07
// 	autor   : Rp7rf
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <set>

using namespace std;
#define rep(i,a) for(int i = 0 ; i < a ; i ++)
#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define vi vector<int>


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

C++: #include<iostream>

using namespace std;

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

	cin >> a >> b >> c;
	
	if(a >= c){
		cout << c << endl;
		return 0;
	}

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

	int t;
	if(c <= a + b) t = c + 60;
	else t = c;

	int i = 0;
	while(t % (a+b) > a){
		t += 60;
		i++;
		if(i > 60){
			cout << -1 << endl;
			return 0;
		}
	}
	cout << t << endl;

	return 0;
}

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

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

C++: #include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <sstream>
#include <numeric>
#include <set>
#include <map>
//#include <bits/stdc++.h>

#define rep(i, j) for(int i = 0; i < j; i++)
#define all(i) i.begin(), i.end()
#define ll long long
#define bl bool
#define nn printf("\n");
#define mod 1000000007

using namespace std;

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

	int a, b, c; cin >> a >> b >> c;
	int t = 1, t_ans = 0;
	int i = 1, cri = 0;
	while (1)
	{
		//if (a + b == 60 && t_ans > 5) 
		//{
		//	printf("-1\n"); 
		//	break;
		//}
		if (t == 60){ t = 0; t_ans++; }
		t++;
		if (i == a && cri == 0){ i = 0; cri = 1; }
		else if (i == b && cri == 1){ i = 0; cri = 0; }
		else if (i <= b && cri == 0 && t == c)
		{ 
			printf("%d\n", (60 * t_ans) + c); 
			break;
		}
		i++;
	}
	return 0;
}

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;
      }
      if(t==10000000){
        cout<<-1<<endl;;
      }
      t++;
    }
  }
  return 0;
}

C++: #include <cstdio>
#include <cstring>

int a,b,c;
bool flag[61];
int main(void){
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	memset(flag,false,sizeof(flag));
	int t=0;
	while(1){
		if(flag[t%60])break;
		flag[t%60]=true;
		int rest=(c-t+60)%60;
		if(rest<=a){
			printf("%d\n",t+rest);
			return 0;
		}
		t+=a+b;
	}
	printf("-1\n");
	return 0;
}

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

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

  int now = 0;
  for(int i=0; i<60; i++){
    for(int j=0; j<=a; j++){
      if(now%60==c){
        cout << now << endl; 
        return 0;
      }
      now++;
    }
    now += b-1;
  }
  cout << -1 << endl;
  return 0;
}

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

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

  if (a + b == 60) {
    if (c <= a)
      cout << c << endl;
    else
      cout << -1 << endl;
  } else {
    int t = a + b;
    if (c % t <= a)
      cout << c << endl;
    else {
      for (; ;) {
	c += 60;
	if (c < 0) {
	  cout << -1 << endl;
	  break;
	}
	if (c % t <= a) {
	  cout << c << endl;
	  break;
	}
      }
    }
  }
  return 0;
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<cmath>
#include<stack>
//#include<stdlib.h>
using namespace std;
int main() {
	int a, b, c,p=0,t=0;
	cin >> a >> b >> c;

	while (true)
	{
		t += a;
		if (t >= c) { t = c; break; }
		t += b;
		if (t > c)
		{
			c += 60; p++;
			if ((60*p) % (a + b) == 0) { t = -1; break; }
		}
	}
	cout << t << endl;
	return 0;
}

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

using namespace std;

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

  set<int> st;
  int ans = c;
  while (true) {
    int d = c % (a + b);
    if (d <= a) {
      ans = c;
      break;
    }
    if (st.find(d) != st.end()) {
      ans = -1;
      break;
    }
    st.insert(d);
    c += 60;
  }
  cout << ans << endl;

  return 0;
}

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

int a, b, c;

int main(){
	scanf("%d%d%d", &a, &b, &c);
	int t = 0, f, l;
	for (int i = 0; i < 5000; i++) {
		f = t % 60;
		l = (f + a) % 60;
		if ((f < l && c >= f && c <= l) || (f > l && (c <= l || c >= f))) {
			printf("%d\n", t - f + c);
			return 0;
		}
		t += a + b;
	}
	printf("-1\n");

	return 0;
}