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 a,b,c;

//???????§?????????????
int start;

//????????£?????????
int passage;

//?????????????????????????????????
bool can;

int main() {
	//??\???
	cin>>a>>b>>c;

	//?????????
	can=false;
	start=0;
	passage=0;

	do {
		//????????????????????????
		if(start<=c && c<=start+a){
			passage+=(c-start);
			can=true;
			break;
		}

		//??????????????????????¬???????????????????
		start+=(a+b);
		start%=60;

		passage +=(a+b);
	}while(start!=0);

	//??????
	if(can)cout<< passage <<endl;
	else   cout<<-1<<endl;

	return 0;
}

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 = -1;
    for(int t = 0; t < 1000; t++){
        if((60 * t + c) % (a + b) <= a){
            ans = 60 * t + c;
            break;
        }
    }
    cout << ans << endl;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e8;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	int s=0,g=a;
	while(g<1e8){
		if(s%60<=c&&c<=g%60)break;
		if(g%60<s%60&&(s%60<=c||c<=g%60))break;
		s+=a+b;
		g+=a+b;
	}
	if(g>=1e8)cout<<-1<<endl;
	else if(s%60<c)cout<<s+c-s%60<<endl;
	else cout<<g+c-g%60<<endl;
}

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

int main() {
    int ot, nt, ct, dt;
    cin >> ot >> nt >> ct;
    dt = ct;
    while(true) {
        if(dt % (ot + nt) <= ot) {
            cout << dt << endl;
            return 0;
        } else {
            if(60 % (ot + nt) == 0) {
                cout << -1  << endl;
                return 0;
            }
            dt += 60;
        }
    }
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<map>
#include<complex>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  bool used[70]={};
  int now=0;
  while(1){
    if(now<=c&&c<=now+a){
      cout<<c<<endl;
      break;
    }
    if(used[(now+a)%60]){
      cout<<-1<<endl;
      break;
    }
    used[(now+a)%60]=true;
    now+=(a+b);
    c+=60;
  }
  return 0;
}

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

using namespace std;

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

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

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

  cin >> a >> b >> c;

  i=a;
  j=c;
  while (1){
    if (i>=c) {
      cout << j << endl;
      break;
    }
    if (a+b==60) {
      cout << -1 << endl;
      break;
    }

    i+=a+b;

    j+=60;
  }
  return 0;
}

C++: #include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
int main(void) {
    long long a, b, c;
    cin >> a >> b >> c;
    long long now = 0;
    for (int i = 0; i < 10000000; i++) {
        if (c % (a + b) <= a) {
            cout << c << endl;
            return 0;
        }
        c += 60;
    }
    cout << -1 << endl;
    return 0;
}

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

#define rep(x,n) for(int x=0;x<n;x++)

int solve(int a, int b, int c){
	rep(i,60){
		if(c%(a+b)<=a)return c;
		c+=60;
	}
	return -1;
}

int main(){
	
	for(int a,b,c;cin>>a>>b>>c;)cout<<solve(a,b,c)<<endl;
	
	return 0;
}

C++: #include <iostream>
using namespace std;
int main() {
  int a, b, c, t;
  cin >> a >> b >> c;
  if ((c%(a+b) > a) && (!(60%(a+b)))) {
    cout << -1 << endl;
  } else {
    t = c;
    while (t%(a+b) > a) t += 60;
    cout << t << endl;
  }
  return 0;
}

C++: #define _USE_MATH_DEFINES
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include<iomanip>
using namespace std;



int main(){
	
	
	bool f[100]={};
	int a,b,c;
	cin>>a>>b>>c;
	int ans=0,y=0;;

	while(1){
		if(f[y]){cout<<"-1"<<endl;break;}
		int x=y%60;
		f[y]++;
		if(c>=y&&c<=y+a){
			ans+=(c-y);
			cout<<ans<<endl;
			break;
		}
		else if(c<y&&(y+a)%60>=c&&y+a>=60){
			ans+=60-y+c;
			cout<<ans<<endl;
			
			break;
		}
		else {y+=a+b;
		ans+=a+b;
		y%=60;
		//cout<<y;
		}


	}
	

	return 0;
}