407407: GYM102785 C Dimensions

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

C. Dimensionstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

When performing various physical calculations, it is often necessary to deal not only with numbers, but also with the dimensions of quantities. In this case, the dimensions can be very complex and they need to be reduced: for example, the dimension kg / (kg / m / s) is just m / s.

Write a program that minimizes the dimension as much as possible and registers all occurring values from left to right in alphabetical order (if the dimension is a fraction, then the numerator and denominator are written in alphabetical order separately).

Input

The first line of the input file contains a single character string - the dimension to be reduced.

Dimensions are denoted by Latin lowercase and uppercase letters.

In addition to the Latin letters in the expression may be signs of multiplication «*», division «/» and brackets. The degrees of magnitudes are expressed as multiple repetitions of magnitude. The order of operations corresponds to the generally accepted. Values differing by letter case are considered different.

The length input string does not exceed 1000 characters.

Output

The output contains a reduced dimension. The first line contains the numerator of the dimension, the second - the denominator. It is possible to use the 1 in the form of the numerator and / or denominator.

ExamplesInput
kg/(kg/(m/s))
Output
m
s
Input
kg*a/(Fs*B)*A*Kt
Output
A*a*Kt*kg
B*Fs
Note

Sorting in alphabetical order implies the following order of letters: «AaBbCbDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz». Shorter lines come earlier, than longer lines.

加入题单

算法标签: