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 <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
 
using namespace std;
 
#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,s,e) for(int i=(s); i<(e); i++)
#define pb(n) push_back((n))
#define mp(n,m) make_pair((n),(m))
#define all(r) r.begin(),r.end()
#define fi first
#define se second
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
 
const int INF = 10000000;



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

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

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

  if (a + b == 60) {
    if (c <= a)
      cout << c << endl;
    else
      cout << -1 << endl;
  } else {
    int t = a + b;
    if (c % t <= a)
      cout << c << endl;
    else {
      for (; ;) {
	c += 60;
	if (c % t <= a) {
	  cout << c << endl;
	  break;
	}
      }
    }
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <cctype>
#include <set>
#include <algorithm>
#include <string>
#include <queue>
#include <map>
#define fcout(n) cout<<fixed<<setprecision((n))
using namespace std;
int main(){
	int a,b,c,t=0;
	cin>>a>>b>>c;
	while(1){
		if(t>10000007){
			t=-1;
			break;
		}
		if((c+60*t)%(a+b)<=a){
			break;
		}
		else t++;
	}
	if(t==-1) cout<<-1<<endl;
	else cout<<60*t+c<<endl;
}

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

C++: #include<bits/stdc++.h>
 
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
 
using namespace std;
 
int a,b,c;
bool used[100];
 
int main(){
  cin >> a >> b >> c;
  int answer = 0, cur = 0;
  bool found = false;
  while( true ){
    if( used[cur%60] ) break;
    used[cur%60] = true;
    if( cur%60 <= c && c <= cur%60+a ) {
      found = true;
      answer = cur + c - cur % 60;
      break;
    }
    cur += a + b;
  }
 
  if( !found ) cout << -1 << endl;
  else cout << answer << endl;
 
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <cctype>
#include <set>
#include <algorithm>
#include <string>
#include <queue>
#include <map>
#define fcout(n) cout<<fixed<<setprecision((n))
using namespace std;
int main(){
	int a,b,c,t=0;
	cin>>a>>b>>c;
	while(1){
		if(t>10000007){
			t=-1;
			break;
		}
		if((c+60*t)%(a+b)<=a){
			break;
		}
		else t++;
	}
	if(t==-1) cout<<-1<<endl;
	else cout<<60*t+c<<endl;
}

C++: #include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()

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

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  cin >> a >> b >> c;
  bool flag = true;
  int s = a + b;
  if(s%60 == 0 && a<c){
    cout << -1 << endl;
  }
  else if(a>c) cout << c << endl;
  else{
  int c1 = s%60;
  int l = c1+(c-c1);
  s = s/60;
  int ans = 60 * s + l;
  cout << ans << endl;
  }
  
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int a,b,c;
  cin>>a>>b>>c;
  int aa=a,bb=b;
  b+=a;
  rep(i,20000){
    if(c <= a){cout<<c<<endl;return 0;}
    else if(c < b) c+=60;
    a+=aa+bb;
    b+=aa+bb;
  }
  cout<<-1<<endl;
 
  return 0;
}

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

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

int func(int a,int b,int c,int d){
  int time;
  
  time=60-b+c-a;
  d+=60;

  if(time<=a)return d;
  else  func(a,b,time,d);

  return 0;
}

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

  cin>>a>>b>>c;

  if(a>=c) rel=c;
  else if(a==b&&a<c) rel=-1;
  else rel+=func(a,b,c,c);

  cout<<rel<<endl;

  return 0;
}

C++: #include<iostream>
int main(){
int n,m,b,c,d;
bool a=false;
std::cin>>n>>m>>b;c=b;
for(int i=0;i<250000000;i++){
if(c%(n+m)<=n){a=true;d=i;}
c+=60;
}
if(a==false){
c=-1;
}
else{
c=b+d*60;
}
std::cout<<c<<"\n";return 0;}

C++: #include<stdio.h>

int main(void)
{
  
  int a,b,c;
  int i;
  int t = 0;
  int total = 0;
  
  scanf("%d %d %d",&a,&b,&c);
    
  while(1){
    for(i=0;i<a;i++){
      total++;

      if(total == 60*t+c){
	printf("%d\n",total);
	return 0;
      }
      
      if(total == 60*(t+1)){
	if(60%(a+b) == 0){
	  puts("-1");
	  return 0;
	}
	else 
	  t++;
      }
    }
    
    for(i=0;i<b;i++){
      total++;
      
      if(total == 60*(t+1)){
	if(60%(a+b) == 0){
	  puts("-1");
	  return 0;
	}
	else 
	  t++;
      }
    }
  }
}