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 <vector>

using std::cin;
using std::cout;
using std::endl;

bool check_vec(std::vector<int> v, int t) {
	for (std::vector<int>::iterator itr = v.begin(); itr != v.end(); ++itr) {
		if (*itr == t) {
			return true;
		}
	}
	return false;
}

int main(void) {
	int a,b,c;
	cin >> a >> b >> c;
	
	bool awake = true;
	bool loop = false;
	bool goal = false;
	std::vector<int> ta,ts;
	int t = 0;
	int cycle = 0;

	for (int i = 1; !(goal) && !(loop); i++) {
		if (i%60 == 0) {
			cycle = 0;
		}
		t++;
		cycle++;
		if (awake) {
			if (i%60 == c) {
				goal = true;
				cout << i << endl;
			}
			if (t == a) {
				awake = false;
				if (check_vec(ts,cycle)) {
					cout << -1 << endl;
					loop = true;
				}
				else {
					ts.push_back(cycle);
				}
				t = 0;
			}
		}
		if (!(awake) && t == b) {
			awake = true;
			t = 0;
			if (check_vec(ta,cycle)) {
				cout << -1 << endl;
				loop = true;
			}
			else {
				ta.push_back(cycle);
			}
		}
	}
	return 0;
}

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

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

	int s=a+b;
	int ans=0;

	//????????????????????????????????§??????????????¢?´¢
	rep(t,5000000)
	{
		int now=60*t+c;
		if(now%s<=a)
		{
			ans=now;
			break;
		}

	}

	if(ans==0) ans=-1;

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

C++: #include<iostream>


#define FOR(i,a,b) for(int i = a;i < b;i++)
#define RFOR(i,a,b) for(int i = a;i >= b;i--)
#define IN cin >> 
#define OUT cout <<
#define E  << endl;

using namespace std;


int goal_time = 0;

int a, b, c;

int x = 0;

void input() {
	IN a >> b >> c;
}

int main() {
	input();
	int memo = 0;

	x = 60.0 / (a + b);
	if (x == 0)x = 1;

	bool flag = false;
	goal_time += c;
	while (true) {
		int n = memo;
		while (true){
			if ((a + b) * n <= goal_time && (a + b) * n + a >= goal_time) {
				OUT goal_time E
				flag = true;
				break;
			}
			if ((a + b) * n > goal_time) {
				memo = n;
				break;
			}
			if (n > 5000) {
				OUT -1 E
				flag = true;
				break;
			}
			n += 1;
			if (goal_time > 60) {
				if ((60 % (a + b) == 0) && c > a) {
					OUT - 1 E
						return 0;
				}
			}

		}
		if (flag)break;
		goal_time += 60;
	}
	

	return 0;
}

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

int main(){
  int a,b,c;
  scanf("%d %d %d",&a,&b,&c);
  
  int t = a + b; //??¨???(???+???)
  
  if(0<=c && c<=a){
    printf("%d\n",c);
  }
  
  else if(t%60==0){
    puts("-1");
  }
  
  else{
    int n=1;
    for(;;){
      if(c < n*t)
	while(c+60 <= n*t+a){
	  c+=60;
	}
      if(c < n*t)
	n++;
      else
	break;
    }

    printf("%d\n",c);
  }
}

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++<10000000){ 
    if(sum%60+a<c)sum+=a+b;
    else ans=sum+(c-sum%60);
  }
  cout <<ans<<endl;
  return 0;
}

C++: #include <cstdio>

int main() {
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);

  for (int t = 0; t < 6000; ++t) {
    bool awaken = (t % (a+b) <= a);
    if (!awaken) continue;
    if (t % 60 == c) return !printf("%d\n", t);
  }
  puts("-1");
}

C++: #include <bits/stdc++.h>
 
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INF=INT_MAX;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))


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

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

int a, b, c;
int solve() {
    int s = 0;
    int e = (a % 60);

    int cycle = 0;
    std::set<int> waked;
    while(true) {
        std::cout << s << "<-" << c << "->" << e << std::endl;
        if(waked.count(s) > 0) {
            return -1;
        }
        waked.insert(s);

        bool f = s <= e ? (s <= c && c <= e) : (s <= c || c <= e);
        if(f) break;

        s = (e + b) % 60;
        e = (s + a) % 60;
        ++cycle;
    }

    return std::max(cycle-1, 0)*60 + c;
}

int main() {
    std::cin >> a >> b >> c;
    std::cout << solve() << std::endl;
}