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>
#include<algorithm>

using namespace std;

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

  for(int i=0;;i+=a+b){
    if(i<=c && c<=i+a){
      cout << i+c%60-i%60 << endl;
      break;
    }
    if(10000<i && 60%(a+b)==0){
      cout << -1 << endl;
      break;
    }
    if(i%60 != (i+a)%60)c+=60;
  }
  
  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;

    int count = 0;
    for(int round = 0; round < 100000 + cost; round++){
      int prev = current;

      current += stand_duration;

      for(int time = prev; time <= current; time++){
        if(time == cost){
          res = count * 60 + cost;
          goto found;
        }
      }

      current += sleep_duration;
      if(current >= 60){
        count++;
        current -= 60;
      }
    }

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

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

int main() {
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);

  int A[4096];
  for(int t = 0; t < 4000;) {
    for(int i = 0; i <= a; ++i) {
      A[t + i] = 1;
    }
    t += a;
    for(int i = 1; i < b; ++i) {
      A[t + i] = -1;
    }
    t += b;
  }
  int res = -1;
  for(int t = c; t < 4000; t += 60) {
    if( A[t] > 0 ) {
      res = t;
      break;
    }
  }

  printf("%d\n", res);  
  
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) begin(a),end(a)
#define MS(m,v) memset(m,v,sizeof(m))
#define D10 fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef long long ll;
const int INF = 114514810;
const int MOD = 1000000007;
const double EPS = 1e-10;
struct edge
{
	int to, cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator >(const edge& e) const { return cost > e.cost; }
};
int dx[] = { -1, 0, 0, 1 }; int dy[] = { 0, -1, 1, 0 };
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
bool valid(int x, int y, int h, int w) { return (x >= 0 && y >= 0 && x < h&&y < w); }
int place(int x, int y, int w) { return w*x + y; }
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///


int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	bool f = true;
	REP(i, 100000)
	{
		int t = c + i * 60;
		if (t % (a + b) <= a)
		{
			f = false;
			cout << t << endl;
			break;
		}
	}
	if (f) puts("-1");
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  int n=0;
  while(n<10000000)
    if(n%60<=c&&c<=n%60+a,n+=a+b){cout<<n/60*60+c<<endl;return 0;}
  cout<<-1<<endl;
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main() {
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    int mod=c%(a+b);
    if(mod==0) printf("%d\n",c);
    else if(60%(a+b)==0) printf("-1\n");
    else {
        int ans=c;
        while((mod+60)%(a+b)<=a) mod=(mod+60)%(a+b),ans+=60;
        printf("%d\n",ans);
    }
}

C++: #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < static_cast<int>(n); ++i)
#define REPR(i, n) for (int i = static_cast<int>(n) - 1; i >= 0; --i)
#define FOR(i, a, b) \
  for (int i = static_cast<int>(a); i < static_cast<int>(b); ++i)
#define FORR(i, a, b) \
  for (int i = static_cast<int>(b) - 1; i >= static_cast<int>(a); --i)
#define ALL(f, x, ...) \
  ([&](auto& y) { return (f)(begin(y), end(y), ##__VA_ARGS__); })(x)
auto INDEX = [](auto& x, auto& xs) { return &x - &xs[0]; };
void async_io() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}
const auto inf = INT_MAX / 3;
const auto pi = 2 * std::acos(0.0);
const auto eps = 1e-14;
using ll = signed long long;
using ull = unsigned long long;

signed main() {
  async_io();
  int a, b, c;
  cin >> a >> b >> c;
  // [0..a] + [a+b % 60 .. $0 + a % 60] ...
  bool seeked[60] = {};
  for (int i = 0, j = 0;;) {
    if (seeked[i]) {
      cout << "-1" << endl;
      return 0;
    }
    if (i <= c and c <= i + a) {
      cout << 60 * j + c << endl;
      return 0;
    }
    seeked[i] = true;
    if (i + a + b >= 60) j++;
    i = (i + a + b) % 60;
  }
}

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

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	
	int cur = 0;
	
	for (int t = 0; t <= 60; ++t) {
		int stop = 60 * t + c;
		
		while (cur <= stop) {
			if (cur <= stop && stop <= cur + a) {
				cout << stop << endl;
				return 0;
			}
			
			cur += a + b;
		}
	}
	
	cout << -1 << endl;
}

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

int main() {
	int a,b,c;
	cin>>a>>b>>c;
	int x=c;
	if(x<=a){
		cout<<c<<endl;
		return 0;
	}
	int t=0;
	while(1){
		x=x-a;
		if(x<=0){
			cout<<(c+60*t)<<endl;
			return 0;
		}
		if(x<b){
			x=x+60-b;
			if(x==c){
				x=-1;
				cout<<x<<endl;
				return 0;
			}
		}else{
			x=x-b;
		}
		t++;
	}
	return 0;
}