PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BS0000377. Tỷ suất hoàn vốn nội bộ (Internal Rate of Return)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Tỷ suất hoàn vốn nội bộ (Internal Rate of Return)

Internal Rate of Return

Source: UVa

Version: Phuoc Hung OJ Extended

Problem Statement

An investment has an initial cash flow CF0<0CF_0<0 followed by TT positive cash flows CF1,…,CFTCF_1,\ldots,CF_T at the ends of subsequent periods. An internal rate of return rr is a value r>−1r>-1 for which the net present value is zero:

CF0+∑i=1TCFi(1+r)i=0.CF_0+\sum_{i=1}^T\frac{CF_i}{(1+r)^i}=0.

Determine the valid rates. A rate may be negative.

Input

The first line contains integer TT. The second line contains T+1T+1 integers CF0,CF1,…,CFTCF_0,CF_1,\ldots,CF_T.

Output

If there is exactly one rate, print it rounded to exactly two decimal places (ties away from zero). If none exists, print No; if multiple exist, print Too many. A rounded zero is printed as 0.00.

Subtasks

  • Subtask 1 (20 points): 1≤T≤11\le T\le 1; −109≤CF0≤−1-10^9\le CF_0\le-1; 1≤CFi≤99991\le CF_i\le9999 for every 1≤i≤T1\le i\le T.
  • Subtask 2 (30 points): 1≤T≤21\le T\le 2; −109≤CF0≤−1-10^9\le CF_0\le-1; 1≤CFi≤99991\le CF_i\le9999 for every 1≤i≤T1\le i\le T.
  • Subtask 3 (50 points): 1≤T≤101\le T\le 10; −109≤CF0≤−1-10^9\le CF_0\le-1; 1≤CFi≤99991\le CF_i\le9999 for every 1≤i≤T1\le i\le T.

Examples

Input

1
-1 2

Output

1.00

Explanation

From −1+2/(1+r)=0-1+2/(1+r)=0, we get 1+r=21+r=2 and r=1r=1.

Input

2
-8 6 9

Output

0.50

Explanation

Let z=1/(1+r)z=1/(1+r). The roots of 9z2+6z−8=09z^2+6z-8=0 are 2/32/3 and −4/3-4/3; only 2/32/3 is positive. Thus r=3/2−1=0.50r=3/2-1=0.50.