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

int main(){
    int a,b,c,sum=0,n=0;
    cin >> a >> b >> c;
    
    if(60 % (a+b) == 0 && a < c){
        printf("-1\n");
    }else{
        while(1){
            n += a; sum+=a;
            if(n>c){
                cout << sum-(n-c) << endl;
                break;
            }
            n += b; sum+=b;
            if(n > 60)
                n -= 60;
            
        }
    }
    
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<ll,ll> P;
const ll MOD=1000000007LL;
const double INF=1000000000;
const int MAX=100001;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    bool f=true;
    for(int i=c;i<=3600+c;i+=60){
        if(i%(a+b)<=a){
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
    return 0;
}

C++: /*--------------------------------------------------------
テ」ツδ敕」ツδォテ」ツδウテ」ツつャテ」ツ?ョテ」ツつイテ」ツδシテ」ツδ?・ツョツ淌ヲツウツ?
  https://www.youtube.com/user/oXpolungaXo

テッツシツ榲ッツシツ榲」ツδ?」ツδ」テ」ツδウテ」ツδ催」ツδォテァツ卍サテゥツ個イテ」ツ?甘ゥツ。ツ佚」ツ??」ツ?療」ツ?セテ」ツ?凖ッツシツ?ッツシツ?ッツシツ愿ッツシツ?
  --------------------------------------------------------*/


#include<bits/stdc++.h>
using namespace std;
int memo[61][2];
int main(){
  int A,B,C;
  cin >> A >> B >> C;
  int time = 0,ok=1;
  int res = 0;
  bool f = false;
  while( !memo[time][ok] ){
    memo[time][ok] = 1;   
    for(int i=1;i<=60;i++){
      time++;
      //      cout << time << " " << ok << endl;
      if( ok == 1 ) {
        if( C == i ) {
          res += i;
          f = true; break;
        }            
        if( time == A ) {
          time = 0; ok = 0;
        }
      } else if( time == B ){
        time = 0; ok = 1;
      }                  
    }
    if( f ) break;
    res += 60;
  }
  if( f ) cout << res << endl;
  else cout << -1 << endl;
}

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

using namespace std;

typedef pair<int,int> pii;
typedef vector<int> vi;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 999999999

int main(){
    int a,b,c;
    while(cin>>a>>b>>c){
        bool f=true;
        int now=0;
        for(int i=0;i<10000000;i++){
            if(now<=c+i*60&&c+i*60<=now+a){
                cout<<c+i*60<<endl;
                f=false;
                break;
            }
            now+=a+b;
        }
        if(f)cout<<"-1"<<endl;
    }
}

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

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

  if (a + b == 60) {
    if (c <= a)
      cout << c << endl;
    else
      cout << -1 << endl;
  } else {
    if (c <= a)
      cout << c << endl;
    else {
      int t = a + b;
      for (; ;) {
	c += 60;
	if (c % t <= a) {
	  cout << c << endl;
	  break;
	}
      }
    }
  }
  return 0;
}

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

int solve(int a, int b, int c) {
    int rem[60];
    fill(rem, rem + 60, -1);
    int t = 0;
    while (rem[t%60] < 0) {
        if (t % 60 <= c && c <= t % 60 + a) {
            return t + (c - t % 60);
        } else {
            rem[t%60] = t;
            t += a + b;
        }
    }
    return -1;
}

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    cout << solve(a, b, c) << endl;
    return 0;
}

C++: #include <cstdio>

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

C++: #include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;

int a,b,c;
int main() {
    cin>>a>>b>>c;
    int t=0;
    int ans=0;

    while(1) {
        rep(i,a) {
            t++;
            ans++;
            t%=60;
            if(t==c) {
                cout<<ans<<endl;
                return 0;
            }
        }
        t+=b;
        ans+=b;
        t%=60;
        if(t==0) {
            cout<<"-1"<<endl;
            return 0;
        }
    }



    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) || (k <= c+60 && c+60 <= k+a)) {
      printf("%d\n", ans*60 + c);
      return 0;
    }

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

C++: #include <iostream>

using namespace std;


int main(){
	int a, b, c;
	cin>>a>>b>>c;
	int t = (a+b)/60;
	int p = 1;
	while(p*(a+b)<60*t+c){
		p *= (a+b);
	}
	int ans;
	if(60*t+c<p+a) ans = 60*t+c;
	else ans = -1;

	cout<<ans<<endl;	
}

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

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

  int T = -1;
  for (int t = 0; t < 60; t++) {
    if ((60 * t + c) % (a + b) <= a) {
      T = 60 * t + c;
      break;
    }
  }

  cout << T << endl;

  return 0;
}

C++: #include<cstdio>
main(){int a,b,c,d;scanf("%d%d%d", &a, &b, &c);c-=60;d=a+b;
while((c+=60)<3600)
if(0<=c%d&&c%d<=a)
break;
printf("%d\n",c>3599?-1:c);}