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++: //	created : 16/01/07
// 	autor   : Rp7rf
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <set>

using namespace std;
#define rep(i,a) for(int i = 0 ; i < a ; i ++)
#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define vi vector<int>


int main(void){
	int n,m;
	cin>>n>>m;
	vector<pair<int,int> > c(n);
	rep(i,n){
		cin>>c[i].first;
		c[i].second=0;
	}
	pair<int,int> r;
//	rep(i,n)cout<<c[i].first<<" "<<c[i].second<<endl;;
	while(m--){
		int a;
		cin>>a;
		r.first = 0;
		rep(i,n){
			//cout<<r.first<<" "<<c[i].first<<" "<<a<<" "<<r.second<<endl;
			if(r.first < c[i].first && c[i].first < a){
				r.first = c[i].first;
				r.second = i;
			}
		}
		c[r.second].second ++;
	}
	int res = -1,ma;
	rep(i,n){
//		cout<<c[i].first<<" "<<c[i].second<<endl;
		if(ma < c[i].second){
			ma = c[i].second;
			res = i;
		}
	}
	cout<<res<<endl;
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<map>
#include<complex>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  bool used[70]={};
  int now=0;
  while(1){
    if(now<=c&&c<=now+a){
      cout<<c<<endl;
      break;
    }
    if(used[(now+a)%60]){
      cout<<-1<<endl;
      break;
    }
    used[(now+a)%60]=true;
    now+=(a+b);
    if(now>c)
      c+=60;
  }
  return 0;
}

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

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	int res = -1;
	for(int t = 0; t < 120; t++) {
		int T;
		T = 60 * t + c;
		if(T % (a+b) <= a) {
			res = T;
			break;
		}
	}
	cout << res << endl;
}

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

vector<vector<bool>> list(1000);

bool check(){
	bool p = true;
	for(int i=0; i < list.size(); i++){
		for(int j=i+1; j < list.size(); j++){
			p = true;
			for(int k = 0; k < list[i].size(); k++) if(list[i] != list[j]){p = false; break;}
			if(p){cout << -1 << endl; return true;}
		}
	}
	return false;
}

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

	int n = 0;
	list[0].push_back(20);
	while(true){
		for(int i=0; i< a; i++){
			if(list[n].size() < 60) list[n].push_back(true);
			else {
				if(list[n][c]){
					cout << n*60+c << endl; return 0;
				}
				n++;
				list[n].push_back(true);
				list[n].push_back(true);
			}
		}
		if(c <= list[n].size() && list[n][c]){
			cout << (n == 0 ? 0 : (n-1))*60+c << endl; return 0;
		}

		if(1 < n && check()) return 0;

		for(int i=0; i< b; i++){
			if(list[n].size() < 60) list[n].push_back(false);
			else {
				n++;
				list[n].push_back(true);
				list[n].push_back(false);
			}
		}
	}
}

C++: #include<iostream>
using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(60%(a+b)==0&&c%(a+b)>a)cout<<-1<<endl;
  else{
    int t=0;
    while(1){
      if((60*t+c)%(a+b)<=a){
        cout<<60*t+c<<endl;
        break;
      }
      t++;
    }
  }
  return 0;
}

C++: #include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())

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

using namespace std;
int main(void)
{
  int a,b,c;
  cin >> a >> b >> c;
  REP(i,200){
    int t=i*60+c;
    if(t%(a+b)<=a){
      cout << t << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}

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

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

    int time=0;
    for(int i=0; i<60; i++){
        while(time < (i+1)*60){
            if(time%60 <= c && c <= time%60+a){
                time += c - time%60;
                cout << time << endl;
                return 0;
            }else{
                time += a+b;
            }
        }
    }
    cout << -1 << 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 <functional>

using namespace std;

#define LOG(...) printf(__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((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

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;

const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 };

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	int memo[60];
	REP(i, 60)
		memo[i] = 999;
	int mi=0;
	REP(i, 60){
		REP(j, a){
			memo[mi] = min(i, memo[mi]);
			mi=(mi + 1) % 60;
		}
			memo[mi] = min(i, memo[mi]);
		REP(j, b){
			mi=(mi+1)%60;
			//memo[mi] = min(i, memo[mi]);
		}
		if (mi == 0)break;
	}
	if (memo[c] != 999)
		cout << 60 * memo[c] + c << endl;
	else
		cout << -1 << endl;
}

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

int main() {
	int a, b, n;
	cin >> a >> b >> n;
	int ans = -1;

	for (int i = 0;i < 60;i++) {
		if (n % (a + b) <= a) {
			ans = n;
			break;
		}
		n += 60;
	}
	cout << ans << endl;
	getchar();
	getchar();
	return 0;
}