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 <algorithm>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string>
#include <vector>

#define el endl
#define fd fixed
#define INF INT_MAX/2-1
#define pb push_back

using namespace std;

int main() {
  int a, b, c, wakingtime, t;
  bool flag;
  while (cin >> a >> b >> c, a | b | c) {
    wakingtime = 0;
    flag = false;
    for (t = 0; t < 60; t++) {
      if (wakingtime <= 60*t+c && 60*t+c <= wakingtime + a) {
        flag = true;
        break;
      } else if (wakingtime < 60*t+c){
        while (wakingtime < 60*t+c) {
          wakingtime += a+b;
        }
      }
    }
    if (flag) cout << 60*t+c << el;
    else cout << "-1" << el;
  }
}

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

int main(){

	  int a,b,c ;
	  cin >> a >> b >> c;

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

			if( 60%(a+b) == 0 ) {
			L1:
				  cout << -1 << endl;
				  return 0;
			}
			else{
				  int x=c;
				  int t=0;
				  set<int> s;
				  while( c % (a+b) > a ) {
						c = c%(a+b);
						c += 60; t++;
						if( s.count(c) != 0)goto L1;
						s.insert(c);
				  }
				  cout << x+(60*t) << endl;
				  return 0;
			}
	  }

}

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

C++: #include <iostream>
#include <vector>

using namespace std;


int a,b,c;

int main(){

	int flag = 0;
	int t=0;
	int i = 0;

	cin >> a >> b >> c;


	while(1){
		if(a == 30 && b == 30 && c > 30){
			cout << "-1" << endl;
			return 0;
		}

		if(flag == 0){
			t += a;
			flag = 1;
		}
		else if(flag == 1){
			t += b;
			flag = 0;
			i++;

		}

		if(flag == 1){
			if(t >= c + 60 * i){
				cout << c + 60*i << endl;
				return 0;
			}
		}
	}

	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{
		bool f = false;
		rep(i, 65){
			int tmp = 60 * i + c;
			if(tmp % (a + b) <= a){
				f = true;
				cout << tmp << endl;
				break;
			}
		}
		assert(f);
	}
	
	return 0;
}

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

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

  set<int> S;
  int ans=-1,sum=0,sta=1;
  while(ans==-1){ 
    if(sum%60+a<c)sum+=a+b;
    else ans=sum+(c-sum%60);
    if(S.count(sum%60))break;
    else S.insert(sum%60);
  }
  cout <<ans<<endl;
  return 0;
}

C++: #include <iostream>

using namespace std;
static const int INF = 1e9;

void solve()
{
	int a[2], c;
	cin >> a[0] >> a[1] >> c;
	if (a[0] >= c)
	{
		cout << c << endl;
		return;
	}
	int diff = INF;
	int now = a[0];
	int cnt = 0;
	while (true)
	{
		int preDiff = diff;
		diff = c - now;
		if (preDiff == diff)
		{
			cout << -1 << endl;
			return;
		}
		while (now < c)
		{
			++cnt;
			now += a[cnt % 2];
			if (now >= c)
			{
				if (cnt % 2 == 1)
				{
					break;
				}
				else
				{
					cout << c << endl;
					return;
				}
			}
		}
		c += 60;
	}
}

int main()
{
	solve();
	return(0);
}

C++: #include <bits/stdc++.h>
 
#define loop(n, i) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;

using namespace std;
typedef long long ll;

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

C++: #include <iostream>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	int l=1;
	if(a+b==60) l=60;
	for(int i=2;i<=30;i++){
		if(l%i==0&&(a+b)%i==0) l=i;
	}
	int shu=-1;
	for(int i=0;i<=60/l;i++){
		if((60*i+c)%(a+b)>0&&(60*i+c)%(a+b)<=a){
			shu=i;
			break;
		}
	}
	if(shu==-1) cout<<-1;
	else cout<<60*shu+c;
    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,n=1,T[4000];
  
  cin>>a>>b>>c;
  while(n<4000){
    for(int i=0;i<a;i++,n++)T[n]=1;
    for(int i=0;i<b;i++,n++)T[n]=0;
    if(n>3800)break;
  }

  for(int i=c;i<4000;i+=60){
    if(T[i]==1){
      cout<<i<<endl;
      break;
    }
    if(i>3600){
      cout<<"-1"<<endl;
      break;
    }
  }
  return 0;
}