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 <algorithm>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string>
#include <vector>

#define el endl
#define fd fixed
#define INF INT_MAX/2-1
#define pb push_back

using namespace std;

int main() {
  int a, b, c, waking = 0, arriving;
  bool flag = false;
  cin >> a >> b >> c;
  arriving = c;
  while (arriving < 3600+c) {
    while (waking < arriving) {
      if (waking <= arriving && arriving <= waking+a) {
        flag = true;
        break;
      }
      waking += a+b;
    }
    if (flag) break;
    arriving += 60;
  }
  if (flag) cout << arriving << el;
  else cout << "-1" << el;
}

C++: #include<iostream>
using namespace std;
int main() {
	int a, b, c; cin >> a >> b >> c;
	for (int i = c; i <= c + 3600; i += 60) {
		if (i % (a + b) <= a) {
			cout << i << endl;
			char c; cin >> c;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;
}

C++: #include <iostream>

using namespace std;

int gcd(int m, int n)
{
	while(1) {
		if (m == n) break;
		if (m > n) m = m - n;
		else n = n - m;
	}
	return m;
}

int lcm(int x, int y)
{
	return x * y / gcd(x, y);
}

int main(void)
{
	int a, b, c;
	cin >> a >> b >> c;
	int get = lcm(a + b, 60);
	int max = get / (a + b);
	int ans = - 1;
	for (int i = 0; i < max; i++) {
		if ((a + b) * i / 60 <= c && (a + b) * i / 60 + a >= c) {
			ans = (a + b) * i / 60 * 60 + c;
			break;
		}
	}

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

C++: #include <iostream>
#include <set>
#define llint long long

using namespace std;

llint a, b, c;

int main(void)
{
  cin >> a >> b >> c;
  llint p = a+b;
  for(int i = 0; i < 100; i++){
    if((60*i+c)%p <= a){
      cout << (60*i+c) << endl;
      return 0;
    }
  }
  cout << -1 << endl;

  return 0;
}

C++: #import<iostream>
int n,m,c,i;main(){std::cin<<n<<m<<c;for(i=0;i<99;i++){if(c%(n+m)<=n)goto a;c+=60;}c=-1;a:printf("%d\n",c);}

C++: #include <iostream>
using namespace std;
int main(){
  int a,b,c,as,af,end;
  cin >> a >> b >> c;
  as=0,af=a;
  end=c-af;
  while(1){
    if(as<=c&&c<=af){
      cout << c << endl;
      break;
    }
    as+=a+b,af+=a+b;
    if(as>c) c+=60;
    if(c-af==end){
      cout << -1 << endl;
      break;
    }
  }
  return 0;
}

C++: #include<iostream>
main(){
int n,m,b,c,i;
std::cin>>n>>m>>b;c=b;
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,i,j,s=0,s2=0,k=0;
	cin>>a>>b>>c;
	for(i=1;i<90;i++){
		s=0;
		for(j=1;j<=60;j++){
			s+=a+b;
			if(s-a-b<=c&&s-b>=c){k++;break;}
		}
		if(k==1)break;
		if(i==111){c=-1;break;}
		c+=60;
	}
	cout<<c<<endl;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c,i,j,s=0,s2=0,k=0;
	cin>>a>>b>>c;
	for(i=1;i<60;i++){
		s=0;
		for(j=1;j<=60;j++){
			s+=a+b;
			if(s-a-b<=c&&s-b>=c){k++;break;}
		}
		if(k==1)break;
		if(i==111){c=-1;break;}
		c+=60;
	}
	cout<<c<<endl;
}

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

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

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

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    int now=0;
    int cnt=0;
    while(cnt<100){
        now+=a;
        if(c<=now){
            cout<<c<<endl;
            return 0;
        }
        now+=b;
        if(now>=c) c+=60;
        cnt++;
    }
    cout<<-1<<endl;
    return 0;
}

C++: #include<iostream>
int main(){
int n,m,b,c;
std::cin>>n>>m>>b;c=b;
for(int i=0;i<199999999;i++){
if(c%(n+m)<=n){goto a;}
c+=60;
}
c=-1;
a:
std::cout<<c<<"\n";return 0;}

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

using namespace std;

int32_t main() {
  while (true) {
    uint32_t a, b, c;
    cin >> a >> b >> c;
    if (a == 0) break;

    if ((a + b) % 60 == 0)
      cout << -1 << endl;
    else {
      uint32_t n = 0;
      while (((60 * n + c) % (a + b)) > a) {
        n++;
      }
      cout << n * 60 + c << endl;
    }
  }

  return 0;
}

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

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

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



int main(){

  int a, b, c;

  cin >> a >> b >> c;

  int cnt = 0;

  int x1 = 0, x2 = a;
  int y1 = a, y2 = a+b;

  if(60 % (a+b) == 0){
    int cp = c;
    while(1){
      if(cp < y2 && cp > y1){
	cp += 60;
	cout << -1 << endl;
	break;
      }
      if(c >= x1 && c <= x2){
	
	cout << c << endl;
	break;
      }else{
	x1=x2+b;
	x2=x1+a;	
	y1= y2+a;
	y2=y1+b;
      }
      
    }

  }else {
    int cp = c;
    while(1){
      if(cp < y2 && cp > y1){
	cp += 60;
	//	cout << cp << endl;
	cnt++;
      }
      if(cp >= x1 && cp <= x2){
	cout << cp << endl;
	break;
      }else{
	x1=x2+b;
	x2=x1+a;
	y1= y2+a;
	y2=y1+b;
      }
    }
  }



}