Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/while-kasrlar-yigindisi

Sum of fractions

Medium 1000 ms 64 MB 49%
Share

Four positive integers $a$, $b$, $c$ and $d$ are given. Find the sum of the fractions $\frac{a}{b}$ and $\frac{c}{d}$ as an irreducible fraction $\frac{p}{q}$ (the greatest common divisor of $p$ and $q$ is $1$):

$$\frac{a}{b} + \frac{c}{d} = \frac{p}{q}$$

Even if the sum is an integer, it is printed as a fraction (for example, for $\frac{2}{1}$ print 2 1).

Adding two fractions with a common denominator and reducing

Input

One line with four positive integers: $a$, $b$, $c$ and $d$.

Output

One line with two integers separated by a space: $p$ and $q$.

Note

$1 \le a, b, c, d \le 10^{6}$

Examples

Input #1
1 2 1 3
Output #1
5 6
Input #2
1 4 1 4
Output #2
1 2

Sign in to submit a solution

Signing up is free and takes a minute.