Toph is experiencing some technical difficulties. We are sorry for the inconvenience.

Practice on Toph

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

Panir Niche Rastaa Bhalo

By HasanAbdullah · Limits 1s, 1.0 GB

Poltu is a cyclist. He loves commuting by cycle. When he was a kid, often he was cycling in his dream. Now he is a software engineer at a ‘software development company’ in Dhaka. He usually goes home to office and office to home using his bicycle. Poltu commutes by cycle over the year even in rainy season.

One morning he took his cycle to go to office. It was a heavy rainy day. After paddling some kilometers he noticed a ‘new born sea’(!) in front of him. He failed to understand how can it be possible in the capital city, Dhaka. He saw a lot of floating plastic packets of chips, empty bottles and cans of soft drinks over the water. He got frustrated! Despite of the fact that most of the people of this area and the outside visitors are highly educated, still they threw away lots of their garbages to the roadside. Why? Who knows? (sigh…) This confined water is not only because of the garbages on the street but also for the lack of proper drainage system.

Anyway, by any means Poltu need to be reached at office. So he decided to cross that ‘sea’. Suddenly he saw a roadside signboard by Dhaka Metropolitan Police - “Panir Niche Rasta Bhalo (The condition of the road under water is well)”. This sign is assuring about the road but not about the depth of the water. He needs to find the height of the ‘sea’ because he can’t swim and he don’t want to take any risk without life jacket.

After a few moments he find a flying gas balloon middle of the sea. The balloon was hooked by a fiber. Another end of the fiber was tied with a heavy stone under the water. Then Poltu boomed the balloon throwing a stone. Then he saw the broken balloon is floating on the water attaching with the string from some distance of the original place. Although the current of the sea broken balloon is fixed on his position. Because the other side of the fiber is still tied with the stone under water.

Poltu assumed the height of the balloon was h from water surface. The displacement of the broken balloon from it’s original place is s. Help Poltu to find the depth d of the sea. If the depth is larger than Poltu’s height he’ll decide to take a ship otherwise he’ll cross the sea by his amazing bicycle.


Input the number of test case T. Then next T lines contain two integers h and s. The details about h and s are mentioned above.


1 <= T<= 10000
1<= h, s <= 100000007 ( where h < s )


Print the value of d. Errors less than 10-4 will be ignored. Check sample for more understanding.


1 5
3 7
2 4



    90% Solution Ratio

    Rajan_sustEarliest, Sep '17

    SmaronbiswasFastest, 0.0s

    evonlochLightest, 262 kB

    mdvirusShortest, 95B


    Login to submit


    Just apply (s*s - h *h)/(2*h)