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>
#include <algorithm>
using namespace std;
using llong = long long;

int main() {
  llong a, b, c;
  llong ans = 1ll << 50ll;
  cin >> a >> b >> c;

  for (llong t = 0; t < 1000; t++) {
    llong valid = 1ll << 50ll;
    llong invalid = -1;

    while (valid - invalid > 1) {
      llong mid = (valid + invalid) / 2;
      if (60*t + c <= mid*(a+b) + a) valid = mid;
      else invalid = mid;
    }

    if (valid*(a+b) <= 60*t + c && 60*t + c <= valid*(a+b) + a) ans = min(ans, 60*t + c);
  }

  if (ans == (1ll << 50ll)) cout << -1 << endl;
  else cout << ans << endl;
}

C++: #include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str(); }
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX / 10;

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

	int ans = -1, t = 0;
	bool updated = true;
	while (updated) {
		updated = false;
		FOR(i, t, t + a) {
			if (i%60 == c) {
				ans = i;
				updated = false;
				break;
			}
			if (y[i%60] == 0) {
				updated = true;
				y[i%60] = 1;
			}
		}
		t += (a + b);
	}

	cout << ans << endl;
	return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>

using std::cin;
using std::cout;
using std::endl;
using std::setprecision;
using std::fixed;
using std::pair;
using std::make_pair;
using std::string;
using std::vector;
using std::list;
using std::map;
using std::set; // insert erase find count
using std::queue;
using std::priority_queue;
using std::stack;
/* c++11
#include <tuple>
using std::tuple; 
using std::make_tuple;
using std::get; // tuple std::get<NUM>(t); (0 <= NUM <= 2)
 */

typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, pair<int, int> > PIII;

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

    int time[60] = {0};
    bool notchange = false;
    int posi = 0;

    while (!notchange) {
        notchange = true;
        while (1) {
            for (int i = posi; i< posi + a; i++) {
                if (time[i] == 0) {
                    time[i] = 1;
                    notchange = false; 
                }
            }
            posi += (a + b);
            if (posi >= 60) {
                posi = posi % 60;
                break;
            }
        }
    }
    /*
    for (int i= 0; i < 60; i++) {
        cout << time[i];
        if (i % 10 == 9) {
            cout << endl;   
        }
    }
    */
    if (time[c - 1] == 0) {
        cout << -1 << endl; 
        return 0;
    }
    int plus = 0;
    int c_temp = c;
    while (1) {
        if (c_temp <= 0) {
            c_temp += 60;    
            plus++;
        }
        if (c_temp - a <= 0) {
            cout << c + plus * 60 << endl; 
            break;
        } 
        c_temp -= (a + b);
    }
    return 0;
}

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

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

C++: #include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
typedef long long int ll;
using namespace std;
int main(){
	int a,b,c; cin >>a>>b>>c;
	int now=0;
	if((a+b)%60==0){
		if(c<=a){
			cout << c << endl;
			return 0;
		}
		else{
			cout << -1 << endl;
			return 0;
		}
	}
	else if(60%(a+b)==0){
		while(1){
		if(now%60<=c&&c<=(now%60+a)){
			cout << now+(c-now%60) << endl;
			return 0;
		}
		else if(now%60+a>=60&&c<=(now%60+a)%60){
			cout << now+(60-now%60+c%60) << endl;
			return 0;
		}
		now+=(a+b);
		if(now>60){
			cout << -1 << endl;
			return 0;

		}
	}
	}
	while(1){
		if(now%60<=c&&c<=(now%60+a)){
			cout << now+(c-now%60) << endl;
			return 0;
		}
		else if(now%60+a>=60&&c<=(now%60+a)%60){
			cout << now+(60-now%60+c%60) << endl;
			return 0;
		}
		now+=(a+b);
	}
}

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

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  int val = 0;
  vector<int> time(1, 0);
  for(int i = 0; val < 60; i++){
    i&1 ? val += a : val += b;
    time.push_back(val);
  }
  val -= 60;
  vector<int> s(1, 0);
  while(val != 0){
    s.push_back(val);
    val += val;
    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;
}