Polynomial#1652

Polynomial

2 seconds
64 megabytes
Easy

Vasyl has been tasked with several similar math problems: "Find the value of a polynomial." He wants to write a program that, given a polynomial and a value for , computes the answer. Write such a program!

Input

The first line of the input contains a polynomial expressed as a sum of monomials. Each monomial is separated by a + or – sign. The first monomial may be preceded by a – sign. A monomial can be written in one of the following forms:

[<Coefficient>*]x[^<Exponent>]

or

<Coefficient>

Here, <\text{Coefficient}> is a natural number not greater than , is the variable (always the lowercase letter ), and <\text{Exponent}> is a natural number not exceeding . Parameters enclosed in square brackets are optional. The second line contains one integer—the value of .

All numbers in the input have absolute values not exceeding . The polynomial consists of at most monomials (there may be multiple monomials with the same degree).

Output

Print one number—the value of the polynomial for the given value.

Examples

Example 1

Loading
Loading