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 main(){
  int a,b,c;
  cin >> a >> b >> c;
  int start_a = 0,start_b = a;
  while(1){
    if( start_a <= c && c <= start_b ){
      cout << c << endl;
      break;
    }
    //int check = c - b;
    start_a += a + b;
    start_b = start_a + a;
    if( c < start_a ){
      c += 60;
     
      // if( c - start_b == check ){
      if( c > 100000 ){
	cout << -1 << endl;
	break;
      }
    }
  }
  return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <sstream>
#include <numeric>
#include <set>
#include <map>
//#include <bits/stdc++.h>

#define rep(i, j) for(int i = 0; i < j; i++)
#define all(i) i.begin(), i.end()
#define ll long long
#define bl bool
#define nn printf("\n");
#define mod 1000000007

using namespace std;

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	int a, b, c; cin >> a >> b >> c;
	int t = 1, t_ans = 0;
	int i = 1, or = 0;
	while (1)
	{
		if (a + b == 60 && t_ans > 5) 
		{
			printf("-1\n"); 
			break;
		}
		if (t == 60){ t = 0; t_ans++; }
		t++;
		if (i == a && or == 0){ i = 0; or = 1; }
		else if (i == b && or == 1){ i = 0; or = 1; }
		else if (i <= b && or == 0 && t == c)
		{ 
			printf("%d\n", (60 * t_ans) + c); 
			break;
		}
		i++;
	}
	
	return 0;
}

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

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

using ll=long long;
#define int ll

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

int read(){
	int i;
	scanf("%lld",&i);
	return i;
}

signed main(){
	int A=read(),B=read(),C=read();
	int time=0;
	bool sleep=false;
	int t=0;
	int i=0;
	while(i<100000){
		time += A;
		if(time >= C) break;
		time += B;
		if(time > C) C += 60;
		
		if(time == 60){
			cout << -1 << endl;
			return 0;
		}
		i++;
	}
	
	cout << C << endl;

}

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

int main(){
    int a, b, c; cin >> a >> b >> c;
    if(a == 30 && b == 30){
        cout << -1 << endl;
        return 0;
    }

    int t = 0;
    int T = a + b;   //??¨???

    while(1){
        
        int temp = (60*t + c) % T;
        if(0 <= temp && temp <= a){
            cout << 60*t + c << endl;
            break;
        }

        t++;
    }

    return 0;
}

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

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;

#define INF 1000000000

int gcd(int a, int b){
  int c;
  while(a!=0){
    c=a;
    a=b%a;
    b=c;
  }
  return b;
}


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

  int reps=60/gcd(a+b,60);

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

  rep(cnt,reps){
    remain = (remain+60)%(a+b);
    if( remain <= a){
      cout << c + (cnt+1)*60 << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}

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 (c % (a + b) >= 0 && c % (a + b) <= a) {
				cout << sum << endl;
				break;
			}
			sum += 60;
		}
	}
}

C++: #include <iostream>

using namespace std;

int main()
{
    int a, b, c;
    
    cin >> a >> b >> c;
    
    while(c < 1000000)
    {
        if(0 <= c % (a + b) && c % (a + b) <= a)
        {
            cout << c << endl; return 0;
        }
    }
    
    cout << -1 << endl;
    
    return 0;
}

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

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

    int start = -1;
    int res = -1;
    int i = 0;
    while(start) {
        start = (a * i + b * i);
        int end = (a * (i + 1) + b * i);
        int c_ = c + (start / 60) * 60;

        if(start <= c_ && c_ <= end) {
            res = c_;
            break;
        }

        i++;
        start = (a * i + b * i) % 60;
    }

    cout << (res < 0 ? -1 : res) << endl;

    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>

#define CH(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)

using namespace std;

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

  return 0;
}

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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  vector<bool> v(60,false);
  int now=60-c;
  int k = 0;
  while(1){
    if(v[now]) break;
    v[now]=true;
    if(60<=now+a){
      cout << k+60-now << endl;
      return 0;
    }
    now=(now+a+b)%60;
    k+=a+b;
  }
  cout << -1 << endl;
  return 0;
}