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 <algorithm>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string>
#include <vector>

#define el endl
#define fd fixed
#define INF INT_MAX/2-1
#define pb push_back

using namespace std;

int main() {
  int a, b, c, waking, arriving;
  bool flag;
  while (cin >> a >> b >> c, a | b | c) {
    waking = 0;
    arriving = c;
    flag = false;
    while (arriving < 3600+c) {
      while (waking < arriving) {
        if (waking <= arriving && arriving <= waking+a) {
          flag = true;
          break;
        }
        waking += a+b;
      }
      if (flag) break;
      arriving += 60;
    }
    if (flag) cout << arriving << el;
    else cout << "-1" << el;
  }
}

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) {
        //std::cout << s << "<-" << c << "->" << e << std::endl;
        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 std::max(cycle-1, 0)*60 + c;
}

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

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

int main(){
  int a,b,c;
  int i,j,k;

  cin >> a >> b >> c;
  if ((a+b==30||a+b==60)&&a<c) {
    cout << -1 << endl;
    return 0;
  }
  i=0;
  j=a;
  k=c;
  if (i>=j){
    cout << j << endl;
    return 0 ;
  }
  while (1){
    if (i<=k&&k<=j){
      cout << k << endl;
      break;
    }
    i+=a+b;
    j+=a+b;
    if (k<i){
      k+=60;
    }
  }
  return 0;
}

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

int func_J(int a,int b,int time){
  if(time<=a) return 1;
 
  time=time-(a+b);
  if(time>0) return func_J(a,b,time);
  else if(time<0) return 0;
  else return 1;

}

int func(int a,int b,int c,int d){
  int time;
   
  time=60-b+c-a;
  d+=60;
  if(time<=a||func_J(a,b,time)==1)return d;
  else  func(a,b,time,d);

  return 0;
}

int main(){
  int a,b,c;
  int rel=0;

  cin>>a>>b>>c;

  if(a>=c) rel=c;
  else if(a==b&&a<c) rel=-1;
  else if(c>a+b){
    if(func_J(a,b,c)==1)rel=c;
    else rel+=func(a,b,c,c); 
  } else rel+=func(a,b,c,c);

  cout<<rel<<endl;

  return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
    int n,m,b,c,d;
    bool a=false;
    cin>>n>>m>>b;c=b;
    for(int i=0;i<250000000;i++){
        if(c%(n+m)<=n && a==false){a=true;d=i;}
            c+=60;
        }
    }
    if(a==false){
        c=-1;
    }
    else{
        c=b+d*60;
    }
    cout<<c<<endl;
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()

int main(void){
    int a,b,c;
    cin>>a>>b>>c;
    int now=0,is=1;
    rep(i,10000){
        if(now%60+a>=c && c>=now%60){
            cout<<now/60*60+c;
            is=0;
            break;
        }else{
            now+=a+b;
        }
    }
    if(is)cout<<-1;
    cout<<endl;
}

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

using namespace std;


int a,b,c;

int main(){

	int flag = 0;
	int t=0;
	int i = 0;



	while(scanf("%d %d %d",&a,&b,&c) != EOF){


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

			if(flag == 0){
				t += a;
				flag = 1;
			}
			else if(flag == 1){
				t += b;
				flag = 0;
			}
			if(t > 60*(i+1)){
				i++;
			}

			if(flag == 1){
				if(t >= c + 60 * i){
					cout << c + 60*i << endl;
					return 0;
				}
			}
		}

	}

	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>

using namespace std;

struct before_main{before_main(){cin.tie(0); ios::sync_with_stdio(false);}} before_main;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;

int main() {

  int a, b, c; cin >> a >> b >> c;
  rep(t, 1000000) {
    int just_over = (60 * t + c) / (a + b) + 1;
    int aright = just_over * (a + b) - b;
    int aleft = aright - a;
    int gesha = 60 * t + c;
    if(aleft <= gesha && gesha <= aright) {
      cout << 60 * t + c << endl;
      return 0;
    }
  }

  cout << -1 << endl;
  
  return 0;
}