/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . ___
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         ·ð×æ±£ÓÓ       ÓÀÎÞBUG
*/
//use readint!
#pragma GCC optimize(1)
#pragma G++ optimize(1)
#pragma GCC optimize(2)
#pragma G++ optimize(2)
#pragma GCC optimize(3)
#pragma G++ optimize(3)
#pragma GCC optimize(4)
#pragma G++ optimize(4)
#pragma GCC optimize(5)
#pragma G++ optimize(5)
#pragma GCC optimize(6)
#pragma G++ optimize(6)
#pragma GCC optimize(7)
#pragma G++ optimize(7)
#pragma GCC optimize(8)
#pragma G++ optimize(8)
#pragma GCC optimize(9)
#pragma G++ optimize(9)
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#include<map>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<set>
#include<cmath>
#include<stdio.h>
#include<fstream>
#include<assert.h>
#include<time.h>
#include<queue>
#include<deque>
#include<stack>
#include<list>
#include<string.h>
#define mp make_pair
#define ll long long
#define all(v) v.begin(),v.end()
#define memset(a,b) memset(a,b,sizeof(a))
using namespace std;
const int INF=1e9;
inline int pt(int a[],int l,int r){
	int p,i,j;
	p=a[l];
	i=l;
	j=r+1;
	for(;;){
		while(a[++i]<p) if(i>=r) break;
		while(a[--j]>p) if(j<=l) break;
		if(i>=j) break;
		else swap(a[i],a[j]);
	}
	if(j==l) return j;
	swap(a[l],a[j]);
	return j;
}
inline void q_sort(int a[],int l,int r){
	int q;
	if(r>l){
		q=pt(a,l,r);
		q_sort(a,l,q-1);
		q_sort(a,q+1,r);
	}
}
inline void rd(long long &val){
    long long x=0;
    int f=1;
    char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
	if(ch=='-'){
		f=-1;
		ch=getchar();
	}
    while(ch>='0'&&ch<='9'){
        x=x*10+ch-'0';
        ch=getchar();
    }
    val=x*f;
}
inline void quickSort(int s[],int l,int r)  {
    if(l<r){
        int i=l,j=r,x=s[l];
        while(i<j){
            while(i<j&&s[j]>=x) j--;
            if(i<j) s[i++]=s[j];
            while(i<j&&s[i]<x) i++;
            if(i<j) s[j--] = s[i];
        }
        s[i]=x;
        quickSort(s, l, i - 1);
        quickSort(s, i + 1, r);
    }
}
ll n;
ll dp[100005];
struct ring{
	ll a,b,h;
	inline bool operator <(const ring x){
		if(b>x.b) return 1;
		if(b<x.b) return 0;
		if(a<x.a) return 1;
		if(a>x.a) return 0;
		return h<x.h;
	}
}rings[100005];
int main(){
	ios_base::sync_with_stdio(false);
	int i,j;
	rd(n);
	rings[0].b=1000000009;
	for(i=1;i<=n;i++) rd(rings[i].a),rd(rings[i].b),rd(rings[i].h);
	sort(rings+1,rings+n+1);
/*	for(i=0;i<=n;i++){
		cout<<rings[i].a<<' '<<rings[i].b<<' '<<rings[i].h<<endl;
	}
*/	for(i=1;i<=n;i++){
		for(j=0;j<i;j++){
			if(rings[j].b>=rings[i].b&&rings[j].a<rings[i].b){
				dp[i]=max(dp[i],dp[j]+rings[i].h);
			}
		}
	}
	cout<<dp[n]<<endl;
	return 0;
}


/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . ___
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         ·ð×æ±£ÓÓ       ÓÀÎÞBUG
*/
//use readint!
#pragma GCC optimize(1)
#pragma G++ optimize(1)
#pragma GCC optimize(2)
#pragma G++ optimize(2)
#pragma GCC optimize(3)
#pragma G++ optimize(3)
#pragma GCC optimize(4)
#pragma G++ optimize(4)
#pragma GCC optimize(5)
#pragma G++ optimize(5)
#pragma GCC optimize(6)
#pragma G++ optimize(6)
#pragma GCC optimize(7)
#pragma G++ optimize(7)
#pragma GCC optimize(8)
#pragma G++ optimize(8)
#pragma GCC optimize(9)
#pragma G++ optimize(9)
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#include<map>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<set>
#include<cmath>
#include<stdio.h>
#include<fstream>
#include<assert.h>
#include<time.h>
#include<queue>
#include<deque>
#include<stack>
#include<list>
#include<string.h>
#define mp make_pair
#define ll long long
#define all(v) v.begin(),v.end()
#define memset(a,b) memset(a,b,sizeof(a))
using namespace std;
const int INF=1e9;
inline int pt(int a[],int l,int r){
	int p,i,j;
	p=a[l];
	i=l;
	j=r+1;
	for(;;){
		while(a[++i]<p) if(i>=r) break;
		while(a[--j]>p) if(j<=l) break;
		if(i>=j) break;
		else swap(a[i],a[j]);
	}
	if(j==l) return j;
	swap(a[l],a[j]);
	return j;
}
inline void q_sort(int a[],int l,int r){
	int q;
	if(r>l){
		q=pt(a,l,r);
		q_sort(a,l,q-1);
		q_sort(a,q+1,r);
	}
}
inline void rd(long long &val){
    long long x=0;
    int f=1;
    char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
	if(ch=='-'){
		f=-1;
		ch=getchar();
	}
    while(ch>='0'&&ch<='9'){
        x=x*10+ch-'0';
        ch=getchar();
    }
    val=x*f;
}
inline void quickSort(int s[],int l,int r)  {
    if(l<r){
        int i=l,j=r,x=s[l];
        while(i<j){
            while(i<j&&s[j]>=x) j--;
            if(i<j) s[i++]=s[j];
            while(i<j&&s[i]<x) i++;
            if(i<j) s[j--] = s[i];
        }
        s[i]=x;
        quickSort(s, l, i - 1);
        quickSort(s, i + 1, r);
    }
}
ll n;
ll dp[100005];
struct ring{
	ll a,b,h;
	inline bool operator <(const ring x){
		if(b>x.b) return 1;
		if(b<x.b) return 0;
		if(a<x.a) return 0;
		if(a>x.a) return 1;
		return h<x.h;
	}
}rings[100005];
int main(){
	ios_base::sync_with_stdio(false);
	int i,j;
	rd(n);
	rings[0].b=1000000009;
	for(i=1;i<=n;i++) rd(rings[i].a),rd(rings[i].b),rd(rings[i].h);
	sort(rings+1,rings+n+1);
/*	for(i=0;i<=n;i++){
		cout<<rings[i].a<<' '<<rings[i].b<<' '<<rings[i].h<<endl;
	}
*/	for(i=1;i<=n;i++){
		for(j=0;j<i;j++){
			if(rings[j].b>=rings[i].b&&rings[j].a<rings[i].b){
				dp[i]=max(dp[i],dp[j]+rings[i].h);
			}
		}
	}
	cout<<dp[n]<<endl;
	return 0;
}


/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . ___
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         ·ð×æ±£ÓÓ       ÓÀÎÞBUG
*/
//use readint!
#pragma GCC optimize(1)
#pragma G++ optimize(1)
#pragma GCC optimize(2)
#pragma G++ optimize(2)
#pragma GCC optimize(3)
#pragma G++ optimize(3)
#pragma GCC optimize(4)
#pragma G++ optimize(4)
#pragma GCC optimize(5)
#pragma G++ optimize(5)
#pragma GCC optimize(6)
#pragma G++ optimize(6)
#pragma GCC optimize(7)
#pragma G++ optimize(7)
#pragma GCC optimize(8)
#pragma G++ optimize(8)
#pragma GCC optimize(9)
#pragma G++ optimize(9)
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#include<map>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<set>
#include<cmath>
#include<stdio.h>
#include<fstream>
#include<assert.h>
#include<time.h>
#include<queue>
#include<deque>
#include<stack>
#include<list>
#include<string.h>
#define mp make_pair
#define ll long long
#define all(v) v.begin(),v.end()
#define memset(a,b) memset(a,b,sizeof(a))
using namespace std;
const int INF=1e9;
inline int pt(int a[],int l,int r){
	int p,i,j;
	p=a[l];
	i=l;
	j=r+1;
	for(;;){
		while(a[++i]<p) if(i>=r) break;
		while(a[--j]>p) if(j<=l) break;
		if(i>=j) break;
		else swap(a[i],a[j]);
	}
	if(j==l) return j;
	swap(a[l],a[j]);
	return j;
}
inline void q_sort(int a[],int l,int r){
	int q;
	if(r>l){
		q=pt(a,l,r);
		q_sort(a,l,q-1);
		q_sort(a,q+1,r);
	}
}
inline void rd(long long &val){
    long long x=0;
    int f=1;
    char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
	if(ch=='-'){
		f=-1;
		ch=getchar();
	}
    while(ch>='0'&&ch<='9'){
        x=x*10+ch-'0';
        ch=getchar();
    }
    val=x*f;
}
inline void quickSort(int s[],int l,int r)  {
    if(l<r){
        int i=l,j=r,x=s[l];
        while(i<j){
            while(i<j&&s[j]>=x) j--;
            if(i<j) s[i++]=s[j];
            while(i<j&&s[i]<x) i++;
            if(i<j) s[j--] = s[i];
        }
        s[i]=x;
        quickSort(s, l, i - 1);
        quickSort(s, i + 1, r);
    }
}
ll n,ans;
ll dp[100005];
struct ring{
	ll a,b,h;
	inline bool operator <(const ring x){
		if(b>x.b) return 1;
		if(b<x.b) return 0;
		if(a<x.a) return 0;
		if(a>x.a) return 1;
		return h<x.h;
	}
}rings[100005];
int main(){
	ios_base::sync_with_stdio(false);
	int i,j;
	rd(n);
	rings[0].b=1000000009;
	for(i=1;i<=n;i++) rd(rings[i].a),rd(rings[i].b),rd(rings[i].h);
	sort(rings+1,rings+n+1);
//	for(i=0;i<=n;i++){
//		cout<<rings[i].a<<' '<<rings[i].b<<' '<<rings[i].h<<endl;
//	}
	for(i=1;i<=n;i++){
		for(j=0;j<i;j++){
			if(rings[j].b>=rings[i].b&&rings[j].a<rings[i].b){
				dp[i]=max(dp[i],dp[j]+rings[i].h);
			}
		}
	}
	for(i=0;i<=n;i++) ans=max(ans,dp[i]);
	cout<<ans<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
struct data
{
    int a,b,h;
};
int n,f[100005],st[800005],b[200005],kq;
data c[100005];
bool cmp(data x,data y)
{
    if (x.a==y.a) return x.b<y.b;
    else return x.a<y.a;
}
int getmax(int id,int l,int r,int x,int y)
{
    if (r<x||l>y) return 0;
    else
        if (l>=x&&r<=y) return st[id];
        else
        {
            int mid=(l+r)/2;
            return max(getmax(id*2,l,mid,x,y),getmax(id*2+1,mid+1,r,x,y));
        }
}
void update(int id,int l,int r,int x,int y)
{
    if (l>x||r<x) return;
    else
        if (l==r) st[id]=y;
        else
        {
            int mid=(l+r)/2;
            update(id*2,l,mid,x,y);
            update(id*2+1,mid+1,r,x,y);
            st[id]=max(st[id*2],st[id*2+1]);
        }
}
void QHD()
{
    int cur=1;
    kq=c[1].h;
    update(1,1,2*1e5,c[1].b,c[1].h);
    for (int i=2;i<=n;i++)
    {
        //while (c[i].b<=c[cur].a) cur++;
        int x=getmax(1,1,2*1e5,c[i].a,c[i].b);
        f[i]=x+c[i].h;
        kq=max(kq,f[i]);
        update(1,1,2*1e5,c[i].b,f[i]);
    }
}
int main()
{
    cin>>n;
    for (int i=1;i<=n;i++)
        cin>>c[i].a>>c[i].b>>c[i].h;
    sort (c+1,c+1+n,cmp);
    QHD();
    cout<<kq;
}


#include <bits/stdc++.h>
using namespace std;
struct data
{
    long long a,b,h;
};
typedef pair <long long,long long> ii;
vector <ii> v;
long long n,f[100005],st[800005],kq;
data c[100005];
bool cmp(data x,data y)
{
    if (x.b==y.b) return x.a>y.a;
    else return x.b>y.b;
}
void shrink()
{
    for(int i=1; i<=n; i++)
    {
        v.push_back(ii(c[i].a,i));
        v.push_back(ii(c[i].b,i));
    }
    sort(v.begin(),v.end());
    int cur=v[0].first,gt=1;
    for (int i=0; i<2*n; i++)
    {
        if (v[i].first==cur)
            v[i].first=gt;
        else
        {
            cur=v[i].first;
            v[i].first=++gt;
        }
        swap(v[i].first,v[i].second);
    }
    sort(v.begin(),v.end());
    for (int i=0;i<n;i++)
    {
        c[i+1].a=v[2*i].second;
        c[i+1].b=v[2*i+1].second;
        //cout<<c[i+1].a<<" "<<c[i+1].b<<" "<<c[i+1].h<<"\n";
    }
}
long long getmax(int id,int l,int r,int x,int y)
{
    if (r<x||l>y) return 0LL;
    else if (l>=x&&r<=y) return st[id];
    else
    {
        int mid=(l+r)/2;
        return max(getmax(id*2,l,mid,x,y),getmax(id*2+1,mid+1,r,x,y));
    }
}
void update(int id,int l,int r,int x,long long y)
{
    if (l>x||r<x) return;
    else if (l==r) st[id]=max(st[id],y);
    else
    {
        int mid=(l+r)/2;
        update(id*2,l,mid,x,y);
        update(id*2+1,mid+1,r,x,y);
        st[id]=max(st[id*2],st[id*2+1]);
    }
}
void QHD()
{
    int cur=1;
    kq=c[1].h;
    update(1,1,2*1e5,c[1].a,c[1].h);
    for (int i=2; i<=n; i++)
    {
        //while (c[i].b<=c[cur].a) cur++;
        int x=getmax(1,1,2*1e5,1,c[i].b);
        f[i]=x+c[i].h;
        kq=max(kq,f[i]);
        update(1,1,2*1e5,c[i].a,f[i]);
    }
}
int main()
{
    cin>>n;
    for (int i=1; i<=n; i++)
        cin>>c[i].a>>c[i].b>>c[i].h;
    shrink();
    sort (c+1,c+1+n,cmp);
    QHD();
    cout<<kq;
}


#include <bits/stdc++.h>
using namespace std;
struct data
{
    int a,b,h;
};
int n,f[100005],kq;
data c[100005];
bool cmp(data x,data y)
{
    if (x.b==y.b) return x.a>y.a;
    else return x.b<y.b;
}
int npl(int x)
{
    int l=0,r=x-1;
    while (r-l>1)
    {
        int mid=(l+r)/2;
        if (c[mid].b<=c[x].b&&c[mid].b>c[x].a) r=mid;
        else l=mid;
    }
    return r;
}
int npr(int x)
{
    int l=1,r=x;
    while (r-l>1)
    {
        int mid=(l+r)/2;
        if (c[mid].b<=c[x].b&&c[mid].b>c[x].a) l=mid;
        else r=mid;
    }
    return l;
}
void QHD()
{
    f[1]=c[1].h;
    for (int i=2;i<=n;i++)
    {
        int x=npr(i);
        //cout<<npl(i)<<" "<<x<<endl;
        for (int j=npl(i);j<=x;j++)
            f[i]=max(f[i],f[j]+c[i].h);
        kq=max(kq,f[i]);
    }
}
int main()
{
    cin>>n;
    for (int i=1;i<=n;i++)
        cin>>c[i].a>>c[i].b>>c[i].h;
    sort (c+1,c+1+n,cmp);
    QHD();
    cout<<kq;
}


#include <bits/stdc++.h>
using namespace std;
struct data
{
    int a,b,h;
};
int n,f[100005],kq;
data c[100005];
bool cmp(data x,data y)
{
    if (x.b==y.b) return x.a>y.a;
    else return x.b<y.b;
}
int npl(int x)
{
    int l=0,r=x-1;
    while (r-l>1)
    {
        int mid=(l+r)/2;
        if (c[mid].b<=c[x].b&&c[mid].b>c[x].a) r=mid;
        else l=mid;
    }
    return r;
}
int npr(int x)
{
    int l=1,r=x;
    while (r-l>1)
    {
        int mid=(l+r)/2;
        if (c[mid].b<=c[x].b&&c[mid].b>c[x].a) l=mid;
        else r=mid;
    }
    return l;
}
void QHD()
{
    f[1]=c[1].h;
    kq=f[1];
    for (int i=2;i<=n;i++)
    {
        int x=npr(i);
        //cout<<npl(i)<<" "<<x<<endl;
        for (int j=npl(i);j<=x;j++)
            f[i]=max(f[i],f[j]+c[i].h);
        kq=max(kq,f[i]);
    }
}
int main()
{
    cin>>n;
    for (int i=1;i<=n;i++)
        cin>>c[i].a>>c[i].b>>c[i].h;
    sort (c+1,c+1+n,cmp);
    QHD();
    cout<<kq;
}


#include <bits/stdc++.h>
using namespace std;
struct data
{
    long long a,b,h;
};
typedef pair <long long,long long> ii;
vector <ii> v;
long long n,f[100005],st[800005],kq;
data c[100005];
bool cmp(data x,data y)
{
    if (x.b==y.b) return x.a>y.a;
    else return x.b>y.b;
}
void shrink()
{
    for(int i=1; i<=n; i++)
    {
        v.push_back(ii(c[i].a,i));
        v.push_back(ii(c[i].b,i));
    }
    sort(v.begin(),v.end());
    int cur=v[0].first,gt=1;
    for (int i=0; i<2*n; i++)
    {
        if (v[i].first==cur)
            v[i].first=gt;
        else
        {
            cur=v[i].first;
            v[i].first=++gt;
        }
        swap(v[i].first,v[i].second);
    }
    sort(v.begin(),v.end());
    for (int i=0;i<n;i++)
    {
        c[i+1].a=v[2*i].second;
        c[i+1].b=v[2*i+1].second;
        //cout<<c[i+1].a<<" "<<c[i+1].b<<" "<<c[i+1].h<<"\n";
    }
}
long long getmax(int id,int l,int r,int x,int y)
{
    if (r<x||l>y) return 0LL;
    else if (l>=x&&r<=y) return st[id];
    else
    {
        int mid=(l+r)/2;
        return max(getmax(id*2,l,mid,x,y),getmax(id*2+1,mid+1,r,x,y));
    }
}
void update(int id,int l,int r,int x,long long y)
{
    if (l>x||r<x) return;
    else if (l==r) st[id]=max(st[id],y);
    else
    {
        int mid=(l+r)/2;
        update(id*2,l,mid,x,y);
        update(id*2+1,mid+1,r,x,y);
        st[id]=max(st[id*2],st[id*2+1]);
    }
}
void QHD()
{
    int cur=1;
    kq=c[1].h;
    update(1,1,2*n,c[1].a,c[1].h);
    for (int i=2; i<=n; i++)
    {
        //while (c[i].b<=c[cur].a) cur++;
        long long x=getmax(1,1,2*n,1,c[i].b-1);
        f[i]=x+c[i].h;
        //cout<<f[i]<<" ";
        kq=max(kq,f[i]);
        update(1,1,2*n,c[i].a,f[i]);
    }
}
int main()
{
    cin>>n;
    for (int i=1; i<=n; i++)
        cin>>c[i].a>>c[i].b>>c[i].h;
    shrink();
    sort (c+1,c+1+n,cmp);
    QHD();
    cout<<kq;
}


#include <bits/stdc++.h>
using namespace std;
struct data
{
    long long a,b,h;
};
typedef pair <long long,long long> ii;
vector <ii> v;
long long n,f[100005],st[800005],kq;
data c[100005];
bool cmp(data x,data y)
{
    if (x.b==y.b) return x.a>y.a;
    else return x.b>y.b;
}
void shrink()
{
    for(int i=1; i<=n; i++)
    {
        v.push_back(ii(c[i].a,i));
        v.push_back(ii(c[i].b,i));
    }
    sort(v.begin(),v.end());
    int cur=v[0].first,gt=1;
    for (int i=0; i<2*n; i++)
    {
        if (v[i].first==cur)
            v[i].first=gt;
        else
        {
            cur=v[i].first;
            v[i].first=++gt;
        }
        swap(v[i].first,v[i].second);
    }
    sort(v.begin(),v.end());
    for (int i=0;i<n;i++)
    {
        c[i+1].a=v[2*i].second;
        c[i+1].b=v[2*i+1].second;
        //cout<<c[i+1].a<<" "<<c[i+1].b<<" "<<c[i+1].h<<"\n";
    }
}
long long getmax(int id,int l,int r,int x,int y)
{
    if (r<x||l>y) return 0LL;
    else if (l>=x&&r<=y) return st[id];
    else
    {
        int mid=(l+r)/2;
        return max(getmax(id*2,l,mid,x,y),getmax(id*2+1,mid+1,r,x,y));
    }
}
void update(int id,int l,int r,int x,long long y)
{
    if (l>x||r<x) return;
    else if (l==r) st[id]=max(st[id],y);
    else
    {
        int mid=(l+r)/2;
        update(id*2,l,mid,x,y);
        update(id*2+1,mid+1,r,x,y);
        st[id]=max(st[id*2],st[id*2+1]);
    }
}
void QHD()
{
    int cur=1;
    kq=c[1].h;
    update(1,1,2*1e5,c[1].a,c[1].h);
    for (int i=2; i<=n; i++)
    {
        //while (c[i].b<=c[cur].a) cur++;
        long long x=getmax(1,1,2*1e5,1,c[i].b);
        f[i]=x+c[i].h;
        //cout<<f[i]<<" ";
        kq=max(kq,f[i]);
        update(1,1,2*1e5,c[i].a,f[i]);
    }
}
int main()
{
    cin>>n;
    for (int i=1; i<=n; i++)
        cin>>c[i].a>>c[i].b>>c[i].h;
    shrink();
    sort (c+1,c+1+n,cmp);
    QHD();
    cout<<kq;
}


#define N 100010
#include<iostream>
#include<stack>
#include<algorithm>
using namespace std;
struct tower
{
    int x,y,h;
} a[N];
bool judge(tower a,tower b)
{
    if(a.y != b.y) return a.y < b.y;
    return a.x < b.x;
}
int dp[N];
int main()
{
    int n;
    while(cin>>n)
    {
        for(int i = 0; i < n; i++)
            cin>>a[i].x>>a[i].y>>a[i].h;
        sort(a,a+n,judge);
        stack<tower> p;
        int ans = 0;
        int mx = 0;
        for(int i = n-1; i >= 0; i--)
        {
            while(1)
            {
                if(p.empty())
                    break;
                tower f = p.top();
                if(f.y >= a[i].y && f.x < a[i].y)
                    break;
                ans -= f.h;
                p.pop();
            }
            p.push(a[i]);
            ans += a[i].h;
            mx = max(mx,ans);
        }
        cout<<mx;
    }
    return 0;
}


#include<iostream>
#include<stack>
#include<algorithm>
using namespace std;
struct tower{
    int a;
    int b;
    int h;};
bool judge(tower a,tower b);
int main()
{
    int n;
    cin>>n;
    tower hanoi[n];
    for(int i=0;i<n;i++) cin>>hanoi[i].a>>hanoi[i].b>>hanoi[i].h;
    sort(hanoi,hanoi+n,judge);
    stack<tower>a1;
    a1.push(hanoi[0]);
    int h_sum=hanoi[0].h,h_max=hanoi[0].h;
    for(int i=1;i<n;i++)
    {
        if(!a1.empty())
        {
        a1.pop();
        }
        while(!a1.empty()&&hanoi[i].b<=a1.top().a)
        {
            h_sum-=a1.top().h;
            a1.pop();
        }
        h_sum+=hanoi[i].h;
    	h_max=max(h_max,h_sum);
    	a1.push(hanoi[0]);
    }
    cout<<h_max;
}
bool judge(tower x,tower y)
{
    if(x.b==y.b)
    return x.a>y.a;
    else
    return x.b>y.b;
}


#include<iostream>
#include<stack>
#include<algorithm>
using namespace std;
struct tower{
    int a;
    int b;
    int h;};
bool judge(tower a,tower b);
int main()
{
    int n;
    cin>>n;
    tower hanoi[n];
    for(int i=0;i<n;i++) cin>>hanoi[i].a>>hanoi[i].b>>hanoi[i].h;
    sort(hanoi,hanoi+n,judge);
    stack<tower>a1;
    a1.push(hanoi[0]);
    int h_sum=hanoi[0].h,h_max=hanoi[0].h;
    for(int i=1;i<n;i++)
    {
        h_sum+=hanoi[i].h;
        if(!a1.empty())
        {
        a1.pop();
        }
        while(!a1.empty()&&hanoi[i].b<=a1.top().a)
        {
            h_sum-=a1.top().h;
            a1.pop();
        }
    	h_max=max(h_max,h_sum);
    	a1.push(hanoi[i]);
    }
    cout<<h_max;
}
bool judge(tower x,tower y)
{
    if(x.b==y.b)
    return x.a>y.a;
    else
    return x.b>y.b;
}


#define N 100010
#include<iostream>
#include<stack>
#include<algorithm>
using namespace std;
struct tower
{
    int x,y,h;
} a[N];
bool judge(tower a,tower b)
{
    if(a.y != b.y) return a.y < b.y;
    return a.x < b.x;
}
int dp[N];
int main()
{
    int n;
    while(cin>>n)
    {
        for(int i = 0; i < n; i++)
            cin>>a[i].x>>a[i].y>>a[i].h;
        sort(a,a+n,judge);
        stack<tower> p;
        long long ans = 0;
        long long mx = 0;
        for(int i = n-1; i >= 0; i--)
        {
            while(1)
            {
                if(p.empty())
                    break;
                tower f = p.top();
                if(f.y >= a[i].y && f.x < a[i].y)
                    break;
                ans -= f.h;
                p.pop();
            }
            p.push(a[i]);
            ans += a[i].h;
            mx = max(mx,ans);
        }
        cout<<mx;
    }
    return 0;
}


#include<iostream>
#include<stack>
#include<algorithm>
using namespace std;
struct tower{
    int a;
    int b;
    int h;};
bool judge(tower a,tower b);
int main()
{
    int n;
    cin>>n;
    tower hanoi[n];
    for(int i=0;i<n;i++) cin>>hanoi[i].a>>hanoi[i].b>>hanoi[i].h;
    sort(hanoi,hanoi+n,judge);
    stack<tower>a1;
    a1.push(hanoi[0]);
    int h_sum=hanoi[0].h,h_max=hanoi[0].h;
    for(int i=1;i<n;i++)
    {
        h_sum+=hanoi[i].h;
        if(!a1.empty())
        {
        a1.pop();
        }
        while(!a1.empty()&&hanoi[i].b<=a1.top().a)
        {
            h_sum-=a1.top().h;
            a1.pop();
        }
    h_max=max(h_max,h_sum);
    a1.push(hanoi[0]);
    }
    cout<<h_max;
}
bool judge(tower x,tower y)
{
    if(x.b==y.b)
    return x.a>y.a;
    else
    return x.b>y.b;
}


#include<iostream>
#include<queue>
#include<string>
#include<map>
#include<cmath>
#include<vector>
#include<cstdio>
#include<stack>
#include<algorithm>
using namespace std;
struct r{
	int a, b, h;
}Arr[100000];
bool cmp(const r& r1, const r& r2){
	if (r1.b != r2.b)return r1.b > r2.b;
	else return r1.a > r2.a;
}
stack<r>s;
int main(){
	int n;
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> Arr[i].a >> Arr[i].b >> Arr[i].h;
	}
	sort(&Arr[0], &Arr[n], cmp);
	s.push(Arr[0]);
	long long ansh = Arr[0].h,maxh=Arr[0].h;
	for (int i = 1; i < n; i++){
		while (!s.empty() && Arr[i].b <= s.top().a){
			ansh -= s.top().h; s.pop();
		}
		s.push(Arr[i]);
		ansh += Arr[i].h;
		if (ansh>maxh)maxh = ansh;
	}
	cout << maxh;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stack>
using namespace std;
const int INF = 1e5 + 10;
typedef long long ll;
typedef struct U{
    int a, b, h;
}u;
u w[INF];
bool cmp(u a, u b) {
	return a.b == b.b ? a.a > b.a : a.b > b.b;
}
int main() {
	int n;
	scanf("%d", &n);
	for(int i = 0; i < n; i++) scanf("%d%d%d", &w[i].a, &w[i].b, &w[i].h);
	sort(w, w + n, cmp);
//	for(int i = 0; i < n; i++) printf("%d %d %d\n", w[i].a, w[i].b, w[i].h);
	stack<u>s;
	s.push(w[0]);
	ll ans = 0; //最大值
	ll cnt = w[0].h; //当前值
	for(int i = 1; i < n; i++) {
		if(s.empty()) {
			cnt = w[i].h;
			s.push(w[i]);
			continue;
		}
		u k = s.top();
	//	printf("i:%d k:%d %d %d w:%d %d %d \n", i, k.a, k.b, k.h, w[i].a, w[i].b, w[i].h);
	//	printf("ans:%d cnt:%d\n", ans, cnt);
		if(w[i].b > k.a) {
			cnt += w[i].h;
			s.push(w[i]);
		}
		else {
			if(cnt > ans) ans = cnt;
			while(w[i].b <= k.a && !s.empty()) {
				cnt -= k.h;
				s.pop();
				if(!s.empty()) {
					k = s.top();
				}
			}
			s.push(w[i]);
			cnt += w[i].h;
		}
//		printf("ans:%d cnt:%d\n", ans, cnt);
	}
	if(ans < cnt) ans = cnt;
	printf("%lld\n", ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
struct st
{
	int a,b,h;
} ho[100005];
bool cnm(st x,st y)
{
	if (x.b==y.b) return x.a>y.a;
	else return x.b>y.b;
}
int main()
{
	int n=0;
	cin>>n;
	for (int i=1;i<=n;i++) scanf("%d %d %d",&ho[i].a,&ho[i].b,&ho[i].h);
	sort(ho+1,ho+1+n,cnm);
	long long sum=ho[1].h;
	long long temp=0;
	for (int i=1;i<=n-1;i++)
	{
		if (ho[i].a<ho[i+1].b) sum+=ho[i+1].h;
			else
			{
				temp=max(sum,temp);
				sum=ho[i+1].h;
			}
	}
	temp=max(sum,temp);
	cout<<temp;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
struct st
{
    int a,b,h;
} ho[100005];
bool cnm(st x,st y)
{
    if (x.b==y.b) return x.a>y.a;
    else return x.b>y.b;
}
long long ll[100005]={0};
int main()
{
    int n=0;
    cin>>n;
    for (int i=1;i<=n;i++) scanf("%d %d %d",&ho[i].a,&ho[i].b,&ho[i].h);
    sort(ho+1,ho+1+n,cnm);
    long long sum=ho[1].h,temp=ho[1].h;
    for (int i=1;i<=n;i++)
    {
        /*int j=i;
        if (ho[i].a<ho[i+1].b) sum+=ho[i+1].h;
            else
            {
                temp=sum;
                do
                {
                    sum-=ho[j].h;
                    j--;
                    ho[j+1].a=0;
                    ho[j+1].b=0;
                    ho[j+1].h=0;
                }
                while (ho[j].a>=ho[i+1].b);
                sum+=ho[i+1].h;
                temp=max(temp,sum);
            }*/
         ll[i]=ho[i].h;
         for (int j=1;j<=i-1;j++)
             if (ho[j].a<ho[i].b) ll[i]=max(ll[i],ll[i]+ho[i].h);


#include<bits/stdc++.h>
using namespace std;
struct st
{
    int a,b,h;
} ho[100005];
bool cnm(st x,st y)
{
    if (x.b==y.b) return x.a>y.a;
    else return x.b>y.b;
}
long long ll[100005]={0};
int main()
{
    int n=0;
    cin>>n;
    for (int i=1;i<=n;i++) scanf("%d %d %d",&ho[i].a,&ho[i].b,&ho[i].h);
    sort(ho+1,ho+1+n,cnm);
    long long sum=ho[1].h,temp=ho[1].h;
    for (int i=1;i<=n;i++)
    {
        /*int j=i;
        if (ho[i].a<ho[i+1].b) sum+=ho[i+1].h;
            else
            {
                temp=sum;
                do
                {
                    sum-=ho[j].h;
                    j--;
                    ho[j+1].a=0;
                    ho[j+1].b=0;
                    ho[j+1].h=0;
                }
                while (ho[j].a>=ho[i+1].b);
                sum+=ho[i+1].h;
                temp=max(temp,sum);
            }*/
         ll[i]=ho[i].h;
         for (int j=1;j<=i-1;j++)
             if (ho[j].a<ho[i].b) ll[i]=max(ll[i],ll[i]+ho[i].h);
        temp=max(temp,ll[i]);
    }
    cout<<temp;
    return 0;
}


/*
    @Author: wchhlbt
    @Date:   2017/2/25
*/
#include <bits/stdc++.h>

#define Fori(x) for(int i=0;i<x;i++)
#define Forj(x) for(int j=0;j<x;j++)
#define maxn 100005
#define inf 0x3f3f3f3f
#define ONES(x) __builtin_popcount(x)
using namespace std;

typedef long long ll ;
const double eps =1e-8;
const int mod = 1000000007;
typedef pair<int, int> P;
const double PI = acos(-1.0);
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};

struct Node
{
    int a,b,h;
}ring[maxn];

 bool cmp(Node r, Node s)
 {
    if(r.b==s.b && r.a==s.a)  return r.h>s.h;
    else if(r.b==s.b)   return r.a>s.a;
    return r.b>s.b;
 }
stack<Node> q;
int main()
{
    //freopen("test.txt","r",stdin);
    //cin>>n;
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    //cout << phi(1) + phi(2) + phi(4) << endl;
    int n;
    cin>>n;
    for(int i = 1; i<=n; i++)
        cin>>ring[i].a>>ring[i].b>>ring[i].h;
    sort(ring+1,ring+1+n,cmp);
    ll ans = ring[1].h;
    ll sum = ring[1].h;
    q.push(ring[1]);

    for(int i = 2; i<=n; i++)
    {
        while(!q.empty() && ring[i].b<=q.top().a)
        {
            sum -= q.top().h;
            q.pop();
        }
        sum += ring[i].h;
        q.push(ring[i]);
        ans = max(ans,sum);
    }
    cout << ans << endl;
    return 0;
}

/*

unsigned   int   0～4294967295
int   2147483648～2147483647
unsigned long 0～4294967295
long   2147483648～2147483647
long long的最大值：9223372036854775807
long long的最小值：-9223372036854775808
unsigned long long的最大值：18446744073709551615

__int64的最大值：9223372036854775807
__int64的最小值：-9223372036854775808
unsigned __int64的最大值：18446744073709551615

*/


/*
题目大意:给你n个圆环,让你建一个尽可能高的塔
要求上面圆坏的外半径小于下面圆环外半径
上面圆坏的外半径大于下面圆环内半径
输入:整数n,每个圆环的内半径,外半径,高度
输出:最大高度
提示:
	本题可能需要用到的新知识比较多大家可以先自行百度下以下知识点,不会可以群里私聊我
	1.结构体的使用
	2.sort()函数的使用
	3.vector,stack,queue,priority queue,set,multiset,map等STL容器的使用方法
解法:
	因为要求外半径递减,所以很容易想到按外半径从大到小排个序,然后实际模拟下
	模拟的时候可以利用stack模拟
	每次一个一个往上面堆,如果出现下一个不满足第二条要求的时候,那么以后的所有的圆环都放不上去了
	那么拿下来最上面的一个圆环,然后继续执行
	在模拟的过程中,有一个nowh随时变换,同时有一个maxh,每次nowh变化的时候看是否超过maxh,然后更新maxh
	stack 的用法
	stack <Node> S;
	S.push(node[i]);
	S.top();
	S.pop();
	另外排序的时候用到了贪心的思想,就是如果外半径一样的时候,我们要让内半径最大的排在后面,
	也就是模拟的时候内半径最大的在上面,这样得到高度结果是最大的.
*/
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <cstdio>
#include <iostream>
#include <stack>
using namespace std;
struct Node { int a, b, h; };
Node node[110000];
bool cmp(Node a, Node b) {
	if (a.b != b.b) return a.b > b.b;
	else return a.a > b.a;
}
int main() {
	int n; cin >> n;
	for (int i = 0; i < n; i++) scanf("%d%d%d", &node[i].a, &node[i].b, &node[i].h);
	sort(node, node + n, cmp);
	stack <Node> S;
	long long maxh = 0;
	long long nowh = 0;
	for (int i = 0; i < n; i++) {
		while (!S.empty() && node[i].b <= S.top().a) {
			nowh -= S.top().h;
			S.pop();
		}
		S.push(node[i]);
		nowh += node[i].h;
		maxh = max(maxh, nowh);
	}
	cout << maxh << endl;
	return 0;
}


#include <stdio.h>

int main(){
	int n,i,j,temp,set,count=0,maxvalue=0;
	scanf("%d",&n);
	int a[n],b[n],c[n];
	for(i=0;i<n;i++){
		scanf("%d %d %d",&a[i],&b[i],&c[i]);
	}
	for(i=0;i<n-1;i++){
		bool isSorted = true;
		for(j=0;j<n-i-1;j++){
			if(b[j]>=b[j+1]){
				isSorted=false;

				temp=b[j];
				b[j]=b[j+1];
				b[j+1]=temp;
				temp=a[j];
				a[j]=a[j+1];
				a[j+1]=temp;
				temp=c[j];
				c[j]=c[j+1];
				c[j+1]=temp;
			}
		}
		if(isSorted) break;
	}
	for(i=n-1;i>0;i--){
		j=i;
		count=c[i];
		while(a[j]<b[j-1]&&j!=0){
			count+=c[j-1];
			j--;
		}
		if(maxvalue<count){
			maxvalue=count;
		}
	}
	if(c[0]>maxvalue){
		maxvalue=c[0];
	}
	printf("%d",maxvalue);
}


#include<iostream>
#include<string.h>
#include<stdio.h>
#include<cstdlib>
#include<queue>
#include<stack>
#include<cmath>
#include<cstring>
#include<algorithm>
typedef long long ll;
using namespace std;

struct Ring{
	int a, b, h;
}ring[100005];

stack<Ring> st;
bool cmp(Ring A, Ring B){
	if(A.b == B.b) return A.a > B.a;
	return A.b > B.b;
}

int main(){
	int n, ans = 0;
	cin >> n;
	for(int i=0; i<n; i++)
		cin >> ring[i].a >> ring[i].b >> ring[i].h;
	sort(ring, ring+n, cmp);

	st.push(ring[0]);
	ans += ring[0].h;

	for(int i=1; i<n; i++){
		Ring t = st.top();
		if(ring[i].b > t.a){
			st.push(ring[i]);
			ans += ring[i].h;
		}
		else{
			while(ring[i].b<=t.a && !st.empty()){
				if(ring[i].h >= t.h){
					ans = ans - t.h;
					st.pop();
					if(!st.empty()) t = st.top();
				}
			}
			ans += ring[i].h;
			st.push(ring[i]);
		}
	}
	cout << ans << endl;
}


#include<iostream>
#include<string.h>
#include<stdio.h>
#include<cstdlib>
#include<queue>
#include<stack>
#include<cmath>
#include<cstring>
#include<algorithm>
typedef long long ll;
using namespace std;

struct Ring{
	ll a, b, h;
}ring[100005];

stack<Ring> st;
bool cmp(Ring A, Ring B){
	if(A.b == B.b) return A.a > B.a;
	return A.b > B.b;
}

int main(){
	ll n, ans = 0, ANS = 0;
	cin >> n;
	for(int i=0; i<n; i++)
		cin >> ring[i].a >> ring[i].b >> ring[i].h;
	sort(ring, ring+n, cmp);

	st.push(ring[0]);
	ans += ring[0].h;

	for(int i=1; i<n; i++){
		Ring t = st.top();
		if(ring[i].b > t.a){
			st.push(ring[i]);
			ans += ring[i].h;
		}
		else{
			ANS = max(ANS, ans);
			while(ring[i].b<=t.a && !st.empty()){
					ans = ans - t.h;
					st.pop();
					if(!st.empty()) t = st.top();
			}
			ans += ring[i].h;
			st.push(ring[i]);
		}
	}
	ans = max(ans, ANS);
	cout << ans << endl;
}


#include <stdio.h>

int main(){
	int n,i,j;
	long temp,count=0,maxvalue=0;
	scanf("%d",&n);
	long a[n],b[n],c[n];
	for(i=0;i<n;i++){
		scanf("%ld %ld %ld",&a[i],&b[i],&c[i]);
	}
	for(i=0;i<n-1;i++){
		bool isSorted = true;
		for(j=0;j<n-i-1;j++){
			if(b[j]>=b[j+1]){
				isSorted=false;
				if(b[j]==b[j+1]&&a[j]<a[j+1]) continue;
				temp=b[j];
				b[j]=b[j+1];
				b[j+1]=temp;
				temp=a[j];
				a[j]=a[j+1];
				a[j+1]=temp;
				temp=c[j];
				c[j]=c[j+1];
				c[j+1]=temp;
			}
		}
		if(isSorted) break;
	}
	for(i=n-1;i>0;i--){
		j=i;
		count=c[i];
		while(a[j]<b[j-1]&&j!=0){
			count+=c[j-1];
			j--;
		}
		if(maxvalue<count){
			maxvalue=count;
		}
	}
	if(c[0]>maxvalue){
		maxvalue=c[0];
	}
	printf("%ld",maxvalue);
}


#include<bits/stdc++.h>
using namespace std;
struct st
{
	int a,b,h;
} ho[100005];
bool cnm(st x,st y)
{
	if (x.b==y.b) return x.a>y.a;
	else return x.b>y.b;
}
long long ll[100005]= {0};
int main()
{
	int n=0,t=1;
	ll[1]=1;
	cin>>n;
	for (int i=1; i<=n; i++) scanf("%d %d %d",&ho[i].a,&ho[i].b,&ho[i].h);
	sort(ho+1,ho+1+n,cnm);
	long long sum=ho[1].h,temp=ho[1].h;
	for (int i=1; i<=n-1; i++)
	{
		if (ho[ll[t]].a<ho[i+1].b)
		{
			sum+=ho[i+1].h;
			t++;
			ll[t]+=i+1;
		}
		else
		{
			while (ho[ll[t]].a>=ho[i+1].b)
			{
				sum-=ho[ll[t]].h;
				ll[t]=0;
				t--;
			}
			sum+=ho[i+1].h;
			t++;
			ll[t]+=i+1;
		}
		temp=max (sum,temp);
	}
	cout<<temp;
	return 0;
}


#include<bits/stdc++.h>
#define manx 100005
typedef long long LL;
using namespace std;
struct R
{
    LL out,in,h;
}a[manx];
bool cmp(R a,R b)
{
    if(a.out==b.out) return a.in > b.in;
    return a.out > b.out;
}
stack<R>s;
int main()
{
    LL n;
    scanf("%I64d",&n);
    for (int i=0; i<n; i++)
        scanf("%I64d%I64d%I64d",&a[i].in,&a[i].out,&a[i].h);
    sort(a,a+n,cmp);
    s.push(a[0]);
    LL cnt=s.top().h,ans=0;
    for (int i=1; i<n; i++){
        if(s.empty()){
            cnt=a[i].h;
            s.push(a[i]);
            continue;
        }
        R t=s.top();
        if(a[i].out > t.in){
            cnt+=a[i].h;
            s.push(a[i]);
        }
        else{
            ans=max(ans,cnt);
            while(a[i].out <= t.in && !s.empty()){
                cnt-=t.h;
                s.pop();
                if(!s.empty()) t=s.top();
            }
            cnt+=a[i].h;
            s.push(a[i]);
        }
    }
    ans=max(ans,cnt);
    printf("%I64d\n",ans);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
struct node{
    int w,n,h;
}ring[100005];
bool cmp(node a,node b)
{
    if((a.w-a.n)==(b.w-b.n))
    {
          return a.h>b.h;
    }
    return (a.w-a.n)>(b.w-b.n);
}
int n;
int main()
{
    scanf("%d",&n);
    int a,b,c;
    for(int i=0;i<n;i++)
    {
        scanf("%d%d%d",&a,&b,&c);
        ring[i].n=a;
        ring[i].w=b;
        ring[i].h=c;
    }
    sort(ring,ring+n,cmp);
    long long ans=0;
    int nn=0,ww=0;
    if(n!=0)
    {ans=ring[0].h;
     nn=ring[0].n;
     ww=ring[0].w;}
     int i=1;
     while(i<n)
     {
         if(ring[i].w<=ww&&ring[i].w>nn)
         {
            // cout<<ring[i].w<<" "<<ring[i].n<<" "<<ring[i].h<<endl;
             ans+=ring[i].h;
             nn=ring[i].n;
         }
         i++;
     }
     cout<<ans<<endl;
}


#include <bits/stdc++.h>
#define maxn 101000
using namespace std;

int n, st;

struct node
{
	int a, b, h;
}in[maxn], s[maxn];

bool cmp(node x, node y)
{
	if (x.b == y.b)
		return x.a > y.a;
	return x.b > y.b;
}

int main()
{
	// freopen("in", "r", stdin);
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d %d %d", &in[i].a, &in[i].b, &in[i].h);
	sort(in, in + n, cmp);
	int ans(0), mx(0);
	for (int i = 0; i < n; i++)
	{
		if (!st)
		{
			mx = in[i].h;
			s[++st] = in[i];
			continue;
		}
		if (s[st].a < in[i].b)
		{
			mx += in[i].h;
			s[++st] = in[i];
		}
		else
		{
			ans = max(ans, mx);
			while (st && s[st].a >= in[i].b)
			{
				mx -= s[st].h;
				st--;
			}
			mx += in[i].h;
			s[++st] = in[i];
		}
	}
	ans = max(ans, mx);
	printf("%d", ans);
	return 0;
}


#include <stdio.h>

int main(){
	int n,i,j,temp,set,count=0,maxvalue=0;
	scanf("%d",&n);
	int a[n],b[n],c[n];
	for(i=0;i<n;i++){
		scanf("%d %d %d",&a[i],&b[i],&c[i]);
	}
	for(i=0;i<n-1;i++){
		bool isSorted = true;
		for(j=0;j<n-i-1;j++){
			if(b[j]>=b[j+1]){
				isSorted=false;
				if(b[j]==b[j+1]&&a[j]<a[j+1]) continue;
				temp=b[j];
				b[j]=b[j+1];
				b[j+1]=temp;
				temp=a[j];
				a[j]=a[j+1];
				a[j+1]=temp;
				temp=c[j];
				c[j]=c[j+1];
				c[j+1]=temp;
			}
		}
		if(isSorted) break;
	}
	for(i=n-1;i>0;i--){
		j=i;
		count=c[i];
		while(a[j]<b[j-1]&&j!=0){
			count+=c[j-1];
			j--;
		}
		if(maxvalue<count){
			maxvalue=count;
		}
	}
	if(c[0]>maxvalue){
		maxvalue=c[0];
	}
	printf("%d",maxvalue);
}


//#include <bits/stdc++.h>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cmath>
#include<stack>
#include<set>
#include<vector>
#include<map>
#include<sstream>
#include<ctime>
#define ll long long
#define LL long long
#define iosfalse ios::sync_with_stdio(false);
#define lowbit(x) x&-x

using namespace std;

//20170727

int n;
struct Ring{
int ra,rb,h;
}ring[100005];
bool cmp(Ring A,Ring B)
{
    if(A.rb!=B.rb)
        return A.rb<B.rb;
    else if(A.ra!=B.ra)
        return A.ra<B.ra;
    else return A.h<B.h;
}
int main()
{
    iosfalse
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>ring[i].ra>>ring[i].rb>>ring[i].h;
    sort(ring,ring+n,cmp);
    long long height=0,curh=0;
    stack<int>st;
    int id=n-1;
    while(id>=0)
    {
        while(st.empty()||ring[st.top()].ra<ring[id].rb)
            {
                st.push(id);
                curh+=ring[id].h;
                id--;
                if(id<0)
                    break;
            }
        height=max(height,curh);
        while(!st.empty()&&ring[id].rb<ring[st.top()].ra)
        {
            curh-=ring[st.top()].h;
            st.pop();
        }
    }
    cout<<height<<endl;
    return 0;
}


#include<cstdio>
#include<algorithm>
#include<stack>
#define maxn 100010
using namespace std;
struct node{
    int a,b,h;
}q[maxn];
int bmp(node a,node b)
{
    if(a.b == b.b)
        return a.a > b.a;
    else return a.b > b.b;
}
int main()
{
    int n;
    scanf("%d",&n);
    stack<node>s;
    for(int i = 0; i < n; i++)
        scanf("%d%d%d",&q[i].a,&q[i].b,&q[i].h);
    sort(q, q + n, bmp);
    long long ans = q[0].h,sum = q[0].h;
    while(!s.empty())s.pop();
    s.push(q[0]);
    for(int i = 1; i < n; i++)
    {
        while(!s.empty() && q[i].b <= s.top().a)
        {
            sum -= s.top().h;
            s.pop();
        }
        sum += q[i].h;
        ans = max(ans,sum);
        s.push(q[i]);
    }
    printf("%I64d\n",ans);
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iostream>
using namespace std;
struct Node
{
	int a;
	int b;
	int h;
};
Node node[110000];
bool cmp(Node a, Node b)
{
	if (a.b != b.b)
	{
		return a.b > b.b;
	}
	else
	{
		return a.a > b.a;
	}
}
int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		scanf("%d%d%d", &node[i].a, &node[i].b, &node[i].h);
	}
	sort(node, node + n, cmp);
	stack <Node> S;
	long long maxh = 0;
	long long nowh = 0;
	for (int i = 0; i < n; i++)
	{
		while (!S.empty() && node[i].b <= S.top().a)
		{
			nowh -= S.top().h;
			S.pop();
		}
		S.push(node[i]);
		nowh += node[i].h;
		maxh = max(maxh, nowh);
	}
	cout << maxh << endl;
	return 0;
}


#include <iostream>
#include<cstdio>
#include <cstring>
#include <cstdlib>//定义杂项函数及内存分配函数
#include <cmath>
#include <string>//c++中的string类 不能用strcpy等c函数去操作
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include<set>
#include <bitset>//bitset可按位定义串//比如：bitset <1000> all;定义一个1000位的串
#include <algorithm>//swap sort merge max min
#include <numeric>//常用数字操作 一般和algorithm搭配使用
#include <functional>//STL定义运算函数（代替运算符）
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;
const long long INFLL  = 0x3f3f3f3f3f3f3f3fLL;
const int N = 100010;
using namespace std;
int max3(int x,int y,int z)
{
    if(x > y)return x > z ? x : z;
    else return y > z ? y : z;
}
int min3(int x,int y,int z)
{
    if(x < y)return x < z ? x : z;
    else return y < z ? y : z;
}
struct s
{
    ll val,id;
    bool operator <(const s &a)const
    {
        return val < a.val;
    }
}A[N];
struct Node
{
    ll a,b,h;
}node[N];
int cmp(Node a,Node b)
{
    if(a.b != b.b)
    return a.b > b.b;
    return a.a > b.a;
}
int main()
{
    int n;
    scanf("%d",&n);
    for(int i = 0; i < n; i++)
        scanf("%I64d%I64d%I64d",&node[i].a,&node[i].b,&node[i].h);
    sort(node,node + n,cmp);
    stack<Node>st;
    ll res = node[0].h,sum = node[0].h;
    st.push(node[0]);
    for(int i = 1; i < n ; i++)
    {
        while(!st.empty() && node[i].b <= st.top().a)
        {
            sum -= st.top().h;
            st.pop();
        }
        sum += node[i].h;
        st.push(node[i]);
        res = max(res,sum);
    }
    printf("%I64d\n",res);
    return 0;
}


#include <iostream>
#include<cstdio>
#include <cstring>
#include <cstdlib>//定义杂项函数及内存分配函数
#include <cmath>
#include <string>//c++中的string类 不能用strcpy等c函数去操作
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include<set>
#include <bitset>//bitset可按位定义串//比如：bitset <1000> all;定义一个1000位的串
#include <algorithm>//swap sort merge max min
#include <numeric>//常用数字操作 一般和algorithm搭配使用
#include <functional>//STL定义运算函数（代替运算符）
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;
const long long INFLL  = 0x3f3f3f3f3f3f3f3fLL;
const int N = 100010;
using namespace std;
int max3(int x,int y,int z)
{
    if(x > y)return x > z ? x : z;
    else return y > z ? y : z;
}
int min3(int x,int y,int z)
{
    if(x < y)return x < z ? x : z;
    else return y < z ? y : z;
}
struct s
{
    ll val,id;
    bool operator <(const s &a)const
    {
        return val < a.val;
    }
}A[N];
struct Node
{
    ll a,b,h;
}node[N];
int cmp(Node a,Node b)
{
    if(a.b != b.b)
    return a.b > b.b;
    return a.a < b.a;
}
int main()
{
    int n;
    scanf("%d",&n);
    for(int i = 0; i < n; i++)
        scanf("%I64d%I64d%I64d",&node[i].a,&node[i].b,&node[i].h);
    sort(node,node + n,cmp);
    ll res = node[0].h;
    for(int i = 1; i < n ; i++)
    {
        if(node[i].b > node[i - 1].a)
        {
            res += node[i].h;
        }
    }
    printf("%I64d\n",res);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
struct node{
    int w,n,h;
}ring[100005];
bool cmp(node a,node b)
{
    if(a.w==b.w)
    {
        if(a.n==b.n)
        {
            return a.h>b.h;
        }
        return a.n>b.n;
    }
    return a.w>b.w;
}
int n;
int main()
{
    scanf("%d",&n);
    int a,b,c;
    for(int i=0;i<n;i++)
    {
        scanf("%d%d%d",&a,&b,&c);
        ring[i].n=a;
        ring[i].w=b;
        ring[i].h=c;
    }
    sort(ring,ring+n,cmp);
    long long ans=0,sum;
     int i=1;
     stack<node> ss;
     sum=ring[0].h;
     ss.push(ring[0]);
     for(int i=1;i<n;i++)
     {
         while(!ss.empty()&&ring[i].w>ss.top().n)
         {
             ss.pop();
             sum-=ss.top().h;
         }
         sum+=ring[i].h;
         if(sum>ans)
         ans=sum;
     }

}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const int MAX = 1e5+5;
struct Node
{
    ll a,b,h;
}ring[MAX];
bool cmp(Node x,Node y)
{
    if(x.b != y.b) return x.b < y.b;
    else return x.a < y.a;
}
int main()
{
    int n;
    scanf("%d",&n);
    for(int i = 0; i < n; i++){
        ll x,y,z;
        scanf("%I64d %I64d %I64d",&x,&y,&z);
        ring[i].a = x,ring[i].b = y,ring[i].h = z;
    }
    sort(ring,ring+n,cmp);
    stack<Node> s;
    ll ans = 0;
    ll tmp = 0;
    for(int i = n-1; i >= 0; i--){
        while(1){
            if(s.empty())break;
            Node p = s.top();
            if(p.b >= ring[i].b && p.a < ring[i].b) break;
            tmp -= p.h;
            s.pop();
        }
        s.push(ring[i]);
        tmp += ring[i].h;
        ans = max(ans,tmp);
    }
    cout << ans<<endl;

    return 0;
}


#include <stdio.h>
#include <algorithm>
#include <iostream>
using namespace std;

const int maxn = 1e5 + 10;

struct Point {
    int a, b, h;
} d[maxn];

bool cmp(const Point &a, const Point &b) {
    if (a.b == b.b) return a.a > b.a;
    return a.b > b.b;
}

int tail;
int list[maxn * 2];

int inx(int x) {
    int i = 0, j = tail - 1, mid;
    while (i <= j) {
        mid = (i + j) >> 1;
        if (list[mid] >= x) j = mid - 1;
        else i = mid + 1;
    }
    return i;
}

long long best[maxn * 4], flag[maxn * 4];
long long query(int u, int x, int y, int loc) {
    if (x > loc) return 0;
    if (y <= loc) return best[u];
    int mid = (x + y) >> 1;

    if (flag[u * 2] < flag[u]) {
        best[u * 2] = max(best[u * 2], flag[u]);
        flag[u * 2] = flag[u];
    }
    if (flag[u * 2 + 1] < flag[u]) {
        best[u * 2 + 1] = max(best[u * 2 + 1], flag[u]);
        flag[u * 2 + 1] = flag[u];
    }
    return max(query(u * 2, x, mid, loc), query(u * 2 + 1, mid + 1, y, loc));
}

void change(int u, int x, int y, int loc, long long val) {
    if (y < loc) return ;
    if (x >= loc) {
        if (val > best[u]) best[u] = val;
        if (val > flag[u]) flag[u] = val;
        return ;
    }
    int mid = (x + y) >> 1;

    if (flag[u * 2] < flag[u]) {
        best[u * 2] = max(best[u * 2], flag[u]);
        flag[u * 2] = flag[u];
    }
    if (flag[u * 2 + 1] < flag[u]) {
        best[u * 2 + 1] = max(best[u * 2 + 1], flag[u]);
        flag[u * 2 + 1] = flag[u];
    }

    change(u * 2, x, mid, loc, val);
    change(u * 2 + 1, mid + 1, y, loc, val);
    best[u] = max(best[u * 2], best[u * 2 + 1]);
}

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d%d%d", &d[i].a, &d[i].b, &d[i].h);
        list[tail++] = d[i].a + 1; list[tail++] = d[i].b;
    }
    sort(d, d + n, cmp);
    sort(list, list + tail);
    int tmp = 1;
    for (int i = 1; i < tail; i++)
        if (list[i] != list[i - 1]) list[tmp++] = list[i];
    tail = tmp;
    long long ans = 0;
    for (int i = 0; i < n; i++) {
        long long best = query(1, 0, tail - 1, inx(d[i].b)) + d[i].h;
        if (best > ans) ans = best;
        change(1, 0, tail - 1, inx(d[i].a + 1), best);

 //       cout << inx(d[i].b) << ' ' << inx(d[i].a + 1) << endl;
    }
    cout << ans << endl;
    return 0;
}


#include <stdio.h>
#include <algorithm>
#include <iostream>
using namespace std;

const int maxn = 1e5 + 10;

struct Point {
    int a, b, h;
} d[maxn];

bool cmp(const Point &a, const Point &b) {
    return a.b > b.b;
}

int tail;
int list[maxn * 2];

int inx(int x) {
    int i = 0, j = tail - 1, mid;
    while (i <= j) {
        mid = (i + j) >> 1;
        if (list[mid] >= x) j = mid - 1;
        else i = mid + 1;
    }
    return i;
}

long long best[maxn * 4], flag[maxn * 4];
long long query(int u, int x, int y, int loc) {
    if (x > loc) return 0;
    if (y <= loc) return best[u];
    int mid = (x + y) >> 1;

    if (flag[u * 2] < flag[u]) {
        best[u * 2] = max(best[u * 2], flag[u]);
        flag[u * 2] = flag[u];
    }
    if (flag[u * 2 + 1] < flag[u]) {
        best[u * 2 + 1] = max(best[u * 2 + 1], flag[u]);
        flag[u * 2 + 1] = flag[u];
    }
    return max(query(u * 2, x, mid, loc), query(u * 2 + 1, mid + 1, y, loc));
}

void change(int u, int x, int y, int loc, long long val) {
    if (y < loc) return ;
    if (x >= loc) {
        if (val > best[u]) best[u] = val;
        if (val > flag[u]) flag[u] = val;
        return ;
    }
    int mid = (x + y) >> 1;

    if (flag[u * 2] < flag[u]) {
        best[u * 2] = max(best[u * 2], flag[u]);
        flag[u * 2] = flag[u];
    }
    if (flag[u * 2 + 1] < flag[u]) {
        best[u * 2 + 1] = max(best[u * 2 + 1], flag[u]);
        flag[u * 2 + 1] = flag[u];
    }

    change(u * 2, x, mid, loc, val);
    change(u * 2 + 1, mid + 1, y, loc, val);
    best[u] = max(best[u * 2], best[u * 2 + 1]);
}

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d%d%d", &d[i].a, &d[i].b, &d[i].h);
        list[tail++] = d[i].a + 1; list[tail++] = d[i].b;
    }
    sort(d, d + n, cmp);
    sort(list, list + tail);
    int tmp = 1;
    for (int i = 1; i < tail; i++)
        if (list[i] != list[i - 1]) list[tmp++] = list[i];
    tail = tmp;
    long long ans = 0;
    for (int i = 0; i < n; i++) {
        int best = query(1, 0, tail - 1, inx(d[i].b)) + d[i].h;
        if (best > ans) ans = best;
        change(1, 0, tail - 1, inx(d[i].a + 1), best);

 //       cout << inx(d[i].b) << ' ' << inx(d[i].a + 1) << endl;
    }
    cout << ans << endl;
    return 0;
}


#include <stdio.h>
#include <algorithm>
#include <iostream>
using namespace std;

const int maxn = 1e5 + 10;

struct Point {
    int a, b, h;
} d[maxn];

bool cmp(const Point &a, const Point &b) {
    return a.b > b.b;
}

int tail;
int list[maxn * 2];

int inx(int x) {
    int i = 0, j = tail - 1, mid;
    while (i <= j) {
        mid = (i + j) >> 1;
        if (list[mid] >= x) j = mid - 1;
        else i = mid + 1;
    }
    return i;
}

long long best[maxn * 4], flag[maxn * 4];
long long query(int u, int x, int y, int loc) {
    if (x > loc) return 0;
    if (y <= loc) return best[u];
    int mid = (x + y) >> 1;

    if (flag[u * 2] < flag[u]) {
        best[u * 2] = max(best[u * 2], flag[u]);
        flag[u * 2] = flag[u];
    }
    if (flag[u * 2 + 1] < flag[u]) {
        best[u * 2 + 1] = max(best[u * 2 + 1], flag[u]);
        flag[u * 2 + 1] = flag[u];
    }
    return max(query(u * 2, x, mid, loc), query(u * 2 + 1, mid + 1, y, loc));
}

void change(int u, int x, int y, int loc, long long val) {
    if (y < loc) return ;
    if (x >= loc) {
        if (val > best[u]) best[u] = val;
        if (val > flag[u]) flag[u] = val;
        return ;
    }
    int mid = (x + y) >> 1;

    if (flag[u * 2] < flag[u]) {
        best[u * 2] = max(best[u * 2], flag[u]);
        flag[u * 2] = flag[u];
    }
    if (flag[u * 2 + 1] < flag[u]) {
        best[u * 2 + 1] = max(best[u * 2 + 1], flag[u]);
        flag[u * 2 + 1] = flag[u];
    }

    change(u * 2, x, mid, loc, val);
    change(u * 2 + 1, mid + 1, y, loc, val);
    best[u] = max(best[u * 2], best[u * 2 + 1]);
}

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d%d%d", &d[i].a, &d[i].b, &d[i].h);
        list[tail++] = d[i].a + 1; list[tail++] = d[i].b;
    }
    sort(d, d + n, cmp);
    sort(list, list + tail);
    int tmp = 1;
    for (int i = 1; i < tail; i++)
        if (list[i] != list[i - 1]) list[tmp++] = list[i];
    tail = tmp;
    long long ans = 0;
    for (int i = 0; i < n; i++) {
        long long best = query(1, 0, tail - 1, inx(d[i].b)) + d[i].h;
        if (best > ans) ans = best;
        change(1, 0, tail - 1, inx(d[i].a + 1), best);

 //       cout << inx(d[i].b) << ' ' << inx(d[i].a + 1) << endl;
    }
    cout << ans << endl;
    return 0;
}


#include <stdio.h>
#include <algorithm>
#include <iostream>
using namespace std;

const int maxn = 1e5 + 10;

struct Point {
    int a, b, h;
} d[maxn];

bool cmp(const Point &a, const Point &b) {
    if (a.b == b.b) return a.a > b.a;
    return a.b > b.b;
}

int tail;
int list[maxn * 2];

int inx(int x) {
    int i = 0, j = tail - 1, mid;
    while (i <= j) {
        mid = (i + j) >> 1;
        if (list[mid] >= x) j = mid - 1;
        else i = mid + 1;
    }
    return i;
}

long long best[maxn * 4], flag[maxn * 4];
long long query(int u, int x, int y, int loc) {
    if (x > loc) return 0;
    if (y <= loc) return best[u];
    int mid = (x + y) >> 1;

    if (flag[u * 2] < flag[u]) {
        best[u * 2] = max(best[u * 2], flag[u]);
        flag[u * 2] = flag[u];
    }
    if (flag[u * 2 + 1] < flag[u]) {
        best[u * 2 + 1] = max(best[u * 2 + 1], flag[u]);
        flag[u * 2 + 1] = flag[u];
    }
    return max(query(u * 2, x, mid, loc), query(u * 2 + 1, mid + 1, y, loc));
}

void change(int u, int x, int y, int loc, long long val) {
    if (y < loc) return ;
    if (x >= loc) {
        if (val > best[u]) best[u] = val;
        if (val > flag[u]) flag[u] = val;
        return ;
    }
    int mid = (x + y) >> 1;

    if (flag[u * 2] < flag[u]) {
        best[u * 2] = max(best[u * 2], flag[u]);
        flag[u * 2] = flag[u];
    }
    if (flag[u * 2 + 1] < flag[u]) {
        best[u * 2 + 1] = max(best[u * 2 + 1], flag[u]);
        flag[u * 2 + 1] = flag[u];
    }

    change(u * 2, x, mid, loc, val);
    change(u * 2 + 1, mid + 1, y, loc, val);
    best[u] = max(best[u * 2], best[u * 2 + 1]);
}

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d%d%d", &d[i].a, &d[i].b, &d[i].h);
        list[tail++] = d[i].a + 1; list[tail++] = d[i].b;
    }
    sort(d, d + n, cmp);
    sort(list, list + tail);
    int tmp = 1;
    for (int i = 1; i < tail; i++)
        if (list[i] != list[i - 1]) list[tmp++] = list[i];
    tail = tmp;
    long long ans = 0;
    for (int i = 0; i < n; i++) {
        long long best = query(1, 0, tail - 1, inx(d[i].b)) + d[i].h;
        if (best > ans) ans = best;
        change(1, 0, tail - 1, inx(d[i].a + 1), best);

 //       cout << inx(d[i].b) << ' ' << inx(d[i].a + 1) << endl;
    }
    cout << ans << endl;
    return 0;
}
close


#include <stdio.h>
#include <algorithm>
#include <iostream>
using namespace std;

const int maxn = 2e5 + 10;

struct Point {
    int a, b, h;
} d[maxn];

bool cmp(const Point &a, const Point &b) {
    if (a.b == b.b) return a.a > b.a;
    return a.b > b.b;
}

int tail;
int list[maxn * 2];

int inx(int x) {
    int i = 0, j = tail - 1, mid;
    while (i <= j) {
        mid = (i + j) >> 1;
        if (list[mid] >= x) j = mid - 1;
        else i = mid + 1;
    }
    return i;
}

long long best[maxn * 4], flag[maxn * 4];
long long query(int u, int x, int y, int loc) {
    if (x > loc) return 0;
    if (y <= loc) return best[u];
    int mid = (x + y) >> 1;

    if (flag[u * 2] < flag[u]) {
        best[u * 2] = max(best[u * 2], flag[u]);
        flag[u * 2] = flag[u];
    }
    if (flag[u * 2 + 1] < flag[u]) {
        best[u * 2 + 1] = max(best[u * 2 + 1], flag[u]);
        flag[u * 2 + 1] = flag[u];
    }
    return max(query(u * 2, x, mid, loc), query(u * 2 + 1, mid + 1, y, loc));
}

void change(int u, int x, int y, int loc, long long val) {
    if (y < loc) return ;
    if (x >= loc) {
        if (val > best[u]) best[u] = val;
        if (val > flag[u]) flag[u] = val;
        return ;
    }
    int mid = (x + y) >> 1;

    if (flag[u * 2] < flag[u]) {
        best[u * 2] = max(best[u * 2], flag[u]);
        flag[u * 2] = flag[u];
    }
    if (flag[u * 2 + 1] < flag[u]) {
        best[u * 2 + 1] = max(best[u * 2 + 1], flag[u]);
        flag[u * 2 + 1] = flag[u];
    }

    change(u * 2, x, mid, loc, val);
    change(u * 2 + 1, mid + 1, y, loc, val);
    best[u] = max(best[u * 2], best[u * 2 + 1]);
}

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d%d%d", &d[i].a, &d[i].b, &d[i].h);
        list[tail++] = d[i].a + 1; list[tail++] = d[i].b;
    }
    sort(d, d + n, cmp);
    sort(list, list + tail);
    int tmp = 1;
    for (int i = 1; i < tail; i++)
        if (list[i] != list[i - 1]) list[tmp++] = list[i];
    tail = tmp;
    long long ans = 0;
    for (int i = 0; i < n; i++) {
        long long best = query(1, 0, tail - 1, inx(d[i].b)) + d[i].h;
        if (best > ans) ans = best;
        change(1, 0, tail - 1, inx(d[i].a + 1), best);

 //       cout << inx(d[i].b) << ' ' << inx(d[i].a + 1) << endl;
    }
    cout << ans << endl;
    return 0;
}


#include <stdio.h>
#include <algorithm>
#include <iostream>
using namespace std;

const int maxn = 1e5 + 10;

struct Point {
    int a, b, h;
} d[maxn];

bool cmp(const Point &a, const Point &b) {
    return a.b > b.b;
}

int tail;
int list[maxn * 2];

int inx(int x) {
    int i = 0, j = tail - 1, mid;
    while (i <= j) {
        mid = (i + j) >> 1;
        if (list[mid] >= x) j = mid - 1;
        else i = mid + 1;
    }
    return i;
}

long long best[maxn * 4], flag[maxn * 4];
long long query(int u, int x, int y, int loc) {
    if (x > loc) return 0;
    if (y <= loc) return best[u];
    int mid = (x + y) >> 1;
    if (flag[u * 2] < flag[u]) {
        best[u * 2] = max(best[u * 2], flag[u]);
        flag[u * 2] = flag[u];
    }
    if (flag[u * 2 + 1] < flag[u]) {
        best[u * 2 + 1] = max(best[u * 2 + 1], flag[u]);
        flag[u * 2 + 1] = flag[u];
    }
    return max(query(u * 2, x, mid, loc), query(u * 2 + 1, mid + 1, y, loc));
}

void change(int u, int x, int y, int loc, long long val) {
    if (y < loc) return ;
    if (x >= loc) {
        if (val > best[u]) best[u] = val;
        if (val > flag[u]) flag[u] = val;
        return ;
    }
    int mid = (x + y) >> 1;
    change(u * 2, x, mid, loc, val);
    change(u * 2 + 1, mid + 1, y, loc, val);
    best[u] = max(best[u * 2], best[u * 2 + 1]);
}

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d%d%d", &d[i].a, &d[i].b, &d[i].h);
        list[tail++] = d[i].a + 1; list[tail++] = d[i].b;
    }
    sort(d, d + n, cmp);
    sort(list, list + tail);
    int tmp = 1;
    for (int i = 1; i < tail; i++)
        if (list[i] != list[i - 1]) list[tmp++] = list[i];
    tail = tmp;
    long long ans = 0;
    for (int i = 0; i < n; i++) {
        int best = query(1, 0, tail - 1, inx(d[i].b)) + d[i].h;
        if (best > ans) ans = best;
        change(1, 0, tail - 1, inx(d[i].a + 1), best);

 //       cout << inx(d[i].b) << ' ' << inx(d[i].a + 1) << endl;
    }
    cout << ans << endl;
    return 0;
}


#include <stdio.h>
#include <algorithm>
#include <iostream>
using namespace std;

const long long maxn = 1e5 + 10;

struct Point {
    long long a, b, h;
} d[maxn];

bool cmp(const Point &a, const Point &b) {
    return a.b > b.b;
}

long long tail;
long long list[maxn * 2];

long long inx(long long x) {
    long long i = 0, j = tail - 1, mid;
    while (i <= j) {
        mid = (i + j) >> 1;
        if (list[mid] >= x) j = mid - 1;
        else i = mid + 1;
    }
    return i;
}

long long best[maxn * 4], flag[maxn * 4];
long long query(long long u, long long x, long long y, long long loc) {
    if (x > loc) return 0;
    if (y <= loc) return best[u];
    long long mid = (x + y) >> 1;

    if (flag[u * 2] < flag[u]) {
        best[u * 2] = max(best[u * 2], flag[u]);
        flag[u * 2] = flag[u];
    }
    if (flag[u * 2 + 1] < flag[u]) {
        best[u * 2 + 1] = max(best[u * 2 + 1], flag[u]);
        flag[u * 2 + 1] = flag[u];
    }
    return max(query(u * 2, x, mid, loc), query(u * 2 + 1, mid + 1, y, loc));
}

void change(long long u, long long x, long long y, long long loc, long long val) {
    if (y < loc) return ;
    if (x >= loc) {
        if (val > best[u]) best[u] = val;
        if (val > flag[u]) flag[u] = val;
        return ;
    }
    long long mid = (x + y) >> 1;

    if (flag[u * 2] < flag[u]) {
        best[u * 2] = max(best[u * 2], flag[u]);
        flag[u * 2] = flag[u];
    }
    if (flag[u * 2 + 1] < flag[u]) {
        best[u * 2 + 1] = max(best[u * 2 + 1], flag[u]);
        flag[u * 2 + 1] = flag[u];
    }

    change(u * 2, x, mid, loc, val);
    change(u * 2 + 1, mid + 1, y, loc, val);
    best[u] = max(best[u * 2], best[u * 2 + 1]);
}

int main() {
    long long n;
    cin >> n;
    for (long long i = 0; i < n; i++) {
    //    scanf("%d%d%d", &d[i].a, &d[i].b, &d[i].h);
        cin >> a[i].a >> d[i].b >> d[i].h;
        list[tail++] = d[i].a + 1; list[tail++] = d[i].b;
    }
    sort(d, d + n, cmp);
    sort(list, list + tail);
    long long tmp = 1;
    for (long long i = 1; i < tail; i++)
        if (list[i] != list[i - 1]) list[tmp++] = list[i];
    tail = tmp;
    long long ans = 0;
    for (long long i = 0; i < n; i++) {
        long long best = query(1, 0, tail - 1, inx(d[i].b)) + d[i].h;
        if (best > ans) ans = best;
        change(1, 0, tail - 1, inx(d[i].a + 1), best);
    }
    cout << ans << endl;
    return 0;
}


#include <stdio.h>
#include <algorithm>
#include <iostream>
using namespace std;

const int maxn = 1e5 + 10;

struct Point {
    int a, b, h;
} d[maxn];

bool cmp(const Point &a, const Point &b) {
    return a.b > b.b;
}

int tail;
int list[maxn * 2];

int inx(int x) {
    int i = 0, j = tail - 1, mid;
    while (i <= j) {
        mid = (i + j) >> 1;
        if (list[mid] >= x) j = mid - 1;
        else i = mid + 1;
    }
    return i;
}

long long best[maxn * 4];
long long query(int u, int x, int y, int loc) {
    if (x > loc) return 0;
    if (y <= loc) return best[u];
    int mid = (x + y) >> 1;
    if (best[u * 2] < best[u]) best[u * 2] = best[u];
    if (best[u * 2 + 1] < best[u]) best[u * 2 + 1] = best[u];
    return max(query(u * 2, x, mid, loc), query(u * 2 + 1, mid + 1, y, loc));
}

void change(int u, int x, int y, int loc, long long val) {
    if (y < loc) return ;
    if (x >= loc) {
        if (val > best[u]) best[u] = val;
        return ;
    }
    int mid = (x + y) >> 1;
    change(u * 2, x, mid, loc, val);
    change(u * 2 + 1, mid + 1, y, loc, val);
}

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d%d%d", &d[i].a, &d[i].b, &d[i].h);
        list[tail++] = d[i].a + 1; list[tail++] = d[i].b;
    }
    sort(d, d + n, cmp);
    sort(list, list + tail);
    int tmp = 1;
    for (int i = 1; i < tail; i++)
        if (list[i] != list[i - 1]) list[tmp++] = list[i];
    tail = tmp;
    long long ans = 0;
    for (int i = 0; i < n; i++) {
        int best = query(1, 0, tail - 1, inx(d[i].b)) + d[i].h;
        if (best > ans) ans = best;
        change(1, 0, tail - 1, inx(d[i].a + 1), best);

 //       cout << inx(d[i].b) << ' ' << inx(d[i].a + 1) << endl;
    }
    cout << ans << endl;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

struct ring
{
    int r_in,r_out,h,id;
};

ring rings[100010];
stack<ring>tmp;
long long dp[100010],ans;
int n,i,j;

bool cmp(ring a,ring b)
{
    if (a.r_out==b.r_out) return a.r_in>b.r_in;
    else return a.r_out>b.r_out;
}

int main()
{
    scanf("%d",&n);
    for (i=1;i<=n;i++)
    {
        scanf("%d%d%d",&rings[i].r_in,&rings[i].r_out,&rings[i].h);
    }
    sort(rings+1,rings+1+n,cmp);
    for (i=1;i<=n;i++) rings[i].id=i;
    rings[0].r_in=rings[0].r_out=rings[1].r_out+1;
    rings[0].h=0;
    dp[0]=0;
    ans=0;
    for (i=1;i<=n;i++)
    {
        dp[i]=rings[i].h;
        while (!tmp.empty()&&tmp.top().r_in>=rings[i].r_out) tmp.pop();
        if (!tmp.empty()) dp[i]=max(dp[i],rings[i].h+dp[tmp.top().id]);
        tmp.push(rings[i]);
        ans=max(ans,dp[i]);
    }
    cout<<ans<<"\n";
}


#include<bits/stdc++.h>

using namespace std;

struct ring
{
    int r_in,r_out,h,rankin;
};

ring rings[100010];
set<int>tmp;
long long dp[100010],ans,rin[100010][2];
int n,i,j,maxin;

bool cmp1(ring a,ring b)
{
    if (a.r_in==b.r_in) return a.r_out>b.r_out;
    else return a.r_in>b.r_in;
}

bool cmp(ring a,ring b)
{
    if (a.r_out==b.r_out) return a.r_in>b.r_in;
    else return a.r_out>b.r_out;
}

int main()
{
    scanf("%d",&n);
    for (i=1;i<=n;i++)
    {
        scanf("%d%d%d",&rings[i].r_in,&rings[i].r_out,&rings[i].h);
    }
    sort(rings+1,rings+1+n,cmp1);
    for (i=1;i<=n;i++)
    {
        rings[i].rankin=i;
        rin[i][0]=rings[i].r_in;
    }
    sort(rings+1,rings+1+n,cmp);
    for (i=1;i<=n;i++)
        rin[rings[i].rankin][1]=i;
    rings[0].r_in=rings[0].r_out=rings[1].r_out+1;
    rings[0].h=0;
    dp[0]=0;
    ans=0;
    maxin=0;
    rin[0][0]=rings[1].r_out+1;
    set<int>::iterator tt;
    tmp.insert(0);
    for (i=1;i<=n;i++)
    {
        dp[i]=rings[i].h;
        tt=tmp.end();
        tt--;
        while (true)
        {
            if (rin[*tt][0]>=rings[i].r_out) break;
            dp[i]=max(dp[i],rings[i].h+dp[rin[*tt][1]]);
            if (tt==tmp.begin()) break;
            tt--;
        }
        ans=max(ans,dp[i]);
        tmp.insert(rings[i].rankin);
    }
    cout<<ans<<"\n";
}


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

#define int long long
#define forn(i,a,n) for (int i=a; i<n; i++)

int h,c,t;

int calcu(int mid){
	int ret=mid*h+(mid-1)*c;
	ret/=(2*mid-1);
	return ret;
}

void solve(){
	cin>>h>>c>>t;
	if (h<=t){
		cout<<1<<endl;
		return;
	}
	if ((h+c)/2>=t){
		cout<<2<<endl;
		return;
	}
	int l=0,r=2e18;
	while (l+1<r){
		int mid=(l+r)>>1;
		if (calcu(mid)>=t) l=mid;
		else r=mid;
	}
	int d1,d2;
	d1=abs(calcu(r)-t);
	d2=abs(calcu(r-1));
	if (d1==d2){
		cout<<r*2-3<<endl;
		return;
	}
	if (d1<d2){
		cout<<r*2-1<<endl;
		return;
	}
	cout<<r*2-3<<endl;
	return;
}

signed main(){
	ios::sync_with_stdio(false);
   	cin.tie(0);

	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);

	int t;
	cin>>t;
	while (t--){
		solve();
	}
	return 0;
}


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

#define ll long long
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define x first
#define y second

long double calculate(ll mid,ll c,ll h){
	long double ret=(long double)(mid*h+(mid-1)*c)/(mid*2-1);
	return ret;
}

void solve(){
	ll h,c,t;
	cin>>h>>c>>t;
	ll l=1,r=2e18;
	if ((c+h)/2==t){
		cout<<2<<endl;
		return;
	}
	while (l+1<r){
		ll mid=(l+r)>>1;
		if (calculate(mid,c,h)>t) l=mid;
		else r=mid;
	}
	//cout<<r<<endl;
	long double differ1,differ2;
	differ1=calculate(r-1,c,h);
	differ2=calculate(r,c,h);
	differ1=abs(differ1-t);
	differ2=abs(differ2-t);
	//cout<<differ1<<" "<<differ2<<endl;
	if (differ1==differ2)
		cout<<r*2-3<<endl;
	else if (differ1<differ2)
		cout<<r*2-3<<endl;
	else
		cout<<r*2-1<<endl;
}

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

	int T;
	cin>>T;
	while (T--){
		solve();
	}
	return 0;
}


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

#define int long long
#define forn(i,a,n) for (int i=a; i<n; i++)

long double h,c,t;

long double calcu(int mid){
	long double ret=mid*h+(mid-1)*c;
	ret/=(2*mid-1);
	return ret;
}

void solve(){
	cin>>h>>c>>t;
	if (h<=t){
		cout<<1<<endl;
		return;
	}
	if ((h+c)/2>=t){
		cout<<2<<endl;
		return;
	}
	int l=0,r=1e9;
	while (l+1<r){
		int mid=(l+r)>>1;
		if (calcu(mid)>=t) l=mid;
		else r=mid;
	}
	long double d1,d2;
	d1=abs(calcu(r)-t);
	d2=abs(calcu(r-1)-t);
	if (d1==d2){
		cout<<r*2-3<<endl;
		return;
	}
	if (d1<d2){
		cout<<r*2-1<<endl;
		return;
	}
	cout<<r*2-3<<endl;
	return;
}

signed main(){
	ios::sync_with_stdio(false);
   	cin.tie(0);

	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);

	int t;
	cin>>t;
	while (t--){
		solve();
	}
	return 0;
}


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

#define ll long long
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define x first
#define y second

long double calculate(ll mid,ll c,ll h){
	long double ret=(long double)(mid*h+(mid-1)*c)/(mid*2-1);
	return ret;
}

void solve(){
	ll h,c,t;
	cin>>h>>c>>t;
	ll l=1,r=2e18;
	if (h<=t){
		cout<<1<<endl;
		return;
	}
	if ((c+h)-t*2>=0){
		cout<<2<<endl;
		return;
	}
	while (l+1<r){
		ll mid=(l+r)>>1;
		if (calculate(mid,c,h)>t) l=mid;
		else r=mid;
	}
	long double differ1,differ2;
	differ1=calculate(r-1,c,h);
	differ2=calculate(r,c,h);
	differ1=abs(differ1-t);
	differ2=abs(differ2-t);
	if (differ1==differ2)
		cout<<r*2-3<<endl;
	else if (differ1<differ2)
		cout<<r*2-3<<endl;
	else
		cout<<r*2-1<<endl;
}

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

	int T;
	cin>>T;
	while (T--){
		solve();
	}
	return 0;
}


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

#define ll long long
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define x first
#define y second

double calc(int i,int l,int r){
	return ((i*r)+((i-1)*l))/(i+i-1);
}

void solve(){
   	int l,r,t;
   	cin>>r>>l>>t;
	if (t>=r){
		cout<<1<<endl;
		return;
	}
	if ((l+r)/2==t){
		cout<<2<<endl;
		return;
	}
	int val=(l+r)/2;
	for (int i=1; i<1000; i++){
		if (calc(i,l,r)<t){
			long double num1=abs(calc(i,l,r)-t),num2=abs(calc(i-1,l,r));
			if (num1>=num2){
				cout<<i+i-3<<endl;
				return;
			}
			else{
				cout<<i+i-1<<endl;
				return;
			}
		}
	}
}

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

   	int test;
   	cin>>test;
   	while (test--){
   		solve();
	}
	return 0;
}


#define int long long
#define MOD 1000000007
#include<bits/stdc++.h>
using namespace std;
    const long double one = 1.0;
long double calculate(int c, int h, int mid) {
        int kek = mid * h + (mid - 1) * c;
        long double res = (one * kek) / (2 * mid - 1);
        return res;
    }
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int h,c,t;
        cin>>h>>c>>t;
        if(t>=h)
        cout<<"1"<<endl;

        else if(h+c>=2*t)
            cout<<"2"<<endl;
        else
        {
            int l=1;
            int r=1e6;
            int m;
            while(r-l>1)
            {
                m=(l+r)/2;
           if(calculate(c,h,m)>=t)
           {
               l=m;
           }
           else
            r=m;

            }
            long double val1=calculate(c,h,2*l);
            long double val2=calculate(c,h,2*l+1);
            if(abs(val1-t)<=abs(val2-t))
            {
                cout<<2*l+1<<endl;
            }
            else
                cout<<2*l-1<<endl;

        }

    }

}


#define ll long long
#define MOD 1000000007
#include<bits/stdc++.h>
using namespace std;
long double calc(ll h,ll c,ll m)
{
    long double ans=(long double)(h*m+c*(m-1))/(long double)(2*m-1);
    return ans;

}
int main()
{
    int tc;
    cin>>tc;
    while(tc--)
    {
  ll h,c,t;
  cin>>h>>c>>t;
  if((2*t)<=(h+c))
  {

      cout<<"2"<<endl;
  }
  else if(t==h)
    cout<<"1"<<endl;
  else
  {
       // cout<<calc(41,15,4)<<endl;

      int  l=1,r=1e9;
      int count=0;
      while(l+1<r)
      {
         // cout<<l<<" "<<r<<endl;
          count++;
          int mid=(l+r)/2;
          if(calc(h,c,mid)>=t)
          {
              l=mid;
          }
          else
          {
              r=mid;
          }

      }
      if(abs(calc(h,c,2*l+1)-t)<abs(calc(h,c,2*l-1)-t))
      {
          cout<<2*l+1<<endl;
      }
      else
        cout<<2*l-1<<endl;

  }

    }

}


#define ll long long
#define MOD 1000000007
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        float h,c,t;
        cin>>h>>c>>t;
        if(h==t)
            cout<<"1"<<endl;
        else if(h<t)
        {
            if(c>h)
                cout<<"2"<<endl;
            else
                cout<<"1"<<endl;

        }
        if(h>t)
        {
            float temp;
           float min=(h-t);
           int cnt=1;
            for(int i=2;i<100000;i++)
            {
                if(i%2==0)
                {
                    temp=(float)((i/2)*h+(i/2)*c)/(float)i;

                }
                else
                {
                    temp=(float)((i/2+1)*h+(i/2)*c)/(float)i;

                }
               // cout<<temp-t<<endl;
                if(abs(temp-t)<min)
                {
                    min=abs(temp-t);
                    cnt=i;

                }

            }
                    cout<<cnt<<endl;

        }

     }

}


#define ll long long
#define MOD 1000000007
#include<bits/stdc++.h>
using namespace std;
    const long double one = 1.0;
long double calculate(int c, int h, int mid) {
        int kek = mid * h + (mid - 1) * c;
        long double res = (one * kek) / (2 * mid - 1);
        return res;
    }
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        ll h,c,t;
        cin>>h>>c>>t;
        if(t>=h)
        cout<<"1"<<endl;

        else if(h+c>=2*t)
            cout<<"2"<<endl;
        else
        {
            ll l=1;
            ll r=1e6;
            ll m;
            while(r-l>1)
            {
                m=(l+r)/2;
           if(calculate(c,h,m)>=t)
           {
               l=m;
           }
           else
            r=m;

            }
            long double val1=calculate(c,h,2*l);
            long double val2=calculate(c,h,2*l+1);
            if(abs(val1-t)<=abs(val2-t))
            {
                cout<<2*l+1<<endl;
            }
            else
                cout<<2*l-1<<endl;

        }

    }

}


#define ll long long
#define MOD 1000000007
#include<bits/stdc++.h>
using namespace std;
long double calc(ll h,ll c,ll m)
{
    long double ans=(long double)(h*m+c*(m-1))/(long double)(2*m-1);
    return ans;

}
int main()
{
    int tc;
    cin>>tc;
    while(tc--)
    {
  ll h,c,t;
  cin>>h>>c>>t;
  if((2*t)<=(h+c))
  {

      cout<<"2"<<endl;
  }
  else if(t==h)
    cout<<"1"<<endl;
  else
  {
       // cout<<calc(41,15,4)<<endl;

      int  l=1,r=1e9;
      int count=0;
      while(l<=r)
      {
         // cout<<l<<" "<<r<<endl;
          count++;
          int mid=(l+r)/2;
          if(calc(h,c,mid)>=t)
          {
              l=mid+1;
          }
          else
          {
              r=mid-1;
          }

      }
      if(abs(calc(h,c,l+1)-t)<abs(calc(h,c,l)-t))
      {
          cout<<2*l+1<<endl;
      }
      else
        cout<<2*l-1<<endl;

  }

    }

}


  //Not Mine :Just Checking Something
    #include <bits/stdc++.h>

    #define int long long

    using namespace std;

    const int INF = 1e12;
    const long double one = 1.0;

    long double calc(int c, int h, int mid) {
        int kek = mid * h + (mid - 1) * c;
        long double res = (one * kek) / (2 * mid - 1);
        return res;
    }

    void solve() {
        int c, h, t;
        cin >> h >> c >> t;
        if (t >= h) {
            cout << 1 << endl;
            return;
        }
        if (t <= (c + h) / 2) {
            cout << 2 << endl;
            return;
        }
        int l = 2, r = INF, mid;
        while (r - l > 1) {
            mid = (l + r) / 2;
            if (calc(c, h, mid) >= t) l = mid;
            else r = mid;
        }
        long double val1 = calc(c, h, l), val2 = calc(c, h, l + 1);
        long double d1 = fabs(t - val1), d2 = fabs(t - val2);
        if (d1 <= d2) {
            cout << 2 * l - 1 << endl;
        } else {
            cout << 2 * l + 1 << endl;
        }
    }

    signed main() {
        //freopen("Desktop/input.txt", "r", stdin);
        ios_base :: sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        int t;
        cin >> t;
        for (int i = 0; i < t; i++) solve();
    }


  //Not Mine :Just Checking Something
    #include <bits/stdc++.h>

    #define int long long

    using namespace std;

    const int INF = 1e12;
    const long double one = 1.0;

    long double calc(int c, int h, int mid) {
        int kek = mid * h + (mid - 1) * c;
        long double res = (one * kek) / (2 * mid - 1);
        return res;
    }

    void solve() {
        int c, h, t;
        cin >> h >> c >> t;
        if (t >= h) {
            cout << 1 << endl;
            return;
        }
        if (t <= (c + h) / 2) {
            cout << 2 << endl;
            return;
        }
        int l = 0, r = INF, mid;
        while (r - l > 1) {
            mid = (l + r) / 2;
            if (calc(c, h, mid) >= t) l = mid;
            else r = mid;
        }
        long double val1 = calc(c, h, l), val2 = calc(c, h, l + 1);
        long double d1 = fabs(t - val1), d2 = fabs(t - val2);
        if (d1 <= d2) {
            cout << 2 * l - 1 << endl;
        } else {
            cout << 2 * l + 1 << endl;
        }
    }

    signed main() {
        //freopen("Desktop/input.txt", "r", stdin);
        ios_base :: sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        int t;
        cin >> t;
        for (int i = 0; i < t; i++) solve();
    }


#define ll long long
#define MOD 1000000007
#include<bits/stdc++.h>
using namespace std;
    const long double one = 1.0;
long double calculate(int c, int h, int mid) {
        int kek = mid * h + (mid - 1) * c;
        long double res = (one * kek) / (2 * mid - 1);
        return res;
    }
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int h,c,t;
        cin>>h>>c>>t;
        if(h+c>=2*t)
            cout<<"2"<<endl;
        else
        {
            int l=1;
            int r=1e6;
            int m;
            while(r-l>1)
            {
                m=(l+r)/2;
           if(calculate(c,h,m)>=t)
           {
               l=m;
           }
           else
            r=m;

            }
            long double val1=calculate(c,h,2*l);
            long double val2=calculate(c,h,2*l+1);
            if(abs(val1-t)<=abs(val2-t))
            {
                cout<<2*l+1<<endl;
            }
            else
                cout<<2*l-1<<endl;

        }

    }

}


#define ll long long
#define MOD 1000000007
#include<bits/stdc++.h>
using namespace std;
long double calc(ll h,ll c,ll m)
{
    long double ans=(long double)(h*m+c*(m-1))/(long double)(2*m-1);
    return ans;

}
int main()
{
    int tc;
    cin>>tc;
    while(tc--)
    {
  ll h,c,t;
  cin>>h>>c>>t;
  if((2*t)<=(h+c))
  {

      cout<<"2"<<endl;
  }
  else if(t==h)
    cout<<"1"<<endl;
  else
  {
       // cout<<calc(41,15,4)<<endl;

      int  l=1,r=1e9;
      int count=0;
      while(l+1<r)
      {
         // cout<<l<<" "<<r<<endl;
          count++;
          int mid=(l+r)/2;
          if(calc(h,c,mid)>=t)
          {
              l=mid;
          }
          else
          {
              r=mid;
          }

      }
      if(abs(calc(h,c,l+1)-t)<abs(calc(h,c,l)-t))
      {
          cout<<2*l+1<<endl;
      }
      else
        cout<<2*l-1<<endl;

  }

    }

}


#define ll long long
#define MOD 1000000007
#include<bits/stdc++.h>
using namespace std;
long double calc(ll h,ll c,ll m)
{
    long double ans=(long double)(h*m+c*(m-1))/(long double)(2*m-1);
    return ans;

}
int main()
{
    int tc;
    cin>>tc;
    while(tc--)
    {
  ll h,c,t;
  cin>>h>>c>>t;
  if((2*t)<=(h+c))
  {

      cout<<"2"<<endl;
  }
  else if(t==h)
    cout<<"1"<<endl;
  else
  {
       // cout<<calc(41,15,4)<<endl;

      int  l=1,r=1e9;
      int count=0;
      while(l<=r)
      {
         // cout<<l<<" "<<r<<endl;
          count++;
          int mid=(l+r)/2;
          if(calc(h,c,mid)>t)
          {
              l=mid+1;
          }
          else
          {
              r=mid-1;
          }

      }
      if(abs(calc(h,c,l+1)-t)<abs(calc(h,c,l)-t))
      {
          cout<<2*l+1<<endl;
      }
      else
        cout<<2*l-1<<endl;

  }

    }

}


#include <bits/stdc++.h>
#define IOS {ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
#define endl "\n"
#define int long long int
#define f(i, a, b) for(int i=a; i<b; i++)
#define fb(i, a, b) for(int i=a; i>=b; i--)
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define S(x) (int) x.size()
#define LB lower_bound
#define UB upper_bound
#define fp(x, y) fixed<<setprecision(y)<<x
#define M 100005
#define mod 1000000007
#define PI 3.141592653589793238462643383279502884
using namespace std;

float h, c, t;

float func(int a)
{
	return (a*h + (a-1)*c)/(2*a - 1);
}

void solve()
{
	cin>>h>>c>>t;
	if(t == h)
	{
		cout<<"1\n";
		return;
	}
	if(t <= (h+c)/2)
	{
		cout<<"2\n";
		return;
	}
	int l = 1, r = 1e9;
	int curr, ans = 1;
	while(l <= r)
	{
		int mid = (l+r)/2;
		if(func(mid) > t) l = mid+1;
		else r = mid-1;
	}
	float cur = (float)INT_MAX;
	f(i, max(0, l-1), l+1)
	{
		if(abs(func(i)-t) < cur)
		{
			cur = abs(func(i)-t);
			ans = i;
		}
	}
	cout<<2*ans-1<<endl;
}

int32_t main()
{
    IOS
    int t = 1;
    cin>>t;
    f(tno, 1, t+1)
    {
        solve();
    }
    return 0;
}


  //Not Mine :Just Checking Something
    #include <bits/stdc++.h>

    #define int long long

    using namespace std;

    const int INF = 1e12;
    const long double one = 1.0;

    long double calc(int c, int h, int mid) {
        int kek = mid * h + (mid - 1) * c;
        long double res = (one * kek) / (2 * mid - 1);
        return res;
    }

    void solve() {
        int c, h, t;
        cin >> h >> c >> t;
        if (t >= h) {
            cout << 1 << endl;
            return;
        }
        if (t <= (c + h) / 2) {
            cout << 2 << endl;
            return;
        }
        int l = 1, r = INF, mid;
        while (r - l > 1) {
            mid = (l + r) / 2;
            if (calc(c, h, mid) >= t) l = mid;
            else r = mid;
        }
        long double val1 = calc(c, h, l), val2 = calc(c, h, l + 1);
        long double d1 = fabs(t - val1), d2 = fabs(t - val2);
        if (d1 <= d2) {
            cout << 2 * l - 1 << endl;
        } else {
            cout << 2 * l + 1 << endl;
        }
    }

    signed main() {
        //freopen("Desktop/input.txt", "r", stdin);
        ios_base :: sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        int t;
        cin >> t;
        for (int i = 0; i < t; i++) solve();
    }


#define ll long long
#define MOD 1000000007
#include<bits/stdc++.h>
using namespace std;
    const long double one = 1.0;
long double calculate(ll c, ll h, ll mid) {
        ll kek = mid * h + (mid - 1) * c;
        long double res = (one * kek) / (2 * mid - 1);
        return res;
    }
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        ll h,c,t;
        cin>>h>>c>>t;
        if(t>=h)
        cout<<"1"<<endl;

        else if(h+c>=2*t)
            cout<<"2"<<endl;
        else
        {
            ll l=1;
            ll r=1e6;
            ll m;
            while(r-l>1)
            {
                m=(l+r)/2;
           if(calculate(c,h,m)>=t)
           {
               l=m;
           }
           else
            r=m;

            }
            long double val1=calculate(c,h,2*l);
            long double val2=calculate(c,h,2*l+1);
            if(abs(val1-t)<=abs(val2-t))
            {
                cout<<2*l+1<<endl;
            }
            else
                cout<<2*l-1<<endl;

        }

    }

}


  //Not Mine :Just Checking Something
    #include <bits/stdc++.h>

    #define int long long

    using namespace std;

    const int INF = 1e12;
    const long double one = 1.0;

    long double calc(int c, int h, int mid) {
        int kek = mid * h + (mid - 1) * c;
        long double res = (one * kek) / (2 * mid - 1);
        return res;
    }

    void solve() {
        int c, h, t;
        cin >> h >> c >> t;
        if (t >= h) {
            cout << 1 << endl;
            return;
        }
        if (t <= (c + h) / 2) {
            cout << 2 << endl;
            return;
        }
        int l = 0, r = INF, mid;
        while (r - l > 1) {
            mid = (l + r) / 2;
            if (calc(c, h, mid) >= t) l = mid+1;
            else r = mid-1;
        }
        long double val1 = calc(c, h, l), val2 = calc(c, h, l + 1);
        long double d1 = fabs(t - val1), d2 = fabs(t - val2);
        if (d1 <= d2) {
            cout << 2 * l - 1 << endl;
        } else {
            cout << 2 * l + 1 << endl;
        }
    }

    signed main() {
        //freopen("Desktop/input.txt", "r", stdin);
        ios_base :: sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        int t;
        cin >> t;
        for (int i = 0; i < t; i++) solve();
    }


#define ll long long
#define MOD 1000000007
#include<bits/stdc++.h>
using namespace std;
    const long double one = 1.0;
long double calculate(int c, int h, int mid) {
        int kek = mid * h + (mid - 1) * c;
        long double res = (one * kek) / (2 * mid - 1);
        return res;
    }
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int h,c,t;
        cin>>h>>c>>t;
        if(t>=h)
        cout<<"1"<<endl;

        else if(h+c>=2*t)
            cout<<"2"<<endl;
        else
        {
            int l=1;
            int r=1e6;
            int m;
            while(r-l>1)
            {
                m=(l+r)/2;
           if(calculate(c,h,m)>=t)
           {
               l=m;
           }
           else
            r=m;

            }
            long double val1=calculate(c,h,2*l);
            long double val2=calculate(c,h,2*l+1);
            if(abs(val1-t)<=abs(val2-t))
            {
                cout<<2*l+1<<endl;
            }
            else
                cout<<2*l-1<<endl;

        }

    }

}


#define ll long long
#define MOD 1000000007
#include<bits/stdc++.h>
using namespace std;
    const long double one = 1.0;
long double calculate(int c, int h, int mid) {
        ll kek = mid * h + (mid - 1) * c;
        long double res = (one * kek) / (2 * mid - 1);
        return res;
    }
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        ll h,c,t;
        cin>>h>>c>>t;
        if(t>=h)
        cout<<"1"<<endl;

        else if(h+c>=2*t)
            cout<<"2"<<endl;
        else
        {
            ll l=1;
            ll r=1e6;
            ll m;
            while(r-l>1)
            {
                m=(l+r)/2;
           if(calculate(c,h,m)>=t)
           {
               l=m;
           }
           else
            r=m;

            }
            long double val1=calculate(c,h,2*l);
            long double val2=calculate(c,h,2*l+1);
            if(abs(val1-t)<=abs(val2-t))
            {
                cout<<2*l+1<<endl;
            }
            else
                cout<<2*l-1<<endl;

        }

    }

}


#define ll long long
#define MOD 1000000007
#include<bits/stdc++.h>
using namespace std;
    const long double one = 1.0;
long double calculate(int c, int h, int mid) {
        int kek = mid * h + (mid - 1) * c;
        long double res = (one * kek) / (2 * mid - 1);
        return res;
    }
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int h,c,t;
        cin>>h>>c>>t;
        if(h+c>=2*t)
            cout<<"2"<<endl;
        else
        {
            int l=1;
            int r=1e9;
            int m;
            while(r-l>1)
            {
                m=(l+r)/2;
           if(calculate(c,h,m)>=t)
           {
               l=m;
           }
           else
            r=m;

            }
            long double val1=calculate(c,h,2*l);
            long double val2=calculate(c,h,2*l+1);
            if(abs(val1-t)<=abs(val2-t))
            {
                cout<<2*l+1<<endl;
            }
            else
                cout<<2*l-1<<endl;

        }

    }

}


#define ll long long
#define MOD 1000000007
#define f(i, a, b) for(int i=a; i<b; i++)
#include<bits/stdc++.h>
using namespace std;
long double calc(ll h,ll c,ll m)
{
    long double ans=(long double)(h*m+c*(m-1))/(long double)(2*m-1);
    return ans;

}
int main()
{
    int tc;
    cin>>tc;
    while(tc--)
    {
  ll h,c,t;
  cin>>h>>c>>t;
  if((2*t)<=(h+c))
  {

      cout<<"2"<<endl;
  }
  else if(t==h)
    cout<<"1"<<endl;
  else
  {
       // cout<<calc(41,15,4)<<endl;

      int  l=1,r=1e9;
      int count=0;
      while(l<=r)
      {
         // cout<<l<<" "<<r<<endl;
          count++;
          int mid=(l+r)/2;
          if(calc(h,c,mid)>t)
          {
              l=mid+1;
          }
          else
          {
              r=mid-1;
          }

      }
      ll ans=1;
      float cur=(float)INT_MAX;
   //   cout<<l<<endl;

    f(i,  max(0,l-1), l+1)
	{
		if(abs(calc(h,c,i)-t) < cur)
		{
			cur = abs((h,c,i)-t);
			ans = i;
		}
	}
//	cout<<ans<<endl;
	cout<<2*ans-1<<endl;

  }

    }

}


#define ll long long
#define MOD 1000000007
#define f(i, a, b) for(int i=a; i<b; i++)
#include<bits/stdc++.h>
using namespace std;
long double calc(ll h,ll c,ll m)
{
    long double ans=(long double)(h*m+c*(m-1))/(long double)(2*m-1);
    return ans;

}
int main()
{
    int tc;
    cin>>tc;
    while(tc--)
    {
  ll h,c,t;
  cin>>h>>c>>t;
  if((2*t)<=(h+c))
  {

      cout<<"2"<<endl;
  }
  else if(t==h)
    cout<<"1"<<endl;
  else
  {
       // cout<<calc(41,15,4)<<endl;

      int  l=1,r=1e9;
      int count=0;
      while(l<=r)
      {
         // cout<<l<<" "<<r<<endl;
          count++;
          int mid=(l+r)/2;
          if(calc(h,c,mid)>t)
          {
              l=mid+1;
          }
          else
          {
              r=mid-1;
          }

      }
      ll ans=1;
      float cur=(float)INT_MAX;
   //   cout<<l<<endl;

    f(i,  max(0,l-5), l+5)
	{
		if(abs(calc(h,c,i)-t) < cur)
		{
			cur = abs((h,c,i)-t);
			ans = i;
		}
	}
//	cout<<ans<<endl;
	cout<<2*ans-1<<endl;

  }

    }

}


#define ll long long
#define MOD 1000000007
#include<bits/stdc++.h>
using namespace std;
long double calc(ll h,ll c,ll m)
{
    long double ans=(long double)(h*m+c*(m-1))/(long double)(2*m-1);
    return ans;

}
int main()
{
    int tc;
    cin>>tc;
    while(tc--)
    {
  ll h,c,t;
  cin>>h>>c>>t;
  if((2*t)<=(h+c))
  {

      cout<<"2"<<endl;
  }
  else if(t==h)
    cout<<"1"<<endl;
  else
  {
       // cout<<calc(41,15,4)<<endl;

      int  l=1,r=1e9;
      int count=0;
      while(l+1<r)
      {
         // cout<<l<<" "<<r<<endl;
          count++;
          int mid=(l+r)/2;
          if(calc(h,c,mid)>=t)
          {
              l=mid;
          }
          else
          {
              r=mid;
          }

      }
    //  cout<<"HEY"<<endl;
      //cout<<l<<endl;
      if(abs(calc(h,c,2*l+1))<abs(calc(h,c,2*l-1)))
      {
          cout<<2*l+1<<endl;
      }
      else
        cout<<2*l-1<<endl;

  }

    }

}


#define ll long long
#define MOD 1000000007
#include<bits/stdc++.h>
using namespace std;
long double calc(ll h,ll c,ll m)
{
    long double ans=(long double)(h*m+c*(m-1))/(long double)(2*m-1);
    return ans;

}
int main()
{
    int tc;
    cin>>tc;
    while(tc--)
    {
  ll h,c,t;
  cin>>h>>c>>t;
  if((2*t)<=(h+c))
  {

      cout<<"2"<<endl;
  }
  else if(t==h)
    cout<<"1"<<endl;
  else
  {
       // cout<<calc(41,15,4)<<endl;

      int  l=1,r=1e9;
      int count=0;
      while(l<=r)
      {
         // cout<<l<<" "<<r<<endl;
          count++;
          int mid=(l+r)/2;
          if(calc(h,c,mid)=t)
          {
              l=mid+1;
          }
          else
          {
              r=mid-1;
          }

      }
      if(abs(calc(h,c,l+1)-t)<abs(calc(h,c,l)-t))
      {
          cout<<2*l+1<<endl;
      }
      else
        cout<<2*l-1<<endl;

  }

    }

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
  int t;
  cin>>t;
  int i=0;
  while(i<t)
  {
    int h,c,t;
    cin>>h>>c>>t;
    double a = (c-t)/(double)((c+h) -2*t);
    if(c+h == 2*t)
    {
      cout<<2<<endl;
    }
    else
    {
      double a1 = ceil(a);
      double a2 = floor(a);
      double ans1 = abs((((h+c)*a1 - c)/(double)(2*a1 - 1)) - (t));
      double ans2 = abs((((h+c)*a2 - c)/(double)(2*a2 - 1)) - (t));
      int ans = (int) ans1>=ans2?2*a2-1:2*a1-1;
      if(ans<0)
        cout<<2<<endl;
      else
        cout<<ans<<endl;
    }
    i++;
  }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
  int t;
  cin>>t;
  int i=0;
  while(i<t)
  {
    int h,c,t;
    cin>>h>>c>>t;
    double a = (c-t)/(double)((c+h) -2*t);
    if((c+h) >= 2*t)
    {
      cout<<2<<endl;
    }
    else
    {
      double a1 = a;
      double a2 = a+1;
      double x1 = (((h+c)*a1 - c)/(double)(2*a1 - 1));
      double x2 = (((h+c)*a2 - c)/(double)(2*a2 - 1));
      double ans1 = fabs(x1-t);
      double ans2 = fabs(x2-t);
      int ans = (int) ans1>ans2?2*a2 -1:2*a1 -1;
      cout<<ans<<endl;
    }
    i++;
  }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
  int t;
  cin>>t;
  int i=0;
  while(i<t)
  {
    int h,c,t;
    cin>>h>>c>>t;
    double a = (c-t)/(double)((c+h) -2*t);
    if(c+h <= 2*t)
    {
      cout<<2<<endl;
    }
    else
    {
      double a1 = ceil(a);
      double a2 = floor(a);
      double x1 = (((h+c)*a1 - c)/(double)(2*a1 - 1));
      double x2 = (((h+c)*a2 - c)/(double)(2*a2 - 1));
      double ans1 = abs(x1-t);
      double ans2 = abs(x2-t);
      int ans = (int) ans1>=ans2?2*a2 -1:2*a1 -1;
      cout<<ans<<endl;
    }
    i++;
  }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
  int t;
  cin>>t;
  int i=0;
  while(i<t)
  {
    int h,c,t;
    cin>>h>>c>>t;
    double a = (c-t)/(double)((c+h) -2*t);
    if(c+h <= 2*t)
    {
      cout<<2<<endl;
    }
    else
    {
      double a1 = ceil(a);
      double a2 = floor(a);
      double x1 = (((h+c)*a1 - c)/(double)(2*a1 - 1));
      double x2 = (((h+c)*a2 - c)/(double)(2*a2 - 1));
      double ans1 = abs(x1-t);
      double ans2 = abs(x2-t);
      int ans = (int) ans1>ans2?2*a2 -1:2*a1 -1;
      cout<<ans<<endl;
    }
    i++;
  }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
  int t;
  cin>>t;
  int i=0;
  while(i<t)
  {
    int h,c,t;
    cin>>h>>c>>t;
    double a = (c-t)/(double)((c+h) -2*t);
    if((c+h) >= 2*t)
    {
      cout<<2<<endl;
    }
    else
    {
      double a1 = floor(a);
      double a2 = a1+1;
      double x1 = (((h+c)*a1 - c)/(double)(2*a1 - 1));
      double x2 = (((h+c)*a2 - c)/(double)(2*a2 - 1));
      double ans1 = abs(x1-t);
      double ans2 = abs(x2-t);
      int ans = ans1>ans2?2*a1+1:2*a1-1;
      cout<<ans<<endl;
    }
    i++;
  }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
  int t;
  cin>>t;
  int i=0;
  while(i<t)
  {
    int h,c,t;
    cin>>h>>c>>t;
    double a = (c-t)/(double)((c+h) -2*t);
    if((c+h) >= 2*t)
    {
      cout<<2<<endl;
    }
    else
    {
      double a1 = ceil(a);
      double a2 = floor(a);
      double x1 = (((h+c)*a1 - c)/(double)(2*a1 - 1));
      double x2 = (((h+c)*a2 - c)/(double)(2*a2 - 1));
      double ans1 = abs(x1-t);
      double ans2 = abs(x2-t);
      int ans = (int) ans1>ans2?2*a2 -1:2*a1 -1;
      cout<<ans<<endl;
    }
    i++;
  }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
  int t;
  cin>>t;
  int i=0;
  while(i<t)
  {
    int h,c,t;
    cin>>h>>c>>t;
    double a = (c-t)/(double)((c+h) -2*t);
    if((c+h) >= 2*t)
    {
      cout<<2<<endl;
    }
    else
    {
      double a1 = ceil(a);
      double a2 = floor(a);
      double x1 = (((h+c)*a1 - c)/(double)(2*a1 - 1));
      double x2 = (((h+c)*a2 - c)/(double)(2*a2 - 1));
      double ans1 = fabs(x1-t);
      double ans2 = fabs(x2-t);
      int ans = (int) ans1>ans2?2*a2 -1:2*a1 -1;
      cout<<ans<<endl;
    }
    i++;
  }
}