This page is still under construction.

Parts of this page are still being built. What you see may change.

Cruel Math Teacher, II

Time limit1sMemory limit128 MB

Summary
Find a real root of an odd-degree polynomial with one real root in [-1e6, 1e6], accurate to 5e-5, and print the root times 1000 truncated toward zero.
Level

Medium5 of 10

Topics
Binary search, Math, Implementation, Brute force
Solved
No attempts yet

Problem

As if raising numbers to powers were not cruel enough, Bessie's cruel math teacher has invented an even crueler assignment: find a root (a zero) of a polynomial.

Every such polynomial has an odd highest degree DD (1≤D≤111 \le D \le 11) and has exactly one real solution in the range −1,000,000≤X≤1,000,000-1{,}000{,}000 \le X \le 1{,}000{,}000; at that solution the polynomial evaluates to a value that is very close to (or exactly) 00 in floating-point arithmetic.

Given a polynomial with real coefficients (−500≤coefi≤500-500 \le coef_i \le 500), find a value of XX that lies within 0.00050.0005 of the true root. Multiply that value of XX by 1,0001{,}000 and print it as a truncated (non-rounded) integer, discarding the fractional part toward zero.

For example, consider the cubic 1.5⋅x3−10=01.5 \cdot x^3 - 10 = 0. Its solution satisfies x3=100/15=20/3=6.6666…x^3 = 100/15 = 20/3 = 6.6666\ldots, so x=1.88207…x = 1.88207\ldots; the correct output is therefore 18821882.

The polynomial is ∑i=0Dcoefi⋅xi\sum_{i=0}^{D} coef_i \cdot x^i, where xix^i means xx raised to the ii-th power.

No answer requires more than six significant digits, and every answer is small enough that it can be incremented by 0.00010.0001 in double-precision floating point without a serious loss of precision.

Hint: choose each new guess for XX so that the search interval shrinks at every step.

Input

  • Line 1: a single integer DD.
  • Lines 2 to D+2D+2: line i+2i+2 contains a single real number coeficoef_i (for i=0,1,…,Di = 0, 1, \ldots, D).

Output

  • Line 1: a single integer — the value of XX closest to the root, multiplied by 1,0001{,}000 and truncated toward zero.

Examples3

  1. Example 1

    Input
    3
    -10.0
    0.0
    0.0
    1.50
    
    Expected output
    1882
    
  2. Example 2

    Input
    1
    -1
    3
    
    Expected output
    333
    
  3. Example 3

    Input
    1
    1
    3
    
    Expected output
    -333