Under construction

Still being built. Things may change

Wrong Calculation

Time limit1sMemory limit128 MB

Summary
Given d+3 noisy samples of a degree-d polynomial with exactly one value corrupted by a large error, identify the index of the corrupted sample.
Level

Medium6 of 10

Topics
Math, Brute force, Implementation
Solved
No attempts yet

Problem

Professor Kim Sang-geun developed a new computing engine for producing numerical tables. It computes the values of a single-variable polynomial function.

For example, if the polynomial function is f(x)=x2+2x+1f(x) = x^2 + 2x + 1, the engine reports 1 (=f(0))1\,(=f(0)), 4 (=f(1))4\,(=f(1)), 9 (=f(2))9\,(=f(2)), 16 (=f(3))16\,(=f(3)), and 25 (=f(4))25\,(=f(4)).

However, while coding drunk, Sang-geun made a mistake, so the engine always outputs exactly one value incorrectly. So for the polynomial above it might report 1,4,12,16,251, 4, 12, 16, 25 instead of 1,4,9,16,251, 4, 9, 16, 25.

Given the values produced by the engine, write a program that finds which result was computed incorrectly.

Input

The input consists of several test cases.

The first line of each test case contains the degree dd of the polynomial. For example, the degree of 4x5+3x+0.54x^5 + 3x + 0.5 is 55, and the degree of 2.4x+3.82.4x + 3.8 is 11. dd is at most 55.

The next d+3d+3 lines contain the results f(0),f(1),…,f(d+2)f(0), f(1), \dots, f(d+2) in order. The polynomial function ff itself is not given. Every reported value is a real number greater than −100.0-100.0 and less than 100.0100.0.

The incorrect value is always one of f(0),f(1),…,f(d+2)f(0), f(1), \dots, f(d+2), and its error from the correct value is greater than 1.01.0. Because floating-point computation cannot avoid rounding, the other values may also carry error, but that error is tiny and never exceeds 10−610^{-6}.

The last line of the input contains a single 00.

Output

For each test case, print the position of the incorrectly computed value. If the result of f(i)f(i) is wrong, print ii.

Examples2

  1. Example 1

    Input
    2
    1.0
    4.0
    12.0
    16.0
    25.0
    1
    -30.5893962764
    5.76397083962
    39.3853798058
    74.3727663177
    4
    42.4715310246
    79.5420238202
    28.0282396675
    -30.3627807522
    -49.8363481393
    -25.5101480106
    7.58575761381
    5
    -21.9161699038
    -48.469304271
    -24.3188578417
    -2.35085940324
    -9.70239202086
    -47.2709510623
    -93.5066246072
    -82.5073836498
    0
    
    Expected output
    2
    1
    1
    6
    
  2. Example 2

    Input
    1
    -5.6737929123
    0.9573710935
    2.1645516008
    3.3717323057
    2
    -4.4575815635
    -5.2736246661
    -1.3840470388
    7.2111510432
    15.8843585195
    3
    0.4593424470
    1.9820544291
    -2.9543101092
    -8.5558137039
    -28.9549717393
    -64.9999993556
    0
    
    Expected output
    0
    4
    2