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 ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr int inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a, b, c;
  cin >> a >> b >> c;
  set<ll> s;
  ll t = 0;
  while(1){
    rep(i,a){
      ++t;
      if(t%60 == c){
        cout << t << endl;
        goto LABEL;
      }
    }
    if(!s.insert(t%60).se){
      cout << -1 << endl;
      break;
    }
    t += b;
  }
LABEL:
  return 0;
}

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

#define lambda(RES_TYPE, ...) (function<RES_TYPE(__VA_ARGS__)>)[&](__VA_ARGS__) -> RES_TYPE
#define method(FUNC_NAME, RES_TYPE, ...) function<RES_TYPE(__VA_ARGS__)> FUNC_NAME = lambda(RES_TYPE, __VA_ARGS__)

#define range(i, l, r) for (int i = l; i < (int)(r); ++i)

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

    cin >> a >> b >> c;

    int s = 0, t = a;
    range(i, 0, 1000) {
        int time = i * 60 + c;
        while (t < time) {
            s += a + b;
            t += a + b;
        }

        if (s <= time && time <= t) {
            cout << time << endl;
            return 0;
        }
    }

    cout << -1 << endl;
}

C++: #include <bits/stdc++.h>
#define range(i, a, n) for(int (i) = (a); (i) < (n); (i)++)
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
using namespace std;
int main(void){
    int a, b, c; cin >> a >> b >> c;
    int t = 0;
    int res = 0;
    vector<vector<int>> visited(a + b + 1, vector<int>(2, 0));
    visited[0][0] = 1;
    bool ok = false;

    while(1){
        int nt = t;
        nt += a;
        res += a;
        if((t <= c      and c      <= nt) or
           (t <= c + 60 and c + 60 <= nt)){
            res -= (nt - c) % 60;
            ok = true;
            break;
        }
        nt %= 60;
        if(visited[nt][1] != 0) break;
        visited[nt][1] = 1;

        t = nt;
        nt += b;
        res += b;
        nt %= 60;
        if(visited[nt][0] != 0) break;
        visited[nt][0] = 1;

        t = nt;
    }

    if(not ok) res = -1;
    cout << res << endl;

	return 0;
}

C++: #include<iostream>

using namespace std;

int main() {
  int w,s,c;
  cin >> w >> s >> c;
  int i = 0;
  i = 0;
  for(i = 0; i < 120;) {
    if(c < (w + s) * i) {
      c += 60;
    }
    else if(  c <= (w + s) * i + w) break;
    else i++;
  }
  if(i >= 120) cout << "-1" << endl;
  else         cout << c << endl;

  
  return 0;
}

C++: #include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
// #include <bits/stdc++.h>

using namespace std;

#define LOG(...) fprintf(stderr, __VA_ARGS__)
//#define LOG(...)
#define FOR(i, a, b) for(int i = (int)(a); i < (int)(b); ++i)
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SQ(n) (n) * (n)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main() {
  int a, b, c;
  vb reach(60, false);
  cin >> a >> b >> c;

  int t = 0;
  int aa = a;
  while(true) {
    if(reach[t % 60]) goto END;
    reach[t % 60] = true;
    REP(i, a){
      t++;
      if(t % 60 == c) goto END;
    }
    t += b;
  }
END:;
  cout << (t % 60 == c ? t : -1) << endl;
}

C++: #include<iostream>

using namespace std;

int main() {
  int w,s,c;
  while(cin >> w >> s >> c) {
    if((w+s) % 60 == 0) cout << "-1" << endl;
    else {
      int i = 0;
      while(1) {
	if(c < (w + s) * i) c += 60;
	if(c <= (w + s) * i + w) break;
	else i++;
      }
      cout << c << endl;
    }
  }
  return 0;
}

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

using namespace std;

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