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;

typedef long long LL;
typedef vector<int>    VI;
typedef vector<bool>   VB;
typedef vector<string> VS;

#define MP make_pair
#define PB push_back
#define ALL(x)  (x).begin(),(x).end()
#define rep(i, N)  for (int i = 0; i < (int)(N); i++)
#define REP(i, init, N)  for (int i = (init); i < (int)(N); i++)
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

int a, b, c;
VI used;

bool check (int t) {
	rep (i, used.size()) {
		if (t == used[i]) return true;
	}
	return false;
}

int main(void) {
	cin >> a >> b >> c;
	int t = 0;
	int h = 0;
	int ans = -1;
	while (1) {
		if (check(t)) break;
		if (t <= c && c <= t + a) {
			ans = t + h * 60 + (c - t);
			break;
		}
		used.PB(t);
		t += a;
		t += b;
		h += t >= 60? 1 : 0;
		t %= 60;
	}
	cout << ans << endl;
    return 0;
}

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

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

    int ans = 0;
    while (1) {
        if (ans % (a + b) <= a && ans % 60 == c) {
            cout << ans << endl;
            break;
        }

        ans++;

        if (ans > 10000) {
            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 cnt = 0;

  int x1 = 0, x2 = a;

  if(60 % (a+b) == 0){
    while(1){
      if(c >= x1 && c <= x2){

	cout << c << endl;
	break;
      }else{
	x1=x2+b;
	x2=x1+a;
      }
      if(x2 >= 60){
	cout << -1 << endl;
	break;
      }
    }

  }else {
    int cp = c;
    while(1){


      if(cp < x1){
	cp += 60;
	//	cout << cp << endl;
	cnt++;
      }
      if(cp >= x1 && cp <= x2){
	cout << cp << endl;
	break;
      }else{
	x1=x2+b;
	x2=x1+a;
      }
    }
  }



}

C++: #include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<functional>
#include<queue>
using namespace std;
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a + b == 60) cout << -1 << endl;
	else {
		int sum = c;
		while (true) {
			if (sum % (a + b) >= 0 && sum % (a + b) <= a) {
				cout << sum << endl;
				break;
			}
			sum += 60;
		}
	}
}

C++: #include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())

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

using namespace std;
string s;
int i;
bool solve(void)
{
  if(i>=s.size()) return false;
  if(s[i]=='m'){
    ++i;
    if(!solve()) return false;
    if(i>=s.size()) return false;
    if(s[i]=='e'){
      ++i;
      if(!solve()) return false;
      if(i>=s.size()) return false;
      if(s[i]=='w'){
	++i;
	return true;
      }
    }
  }else return true;
}
int main(void)
{
  cin >> s;
  i=0;
  if(solve()&&i==s.size()) cout << "Cat" << endl;
  else cout << "Rabbit" << endl;
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
//const ll mod = 1000000007;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    for(int t = 0; t <= 1e6; t++) {
        int T = 60 * t + c;
        int delta = T % (a + b);
        if(delta <= a) {
            cout << T << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

C++: #include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)

typedef long long ll;

int main(void) {
    int a,b,c;
    cin >> a >> b >> c;
    int t=0;
    while (t<60){
        int k = (60*t+c)%(a+b);
        if (k<=a){
            cout << 60*t+c << endl;
            return 0;
        }
        t++;
    }
    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);
  
  set <int> s;

  int t = a + b; //??¨???(???+???)
  
  if(0<=c && c<=a){
    printf("%d\n",c);
  }
  
  else if(t%60==0){
    puts("-1");
  }
  
  else{
    int n=1;
    for(;;){
      if(s.count(c%60)){
	c=-1;
	break;
      }
      s.insert(c%60);
      if(c < n*t)
	while(c+60 <= n*t+a){
	  c+=60;
	}
      if(c < n*t)
	n++;
      else
	break;
    }
    printf("%d\n",c);
  }
}

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

int main(){
  int a, b, c, t = 0, e = 0, temp;
  int i, j, k;
  cin>>a>>b>>c;

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