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 <iomanip>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>

using std::cin;
using std::cout;
using std::endl;
using std::setprecision;
using std::fixed;
using std::pair;
using std::make_pair;
using std::string;
using std::vector;
using std::list;
using std::map;
using std::set; // insert erase find count
using std::queue;
using std::priority_queue;
using std::stack;
/* c++11
#include <tuple>
using std::tuple; 
using std::make_tuple;
using std::get; // tuple std::get<NUM>(t); (0 <= NUM <= 2)
 */

typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, pair<int, int> > PIII;

int main(void) {
    int a;
    int b;
    int c;
    cin >> a >> b >> c;
    bool repeat = !(60 % (a + b));
    int plus = 0;
    int c_temp = c;
    while (1) {
        if (c_temp <= 0) {
            if (repeat) {
                cout << -1 << endl;
                break;
            } else {
                c_temp += 60;    
                plus++;
            }
        }
        if (c_temp - a <= 0) {
            cout << c + plus * 60 << endl; 
            break;
        } 
        c_temp -= (a + b);
    }
    return 0;
}

C++: #include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define P pair<int,int>
#define ll __int64
int a,b,c;
int main(){
cin>>a>>b>>c;
int time=0,time2=0;
int ans=-1;
for(int i=0;i<10000;i++){

	int now;
	if((i+1)%2)now=a;
	else now=b;

		for(int j=0;j<now;j++){
			time++;
			time2++;
			if(time==60)time=0;
			if((i+1)%2&&time==c){
				cout<<time2<<endl;
				return 0;
			}
		}
	}


cout<<ans<<endl;
	return 0;
}

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

C++: #include<bits/stdc++.h>
using namespace std;
 
#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

typedef long long ll;
typedef pair<int, int> ii;



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

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

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

  return 0;
}

C++: define rep(i,a) for(int i = 0 ; i < a ; i ++)

int main(void){
  int a,b,c;
  cin>>a>>b>>c;
  if(a>=c){
    cout<<c<<endl;
    return 0;
  }
  int n = 10000;
  int sum = c;
  int cnt = 0;
  while(n--){
    
    //cout<<cnt<<" "<<sum<<" "<<cnt+b<<endl;
    while(cnt > sum)sum += 60;
    if(cnt <= sum && sum <= cnt + b){
      cout<<sum<<endl;
      //  break;
      return 0;
    }
    
    cnt += a + b;
  }
  cout<<-1<<endl;
}

C++: #include<iostream>
#include<climits>
#define ll long long 
using namespace std;

int main(){
  int a,b;
  ll c,time=0;

  cin>>a>>b>>c;

  bool flag=0;
  while(1){

    if(time>=60) flag=0;
    if(c>=INT_MAX){
      c=-1;
      break;
    }

    time+=a;
    if(time>=c) break;
    time+=b;


    if(flag==0){
      c+=60;
      flag=1;
    }

  }

  cout<<c<<endl;
  
  return 0;
}

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

C++: #include <stdio.h>

int main(void){
    int a,b,c,sign,sign1,time,t,sum;
    scanf("%d %d %d",&a,&b,&c);
    if(!(60 % (a+b)))
            sign1=1;
    for(time=0,t=0,sign=0;;sign=1-sign){
        if(!sign){
            time+=a;
        }
        else{
            time+=b;
        }
        if(time >= c && time-a <= c && !sign){
            sum=t*60+c;
            break;
        }
        if(time >= 60){
            t++;
            time-=60;
            if(time >= c && !sign){
                sum=t*60+c;
                break;
            }
            if(sign1){
                sum=-1;
                break;
            }
        }
    }
    printf("%d\n",sum);
    return 0;
}

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

#define rep(i, n) for(int i = 0; i < n; i++)

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    int a, b, c; cin >> a >> b >> c;
    int arv[60] = {c};
    rep(i, 59) arv[i+1] = arv[i] + 60;
    //時刻tで寝ているかどうか判定
    //a分起きてb分寝るので、0 - a, a+b - 2a+b, 2a+2b - 3a+2b...は起きている
    rep(i, 60){
        int awake_beg = 0, awake_fin = a;
        int t = arv[i];
        while(awake_beg <= t){
            if(t <= awake_fin){
                cout << t << endl;
                return 0;
            }
            awake_beg += a+b;
            awake_fin += a+b;
        }
    }
    cout << -1 << endl;
    return 0;
}