407037: GYM102697 008 N-Dimensional Distance

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

008. N-Dimensional Distancetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

Calculate the distance between two points of a specified dimension. The common distance formula still applies to higher dimensional points with a small modification. You will input two points and display the distance between them as you normally would with the distance formula.

The n-dimensional distance formula can be expressed as

$$$d(p,q) = \sqrt{(q_{1}-p_{1})^2 + (q_{2}-p_{2})^2 + ... + (q_{n}-p_{n})^2}$$$

or in other terms:

$$$\sqrt{\sum_{i=1}^{n} (q_{i}-p_{i})^2} = d$$$

Remember that math.sqrt will calculate the square root of a number (you also have to add the line import math at the top of the program).

Input

The first line contains the dimension D between 2 and 500. Then, D test cases will follow.

Each test case N will consist of two lines: the value of the first point, and the value of the second point, in the Nth dimension.

Each of these values is an integer between -5000 and 5000, inclusive.

Output

A decimal number N representing the distance between the two points. Do not round your answer.

ExamplesInput
2
1
1
1
2
Output
1.0
Input
3
7
4
3
17
6
2
Output
14.866068747318506
Input
4
-2367
-2873
-4279
-2321
-1302
-1341
-2893
651
Output
4080.5951771769764

加入题单

算法标签: