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 <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] == 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 "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2639&lang=jp>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */
ll solve(){
    ll res = 0;
    ll a,b,c; cin >> a >> b >> c;
    vector<ll> time; for(ll t = 0; t < 10000; t++) time.push_back(60*t+c);
    for(ll t = 0; t <= 100; t++){
        ll from = t*(a+b), to = t*(a+b)+a;
        if(upper_bound(time.begin(),time.end(),to) - lower_bound(time.begin(),time.end(),from)){
            return *lower_bound(time.begin(),time.end(),from);
        }
    }
    return res = -1;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    cout << solve() << endl;
    return 0;
}

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

int main()
{
  int a,b,c,n=1,T[4000];
  
  cin>>a>>b>>c;
  while(n<4000){
    for(int i=0;i<a;i++,n++)T[n]=1;
    for(int i=0;i<b;i++,n++)T[n]=0;
  }
  for(int i=c;i<4000;i+=60){
    if(T[i]==1){
      cout<<i<<endl;
      break;
    }
    if(i>3600){
      cout<<-1<<endl;
      break;
    }
  }
}

C++: #include <iostream>
#define REP(i, a, n) for(int i = (a); i < (n); i++)
using namespace std;

int A, B, C;

int main(void) {
  cin >> A >> B >> C;

  int s = 0;
  int t = C;
  REP(i, 0, 60) {
    while(t < s) t += 60;
    if(s <= t && t <= s + A) {
      cout << t << endl;
      return 0;
    }
    s += A + B;
  }

  cout << -1 << endl;

  return 0;
}

C++: /*
 * 2639.cc: Yamanote Line
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int R = 60;

/* typedef */

/* global variables */

/* subroutines */

/* main */

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

  int ans = -1;
  for (int t = 0; t < R; t++) {
    int ct = t * R + c;
    int cab = ct % ab;
    if (cab >= 0 && cab <= a) {
      ans = ct;
      break;
    }
  }

  printf("%d\n", ans);
  return 0;
}

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

int main(){

  int a,b,c,i=1,get;
  cin>>a>>b>>c;
  if(a>=c) cout<<c<<endl;
  else if(a+b==60 && a<c) cout<<"-1"<<endl;
  else {
    get=a+b;
    while(1){
      get+=a;
      if(60*i+c<=get){
	cout<<60*i+c<<endl;
	break;
      }
      get+=b;
    }
  }
      
      
  return 0;
}