题目描述
Background
Xiao Ming has started middle school and always makes mistakes in polynomial calculations. Therefore, he has turned to you, a programming enthusiast, to design a program to help him.
Problem Description
Input several monomials or polynomials and compute the result.
Input Format
The input includes operators (+, -, *), letters (only lowercase letters from a to z), monomials without parentheses on both sides, and polynomials with parentheses ( ) or brackets [ ] on both sides. It is guaranteed that within each factor, monomials precede polynomials. (The length does not exceed 255 characters)
Output Format
Output the result of the expression, with each factor sorted lexicographically.
Sample Input and Output
Input Sample #1
(a+b)*(a+b+c)
Output Sample #1
a^2+2ab+ac+b^2+bc
Input Sample #2
(a+b)*(a+b+c)
Output Sample #2
a^2+2ab+ac+b^2+bc
Input Sample #3
(2a+b)*(2a-b)
Output Sample #3
4a^2-b^2
Input Sample #4
(a+b)*(a+b)*(a+b)
Output Sample #4
a^3+3a^2b+3ab^2+b^3
Input Sample #5
f*(a+b+d+z)+f^2
Output Sample #5
af+bf+df+fz+f^2
Input Sample #6
(a+b+2c)*(a+b-2c)-(a+b)*(a+b)
Output Sample #6
-4c^2
Notes
This is an easy problem.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分
样例输入
(a+b)*(a+b+c)
样例输出
a^2+2ab+ac+b^2+bc