This page is still under construction.

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

Garland

Interview

Time limit1sMemory limit128 MB

Summary
Given the leftmost height A and the sag rule H_i = (H_{i-1}+H_{i+1})/2 - 1, find the smallest rightmost height B so all heights stay nonnegative.
Level

Medium6 of 10

Topics
Math, Binary search, Implementation
Solved
No attempts yet

Problem

A New Year garland consists of NN lamps attached to a single wire whose two ends hang down to the points where the outermost lamps are fixed. The wire sags under the weight of the lamps, so each lamp hangs exactly 1 mm1\,\text{mm} lower than the average height of its two immediate neighbours.

The leftmost lamp hangs at a height of A mmA\,\text{mm} above the ground. Determine the lowest possible height BB of the rightmost lamp such that no lamp goes below the ground, although some lamps may touch it.

Ignore the size of each lamp. Number the lamps from 11 to NN from left to right and let HiH_i denote the height of the ii-th lamp in millimetres. Then the following relations hold:

  • H1=AH_1 = A
  • Hi=Hi−1+Hi+12−1H_i = \dfrac{H_{i-1} + H_{i+1}}{2} - 1 for every ii with 1<i<N1 < i < N
  • HN=BH_N = B
  • Hi≥0H_i \ge 0 for every ii with 1≤i≤N1 \le i \le N

The figure above shows an example garland with 8 lamps.

Input

A single line contains two numbers NN and AA separated by a space. NN (3≤N≤10003 \le N \le 1000) is an integer, the number of lamps in the garland. AA (10≤A≤100010 \le A \le 1000) is a real number, the height of the leftmost lamp above the ground in millimetres.

Output

Print a single real number BB, the lowest possible height of the rightmost lamp, accurate to two digits after the decimal point.

Examples2

  1. Example 1

    Input
    8 15
    
    Expected output
    9.75
    
  2. Example 2

    Input
    692 532.81
    
    Expected output
    446113.34