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 <bits/stdc++.h>
using namespace std;

int main(){

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

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

			if( 60%(a+b) == 0 ) {
			L1:
				  cout << -1 << endl;
				  return 0;
			}
			else{
				  int t=0;
				  set<int> s;
				  while( c % (a+b) > a ) {
						c = c%(a+b);
						c += 60; t++;
						if( s.count(c) != 0)goto L1;
						s.insert(c);
				  }
				  cout << c+(60*t)-60 << endl;
				  return 0;
			}
	  }

}

C++: #include<iostream>
using namespace std;
int main(){
    int n,m,b,d;
long long c;
    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){
        cout<<"-1"<<endl;
    }
    else{
        c=b+d*60;
        cout<<c<<endl;
    }
    return 0;
}

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

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

  cin >> a >> b >> c;

  i=a;
  j=c;
  while (1){
    if (i>=j) {
      if (i-j<=60){
	cout << j << endl;
	break;
      }else{
	j+=60;
	continue;
      }
    }
    if (a+b==60) {
      cout << -1 << endl;
      break;
    }

    i+=a+b;

    j+=60;
  }
  return 0;
}

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

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

    int time=0, time_;
    for(int i=0; i<60; i++){
        if(time%60 != time_%60)
            break;
        time_ = time;
        
        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 <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int a, b, c;
set<int> si;

int main(){
	bool f = 0;
	cin >> a >> b >> c;
	while (1){
		int now = c;
		now %= (a + b);
		if (now <= a){
			cout << c << endl;
			f = 1;
			break;
		}
		else{
			if (si.insert(now).second == false)break;
			c += 60;
		}
	}
	if (!f)cout << -1 << endl;
}

C++: #include <iostream>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <cctype>
#include <set>
#include <algorithm>
#include <string>
#include <queue>
#include <map>
#define fcout(n) cout<<fixed<<setprecision((n))
using namespace std;
int main(){
	int a,b,c,t=0;
	cin>>a>>b>>c;
	while(1){
		if(c%(a+b)>a&&(c+60)%(a+b)>a){
			t=-1;
			break;
		}
		if((c+60*t)%(a+b)<=a){
			break;
		}
		else t++;
	}
	if(t==-1) cout<<-1<<endl;
	else cout<<60*t+c<<endl;
}