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 <cstdio>
#include <cstring>

int a,b,c;
bool flag[61];
int main(void){
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	memset(flag,false,sizeof(flag));
	int t=0;
	while(1){
		if(flag[t%60])break;
		flag[t%60]=true;
		int rest=(c-t+6000000)%60;
		if(rest<=a){
			printf("%d\n",t+rest);
			return 0;
		}
		t+=a+b;
	}
	printf("-1\n");
	return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i, a, n) for(int i=a;i<n;i++)
#define REP(i,n) rep(i,0,n)
#define ALL(a) a.begin(), a.end()
using namespace std;
typedef long long ll;

int main(){
	ll a,b,c;
	cin >>a>>b>>c;
	ll t =0,tmpt =0;
	set<ll> ts;
	bool f = true;
	while(f){
		rep(i,0,a){
			t += 1;
			if(t%60 >= c){
				if(t > 60){
					cout << t - t % 60 + c<<endl;
				}
				else{
					cout << c << endl;
			
				}
				f = false;
				break;
			}
		}
		if(!ts.insert(t % 60).second){
			cout << -1 << endl;
			break;
		}
		t += b;
	}
}

C++: #include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    int t = 0;
    for (int i = 0; i <= 3600; ++i) {
        int p = t, q = (t+a);
        for (int j = 0; j <= 3600; ++j) {
            if(p <= 60*j+c && 60*j+c <= q){
                cout << 60*j+c << "\n";
                return 0;
            }
        }
        t += a+b;
    }
    puts("-1");
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<ll,ll> P;
const ll MOD=1000000007LL;
const double INF=1000000000;
const int MAX=100001;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    int aa=0;int bb=0;bool f=true;
    for(int i=0;i<=3600+c;i++){
        if((i-c+60)%60==0){
            if(f){
                cout<<i<<endl;
                return 0;
            }
        }
        if(f){
            aa++;
            if(aa>a){
                f=false;
                aa=0;
                continue;
            }
        }else{
            bb++;
            if(bb>b){
                bb=0;
                f=true;
                continue;
            }
        }
    }
    cout<<-1<<endl;
    return 0;
}

C++: #define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
 
#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
   
using namespace std;
   
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
   
static const double EPS = 1e-8;
   
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

int main(){
  int stand_duration;
  int sleep_duration;
  int cost;
  while(~scanf("%d %d %d",
               &stand_duration,
               &sleep_duration,
               &cost)){
    int current = 0;

    int res = -1;
    for(int round = 0; round < 60; round++){
      int prev = current;
      current += stand_duration;

      for(int time = prev; time <= current; time++){
        if(time % 60 == 0) {
          res = time + cost;
          goto found;
        }
      }
      current += sleep_duration;
    }

  found:;
    printf("%d\n",res);
  }
}

C++: #include <iostream>

using namespace std;

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

    bool wakeUp = true;
    size_t count = 0;
    // 一周で 1 ずつずれる場合でも 60 周すれば元に戻るはずなので，3600
    // まで調べれば良い
    for (int i = 0; i <= 3600; ++i) {
        if (wakeUp) {
            if (i % 60 == c) {
                cout << i << endl;
                return 0;
            }
            if (count >= a) {
                wakeUp = false;
                count = 0;
            }
        }
        else {
            if (count >= b) {
                wakeUp = true;
                count = 0;
            }
        }
        count += 1;
    }
    cout << -1 << endl;
}

C++: #include <iostream>

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

using namespace std;

typedef long long int lli;

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

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

int main() {

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

  if ( ( 60 % ( a + b ) ) == 0 ) {

    if ( ( c % ( a + b ) ) <= a ) {
      cout << c << endl;
    }else {
      cout << -1 << endl;
    }

  }else {

    for ( long long int t = 0;; t++ ) {

      if ( ( ( c + 60 * t ) % ( a + b ) ) <= a ) {

	cout << c + 60 * t << endl;
	break;

      }else if ( t > 60 ) {
	cout << -1 << endl;
	break;
      }

    }

  }

  return 0;

}