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 solve(int a, int b, int c) {
    vector<char> vis(60, 0);
    for (int t = 0, s = 0;;) {
        if (vis[s]) return -1; else vis[s] = 1;
        if (s <= c && c <= s + a) return 60 * t + c;
        if ((s += a + b) >= 60) s -= 60, t++;
    }
}

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

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

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

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

int main()
{
  int a, b, c;
  cin >> a >> b >> c;
  int st, et, r;
  for(st = r = 0, et = a;; st = et + b, et = st + a){
    if(st >= 60){
      st -= 60;
      et -= 60;
      r++;
    }
    if(c >= st && c <= et){
      cout << r*60+c << endl;
      break;
    }
    if(a + b == 60){
      cout << "-1" << endl;
      break;
    }
  }
}

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

using namespace std;

typedef long long  ll;

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

    const int lim = 3600;
    int a, b, c, t = 0;
    bool flag = false;

    cin >> a >> b >> c;
    while (t * (a + b) <= lim) {
        int l = (t * (a + b)) % 60;
        int r = (t * (a + b) + a) % 60;

        if (l <= r) {
            if (l <= c && c <= r) {
                t = (c - l) + t * (a + b);
                flag = true;
                break;
            }
        }
        else {
            if ((t * (a + b) % 60) <= c || c <= (t * (a + b) + a) % 60) {
                t = (c - l) + t * (a + b);
                flag = true;
                break;
            }
        }
        ++t;
    }

    if (flag)
        cout << t << endl;
    else
        cout << "-1\n";

    return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

signed main(){
	int a,b,c;
	cin>>a>>b>>c;
	int ans=-1;
	rep(i,0,10000){
		int tmp=60*i+c;
		if(tmp%(a+b)<=a){
			ans=tmp; break;
		}
	}
	o(ans);
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c; cin >> a >> b >> c;
    for (int i=0;i<120;++i){
        int t=60*i+c;
        if (t%(a+b)<=a){
            cout << t << '\n';
            return 0;
        }
    }
    cout << -1 << '\n';
}

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

vector<vector<bool>> list(3000);

bool check(){
	bool p = true;
	for(int i=0; i < list.size(); i++){
		for(int j=i+1; j < list.size(); j++){
			p = true;
			for(int k = 0; k < list[i].size(); k++) if(list[i] != list[j]){p = false; break;}
			if(p){cout << -1 << endl; return true;}
		}
	}
	return false;
}

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

	int n = 0;
	list[0].push_back(20);
	while(true){
		for(int i=0; i< a; i++){
			if(list[n].size() <= 60) list[n].push_back(true);
			else {
				if(list[n][c]){
					cout << n*60+c << endl; return 0;
				}
				n++;
				list[n].push_back(true);
				list[n].push_back(true);
			}
		}
		if(c <= list[n].size() && list[n][c]){
			cout << (n == 0 ? 0 : (n-1))*60+c << endl; return 0;
		}

		if(1 < n && check()) return 0;

		for(int i=0; i< b; i++){
			if(list[n].size() <= 60) list[n].push_back(false);
			else {
				n++;
				list[n].push_back(true);
				list[n].push_back(false);
			}
		}
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define mem(a) memset(a,0,sizeof(a))
#define pd(a) printf("%.10f\n",a)
#define pb(a) push_back(a)
#define in(a) insert(a)
#define pi M_PI
#define R cin>>
#define F first
#define S second
#define C class
#define ll long long
#define ln cout<<'\n'
template<C T>void pr(T a){cout<<a;ln;}
template<C T,C T2>void pr(T a,T2 b){cout<<a<<' '<<b;ln;}
template<C T,C T2,C T3>void pr(T a,T2 b,T3 c){cout<<a<<' '<<b<<' '<<c;ln;}
template<C T>void PR(T a,int n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
bool check(int n,int m,int x,int y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int a,b,c;
  cin >> a >> b >> c;
  int t=a;
  bool f=1;
  REP(i,1,60*60+c+1) {
    c--;t--;
    if(c==0&&f) {
      pr(i);
      return;
    }
    if(!c) c=60;
    if(!t) {
      if(f) {
        f=0;
        t=b;
      } else {
        f=1;
        t=a;
      }
    }
  }
  pr(-1);
}

int main() {
  ios::sync_with_stdio(0);cin.tie(0);
  Main();return 0;
}

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

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

using namespace std;

int main(){

  int a,b,c;

  cin>>a>>b>>c;

  int time = 0;
  int cnt = 100;

  while(cnt!=0){
	time+=a;
	if(time>=c)
	  break;
	time+=b;
	if(time>=c)
	  c+=60;

	cnt--;
	if(cnt==0){
	  cout<<-1<<endl;
	  return 0;
	}
	
	}
  
  cout<<c<<endl;
  
}