Problem:
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

Distance II

Your task is to calculate the distance between two $n$ dimensional vectors $x = \{x_1, x_2, ..., x_n\}$ and $y = \{y_1, y_2, ..., y_n\}$.

The Minkowski's distance defined below is a metric which is a generalization of both the Manhattan distance and the Euclidean distance.

\[
D_{xy} = (\sum_{i=1}^n |x_i - y_i|^p)^{\frac{1}{p}}
\]

It can be the Manhattan distance

\[
D_{xy} = |x_1 - y_1| + |x_2 - y_2| + ... + |x_n - y_n|
\]

where $p = 1 $.

It can be the Euclidean distance

\[
D_{xy} = \sqrt{(|x_1 - y_1|)^{2} + (|x_2 - y_2|)^{2} + ... + (|x_n - y_n|)^{2}}
\]

where $p = 2 $.

Also, it can be the Chebyshev distance

\[
D_{xy} = max_{i=1}^n (|x_i - y_i|)
\]

where $p = \infty$

Write a program which reads two $n$ dimensional vectors $x$ and $y$, and calculates Minkowski's distance where $p = 1, 2, 3, \infty$ respectively.

Input

In the first line, an integer $n$ is given. In the second and third line, $x = \{x_1, x_2, ... x_n\}$ and $y = \{y_1, y_2, ... y_n\}$ are given respectively. The elements in $x$ and $y$ are given in integers.

Output

Print the distance where $p = 1, 2, 3$ and $\infty$ in a line respectively.
The output should not contain an absolute error greater than 10-5.

Constraints

$1 \leq n \leq 100$

$0 \leq x_i, y_i \leq 1000$

Sample Input

3
1 2 3
2 0 4

Sample Output

4.000000
2.449490
2.154435
2.000000

Solution in C# (judge verdict: Wrong Answer)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ITP1_10D
{
    class Program
    {
        class Pair<T1, T2>
        {
            public T1 Item1 { get; set; }
            public T2 Item2 { get; set; }
        }


        static IEnumerable<Pair<T1, T2>> GetPair<T1, T2>(IEnumerable<T1> source1, IEnumerable<T2> source2)
        {
            var s1 = source1.GetEnumerator();
            var s2 = source2.GetEnumerator();
            while (s1.MoveNext() && s2.MoveNext()) 
            {
                yield return new Pair<T1, T2> { Item1 = s1.Current, Item2 = s2.Current };
            }
        }


        static T Fn<T>(int count, Func<T, T> f, T x)
        {
            for (var i = 0; i < count; ++i)
            {
                x = f(x);
            }
            return x;
        }


        static double Root(int dimension, double a)
        {
            //return Math.Pow(a, 1.0 / (double)dimension);

            if (a == 0)
            {
                return 0;
            }

            // Newton's Method
            var n = 1.0;
            while (true)
            {
                var powerOfN = Fn(dimension, _ => _ * n, 1.0);
                var fx = powerOfN - a;
                var fx_d = dimension * (powerOfN / n);

                n = n - fx / fx_d;

                if (Math.Abs(fx) < 0.00001)
                {
                    break;
                }
            }

            return n;
        }


        static double MinkowskiDistance(int p, IEnumerable<int> d)
        {
            var sumOfDistance = 0;
            foreach (var n in d)
            {
                sumOfDistance += Fn(p, _ => _ * n, 1);
            }

            return Root(p, sumOfDistance);
        }


        static void Main(string[] args)
        {
            Console.ReadLine();
            var arrayOfX = Console.ReadLine().Split(' ');
            var arrayOfY = Console.ReadLine().Split(' ');

            var d = GetPair(arrayOfX, arrayOfY)
                .Select(_ => int.Parse(_.Item1) - int.Parse(_.Item2))
                .Select(_ => Math.Abs(_))
                .ToArray();

            Console.WriteLine(MinkowskiDistance(1, d));
            Console.WriteLine(MinkowskiDistance(2, d));
            Console.WriteLine(MinkowskiDistance(3, d));
            Console.WriteLine(d.Max());
        }
    }
}