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;
    
    while(c < 1000000)
    {
        if(0 <= c % (a + b) && c % (a + b) <= a)
        {
            cout << c << endl; return 0;
        }
        
        c += 60;
    }
    
    cout << -1 << endl;
    
    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<=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>
#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) {
		time += A+B;
		if(time > 60) {
			time -= 60; ++t;		
		}
		if(C <= A || time <= A) { // ?????????????????¨???
			is_clear = true;	
		}
		if(is_clear) break;
	}

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

C++: #include<iostream>
#include<climits>
#define ll long long 
using namespace std;

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

  cin>>a>>b>>c;
  
  while(1){
    if(c>=INT_MAX){
      c=-1;
      break;
    }
    time+=a;
    if(time>=c) break;
    time+=b;
    if(time>=c) c+=60; 
  }

  cout<<c<<endl;
  
  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) rel=-1;
  else rel+=func(a,b,c,c);

  cout<<rel<<endl;

  return 0;
}

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

int main(){
    int a, b, c; cin >> a >> b >> c;
    if(a == 30 && b == 30){
        cout << -1 << endl;
        return 0;
    }

    int t = 0;
    int T = a + b;   //??¨???

    while(t < 100000000){
        
        int temp = (60*t + c) % T;
        if(0 <= temp && temp <= a){
            cout << 60*t + c << endl;
            return 0;
        }

        t++;
    }

    cout << -1 << endl;

    return 0;
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<functional>
#include<queue>
using namespace std;
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a + b == 60) cout << -1 << endl;
	else {
		bool v[120];
		fill(v, v + 60, false);
		int sum = c;
		while (true) {
			if (v[sum % (a+b)]) {
				cout << -1 << endl;
				break;
			}
			if (sum % (a + b) >= 0 && sum % (a + b) <= a) {
				cout << sum << endl;
				break;
			}
			v[sum%(a+b)] = true;
			sum += 60;
		}
	}
}

C++: #include<iostream>
n,m,c,i;main(){std::cin>>n>>m>>c;for(i=0;i<99;i++){if(c%(n+m)<=n)goto a;c+=60;}c=-1;a:printf("%d\n",c);}

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

using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) reep((i),0,(n))

typedef long long ll;

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

C++: #include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
typedef long long int ll;
using namespace std;
int main(){
	int a,b,c; cin >>a>>b>>c;
	int now=0;
	if((a+b)%60==0){
		if(c<=a){
			cout << c << endl;
			return 0;
		}
		else{
			cout << -1 << endl;
			return 0;
		}
	}
	else if(60%(a+b)==0){
		while(1){
		if(now%60<=c&&c<=(now%60+a)){
			cout << now+(c-now%60) << endl;
			return 0;
		}
		else if(now%60+a>=60&&c<=(now%60+a)%60){
			cout << now+(60-now%60+c%60) << endl;
			return 0;
		}
		now+=(a+b);
		if(now>60){
			cout << -1 << endl;
			return 0;

		}
	}
	}
	while(1){
		if(now%60<=c&&c<=(now%60+a)){
			cout << now+(c-now%60) << endl;
			return 0;
		}
		else if(now%60+a>=60&&c<=(now%60+a)%60){
			cout << now+(60-now%60+c%60) << endl;
			return 0;
		}
		now+=(a+b);
		if(now%60==0){
			cout << -1 << endl;
			return 0;
		}
	}
}

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

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

C++: #include<iostream>
int n,m,c,i;main(){std::cin<<n<<m<<c;for(i=0;i<99;i++){if(c%(n+m)<=n)goto a;c+=60;}c=-1;a:printf("%d\n",c);}

C++: #include<iostream>
#include<vector>
using namespace std;
int main(){
  int a,b,c;
  int t=0;
  cin >> a >> b >> c;
  int x=0;
  vector <int> m;
  int f=0;
  while(f==0&&(60*x+c)%(a+b)>a) {
    for(int i=0;i<m.size();i++){
      if(m[i]==(60*x+c)%(a+b)) {
	f=1;
	cout << -1 << endl;
      }
    }
    m.push_back((60*x+c)%(a+b));
    x++;
  }
  if(f==0)
  cout << (60*x+c) << endl;
  return 0;
}