A polynomial in three variables , and is symmetric if and only if for the six permutations of the variables.
For example, , , and are symmetric polynomials, while and are not.
We introduce the notation
[a
b
c]
with
to denote the symmetric polynomial that results from adding all the
monomials of the form
for any permutation of
,
and ,
where all the resulting monomials appear with coefficient 1. For
example, [a]
,
[ab] ,
and [a2bc]
.
(Note the special cases for the notation when the exponent of a variable
is zero or one.)
Symmetric polynomials that do not have any variables of degree larger
than one, that is, [a], [ab] and
[abc], are called elementary symmetric
polynomials. The fundamental theorem of symmetric polynomials, already
known to Newton, states that any symmetric polynomial can be
expressed as the sum and product of elementary symmetric
polynomials.
Here, we don’t ask you to find these expressions. Instead, we ask you
a much simpler task: calculate the product between a symmetric
polynomial
[a
b
c]
and an elementary symmetric polynomial. (If you do this, you are not far
away from establishing a recurrence relation and explicitly finding the
expressions from the fundamental theorem.)
Input consists of several cases, each with the product of a symmetric polynomial and an elementary symmetric polynomial. Assume and .
For every product, print its result. Make sure that the terms are in lexicographical order, that is, first the term with the largest , and in case of a tie, first the term with the largest .
Input
[a]*[a] [ab]*[a] [a^2b]*[ab] [a^3b]*[ab] [a^3b]*[abc] [a^1000b^700c^42]*[ab]
Output
[a^2] + 2[ab] [a^2b] + 3[abc] [a^3b^2] + 2[a^3bc] + 2[a^2b^2c] [a^4b^2] + 2[a^4bc] + [a^3b^2c] [a^4b^2c] [a^1001b^701c^42] + [a^1001b^700c^43] + [a^1000b^701c^43]