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 <sstream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <functional>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define SQ(x) ((x)*(x))
#define Mod(x, mod) (((x)+(mod)%(mod))
#define MP make_pair
#define PB push_back
#define Fi first
#define Se second
#define INF (1<<29)
#define EPS 1e-10
#define MOD 1000000007

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int main()
{
  int a, b, c;
  int t[60]; memset(t, 0, sizeof(t));
  t[0] = 1;
  cin >> a >> b >> c;
  int n = 0;
  while(1){
    //    cout << n%60 << " " << (n%60) + a << endl;
    if(((n%60) <= c && c <= ((n%60)+a) || (n%60)+a > 60 && 0 <= c && c <= ((n+a)%60))){
      cout << n  + (c-(n%60)) << endl;
      break;
    }
    n += a;
    if(t[n%60]){
      cout << -1 << endl;
      break;
    }
    t[n] = 1;
    n += b;
  }
  return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
const double PI = 3.14159265358979;
const double E = 2.718281828459045;
const double root2 = sqrt(2);
typedef pair<int, int> P;
typedef unsigned int ui;
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	int i;
	for (i = 0; i < 60; i++) {
		int t = (i * 60 + c) % (a + b);
		if (t<=a) {
			cout << i * 60 + c << endl; break;
		}
	}
	if (i == 60) {
		cout << -1 << endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  int x;
  bool flag=false;
  for(int t=0; t<=100; t++){
    for(int k=0; k<=10000; k++){
      if(0<=60*t+c-(a+b)*k&&60*t+c-(a+b)*k<=a){
      x=t,flag=true;
      goto end;
      }
    }
  }
  end:
  if(flag){cout<<60*x+c<<endl;}
  else cout<<-1<<endl;
}

C++: #include<iostream>

using namespace std;

int main() {
  int w,s,c;
  cin >> w >> s >> c;
  if(c > w && (w+s) % 60 == 0) cout << "-1" << endl;
  else {
    int i = 0;
    while(1) {
      if(c < (w + s) * i) c += 60;
      if(c <= (w + s) * i + w) break;
      else i++;
    }
    cout << c << endl;
  }
  
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1000000000;
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define rep(i,n) REP(i, 0, n)
bool mo[60];
int main(){
    int a, b, c; scanf("%d%d%d", &a, &b, &c);
    int now = 0;
    memset(mo, 0, sizeof(mo));
    while(true){
        int q = now % 60, cc = 60 * (now / 60) + c;
        if(now <= cc && cc <= now + a){
            printf("%d\n", cc);
            break;
        }
        if(mo[q]){
            puts("-1");
            return 0;
        }
        mo[q] = true;
        now += a + b;
    }
    return 0;
}

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

int main(void) {
    int a, b, c; cin >> a >> b >> c;
    set<int> wt;
    int t = 0;
    while (1) {
        auto st = wt.insert(t%60);
        if (!st.second) {
            cout << -1 << endl;
            break;
        }

        if (t%60 <= c && c <= t%60+a) {
            cout << t + c-t%60 << endl;
            break;
        }

        t += a+b;
    }

    return 0;
}

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<iostream>
#include<string>
using namespace std;
int main(){
	int a,b,c,w;
	cin>>a>>b>>c;
	w=-1;
	while(true){
		if(a+b==60&&c>a){
			break;
		}
		if(c%(a+b)>a)
			c+=60;
		if(c%(a+b)<=a){
			w=c;
			break;
		}
	}
	cout<<w<<endl;
    return 0;
}

C++: #import<iostream>
n,m,c,i;main(){std::cin>>n>>m>>c;for(i=0;i<99;i++){if(c%(n+m)<=n)goto a;c+=60;}c=-1;a:printf("%d\n",c);}

C++: #include<iostream>
using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(60%(a+b)==0&&c%(a+b)>a)cout<<-1<<endl;
  else{
    long long t=0;
    while(1){
      if((60*t+c)%(a+b)<=a){
        cout<<60*t+c<<endl;
        break;
      }
      if(t==10000000){
        cout<<-1<<endl;
      }
      t++;
    }
  }
  return 0;
}