#pragma once
#include <iostream>
using std::ostream;
using std::istream;
using std::cin;
using std::cout;
#include <vector>;
using std::vector;

int gcd(const int& a, int b) {
	//cout << a << ',' << b << '\n';
	return (b == 0) ? a : gcd(b, a%b);
}

class Rational {
	int den; //den
	int num; //num
public:
	Rational(int n=0, int d=1) : num(n / gcd(n, d)), den(d / gcd(n, d)) {}
	Rational operator*(const Rational& rho);
	Rational operator/(const Rational& rho);
	Rational operator+(const Rational& rho);
	Rational operator-(const Rational& rho);
	Rational reduce();
	void operator+=(const Rational& rho);
	int getDen() const { return den; }
	int getNum() const { return num; }
};

//ostream& operator<<(ostream&, Rational&) const;


ostream& operator<<(ostream& os, Rational& r) {
	os << r.getNum() << '/' << r.getDen();
	return os;
}

istream& operator>>(istream& is, Rational& r) {
	int a, b;
	char ch;
	is >> a;
	is >> ch; //eat the '/'
	if (ch != '/') std::cerr << "wth?\n";
	is >> b;
	r = Rational(a, b);
	return is;
}
Rational Rational::operator*(const Rational& rho) {
	return Rational(num*rho.getNum(), den*rho.getDen());
}

Rational Rational::operator/(const Rational& rho) {
	return Rational(num*rho.getDen(),
		den*rho.getNum());
}
Rational Rational::operator+(const Rational& rho) {
	return Rational(num*rho.getDen() + den * rho.getNum(),
		den*rho.getDen());
}
Rational Rational::operator-(const Rational& rho) {
	return Rational(num*rho.getDen() - den * rho.getNum(),
		den*rho.getDen());
}
void Rational::operator+=(const Rational& rho) {
	num = num * rho.getDen() + den * rho.getNum();
	den = den * rho.getDen();
	*this = this->reduce();
}

Rational Rational::reduce() {
	int div = gcd(num, den);
	return Rational(num / div,
		den / div);
}