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"
#define pb push_back
#define mt make_tuple
#define all(a) (a).begin(),(a).end()
#define frep(i,a,n) for(int i=(a);i<(n);++i)
#define rep(i, n) for(int i=0;i<(n);++i)
#define rrep(i, n) for(int i=n-1;i>=0;--i)
#define debug(x) cout << #x << " : " << x << " ------------ " << endl;

using namespace std;

int mod(int a, int b) {
    int m = a % b;
    if (m < 0) {
        m += ceil(abs(m)/a) * a;
    }
    return m;
}
int main()
{
    int a,b,c;
    cin >> a >> b >> c;
    
    int d = c % (a + b);
    if (d <= a) {
        cout << c << endl;
        return 0;
    }
    int diff = 60 - a - b;
    if (diff == 0) {
        cout << -1 << endl;
        return 0;
    }
    int i = 1;
    int s = mod(c + i * diff, a + b);
    int m = s;
    while(m > a) {
        m = mod(c + ++i * diff, a + b);
        if (m == s) {
            i = 0;
            break;
        }
    }
    cout << (i > 0 ? (c + 60 * i) : -1) << endl;
    
    return EXIT_SUCCESS;
}

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

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

    int tim=0;
    while(true){
        if((tim%60<=c&&tim%60+a>=c)||(tim%60>=c&&(tim+a)%60)>=c&&tim%60>(tim+a)%60){
            while(tim%60!=c)tim++;
            cout<<tim<<endl;
            break;
        }
        tim+=a+b;
        if(tim%60==0){
            cout<<-1<<endl;
            break;
        }
    }

    return 0;
}

C++: #include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
using namespace std;
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	int i = 0;
	while (true) {
		int sum = (a + b)*i;
		if (c >= sum % 60 && c <= sum % 60+a) {
			sum = ceil(sum / c)*c;
			cout << sum << endl;
			break;
		}
		if (i >= 1000000) {
			cout << -1 << endl;
			break;
		}
		i++;
	}

}

C++: #include<bits/stdc++.h>
using namespace std;
#define lp(i,n) for(int i=0;i<n;i++)
#define lpin(a,i,n) for(int i=0;i<n;i++){cin>>a[i];}

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

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

int main()
{
  int a, b, c;
  cin >> a >> b >> c;
  int st, et, r;
  int d[60] = {};
  for(st = r = 0, et = a;; st = et + b, et = st + a, d[st] = et){
    if(st >= 60){
      st -= 60;
      et -= 60;
      r++;
    }
    if(c >= st && c <= et){
      cout << r*60+c << endl;
      break;
    }
    if(d[st] == et){
      cout << "-1" << endl;
      break;
    }
  }
}

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

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

    int tim=0;
    while(true){
        for(int i=0;i<=a;i++){
            if(tim%60==c){
                cout<<tim<<endl;
                return 0;
            }
            if(i==a)break;
            tim++;
        }
        tim+=b;
        if(tim%60==0){
            cout<<-1<<endl;
            break;
        }
    }

    return 0;
}

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

using ll=long long;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)

int read(){
	int i;
	scanf("%lld",&i);
	return i;
}

signed main(){
	int A=read(),B=read(),C=read();
	int time=0;
	bool sleep=false;
	int t=0;
	int i=0;
	while(i<1000){
		time += A;
		if(time >= C) break;
		time += B;
		if(time > C) C += 60;
		
		if(time == 60){
			cout << -1 << endl;
			return 0;
		}
		i++;
	}
	
	cout << C << endl;

}

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

int main(void){
    int awake, asleep, destination;
    cin >> awake >> asleep >> destination;

    int now = 0;
    int a = awake, b = 0;

    while(now < 1000){
        //if( now!=0 && now%60==0 && a==awake ){
        //    cout << -1 << endl;
        //    return 0;
        //}
        if( now%60==destination && (a!=0 || (a==0 && b==asleep))){
            cout << now << endl;
            return 0;
        }

        if(a){
            a--;
            now++;
            if(a == 0){
                b = asleep;
            }
        }else if(b){
            b--;
            now++;
            if(b == 0){
                a = asleep;
            }
        }
    }
    cout << -1 << endl;
    return 0;
}

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


int euc(int a,int b){
  if(a%b==0){return b;}
  return euc(b,a%b);
}


int main(){
  int a,b,c;
  cin>>a>>b>>c;
  int MX=euc(a+b,60);
  int ans=-1;
  int time=c;
  while(1){
    c%=a+b;
    if(c<=a){ans=time; break;}
    c+=60;
    time+=60;
    if(time>(a+b)*60/MX*2){break;}
  }
  cout<<ans<<endl;
  
  
  return 0;
}

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

int a, b, c;
int solve() {
    int s = 0, t = 0;

    std::vector<bool> waked(61, false);
    while(true) {
        if(waked[s]) {
            return -1;
        }
        waked[s] = true;

        if(s <= c && c <= s+a) {
            break;
        }

        t += (a + b);
        s = (a+b+s)%60;
    }
    return t + c - s;
}

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

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

int main(){
  int a, b, c, t = 0, e = 0, temp;
  int i, j, k;
  cin>>a>>b>>c;


  if(60%(a+b) == 0 && (a + b) <=  60){
    if(t <= c && c <= t + a){
      t = c;
    } else t = -1;

  } else{
      while(1){cout<<t<<endl;
      if(t%60 <= c && c <= t%60 + a){
      t = e * 60 + c ;
      break;
      }
      t += a + b;
      e++;
    }
  }

  
  cout<<t<<endl;
  return 0;
}