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>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

	bool used[60][2];
	memset(used, 0, sizeof(used));

	int cnt = 0, ans = 0;
	bool flag = true;
	while(true) {
		if(cnt & 1) {
			ans += b;
			if(used[ans%60][1]) {
				flag = false;
				break;
			}
			used[ans%60][1] = true;
		} else {
			if(ans % 60 + a >= 60 && ans % 60 <= c) {
				ans += c - ans % 60;
				break;
			}
			else if(c >= ans % 60 && (ans + a) % 60 >= c) {
				ans += c - ans % 60;
				break;
			} else {
				ans += a;
				if(used[ans%60][0]) {
					flag = false;
					break;
				}
				used[ans%60][0] = true;
			}
		}
		cnt++;
	}

	if(flag) cout << ans << endl;
	else cout << -1 << endl;

	return 0;
}

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

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

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
typedef pair<int,int> P;

//-----------------------------------------------------------------------

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int a,b,c;
    cin>>a>>b>>c;
    int ret=-1;
    REP(i,1e5){
        if(c%(a+b)<=a){
            ret=c;
            break;
        }else{
            c+=60;
        }
    }
    cout<<ret<<endl;
}

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

int main() {
	int a,b,c;
	cin>>a>>b>>c;
	int x=c;
	int t=0;
	if((a+b)==60){
		x=-1;
		cout<<x<<endl;
		return 0;
	}
	while(t<61){
		x=x-a;
		if(x<=0){
			cout<<(c+60*t)<<endl;
			return 0;
		}
		if(x<b){
			x=x+60-b;
			t++;
		}else if (x==b){
			cout<<(c+60*t)<<endl;
			return 0;
		}else{
			x=x-b;
			continue;
		}
	}
	return 0;
}

C++: #include <stdio.h>

int main(void) {
  int i, j, a, b, c, now = 0;
  scanf("%d%d%d", &a, &b, &c);
  while( 1 ) {
    if((now % 60) <= c && c <= now % 60 + a) {
      for(j = 0; j <= a; ++j) {
        if(now % 60 == c) break;
        ++now;
      }
      printf("%d\n", now);
      return 0;
    } else {
      now += a + b;
      if(!(now % 60)) {
        printf("-1\n");
        return 0;
      }
    }
  }
  return 0;
}

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

#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m);i>=(int)(n);--i)
#define debug(x) cout << #x << "=" << (x) << endl;

template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> void fail(T v){cout << v << endl;exit(0);}
//template end

void solve(){
  int a,b,c;
  cin>>a>>b>>c;
  int l=0,r=a;
  while(true){
    int v=l/60*60;
    if(v+c>(a+b)*60){cout << -1 << endl;return;}
    if(l<=v+c&&v+c<=r)
    {cout << v+c << endl;return;}
    l=r+b;
    r=l+a;
  }
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}

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

int a;
int b;
int c;
set<int> considered;

int main() {
  scanf("%d%d%d", &a, &b, &c);
  
  int k = 0;
  int ans = 0;
  while (1) {
    if (considered.count(k)) {
      puts("-1");
      return 0;
    }

    if (k <= c && c <= k+a) {
      printf("%d\n", ans*60 + c);
      return 0;
    }

    considered.insert(k);
    k = (k+a+b)%60;
    ans++;
  }
}

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;

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

int main() {
	input();
	int memo = 0;
	if ((60 / (a + b)) % 2 == 0 && c > a) {
		OUT - 1 E
		return 0;
	}
	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;
			}
			n++;
		}
		if (flag)break;
		goal_time += 60;
	}

	return 0;
}

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

C++: #include <cstdio>

int main() {
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);
  int t = 0;
  while (true) {
    if (c <= t+a) {
      printf("%d\n", c);
      break;
    }
    t += a+b;
    if (t > c) {
      if ((a+b)%60 == 0) {
        puts("-1");
        break;
      }
      c += 60;
    }
  }
  return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
	int a,b,c,w;
	cin>>a>>b>>c;
	while(true){
		if(c%(a+b)>a)
			c+=60;
		if(c%(a+b)<=a){
			w=c;
			break;
		}
		if(c>60*(a+c)){
			w=-1;
			break;
		}
	}
	cout<<w<<endl;
    return 0;
}