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: Accepted)

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

class Program
{
    static void Main(string[] args)
    {
        io.r<int>();
        double[][] d = io.r<double>(2, ' ');
        io.w(DISTANCE.MANHATTAN(d[0], d[1]));
        io.w(DISTANCE.EUCLIDEAN(d[0], d[1]));
        io.w(DISTANCE.MINKOWSKI(3, d[0], d[1]));
        io.w(DISTANCE.CHEBYSHEV(d[0], d[1]));
        io.wflush();
    }
}
#region DISTANCE
namespace LIB
{
    public class DISTANCE
    {
        public static double MINKOWSKI(int m, double[] a, double[] b)
        {
            double r = 0;
            for (int i = 0; i < a.Count(); i++) { double d = Math.Abs(a[i] - b[i]); r += Math.Pow(d, m); }
            return Math.Pow(r, (double)1 / m);
        }
        public static double MANHATTAN(double[] a, double[] b) { return MINKOWSKI(1, a, b); }
        public static double EUCLIDEAN(double[] a, double[] b) { return MINKOWSKI(2, a, b); }
        public static double CHEBYSHEV(double[] a, double[] b)
        {
            double r = 0;
            for (int i = 0; i < a.Count(); i++) { double d = Math.Abs(a[i] - b[i]); if (d > r) { r = d; } }
            return r;
        }
    }
}
#endregion
namespace LIB
{
    public class io
    {
        private const int WMAX = 1000;
        private static StringBuilder S = new StringBuilder();
        public static T r<T>() { return util.parse<T>(r()); }
        public static T[] r<T>(char s = ' ') { return r().Split(s).Select(util.parse<T>).ToArray(); }
        public static T[] r<T>(int l) { T[] r = new T[l]; for (int i = 0; i < l; i++) { r[i] = r<T>(); } return r; }
        public static T[][] r<T>(int l, char s = ' ') { T[][] r = new T[l][]; for (int i = 0; i < l; i++) { r[i] = r<T>(s); } return r; }
        private static string r() { return Console.ReadLine(); }
        public static void w(object v, bool lf = true) { S.Append(util.parse<string>(v)); if (lf == true) { S.Append('\n'); } if (S.Length >= WMAX) { wflush(); } }
        public static void wflush() { Console.Write(S.ToString()); S.Length = 0; }
    }
    public class util
    {
        public static T parse<T>(object value) { return (T)(Convert.ChangeType(value, typeof(T))); }
    }
    public class memo<Key, Result>
    {
        private Dictionary<Key, Result> R;
        public memo() { R = new Dictionary<Key, Result>(); }
        public Result exec(Key k, Func<Key, Result> f) { Result r; if (R.ContainsKey(k)) { r = R[k]; } else { r = f(k); R.Add(k, r); } return r; }
    }
    public class math
    {
        public static double distance(int p, double[] a, double[] b)
        {
            int c = a.Count(); double d = 0; for (int i = 0; i < c; i++) { d += Math.Pow(Math.Abs(a[i] - b[i]), p); }
            return Math.Pow(d, (double)1 / p);
        }
    }
}