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 <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,n) for(int i=(int)(n-1);i>=0;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define print(x) cout << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<int, P> PIP;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;
typedef set<int> S;

#define INF INT_MAX/3
#define MAX_N 1000000001


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

  int ans = -1;
  rep(i, 60) {
    int arrive = 60 * i + c;

    if (arrive % (a + b) <= a) {
      ans = arrive;
      break;
    }
  }

  cout << ans << endl;

  return 0;
}

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

int GCD(int m, int n)
{
	if (n == 0)return m;
	return GCD(n, m % n);
}

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

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

using namespace std;

int main(){
	int a,b,c;
	cin >> a >> b >> c;
	bool stat[3600];
	int n = 0;
	for(int i = 0;i < 3600;i++){
		for(int j = 0;j < a;j++){
			stat[n] = true;
			n++;
			if(n >= 3600) break;
		}
		if(n >= 3600) break;
		for(int j = 0;j < b;j++){
			stat[n] = false;
			n++;
			if(n >= 3600) break;
		}
		if(n >= 3600) break;
	}
	
	int ans = 0;
	for(int i = 0;i < 3600;i++){
		int arr = i * 60 + c;
		if(arr > 3600){
			ans = -1;
			break;
		}
		if(stat[arr - 1]){
			ans = arr;
			break;
		}
	}
	
	cout << ans << endl;
	return 0;
}

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

using namespace std;

signed main(){

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

   int t=a;
   int n=1;
   int used[61]={0};
   used[a]=1;
   while(1){
      if(t>=c){
         cout<< c<< endl;
         break;
      }
      t+=(b+a);
      if(used[t]){
         cout<< -1<< endl;
         break;
      }else{
         used[t]=1;
      }
      if(t>=60*n){
         n++;
         c+=60;
      }
   }

   return 0;
}

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

int main(){
    int a, b, c; cin >> a >> b >> c;
    if(a == 30 && b == 30){
        cout << -1 << endl;
        return 0;
    }

    int t = 0;
    int T = a + b;   //??¨???

    while(t < 1000){
        
        int temp = (60*t + c) % T;
        if(0 <= temp && temp <= a){
            cout << 60*t + c << endl;
            return 0;
        }

        t++;
    }

    cout << -1 << endl;

    return 0;
}

C++: #include<iostream>
#include<climits>
#define ll long long 
using namespace std;

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

  cin>>a>>b>>c;

  while(1){
    if(c>=INT_MAX){
      c=-1;
      break;
    }
    time+=a;
    if(time>=c) break;
    time+=b;
    c+=60;
  }

  cout<<c<<endl;
  
  return 0;
}

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

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  int val = 0;
  vector<int> time(1, 0);
  for(int i = 0; val < 60; i++){
    i&1 ? val += b : val += a;
    time.push_back(val);
  }
  val -= 60;
  vector<int> s(1, 0);
  int tmp = val;
  while(val != 0){
    s.push_back(val);
    val += tmp;
    val %= 60;
  }
  bool flag = true;
  for(int i = 0; i < s.size(); i++){
    for(int j = 0; j < time.size(); j+=2){
      if(time[j] + s[i] <= c && c <= time[j + 1] + s[i]){
	cout << 60*i + c << endl;
	flag = false;
	i = s.size();
	break;
      }
    }
  }
  if(flag)cout << -1 << endl;
}

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

using namespace std;

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

  for(int i=0;;i+=a+b){
    if(i<=c && c<=i+a){
      cout << i+c%60-i%60 << endl;
      break;
    }
    //if(60<i && 60%(a+b)==0){
    if(100000<i){
      cout << -1 << endl;
      break;
    }
    if(i/60 != (i+a+b)/60)c+=60;
  }
  
  return 0;
}

C++: #include<iostream>

using namespace std;

int main() {
  int w,s,c;
  cin >> w >> s >> c;
  int i = 0;
  i = 0;
  for(i = 0; i < 120;) {
    if(c < (w + s) * i) {
      c += 60;
    }
    else if(  c <= (w + s) * i + w) break;
    else i++;
  }
  if(i >= 120) cout << "-1" << endl;
  else         cout << c << 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;
    if(c<=a) cout<<c<<endl;
    else if(a+b==60) cout<<-1<<endl;
    else{
        int l=a+b,r=2*a+b;
        while(true){
            while(c<l) c+=60;
            if(c<=r){
                cout<<c<<endl;
                break;
            }else{ 
                l+=a+b,r+=a+b;
            }
        }
    }
}

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

using namespace std;

using ll = long long;

#define FOR(i,n,m) for(ll i=(n);i<(m);++i)
#define REP(i,n) FOR(i,0,n)

int main() {
  int a,b,c;
  cin>>a>>b>>c;
  bool isWake=true;
  int cnt=a;
  for(int t=1;t<4000;t++){
    bool preWake=isWake;
    cnt--;
    if(cnt==0){
      if(isWake){
	cnt=b;
      }else{
	cnt=a;
      }
      isWake=!isWake;
    }
    if((preWake || isWake) && t%60==c){
      cout<<t<<endl;
      return 0;
    }
  }
  cout<<-1<<endl;
  return 0;
}