Problem:
A 君は山手線に乗って目的地にたどり着きたい．
A 君は電車に乗ってから
a
分起きて
b
分寝ることを繰り返す．目的地までは乗車後
c
分であり，このとき起きていれば下車できるが，逆に寝ている途中であれば乗り過ごしてしまう．また，A 君は乗り過ごしてもずっと同じ電車に乗り続け，電車は山手線を一周するのに
60
分かかる．したがって，A 君は目的地に
60t + c
(
t
は非負整数) 分後に着くことになる．
何分後にA 君は目的地に到着できるか．到着不可能なときは-1 を出力せよ．ただし，目的地に到着した時が寝ている時間と起きている時間の境目だった場合は降りることができるものとする．
Input
入力は以下の形式で1 行で与えられる．
a
b
c
入力は3 つの整数
a, b, c
からなる．
a
は起きている時間，
b
は寝ている時間，
c
は乗車してから目的地までにかかる時間である．また，
a, b, c
の単位は分である．
Constraints
0 <
a, b, c
< 60
Output
A 君が目的地に到着できる場合はA 君の目的地到着までにかかる時間を出力せよ．それ以外の場合は-1 を出力せよ．
Sample Input 1
10 10 5
Output for the Sample Input 1
5
寝る前に目的地にたどり着く．
Sample Input 2
50 40 51
Output for the Sample Input 2
111
一回乗り過ごしてしまう．
Sample Input 3
20 20 20
Output for the Sample Input 3
20
もうちょっとで寝るところだったがなんとか目的地で起きていられた．
Sample Input 4
30 30 40
Output for the Sample Input 4
-1
一周の前半では起きているが後半で寝ているということを繰り返す．
このため目的地にはたどり着けない．

Submitted solutions:

code_snippet: #include <iostream>
#include<string.h>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include<math.h>


using namespace std;


int main()
{
    int sleep;
    int wake;
    int stop;

    cin >> wake >> sleep >> stop;
    while (1) {
        if (stop <= wake % 60) {
            wake = wake / 60;
            stop = wake * 60 + stop;
            break;
        }
        if (wake % 60 == 0 || (wake + sleep) % 60 == 0) {
            stop = -1;
            break;
        }

        wake = wake + sleep;


    }


    cout << stop << endl;
}
accuracy: 0.1111111111111111
time_ms: 210
memory_kb: 3092
final_rank: 14

code_snippet: #include <iostream>
#include<string.h>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include<math.h>


using namespace std;


int main()
{
    int sleep;
    int wake;
    int stop;
    int time;
    cin >> wake >> sleep >> stop;
    time = wake;
    while (1) {

        if (stop <= (time % 60)) {


            time = time / 60;
            time = time * 60;


            stop = time + stop;
            cout << stop << endl;
            return 0;
        }
        time = time + wake;
        if ((time % 60) == 0) {
            stop = -1;
            cout << stop << endl;


            return 0;
        }

        time = time + sleep;


    }


    cout << stop << endl;
}
accuracy: 0.027777777777777776
time_ms: 540
memory_kb: 3096
final_rank: 20

code_snippet: #include <iostream>
#include<string.h>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include<math.h>


using namespace std;


int main()
{
    int sleep;
    int wake;
    int stop;

    cin >> wake >> sleep >> stop;
    while (1) {
        if (stop <= wake % 60) {
            wake = wake / 60;
            stop = wake * 60 + stop;
            break;
        }
        if (wake % 60 == 0 || (wake + sleep) % 60== 0) {
            stop == 0;
            break;
        }

        wake = wake + sleep;


    }

    if (stop == 0) {
        cout << -1 << endl;
        return 0;
    }
    cout << stop << endl;
}
accuracy: 0.08333333333333333
time_ms: 210
memory_kb: 3092
final_rank: 18

code_snippet: #include <bits/stdc++.h>
//#include <atcoder/all>
//using namespace atcoder;
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
#define all(A) A.begin(),A.end()
#define rep(i, n) for (ll i = 0; i < (ll) (n); i++)
using pqr = priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>;

vector<ll> fact, factinv, inv;
ll mod = 998244353;
void prenCkModp(ll n) {
    fact.resize(n + 5);
    factinv.resize(n + 5);
    inv.resize(n + 5);
    fact.at(0) = fact.at(1) = 1;
    factinv.at(0) = factinv.at(1) = 1;
    inv.at(1) = 1;
    for (ll i = 2; i < n + 5; i++) {
        fact.at(i) = (fact.at(i - 1) * i) % mod;
        inv.at(i) = mod - (inv.at(mod % i) * (mod / i)) % mod;
        factinv.at(i) = (factinv.at(i - 1) * inv.at(i)) % mod;
    }

}
ll nCk(ll n, ll k) {
    if (n < k) return 0;
    return fact.at(n) * (factinv.at(k) * factinv.at(n - k) % mod) % mod;
}

bool chmax(ll& p, ll q) {
    if (p < q) {
        p = q;
        return 1;
    }
    else {
        return 0;
    }
}

bool chmin(ll& p, ll q) {
    if (p > q) {
        p = q;
        return 1;
    }
    else {
        return 0;
    }
}

ll sti(string S){
    ll res=0;
    rep(i,S.size()){
        res+=S[i]-'0';
        res*=10;
    }
    return res/10;
}

string ist(ll n,ll L){
    string res="";
    rep(l,L)res+='0';
    ll p=L-1;
    while(n>0){
        res[p]=char(n%10+'0');
        p--;
        n/=10;
    }
    return res;
}


int main() {
    //cin.tie(nullptr);
    //ios::sync_with_stdio(false);
    

    ll P,Q,R;
    cin>>P>>Q>>R;

    ll t=0;
    while(t<1e7){
        if((t+(60-R))%60==0){
            cout<<t<<endl;
            return 0;
        }
        if((t+Q)%(P+Q)==0){
            t+=Q;
        }
        else{
            t++;
        }
    }
    cout<<-1<<endl;

    
}
accuracy: 1
time_ms: 70
memory_kb: 3476
final_rank: 5

code_snippet: #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
typedef long long ll;
using namespace std;

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

    int cnt = 1e7;
    while (cnt--) {
        int now = c / (a + b);
        if (c - (now * (a + b)) <= a) {
            cout << c << endl;
            return 0;
        }
        c += 60;
    }
    cout << -1 << endl;

    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3428
final_rank: 4

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
    ll a, b, c;
    cin >> a >> b >> c;
    ll kukan = a + b;

    for(ll t = 0; t <= 1000000000; t++){
        ll ans = 60 * t + c;
        if(ans <= a){
            cout << ans << endl;
            return 0;
        }
        a = kukan + a;
    }

    cout << -1 << endl;
}
accuracy: 0.1111111111111111
time_ms: 420
memory_kb: 3436
final_rank: 17

code_snippet: #include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<ll, ll>;
const long double PI = acos(-1.0L);
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

int a, b, c;

int main() {
    cin >> a >> b >> c;
    int g = GCD(60, a+b);
    if(g == 60 || g == a+b) {
        if((c%(a+b)) <= a) cout << c << endl;
        else cout << -1 << endl;
    }else {
        int now = 0;
        while(1) {
            if((c+60*now)%(a+b) <= a) break;
            now++;
        }
        cout << 60*now+c << endl;
    }
}
accuracy: 0.25
time_ms: 80
memory_kb: 3116
final_rank: 9

code_snippet: #include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
#define DEBUG
#ifdef DEBUG
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << '{';
    for(int i = 0; i < (int)v.size(); i++) {
        if(i) {
            os << ',';
        }
        os << v[i];
    }
    os << '}';
    return os;
}
void debugg() { cerr << endl; }
template <class T, class... Args>
void debugg(const T &x, const Args &... args) {
    cerr << " " << x;
    debugg(args...);
}
#define debug(...)                                                             \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]: ", debugg(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

struct Setup {
    Setup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
    }
} __Setup;

using ll = long long;
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if(a + b == 60 && a < c) {
        cout << -1 << endl;
        return 0;
    }
    int now = 0;
    for(int t = 0;; t++) {
        int time = 60 * t + c;
        if(now <= time && time <= now + a) {
            cout << 60 * t + c << endl;
            return 0;
        }
        now += a + b;
    }
}
accuracy: 0.1111111111111111
time_ms: 30
memory_kb: 3372
final_rank: 16

code_snippet: #include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
//typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
    int a,b,c; cin >> a >> b >> c;
    if(60 % (a+b) == 0){
        int now = 0;
        while(now < 60){
            if(now <= c && c <= now+a){
                cout << c << endl;
                return 0;
            }
            now += a+b;
        }
        cout << -1 << endl;
        return 0;
    }else{
        int now = 0;
        while(1){
            if(now%60 < (now+a)%60){
                if(now%60 <= c && c <= (now+a)%60){
                    cout << now+c-now%60 << endl;
                    return 0;
                }
            }else{
                if(c >= now%60 || c <= (now+a)%60){
                    if(c >= now%60){
                        cout << now+c-now%60 << endl;
                    }else{
                        cout << now+c+60-now%60 << endl;
                    }
                    return 0;
                }
            }
            now += a+b;
        }
    }
}
accuracy: 0.25
time_ms: 90
memory_kb: 3088
final_rank: 8

code_snippet: #include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
//typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
    int a,b,c; cin >> a >> b >> c;
    if((a+b) % 60 == 0){
        if(0 <= c && c <= a){
            cout << c << endl;
        }else{
            cout << -1 << endl;
        }
    }else{
        int now = 0;
        while(1){
            if(now%60 < (now+a)%60){
                if(now%60 <= c && c <= (now+a)%60){
                    cout << now+c-now%60 << endl;
                    return 0;
                }
            }else{
                if(c >= now%60 || c <= (now+a)%60){
                    if(c >= now%60){
                        cout << now+c-now%60 << endl;
                    }else{
                        cout << now+c+60-now%60 << endl;
                    }
                    return 0;
                }
            }
            now += a+b;
        }
    }
}
accuracy: 0.25
time_ms: 100
memory_kb: 3080
final_rank: 7

code_snippet: #include <bits/stdc++.h>
using namespace std;
int main(void){
    int a,b,c;
    cin>>a>>b>>c;
    long long int count=0;
    long long int now=0;
    long long int ans=0;
    while (1) {
        if (count==10000000) {
            cout<<-1<<endl;
            break;
        } else {
            if (now<c&&now+a>=c) {
                cout<<ans+c-now<<endl;
                break;
            } else {
                now+=a+b;
                ans+=a+b;
                if (now>=60) {
                    now-=60;
                }
                count++;
            }
        }
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3108
final_rank: 1

code_snippet: #include <bits/stdc++.h>
using namespace std;
int main(void){
    int a,b,c;
    cin>>a>>b>>c;
    long long int count=0;
    long long int now=0;
    long long int ans=0;
    while (1) {
        if (count==10000000) {
            cout<<-1<<endl;
            break;
        } else {
            if (now<c&&now+a>=c) {
                cout<<ans+c<<endl;
                break;
            } else {
                now+=a+b;
                ans+=a+b;
                if (now>=60) {
                    now-=60;
                    c-=now;
                }
                count++;
            }
        }
    }
}
accuracy: 0.027777777777777776
time_ms: 20
memory_kb: 3076
final_rank: 19

code_snippet: #include <bits/stdc++.h>
using namespace std;
int main(void){
    int a,b,c;
    cin>>a>>b>>c;
    long long int count=0;
    int now=0;
    int ans=0;
    int flag=0;
    while (1) {
        if (count==100000000) {
            cout<<-1<<endl;
            break;
        } else {
            if (now+a>=c) {
                if (flag==0) {
                    cout<<c<<endl;
                    break;
                } else {
                    cout<<ans+c-now<<endl;
                    break;
                }
            } else {
                now+=a+b;
                ans+=a+b;
                if (now>=60) {
                    now-=60;
                    flag=1;
                }
            }
            count++;
        }
    }
}
accuracy: 0.1111111111111111
time_ms: 60
memory_kb: 3088
final_rank: 13

code_snippet: #include <bits/stdc++.h>
using namespace std;
int main(void){
    int a,b,c;
    cin>>a>>b>>c;
    long long int count=0;
    int tmp=0;
    while (1) {
        if (count==100000000) {
            cout<<-1<<endl;
            break;
        } else {
            if (a+tmp>=c) {
                cout<<c+count*60<<endl;
                break;
            } else {
                if (a+b>=60) {
                    tmp=a+b-60;
                } else {
                    tmp=a+b;
                }
            }
            count++;
        }
    }
}
accuracy: 0.19444444444444445
time_ms: 30
memory_kb: 3108
final_rank: 12

code_snippet: #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;
  if(60%(a+b)==0&&c%(a+b)>b)
  {cout << -1 << endl;return;}
  int l=0,r=a;
  while(true){
    int v=l/60*60;
    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;
}
accuracy: 0.25
time_ms: 260
memory_kb: 3160
final_rank: 11

code_snippet: #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;
  if(a+b==60&&c>b){
    cout << -1 << endl;return;
  }
  int l=0,r=a;
  while(true){
    if(l%60<=c&&c<=r%60)
    {cout << c+l/60*60 << endl; return;}
    l+=b;r+=b;
  }
  
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}
accuracy: 0.1111111111111111
time_ms: 190
memory_kb: 3204
final_rank: 15

code_snippet: /* monkukui 競技プログラミング用のテンプレート  (ここから) */
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
using ll = long long int;
using lnt = long long int;
using graph = vector<vector<int>>;
using wgraph = vector<vector<pair<int, long long int>>>;
long long int INF = 1001001001001001LL;
int inf = 100100100;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;
long long int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
long long int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
inline void yes(){ cout << "yes" << endl; }
inline void Yes(){ cout << "Yes" << endl; }
inline void YES(){ cout << "YES" << endl; }
inline void no(){ cout << "no" << endl; }
inline void No(){ cout << "No" << endl; }
inline void NO(){ cout << "NO" << endl; }
inline void possible(){ cout << "possible" << endl; }
inline void Possible(){ cout << "Possible" << endl; }
inline void POSSIBLE(){ cout << "POSSIBLE" << endl; }
inline void impossible(){ cout << "impossible" << endl; }
inline void Impossible(){ cout << "Impossible" << endl; }
inline void IMPOSSIBLE(){ cout << "IMPOSSIBLE" << endl; }

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define drep(i,n) for(int i = (n)-1; i >= 0; i--)
#define srep(i,s,t) for(int i = s; i < t; i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back

/* monkukui 競技プログラミング用のテンプレート (ここまで)*/

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

  for(int t = 0; t <= 10000000; t++) {
    if((60 * t + c) % (a + b) <= a) {
      cout << 60 * t + c << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3112
final_rank: 2

code_snippet: /* monkukui 競技プログラミング用のテンプレート  (ここから) */
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
using ll = long long int;
using lnt = long long int;
using graph = vector<vector<int>>;
using wgraph = vector<vector<pair<int, long long int>>>;
long long int INF = 1001001001001001LL;
int inf = 100100100;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;
long long int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
long long int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
inline void yes(){ cout << "yes" << endl; }
inline void Yes(){ cout << "Yes" << endl; }
inline void YES(){ cout << "YES" << endl; }
inline void no(){ cout << "no" << endl; }
inline void No(){ cout << "No" << endl; }
inline void NO(){ cout << "NO" << endl; }
inline void possible(){ cout << "possible" << endl; }
inline void Possible(){ cout << "Possible" << endl; }
inline void POSSIBLE(){ cout << "POSSIBLE" << endl; }
inline void impossible(){ cout << "impossible" << endl; }
inline void Impossible(){ cout << "Impossible" << endl; }
inline void IMPOSSIBLE(){ cout << "IMPOSSIBLE" << endl; }

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define drep(i,n) for(int i = (n)-1; i >= 0; i--)
#define srep(i,s,t) for(int i = s; i < t; i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back

/* monkukui 競技プログラミング用のテンプレート (ここまで)*/

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


  for(int t = 0; t <= 10000000; t++) {
    if((60 * t + c) % (a + b) <= a) {
      cout << 60 * t + c << endl;
      return 0;
    }
  }
  return 0;
}
accuracy: 0.25
time_ms: 20
memory_kb: 3080
final_rank: 6

code_snippet: #include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int A,B,C;
    cin >> A >> B >> C;
    if(A + B == 60 && A < C){
        cout << -1 << endl;
        return 0;
    }
    int time = 0;
    while(1){
        int l = time % 60;
        int r = (time + A) % 60;
        /*
        int next = time + C;
        if(next >= l && next <= r){
            cout << next << endl;
            return 0;
        }
        */
        
        if  (l < r && C >= l && C <= r || 
             l > r && ( (C >= l && C <= 60) || (C >= 0 && C <= r)) ){
            cout << time + C - time % 60 << endl;
            //cout << time << endl;
            return 0;
        }
        
        time += A + B;
    }
}
accuracy: 0.25
time_ms: 280
memory_kb: 3092
final_rank: 10

code_snippet: #include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
int main(void) {
    long long a, b, c;
    cin >> a >> b >> c;
    long long now = 0;
    for (int i = 0; i < 10000000; i++) {
        if (c % (a + b) <= a) {
            cout << c << endl;
            return 0;
        }
        c += 60;
    }
    cout << -1 << endl;
    return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 3112
final_rank: 3