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>

using namespace std;

int a, b, c;

int calc() {
    for (int t = 0; t <= a + b; t++) {
        int x = (60 * t + c) % (a + b);
        if (0 <= x && x <= a) {
            return 60 * t + c;
        }
    }
    return -1;
}

int main() {
    cin >> a >> b >> c;
    cout << calc() << endl;
    return 0;
}

C++: #include<cstdio>
using namespace std;
int main(){
  int a,b,c,z=0;
  
  scanf("%d %d %d",&a,&b,&c);
  if( (a+b)%60 == 0){
    if(a>=c) printf("%d\n",c);
    else printf("-1\n");
  }
  
  else {
    while(1){
      
      if(z<=c && a>=c){
	printf("%d\n",c);
	break;
      }
      else {
	z += a+b;
	a += z;
	c += 60;
      }
    }
  }
  return (0);
}

C++: #include <iostream>

using namespace std;
const int LIMIT = 1e5;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
	int a,b,c;
	cin >> a >> b >> c;
	int ct = 0,t = 0,time =0;
	while(true){
		if((c + 60 - t)%60 <= a){
			time += (c + 60 - t) % 60;
			break;
		}else{
			t = (a + b) % 60;
			time += a+b;
		}
		if(time > LIMIT){
			time = -1;
			break;
		}
	}
	cout << time << endl;
  return 0;
}

C++: #include<iostream>
int main(){
int n,m,b,c;
std::cin>>n>>m>>b;c=b;
for(int i=0;i<99;i++){
if(c%(n+m)<=n){goto a;}
c+=60;
}
c=-1;
a:
std::cout<<c<<endl;return 0;}

C++: #include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define EPS 1e-10
#define INF 1000000000
#define mp make_pair
#define pb push_back

typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int,int> pii;
typedef long long ll;

int main() {
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);
  int ans = -1;
  for (int i = 0; i <= 120; i++) {
    int lhs = i * a + i * b,
        rhs = lhs + a;
    if ((lhs % 60 <= c && c <= rhs % 60) ||
        (lhs % 60 <= c && 60 <= (lhs % 60) + a) ||
        (c <= rhs % 60 && 60 <= (lhs % 60) + a)) {
      ans = lhs + c - (lhs % 60);
      break;
    }
  }
  cout << ans << endl;
}

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

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

  for(int i = 0;; i++) {
    if(sum%60 <= c && c <= (sum%60+a)) {
      cout << sum/60*60 + c << endl;
      break;
    }
    sum	+= a + b;
    if(sum % 60 == 0) {
      cout << "-1" << endl;
      break;
    }
  }

  return 0;
}

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

int main()
{
  int a, b, c;
  cin >> a >> b >> c;
  
  int step = a + b;
  int minute = c;
  for(int i = 0; i++ < 500000; minute += 60) {
    if(minute % step <= a) {
      cout << minute << endl;
      exit(0);
    }
  }
  cout << -1 << endl;
}