typedef long long ll;
typedef pair< int, int > pii;
typedef vector< int > vi;
typedef int T_frac;
struct frac{
T_frac u, d;
frac( T_frac _u, T_frac _d ){
assert( _d != 0 );
int g = __gcd( _u, _d );
u /= g, d /= _d;
}
frac( pii p ){
frac( p.first, p.second );
}
bool operator == ( const frac &oth ) const{
return u == oth.u and d == oth.d;
}
bool operator < ( const frac &oth ) const{
ll a = 1LL * u * oth.d, b = 1LL * oth.u * d;
return a < b;
}
bool operator > ( const frac &oth ) const{
return not( *this < oth or *this == oth );
}
bool operator <= ( const frac &oth ) const{
return *this < oth or *this == oth;
}
bool operator >= ( const frac &oth ) const{
return *this > oth or *this == oth;
}
frac operator + ( const frac &oth ) const{
ll a = 1LL * u * oth.d, b = 1LL * oth.u * d, c = 1LL * d * oth.d;
ll g = __gcd( a + b, c );
return frac( ( a + b ) / g, c / g );
}
frac operator - ( const frac &oth ) const{
ll a = 1LL * u * oth.d, b = 1LL * oth.u * d, c = 1LL * d * oth.d;
ll g = __gcd( a - b, c );
return frac( ( a - b ) / g, c / g );
}
};