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>
#define rep(i, a, n) for(int i=a;i<n;i++)
#define REP(i,n) rep(i,0,n)
#define ALL(a) a.begin(), a.end()
using namespace std;
typedef long long ll;

int main(){
	ll a,b,c;
	cin >>a>>b>>c;
	ll t =0,tmpt =0;
	set<ll> ts;
	bool f = true;
	/*while(f){
		rep(i,0,a){
			t += 1;
			if(t%60 >= c){
				if(t > 60){
					cout << t - t % 60 + c<<endl;
				}
				else{
					cout << c << endl;
			
				}
				f = false;
				break;
			}
		}
		if(!ts.insert(t % 60).second){
			cout << -1 << endl;
			break;
		}
		t += b;
	}*/
	while(1){
	bool f=0;
	t = c;
	while(a+b<t){
		t-=a+b;
	}
	if(t<=a){
		cout<<c<<endl;
		break;
	}
	else{
		if(!ts.insert(t).second){
			cout<<-1<<endl;
			break;
		}
	}
		c+=60;
	}
}

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(a + b != 60){ 
    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;
    int d=0;
    int n=0;
    cin >> a >> b >> c;
    while(true){
        if(d<=c && c<=d+a){
            cout << n*60 + c << endl;
            break;
        }
        d+=a+b;
        if(d>=60){
            n+=d/60;
            d%=60;
        }
        if(d==0){
            cout << -1 << endl;
            break;
        }
    }
}

C++: #include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <functional>
#include <complex>
#include <stack>
#include <tuple>
#include <array>
using namespace std;
#define rep(i,n) for (int i=0; i < (n); i++)


typedef long long int ll;
typedef double D;      // ??§?¨?????????????double???long double?????????
typedef complex<D> P;  // Point
typedef pair<P, P> L;  // Line
typedef vector<P> VP;


const int INF = (1<<30) - 1;
const D EPS = 1e-9;

#define X real()
#define Y imag()
#define LE(n,m) ((n) < (m) + EPS)
#define GE(n,m) ((n) + EPS > (m))
#define EQ(n,m) (abs((n)-(m)) < EPS)

int a, b, c;
int solve(){
    if(a + b == 60 && c > a) return -1;
    
    for(int t=0;; t++){
        if((60*t + c) % (a+b) <= a)
            return 60*t + c;
    }
}

//g++ -std=c++0x -msse4.2 -O3
//#include <bits/stdc++.h>
int main(){
    //ios::sync_with_stdio(false);
    //cin.tie(0);
    //cout.precision(16);
    
    cin >> a >> b >> c;
    cout << solve() << endl;
    return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define INF 10000000
using namespace std;
int main(){
  int a,b,c;
  cin >> a >> b >> c;
  int t=0;
  while(1){
    int tmp = (60*t+c) % (a+b);
    if(tmp<=a) {
      cout << 60*t+c << endl;
      break;
    }
    t++;
    if(t==INF){
      cout << -1 << endl;
      break;
    }
  }
  return 0;
}

C++: 
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define ll long long
#define pii pair<int,int> 
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
const int INF = 1001001001;
//int 2×10の9乗
//vector<vector<int>> a(n, vector<int>(m));
  //rep(i,n) rep(j,m) cin >> a[i][j]; 
//cout << fixed << setprecision(10);
//int gcd(int x, int y){
  //if(y==0) return x;
  //return gcd(y, x%y);
//}
//sort小さい順(昇順)
//g++ code.cpp   ./a.out 
int main(){
  ll a,b,c;
  cin >> a >> b >> c;
  if(a>=c){
    cout << c << endl;
    return 0;
  }
  else if(a+b==60){
    cout << "-1" << endl;
    return 0;
  } 
  else{
    rep(i,1000){
      rep(j,10000){
        if(i*a+b*i<=c+60*j && c+60*j<=(i+1)*a+b*i){
          cout << c+60*j << endl;
          return 0;
        }  
      }
    }
    cout << -1 << endl;
  }
}

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

int main()
{
	int a, b, c;
	cin>>a>>b>>c;
	
	for (int i=0; i<10000000; i++) {
		int t = ((a+b)*i) / 60;
		if ((a+b)*i <= c+60*t && c+60*t <= b*i + a*(i+1)) {
			cout << c + 60*t << endl;
			return 0;
		}
	}
	cout << -1 << endl;
}

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

using ll=long long;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)

int read(){
	int i;
	scanf("%lld",&i);
	return i;
}

signed main(){
	int A=read(),B=read(),C=read();
	int time=0;
	bool sleep=false;
	int t=0;
	while(true){
		time += A;
		if(time >= C) break;
		time += B;
		if(time > C) C += 60;
		
		if(time == 60){
			cout << -1;
			return 0;
		}
	}
	
	cout << C << endl;

}

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

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  int val = 0;
  vector<int> time;
  for(int i = 0; val < 60; i++){
    time.push_back(val);
    i&1 ? val += b : val += a;
  }
  val -= 60;
  vector<int> s(1, 0);
  int tmp = val;
  while(val != 0){
    s.push_back(val);
    val += tmp;
    val %= 60;
  }
  bool flag = true;
  for(int i = 0; i < s.size(); i++){
    for(int j = 0; j < time.size(); j+=2){
      if(time[j] + s[i] <= c && c <= time[j + 1] + s[i]){
	cout << 60*i + c << endl;
	flag = false;
	i = s.size();
	break;
      }
    }
  }
  if(flag)cout << -1 << endl;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  int n=0;
  while(n<1000000){
    if(n%60<c&&c<n%60+a)cout<<n/60*60+c<<endl,n=10000000;
    n+=a+b;

  }
  return 0;
}