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>


#define FOR(i,a,b) for(int i = a;i < b;i++)
#define RFOR(i,a,b) for(int i = a;i >= b;i--)
#define IN cin >> 
#define OUT cout <<
#define E  << endl;

using namespace std;


int goal_time = 0;

int a, b, c;

void input() {
	IN a >> b >> c;
}

int main() {
	input();
	int memo = 1;
	if ((60 % (a + b) == 0) &&  c > a) {
		OUT - 1 E
		return 0;
	}
	bool flag = false;
	goal_time += c;
	while (true) {
		int n = memo;
		while (true){
			if ((a + b) * n <= goal_time && (a + b) * n + a >= goal_time) {
				OUT goal_time E
				flag = true;
				break;
			}
			if ((a + b) * n > goal_time) {
				memo = n;
				break;
			}
			n++;
		}
		if (flag)break;
		goal_time += 60;
	}

	return 0;
}

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

int a, b, c;
int solve() {
    int s = 0;
    int e = (a % 60);

    int cycle = 0;
    std::set<int> waked;
    while(true) {
        if(waked.count(s) > 0) {
            return -1;
        }
        waked.insert(s);

        bool f = s < e ? (s <= c && c <= e) : (s <= c || c <= e);
        if(f) break;

        s = (e + b) % 60;
        e = (s + a) % 60;
        ++cycle;
    }
    return (cycle*60 + c);
}

int main() {
    std::cin >> a >> b >> c;
    std::cout << solve() << std::endl;
}

C++: #include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<N;i++)
#define p(S) cout<<S<<endl
using namespace std;


int main(){
	int a,b,c;
	int t=0;
	set<int> s;
	cin>>a>>b>>c;
	while(1){
		int now=c%(a+b);
		if(now<=a){
			t=c;
			break;
		}else if(s.find(now)!=s.end()){
			t=-1;
			break;
		}else{
			s.insert(now);
			c+=60;
		}
	}
	p(t);
	return 0;
}

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

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

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

int main(void){
  int a,b,c;
  cin>>a>>b>>c;
  if(a>=c){
    cout<<c<<endl;
    return 0;
  }
  int n = 60;
  int sum = c;
  int cnt = 0;
  while(n--){
    
    //cout<<cnt<<" "<<sum<<" "<<cnt+b<<endl;
    while(cnt > sum)sum += 60;
    if(cnt <= sum && sum <= cnt + b){
      cout<<sum<<endl;
      //  break;
      return 0;
    }
    
    cnt += a + b;
  }
  cout<<-1<<endl;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f(i,x,n) for(int i=x;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=200005,INF=1<<30;
int dp[13][203];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(1){
        int A,B,C;cin>>A>>B>>C;
        //if(A+B+C==0) break;
        
        int now=0;
        int ans=INF;
        
        while(now<=7200){
            if(now%60<=C%60){
                if(now%60+A>=C%60){
                    ans=min(ans,now/60*60+C);
                }
            }else{
                if((now+A)%60>=C%60&&now%60+A>=60){
                    ans=min(ans,(now+A)/60*60+C);
                }
            }
            
            now+=A+B;
        }
        
        if(ans==INF) cout<<-1<<endl;
        else cout<<ans<<endl;
        
        break;
    }
}

C++: #include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<functional>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(10)

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

int main()
{
	int a[2],b;
	cin >> a[0] >> a[1] >> b;
	
	int num = 0;
	for(int i = 0;i < 3700;i++)
	{
		REP(j,a[i%2])
		{
			num++;
			if(num%60 == b && i%2 == 0)
			{
				cout << num << endl;
				return 0;
			}
		}
	}
	cout << -1 << endl;
	
	
	return 0;
}

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

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    bool found_ans = false;
    bool awake = true;
    int cnt = 0;
    for(int t=1;t<=4000;++t){
        cnt++;
        if(awake && cnt > a){
            cnt = 1;
            awake = false;
        }
        if(!awake && cnt >= b){
            cnt = 0;
            awake = true;
        }
        if(t%60 == c && awake){
            cout << t << endl;
            found_ans = true;
            break;
        }
    }

    if(!found_ans)cout << -1 << endl;

    return 0;
}

C++: #include<iostream>
#include<vector>

using namespace std;

signed main(){

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

   int t=a;
   int n=1;
   int used[61]={0};
   used[a]=1;
   while(1){
      if(t>=c){
         cout<< c<< endl;
         break;
      }
      t+=(b+a);
      if(used[t%60]){
         cout<< -1<< endl;
         break;
      }else{
         used[t%60]=1;
      }
      if(t>=60*n){
         n++;
         c+=60;
      }
   }

   return 0;
}