407407: GYM102785 C Dimensions
Description
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).
InputThe 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.
OutputThe 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.
ExamplesInputkg/(kg/(m/s))Output
mInput
s
kg*a/(Fs*B)*A*KtOutput
A*a*Kt*kgNote
B*Fs
Sorting in alphabetical order implies the following order of letters: «AaBbCbDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz». Shorter lines come earlier, than longer lines.