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

int main() {
    int N;
    int64_t ans = -1;
    cin >> N;
    vector<vector<int64_t>> v(N, vector<int64_t>(3));
    rep(i, N) {
        rep(j, 3) cin >> v.at(i).at(j);
        v.at(i).at(0) *= 2;
        if(v.at(i).at(0) < 2*v.at(i).at(2)-1) {
            if(ans == -1) ans = v.at(i).at(1);
            else ans = min(ans, v.at(i).at(1));
        }
    }
    cout << ans << endl;
}
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef std::vector<std::vector<int64_t> > Graph;

#define rep(i, n) for (int64_t i = 0; i < n; ++i)
#define rep2(i, n) for (int64_t i = 1; i <= n; ++i)
#define repb(i, l, n) for (int64_t i = l; i < n; ++i)
#define repb2(i, l, n) for (int64_t i = l; i <= n; ++i)
#define repc(i, l, n, d) for (int64_t i = l; i < n; i+=d)
#define repc2(i, l, n, d) for (int64_t i = l; i <= n; i+=d)
#define repi(a, b) for (auto&(a) : (b))
#define ALL(v) (v).begin(), (v).end()
#define Sort(x) sort(ALL(x))
#define Sort_rev(x) Sort(x);reverse(ALL(x))
#define Sort_pair(x, p) sort(ALL(x), (p))
#define mp(a, b) make_pair((a), (b))
#define Push_back(a, b) push_back( mp( (a), (b) ) )
#define ctoi(c) (c)-'0'

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;  } return 0;  }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;  } return 0;  }
template<typename V,typename T> bool find_num(V v, T num) { if ( find(ALL(v), num) == v.end() ) { return false; } return true; }

const int inf = 0x3fffffff;
const int64_t INF = 0x3fffffffffffffff;
const int64_t MOD = 1e9+7;

vector<int64_t> enum_div(int64_t n) {
    vector<int64_t> ret;
    for(int64_t i = 1; i*i <= n; ++i){
        if(n%i == 0){
            ret.push_back(i);
            if(i*i != n){
                ret.push_back(n/i);
            }
        }
    }
    return ret;
}

int main() {
    int64_t n;
    cin >> n;

    std::vector<int64_t> v = enum_div(2*n);
    int64_t ans = 0;
    rep(i, v.size()) {
        int64_t num = (2*n/v[i])-(v[i]-1);
        if (num%2 == 0) ++ans;
    }
    cout << ans << endl;
    return 0;
}
