407132: GYM102697 103 Home Computer

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

Description

103. Home Computertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

Home Computer

You are programming your home computer. You want your computer to learn Calculus, so today you decide to write a computer program to calculate the derivative of a polynomial function.

The derivative of a "power function" $$$x^n$$$ is defined as $$$nx^{n-1}$$$. For example, the derivative of $$$x^5$$$ would be $$$5x^4$$$.

The derivative of a constant multiple of a power function $$$kx^n$$$ is defined as $$$knx^{n-1}$$$. For example, the derivative of $$$3x^4$$$ would be $$$12x^3$$$.

When taking the derivative of several terms added or subtracted to each other, you take the derivative of each term individually. For example, the derivative of $$$3x^5 - 5x^4$$$ would be $$$15x^4 - 20x^3$$$.

The "power rule" described above works intuitively if all terms have at least a degree of two (the number that $$$x$$$ is taken to the power of). For terms with a degree of one, such as $$$7x$$$, the derivative is just the constant multiple in front of $$$x$$$, which is $$$7$$$ for this example. For constant terms (with a degree of zero), the derivative is zero, and can be cancelled out.

Using this knowledge, your task is to write a program to determine the derivative of a given polynomial function.

Input

The only line of input contains a polynomial function. Each term in the polynomial function will be separated either by " + " or " - " (with a space on either side). See the example inputs to further understand the formatting. Additionally, you are guaranteed that the first term in the polynomial is not a constant.

Output

Output a single line, consisting of a polynomial, in the format described above: the derivative of the given polynomial function.

ExamplesInput
5x^5 + 3x^4 + 2x^3 + 8x^2 + 9x + 10
Output
25x^4 + 12x^3 + 6x^2 + 16x + 9
Input
x + 10 + 3x + 5 + 8x + 16x^7 + 8x^30 + 300x^200
Output
1 + 3 + 8 + 112x^6 + 240x^29 + 60000x^199
Note

If you're using Java, take in the line of input, and use the .split(" ") command to separate it by spaces, rather than using scn.nextInt() or something similar.

加入题单

上一题 下一题 算法标签: