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 <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>
#include <string>
using namespace std;


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

C++: #include<cstdio>
main(){int a,b,c,d;scanf("%d%d%d", &a, &b, &c);c-=60;d=a+b;
while((c+=60)<3600)
if(0<=c%d&&c%d<=a)
break;
printf("%d\n",c>3599?-1:c);return 0;}

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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if( a + b == 60 ) cout << -1 << endl;
  else if( c <= a ) cout << c << endl;
  else if ( c > a ){
    c -= a + b - 60;
    c += a + b;
    cout << c << endl;
  }

  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c,i,j,s=0,s2=0,k=0;
	cin>>a>>b>>c;
	for(i=1;i<120;i++){
		s=0;
		for(j=1;j<=60;j++){
			s+=a+b;
			if(s-a-b<=c&&s-b>=c){k++;break;}
		}
		if(k==1)break;
		if(i==111){c=-1;break;}
		c+=60;
	}
	cout<<c<<endl;
}

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

int main()
{
  int a, b, c;
  cin >> a >> b >> c;
  int st, et;
  for(st = 0, a = 0;; c+= 60, st = et + b, et = st + a){
    if(c >= st && c <= et){
      cout << c << endl;
      break;
    }
    if(a + b == 60){
      cout << "-1" << endl;
      break;
    }
  }
}

C++: #include<stdio.h>
#include<algorithm>
using namespace std;
int main(){
	int a,b,c;
	int ret=-1;
	scanf("%d%d%d",&a,&b,&c);
	while(c<10000){
		if(c%(a+b)<=a){
			ret=c;
			break;
		}
		c+=60;
	}
	printf("%d\n",ret);
}

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;
	while(true){
		time += A;
		if(time >= C) break;
		if(time == 60){
			cout << -1 << endl;
			return 0;
		}
		time += B;
		if(time > C) C += 60;
		
		if(time == 60){
			cout << -1 << endl;
			return 0;
		}
	}
	
	cout << C << endl;

}

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

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

    int now = 0;
    int ans = 1e9;
    for(int i = 0; i < 1000; i++){
        for(int j = 0; j < 1000; j++){
            now = (a + b) * i;
            if(now <= c + 60 * j && c + 60 * j <= now + a){
                ans = min(ans, c + 60 * j);
            }
        }
    }
    if (ans == 1e9) {
        puts("-1");
    } else {
        cout << ans << endl;
    }
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<cstdlib>
#include<sstream>
#include<queue>
#include<deque>
#include<cmath>
#include<algorithm>
#include<stack>
#include<map>
#include<set>
#include<iomanip>
#define INF 2147483647
#define lli long long int
#define MOD 1000000007
#define pb push_back

using namespace std;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
int main() {
	int a,b,c; cin >> a >> b >> c;
	int ans = 0;
	bool awake = true;
	int interval = a;
	while(1){
		ans++;
		if (ans > 3600) {
			ans = -1;
			break;
		}
		if (awake and ans%60 == c){
			break;	
		}
		if (awake){
			interval--;
			if (interval == 0){
				awake = false;
				interval = b;
			}
		}else{
			interval--;
			if (interval == 0){
				awake = true;
				interval = a;
			}

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

}

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;
  for (int offset = 0; offset < 60 * (A + B); offset += (A + B)) {
    while (offset > C) {
      C += 60;
    }
    if (C <= offset + 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 ans=-1,sum=0,cnt=0;
  while(ans==-1&&cnt++<2000000)
    if(sum%60+a<c||sum%60>c)sum+=a+b;
    else ans=sum+(c-sum%60);
  cout <<ans<<endl;
  return 0;
}