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;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
#define int ll

signed main(void)
{
  int a, b, c, t = 0;
  cin >> a >> b >> c;
  bool flag = true;
  REP(i, 10000000) {
    if(flag) {
      if(t <= c && c <= t+a) {
        cout << c << endl;
        return 0;
      }
      t += a;
      flag = false;
    } else {
      t += b;
      if(t >= c) c += 60;
      flag = true;
    }
  }
  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;
	bool v[60];
	fill(v, v + 60, false);
	int sum = c;
	int time = c;
	while (true) {
		if (sum <= a) {
			cout << time << endl;
		}
		time << 60;
		sum << 60;
		sum /= (a + b);
		if (v[sum]) {
			cout << -1 << endl;
			break;
		}
		v[sum] = true;
	}
}

C++: #include <bits/stdc++.h>
 
#define loop(n, i) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;

using namespace std;
typedef long long ll;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    int loop = 0;
    int time = 0;
    for(;;) {
        time += a;
        //cout << "time: " << time << endl;
        if (time >= c) {
            cout << 60 * loop + c << endl;
            break;
        } 
        if (time + b >= c) loop++;

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

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

bool flag[60];
bool wake = true;

bool check(int c)
{
	return flag[c - 1];
}

int solve(int a, int b, int c)
{
	int count = 0;
	int cur = 0;
	int time = 0;
	while (true) {
		flag[cur] = wake;
		count++;
		cur++;
		if (count == a&&wake == true) {
			wake = false;
			count = 0;
		}
		if (count == b&&wake == false) {
			wake = true;
			count = 0;
		}

		if (cur == 60) {
			if (check(c) == true) {
				time += c;
				break;
			}
			else {
				time += 60;
				cur = 0;
			}
		}

		if (time >= 3600) {
			break;
		}
	}

	if (time >= 3600) {
		return -1;
	}
	else {
		return time;
	}
}

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

	for (int i = 0; i < 60; i++) {
		flag[i] = false;
	}

	cout << solve(a, b, c) << 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", i*60 + c);
			return 0;
		}
		t += a + b;
	}
	printf("-1\n");

	return 0;
}

C++: /*
2017_03_14_AC
????????????
????????§???????????§??°???????????°?????????????????§??????????????°??§AC??????????????£????????????

*/

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>

#define CH(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)

using namespace std;

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

  for(int k=0; ;k++){
    for(int i=0; ;i++){
      if((a + b)*i - 60*k <= c && c <= (a + b)*i + a - 60*k){
        cout<<c + 60*k<<endl;
        return 0;
      }
      if((a + b)*i == 0){
        cout<<-1<<endl;
        return 0;
      }
    }
  }

  return 0;
}

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

C++: #include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <list>
#include <tuple>
#include <bitset>
#include <ciso646>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;

inline bool cheak(ll x, ll y, ll xMax, ll yMax){ return x >= 0 && y >= 0 && xMax > x && yMax > y; }
inline ll toInt(string s) { ll v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
template<class T> inline T sqr(T x) { return x*x; }

#define For(i,a,b)	for(ll (i) = (a);i < (b);(i)++)
#define rep(i,n)	For(i,0,n)
#define rFor(i,a,b)	for(ll (i) = (a-1);i >= (b);(i)--)
#define rrep(i,n)	rFor(i,n,0)
#define clr(a)		memset((a), 0 ,sizeof(a))
#define mclr(a)		memset((a), -1 ,sizeof(a))
#define all(a)		(a).begin(),(a).end()
#define sz(a)		(sizeof(a))

const ll dx[8] = { 1, 0, -1, 0, 1, 1, -1, -1 }, dy[8] = { 0, -1, 0, 1, -1, 1, -1, 1 };
const ll mod = 1e9 + 7;
const ll INF = 1e9 + 9;

int main(){

	int a, b, c;
	cin >> a >> b >> c;

	int t = 0, cnt = 0,acnt = 0, bcnt = -1;

	while (true){
		if (cnt >= 1e6)break;
		if (60 * t + c == cnt && bcnt <= 0){
			cout << cnt << endl;
			return 0;
		}
		if (bcnt == -1){
			if (++acnt == a){
				acnt = -1;
				bcnt =  0;
			}
		}else
		if (acnt == -1){
			if (++bcnt == b){
				acnt =  0;
				bcnt = -1;
			}
		}
		if (++cnt == 60)t++;
	}
	cout << -1 << endl;

	return 0;
}