#define Online

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Diagnostics;
using System.Threading;

namespace CF
{
    delegate double F(double x);
    delegate decimal Fdec(decimal x);

    class Team : IComparable<Team>
    {
        public string name;
        public int goal;
        public int miss;
        public int point;
        public int cnt;
        public int CompareTo(Team y)
        {
            if (this.point > y.point)
            {
                return 1;
            }
            else
            {
                if (this.point == y.point)
                {
                    if (this.goal - this.miss > y.goal - y.miss)
                    {
                        return 1;
                    }
                    else
                    {
                        if (this.goal - this.miss == y.goal - y.miss)
                        {
                            if (this.goal > y.goal)
                            {
                                return 1;
                            }
                            else
                            {
                                if (this.goal == y.goal)
                                {
                                    if (this.name.CompareTo(y.name) < 0)
                                        return 1;
                                    else
                                        return -1;
                                }
                                else
                                {
                                    return -1;
                                }
                            }

                        }
                        else
                        {
                            return -1;
                        }
                    }
                }
                else
                {
                    return -1;
                }
            }
        }
    }

    class Program
    {

        static void Main(string[] args)
        {

#if FileIO
            StreamReader sr = new StreamReader("input.txt");
            StreamWriter sw = new StreamWriter("output.txt");
            Console.SetIn(sr);
            Console.SetOut(sw);
#endif

            Team[] t = new Team[4];
            for (int i = 0; i < 5; i++)
            {
                string[] input = ReadArray();
                string[] score = input[2].Split(':');
                int x = int.Parse(score[0]);
                int y = int.Parse(score[1]);
                for (int j = 0; j < 4; j++)
                {
                    if (t[j] == null)
                    {
                        t[j] = new Team();
                        t[j].name = input[0];
                    }
                    if (t[j].name.Equals(input[0]))
                    {
                        if (x > y) t[j].point += 3;
                        if (x == y) t[j].point++;
                        t[j].goal += x;
                        t[j].miss += y;
                        t[j].cnt++;
                        break;
                    }

                }
                for (int j = 0; j < 4; j++)
                {
                    if (t[j] == null)
                    {
                        t[j] = new Team();
                        t[j].name = input[1];
                    }
                    if (t[j].name.Equals(input[1]))
                    {
                        if (y > x) t[j].point += 3;
                        if (x == y) t[j].point++;
                        t[j].goal += y;
                        t[j].miss += x;
                        t[j].cnt++;
                        break;
                    }
                }
            }

            for (int i = 0; i < 4; i++)
                if (t[i].name.Equals("BERLAND"))
                    t[i].point += 3;

            Team[] L = new Team[4];
            Team[] R = new Team[4];
            ArrayUtils.Merge_Sort(t, 0, 3, L, R);

            int ber, opp;
            ber = opp = 0;
            for (int i = 0; i < 4; i++)
            {
                if (t[i].name.Equals("BERLAND"))
                {
                    ber = i;
                }
                else if (t[i].cnt == 2)
                {
                    opp = i;
                }
            }

            int dif_max = int.MinValue;
            int goal_max = int.MinValue;
            for (int i = 0; i < 4; i++)
            {
                if (i == ber) continue;
                dif_max = Math.Max(t[i].goal - t[i].miss + Math.Abs(t[ber].goal - t[ber].miss), dif_max);
                goal_max = Math.Max(t[i].goal, goal_max);
            }
            for (int i = 1; i <= dif_max; i++)
            {

                for (int j = i; j <= goal_max + 1; j++)
                {
                    int comp = 0;
                    t[opp].goal += j - i;
                    t[opp].miss += j;
                    t[ber].goal += j;
                    t[ber].miss += j - i;
                    for (int z = 0; z < 4; z++)
                    {
                        if (z == ber) continue;
                        if (t[ber].CompareTo(t[z]) > 0)
                            comp++;
                    }
                    if (comp >= 2)
                    {
                        Console.WriteLine(j + ":" + (j - i));
                        return;
                    }
                    else
                    {
                        t[opp].goal -= j - i;
                        t[opp].miss -= j;
                        t[ber].goal -= j;
                        t[ber].miss -= j - i;
                    }
                }
            }
            Console.WriteLine("IMPOSSIBLE");

#if Online
            Console.ReadLine();
#endif

#if FileIO
            sr.Close();
            sw.Close();
#endif
        }

        static string[] ReadArray()
        {
            return Console.ReadLine().Split(' ');
        }

        static int ReadInt()
        {
            return int.Parse(Console.ReadLine());
        }
    }

   /* public static class MyMath
    {
        public static long BinPow(long a, long n, long mod)
        {
            long res = 1;
            while (n > 0)
            {
                if ((n & 1) == 1)
                {
                    res = (res * a) % mod;
                }
                a = (a * a) % mod;
                n >>= 1;
            }
            return res;
        }

        public static long GCD(long a, long b)
        {
            while (b != 0) b = a % (a = b);
            return a;
        }

        public static int GCD(int a, int b)
        {
            while (b != 0) b = a % (a = b);
            return a;
        }

        public static long LCM(long a, long b)
        {
            return (a * b) / GCD(a, b);
        }

        public static int LCM(int a, int b)
        {
            return (a * b) / GCD(a, b);
        }
    }

    public class SegmentTree
    {
        int[] v_min;
        int[] v_max;
        int[] mas;
        public void BuildTree(int[] a)
        {
            int n = a.Length - 1;
            int z = 0;
            while (n >= 2)
            {
                z++;
                n >>= 1;
            }
            n = 1 << (z + 1);
            v_min = new int[n << 1];
            v_max = new int[n << 1];
            mas = new int[n << 1];
            for (int i = n; i < n + a.Length; i++)
                v_min[i] = a[i - n];
            for (int i = n + a.Length; i < v_min.Length; i++)
                v_min[i] = int.MaxValue;
            for (int i = n - 1; i > 0; i--)
                v_min[i] = Math.Min(v_min[(i << 1)], v_min[(i << 1) + 1]);

            for (int i = n; i < n + a.Length; i++)
                v_max[i] = a[i - n];
            for (int i = n + a.Length; i < v_max.Length; i++)
                v_max[i] = int.MinValue;
            for (int i = n - 1; i > 0; i--)
                v_max[i] = Math.Max(v_max[(i << 1)], v_max[(i << 1) + 1]);

        }
        //nil
        public int RMQ_MIN(int l, int r)
        {
            int ans = int.MaxValue;
            l += v_min.Length >> 1;
            r += v_min.Length >> 1;
            const int o = 1;
            while (l <= r)
            {
                if ((l & 1) == o)
                    ans = Math.Min(ans, v_min[l]);
                if (!((r & 1) == 0))
                    ans = Math.Min(ans, v_min[r]);
                l = (l + 1) >> 1;
                r = (r - 1) >> 1;
            }
            return ans;
        }

        public int RMQ_MAX(int l, int r)
        {
            int ans = int.MinValue;
            l += v_max.Length >> 1;
            r += v_max.Length >> 1;
            const int o = 1;
            while (l <= r)
            {
                if ((l & 1) == o)
                    ans = Math.Max(ans, v_max[l]);
                if (!((r & 1) == 0))
                    ans = Math.Max(ans, v_max[r]);
                l = (l + 1) >> 1;
                r = (r - 1) >> 1;
            }
            return ans;
        }

        public void Put(int l, int r, int op)
        {
            l += mas.Length >> 1;
            r += mas.Length >> 1;
            while (l <= r)
            {
                if (l % 2 != 0)
                    mas[l] = op;
                if (r % 2 == 0)
                    mas[r] = op;
                l = (l + 1) >> 1;
                r = (r - 1) >> 1;
            }
        }

        public int Get(int x)
        {
            x += mas.Length >> 1;
            int ans = int.MinValue;
            while (x > 0)
            {
                ans = Math.Max(mas[x], ans);
                x >>= 1;
            }
            return ans;
        }

        public void Update(int i, int x)
        {
            i += v_min.Length >> 1;
            v_min[i] = x;
            v_max[i] = x;
            i >>= 1;
            while (i > 0)
            {
                v_min[i] = Math.Min(v_min[(i << 1)], v_min[(i << 1) + 1]);
                v_max[i] = Math.Max(v_max[(i << 1)], v_max[(i << 1) + 1]);
                i >>= 1;
            }
        }
    }

    class Edge
    {
        public int a;
        public int b;
        public int w;

        public Edge(int a, int b, int w)
        {
            this.a = a;
            this.b = b;
            this.w = w;
        }
    }

   /* class Graph
    {
        public List<int>[] g;
        public int[] color; //0-white, 1-gray, 2-black
        public int[] o; //open
        public int[] c; //close
        public int[] p;
        public int[] d;
        public List<Edge> e;

        public Graph(int n)
        {
            g = new List<int>[n + 1];
            color = new int[n + 1];
            o = new int[n + 1];
            c = new int[n + 1];
            p = new int[n + 1];
            d = new int[n + 1];
        }
    }

    static class GraphUtils
    {
        const int white = 0;
        const int gray = 1;
        const int black = 2;

        public static void BFS(int s, Graph g)
        {
            Queue<int> q = new Queue<int>();
            q.Enqueue(s);
            while (q.Count != 0)
            {
                int u = q.Dequeue();
                for (int i = 0; i < g.g[u].Count; i++)
                {
                    int v = g.g[u][i];
                    if (g.color[v] == white)
                    {
                        g.color[v] = gray;
                        g.d[v] = g.d[u] + 1;
                        g.p[v] = u;
                        q.Enqueue(v);
                    }
                }
                g.color[u] = black;
            }
        }

        public static void DFS(int u, ref int time, Graph g)
        {
            g.color[u] = gray;
            time++;
            g.o[u] = time;
            for (int i = 0; i < g.g[u].Count; i++)
            {
                int v = g.g[u][i];
                if (g.color[v] == white)
                {
                    g.p[v] = u;
                    DFS(v, ref time, g);
                }
            }
            g.color[u] = black;
            g.c[u] = time;
            time++;
        }

        public static void FordBellman(int u, Graph g)
        {
            int n = g.g.Length;
            for (int i = 0; i <= n; i++)
            {
                g.d[i] = int.MaxValue;
                g.p[i] = 0;
            }

            g.d[u] = 0;

            for (int i = 0; i < n - 1; i++)
            {
                for (int j = 0; j < g.e.Count; j++)
                {
                    if (g.d[g.e[j].a] != int.MaxValue)
                    {
                        if (g.d[g.e[j].a] + g.e[j].w < g.d[g.e[j].b])
                        {
                            g.d[g.e[j].b] = g.d[g.e[j].a] + g.e[j].w;
                            g.p[g.e[j].b] = g.e[j].a;
                        }
                    }
                }
            }
        }
    }*/
    static class ArrayUtils
    {
        public static int BinarySearch(int[] a, int val)
        {
            int left = 0;
            int right = a.Length - 1;
            int mid;

            while (left < right)
            {
                mid = left + ((right - left) >> 1);
                if (val <= a[mid])
                {
                    right = mid;
                }
                else
                {
                    left = mid + 1;
                }
            }

            if (a[left] == val)
                return left;
            else
                return -1;
        }

        public static double Bisection(F f, double left, double right, double eps)
        {
            double mid;
            while (right - left > eps)
            {
                mid = left + ((right - left) / 2d);
                if (Math.Sign(f(mid)) != Math.Sign(f(left)))
                    right = mid;
                else
                    left = mid;
            }
            return (left + right) / 2d;
        }

        public static decimal TernarySearchDec(Fdec f, decimal eps, decimal l, decimal r, bool isMax)
        {
            decimal m1, m2;
            while (r - l > eps)
            {
                m1 = l + (r - l) / 3m;
                m2 = r - (r - l) / 3m;
                if (f(m1) < f(m2))
                    if (isMax)
                        l = m1;
                    else
                        r = m2;
                else
                    if (isMax)
                        r = m2;
                    else
                        l = m1;
            }
            return r;
        }

        public static double TernarySearch(F f, double eps, double l, double r, bool isMax)
        {
            double m1, m2;
            while (r - l > eps)
            {
                m1 = l + (r - l) / 3d;
                m2 = r - (r - l) / 3d;
                if (f(m1) < f(m2))
                    if (isMax)
                        l = m1;
                    else
                        r = m2;
                else
                    if (isMax)
                        r = m2;
                    else
                        l = m1;
            }
            return r;
        }

        public static void Merge<T>(T[] A, int p, int q, int r, T[] L, T[] R) where T : IComparable<T>
        {
            for (int i = p; i <= q; i++)
                L[i] = A[i];
            for (int i = q + 1; i <= r; i++)
                R[i] = A[i];

            for (int k = p, i = p, j = q + 1; k <= r; k++)
            {
                if (i > q)
                {
                    for (; k <= r; k++, j++)
                        A[k] = R[j];
                    return;
                }
                if (j > r)
                {
                    for (; k <= r; k++, i++)
                        A[k] = L[i];
                    return;
                }
                if (L[i].CompareTo(R[j]) <= 0)
                {
                    A[k] = L[i];
                    i++;
                }
                else
                {
                    A[k] = R[j];
                    j++;
                }
            }
        }

        public static void Merge_Sort<T>(T[] A, int p, int r, T[] L, T[] R) where T : IComparable<T>
        {
            if (p >= r) return;
            int q = p + ((r - p) >> 1);
            Merge_Sort(A, p, q, L, R);
            Merge_Sort(A, q + 1, r, L, R);
            Merge(A, p, q, r, L, R);
        }

        static void Shake<T>(T[] a)
        {
            Random rnd = new Random(Environment.TickCount);
            T temp;
            int b, c;
            for (int i = 0; i < a.Length; i++)
            {
                b = rnd.Next(0, a.Length);
                c = rnd.Next(0, a.Length);
                temp = a[b];
                a[b] = a[c];
                a[c] = temp;
            }
        }
    }
}


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

namespace King_s_Problem
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            int n = Next();
            int k = Next();

            var nn = new int[n];
            for (int i = 0; i < n; i++)
            {
                nn[i] = Next();
            }
            long x = Next(), y = Next();
            double ans;
            if (k == n + 1)
            {
                int min = nn.Min();
                int max = nn.Max();
                ans = max - min + Math.Min(Math.Sqrt((x - min)*(x - min) + y*y), Math.Sqrt((x - max)*(x - max) + y*y));
            }
            else
            {
                int xx = nn[k - 1];

                ans = GM(nn, x, y, xx);
                for (int i = 0; i < nn.Length; i++)
                {
                    nn[i] = - nn[i];
                }
                x = - x;
                xx = - xx;
                ans = Math.Min(ans, GM(nn, x, y, xx));

                Array.Sort(nn);
                int min = nn[0];
                int max = nn[n - 1];
                for (int i = 0; i < n; i++)
                {
                    if (xx > nn[i])
                    {
                        ans = Math.Min(ans, nn[i] - min + Math.Sqrt((x - nn[i])*(x - nn[i]) + y*y)
                                            + Math.Sqrt((x - nn[i + 1])*(x - nn[i + 1]) + y*y)
                                            + max - nn[i + 1] + max - xx);
                        ans = Math.Min(ans, nn[i] - min + Math.Sqrt((x - nn[i])*(x - nn[i]) + y*y)
                                            + Math.Sqrt((x - max)*(x - max) + y*y)
                                            + max - nn[i + 1] + xx - nn[i + 1]);
                    }
                    else if (xx < nn[i])
                    {
                        ans = Math.Min(ans, max - nn[i] + Math.Sqrt((x - nn[i])*(x - nn[i]) + y*y)
                                            + Math.Sqrt((x - nn[i - 1])*(x - nn[i - 1]) + y*y)
                                            + nn[i - 1] - min + xx - min);
                        ans = Math.Min(ans, max - nn[i] + Math.Sqrt((x - nn[i])*(x - nn[i]) + y*y)
                                            + Math.Sqrt((x - min)*(x - min) + y*y)
                                            + nn[i - 1] - min + nn[i - 1] - xx);
                    }
                }
            }

            writer.WriteLine(ans.ToString("#0.0000000", CultureInfo.InvariantCulture));
            writer.Flush();
        }

        private static double GM(int[] nn, long x, long y, int xx)
        {
            double ans;

            int min = nn.Min();
            int max = nn.Max();

            //  ___/___\
            if (xx == min)
            {
                ans = max - xx + Math.Sqrt((x - max)*(x - max) + y*y);
            }
            else
            {
                int mix = nn.Where(e => e < xx).Max();
                ans = max - xx + Math.Sqrt((x - max)*(x - max) + y*y)
                      + Math.Sqrt((x - mix)*(x - mix) + y*y) + mix - min;
            }

            // <- ->\
            if (xx != min)
            {
                ans = Math.Min(ans, xx - min + max - min + Math.Sqrt((x - max)*(x - max) + y*y));
            }

            if (xx < x && xx != max)
            {
                int max1 = nn.Where(e => e < x).Max();
                int max2 = nn.Where(e => e <= x).Max();

                List<int> lmax1 = nn.Where(e => e > max1).ToList();
                if (lmax1.Any())
                {
                    int nmax1 = lmax1.Min();
                    ans = Math.Min(ans, xx - min + max1 - min + Math.Sqrt((x - max1)*(x - max1) + y*y) +
                                        Math.Sqrt((x - nmax1)*(x - nmax1) + y*y) + max - nmax1);

                    if (max1 != max2)
                    {
                        List<int> lmax2 = nn.Where(e => e > max2).ToList();
                        if (lmax2.Any())
                        {
                            int nmax2 = lmax2.Min();
                            ans = Math.Min(ans, xx - min + max2 - min + Math.Sqrt((x - max2)*(x - max2) + y*y) +
                                                Math.Sqrt((x - nmax2)*(x - nmax2) + y*y) + max - nmax2);
                        }
                    }
                }
            }

            return ans;
        }

        private static int Next()
        {
            int c;
            int m = 1;
            do
            {
                c = reader.Read();
                if (c == '-')
                    m = -1;
            } while (c < '0' || c > '9');
            int res = c - '0';
            while (true)
            {
                c = reader.Read();
                if (c < '0' || c > '9')
                    return m*res;
                res *= 10;
                res += c - '0';
            }
        }
    }
}


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

namespace King_s_Problem
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            int n = Next();
            int k = Next();

            var nn = new int[n];
            for (int i = 0; i < n; i++)
            {
                nn[i] = Next();
            }
            long x = Next(), y = Next();
            double ans;
            if (k == n + 1)
            {
                int min = nn.Min();
                int max = nn.Max();
                ans = max - min + Math.Min(Math.Sqrt((x - min)*(x - min) + y*y), Math.Sqrt((x - max)*(x - max) + y*y));
            }
            else
            {
                int xx = nn[k - 1];

                ans = GM(nn, x, y, xx);
                for (int i = 0; i < nn.Length; i++)
                {
                    nn[i] = - nn[i];
                }
                x = - x;
                xx = - xx;
                ans = Math.Min(ans, GM(nn, x, y, xx));
            }

            writer.WriteLine(ans.ToString("#0.0000000", CultureInfo.InvariantCulture));
            writer.Flush();
        }

        private static double GM(int[] nn, long x, long y, int xx)
        {
            double ans;

            int min = nn.Min();
            int max = nn.Max();

            //  ___/___\
            if (xx == min)
            {
                ans = max - xx + Math.Sqrt((x - max)*(x - max) + y*y);
            }
            else
            {
                int mix = nn.Where(e => e < xx).Max();
                ans = max - xx + Math.Sqrt((x - max)*(x - max) + y*y)
                      + Math.Sqrt((x - mix)*(x - mix) + y*y) + mix - min;
            }

            // <- ->\
            if (xx != min)
            {
                ans = Math.Min(ans, xx - min + max - min + Math.Sqrt((x - max)*(x - max) + y*y));
            }

            if (xx < x && xx != max)
            {
                int max1 = nn.Where(e => e < x).Max();
                int max2 = nn.Where(e => e <= x).Max();

                List<int> lmax1 = nn.Where(e => e > max1).ToList();
                if (lmax1.Any())
                {
                    int nmax1 = lmax1.Min();
                    ans = Math.Min(ans, xx - min + max1 - min + Math.Sqrt((x - max1)*(x - max1) + y*y) +
                                        Math.Sqrt((x - nmax1)*(x - nmax1) + y*y) + max - nmax1);

                    if (max1 != max2)
                    {
                        List<int> lmax2 = nn.Where(e => e > max2).ToList();
                        if (lmax2.Any())
                        {
                            int nmax2 = lmax2.Min();
                            ans = Math.Min(ans, xx - min + max2 - min + Math.Sqrt((x - max2)*(x - max2) + y*y) +
                                                Math.Sqrt((x - nmax2)*(x - nmax2) + y*y) + max - nmax2);
                        }
                    }
                }
            }

            return ans;
        }

        private static int Next()
        {
            int c;
            int m = 1;
            do
            {
                c = reader.Read();
                if (c == '-')
                    m = -1;
            } while (c < '0' || c > '9');
            int res = c - '0';
            while (true)
            {
                c = reader.Read();
                if (c < '0' || c > '9')
                    return m*res;
                res *= 10;
                res += c - '0';
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;

// (づ°ω°)づﾐe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    public class Heap<T>
    {
        private readonly List<T> data;
        private readonly Comparison<T> compare;

        public Heap(Comparison<T> compare)
        {
            this.compare = compare;
            data = new List<T> { default(T) };
        }

        public int Count
        {
            get { return data.Count - 1; }
        }

        public T Peek()
        {
            return data[1];
        }

        public void Push(T item)
        {
            data.Add(item);
            var curPlace = Count;
            while (curPlace > 1 && compare(item, data[curPlace / 2]) < 0)
            {
                data[curPlace] = data[curPlace / 2];
                data[curPlace / 2] = item;
                curPlace /= 2;
            }
        }

        public T Pop()
        {
            var ret = data[1];
            data[1] = data[Count];
            data.RemoveAt(Count);
            var curPlace = 1;
            while (true)
            {
                var max = curPlace;
                if (Count >= curPlace * 2 && compare(data[max], data[2 * curPlace]) > 0)
                    max = 2 * curPlace;
                if (Count >= curPlace * 2 + 1 && compare(data[max], data[2 * curPlace + 1]) > 0)
                    max = 2 * curPlace + 1;
                if (max == curPlace)
                    break;
                var item = data[max];
                data[max] = data[curPlace];
                data[curPlace] = item;
                curPlace = max;
            }

            return ret;
        }
    }

    class Edge
    {
        public int to;
        public double weight;
        public Edge(int to, double weight)
        {
            this.to = to;
            this.weight = weight;
        }
    }

    double[] Dijkstra(int start, List<Edge>[] edges)
    {
        int n = edges.Length;
        var dist = Enumerable.Repeat(double.MaxValue / 2, n).ToArray();
        dist[start] = 0;

        var q = new Heap<KeyValuePair<int, double>>((x, y) => x.Value.CompareTo(y.Value));
        q.Push(new KeyValuePair<int, double>(start, 0));

        while (q.Count > 0)
        {
            var t = q.Pop();
            if (t.Value != dist[t.Key])
                continue;

            foreach (var e in edges[t.Key])
            {
                var ndist = e.weight + t.Value;
                if (dist[e.to] > ndist)
                {
                    dist[e.to] = ndist;
                    q.Push(new KeyValuePair<int, double>(e.to, ndist));
                }
            }
        }

        return dist;
    }

    bool NextPerm(int[] a)
    {
        int n = a.Length;
        for (int k = n - 2; k >= 0; k--)
            if (a[k] < a[k + 1])
                for (int l = n - 1; l >= 0; l--)
                    if (a[k] < a[l])
                    {
                        Swap(ref a[k], ref a[l]);
                        for (int i = k + 1, j = n - 1; i < j; i++, j--)
                            Swap(ref a[i], ref a[j]);
                        return true;
                    }
        return false;
    }

    void Swap<T>(ref T a, ref T b)
    {
        T t = a;
        a = b;
        b = t;
    }

    double Dist(int x1, int y1, int x2, int y2)
    {
        return Math.Sqrt(1L * (x1 - x2) * (x1 - x2) + 1L * (y1 - y2) * (y1 - y2));
    }

    public void Solve()
    {
        int n = ReadInt(), m = ReadInt() - 1;
        var x = ReadIntArray();
        int xn = x[n], yn = ReadInt();

        int xm = m < n ? x[m] : 0;
        Array.Sort(x, 0, n);
        if (m < n)
            for (int i = 0; i < n; i++)
                if (x[i] == xm)
                    m = i;

        var o = new HashSet<int> { m, n, 0, n - 1 };
        for (int i = 0; i + 1 < n; i++)
        {
            if (x[i] == xn)
            {
                o.Add(i);
                if (i > 0)
                    o.Add(i - 1);
                o.Add(i + 1);
            }
            else if (x[i] < xn && x[i + 1] > xn)
            {
                o.Add(i);
                o.Add(i + 1);
            }
        }

        var g = Init<List<Edge>>(n + 1);
        for (int i = 0; i < n; i++)
        {
            if (i > 0)
                g[i].Add(new Edge(i - 1, Dist(x[i], 0, x[i - 1], 0)));
            if (i + 1 < n)
                g[i].Add(new Edge(i + 1, Dist(x[i], 0, x[i + 1], 0)));
            g[i].Add(new Edge(n, Dist(x[i], 0, xn, yn)));
            g[n].Add(new Edge(i, Dist(x[i], 0, xn, yn)));
        }

        var d = new double[n + 1][];
        var p = o.ToArray();
        Array.Sort(p);
        foreach (int v in p)
            d[v] = Dijkstra(v, g);

        double ans = double.MaxValue;
        do
        {
            if (p[0] != m)
                continue;
            double sum = 0;
            for (int i = 1; i < p.Length; i++)
                sum += d[p[i - 1]][p[i]];
            ans = Math.Min(ans, sum);
        } while (NextPerm(p));

        Write(ans.ToString(CultureInfo.InvariantCulture));
    }

    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;
    static void Main()
    {
#if DEBUG
        reader = new StreamReader("..\\..\\input.txt");
        //reader = new StreamReader(Console.OpenStandardInput());
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
#else
        reader = new StreamReader(Console.OpenStandardInput());
        writer = new StreamWriter(Console.OpenStandardOutput());
        //reader = new StreamReader("input.txt");
        //writer = new StreamWriter("output.txt");
#endif
        try
        {
            new Solver().Solve();
            //var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);
            //thread.Start();
            //thread.Join();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex);
#if DEBUG
#else
            throw;
#endif
        }
        reader.Close();
        writer.Close();
    }

    #endregion

    #region Read / Write
    private static Queue<string> currentLineTokens = new Queue<string>();
    private static string[] ReadAndSplitLine() { return reader.ReadLine().Split(new[] { ' ', '\t', }, StringSplitOptions.RemoveEmptyEntries); }
    public static string ReadToken() { while (currentLineTokens.Count == 0)currentLineTokens = new Queue<string>(ReadAndSplitLine()); return currentLineTokens.Dequeue(); }
    public static int ReadInt() { return int.Parse(ReadToken()); }
    public static long ReadLong() { return long.Parse(ReadToken()); }
    public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); }
    public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); }
    public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); }
    public static double[] ReadDoubleArray() { return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray(); }
    public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int[numberOfRows][]; for (int i = 0; i < numberOfRows; i++)matrix[i] = ReadIntArray(); return matrix; }
    public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)
    {
        int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][];
        for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++)ret[i][j] = matrix[j][i]; } return ret;
    }
    public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++)lines[i] = reader.ReadLine().Trim(); return lines; }
    public static void WriteArray<T>(IEnumerable<T> array) { writer.WriteLine(string.Join(" ", array)); }
    public static void Write(params object[] array) { WriteArray(array); }
    public static void WriteLines<T>(IEnumerable<T> array) { foreach (var a in array)writer.WriteLine(a); }
    private class SDictionary<TKey, TValue> : Dictionary<TKey, TValue>
    {
        public new TValue this[TKey key]
        {
            get { return ContainsKey(key) ? base[key] : default(TValue); }
            set { base[key] = value; }
        }
    }
    private static T[] Init<T>(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++)ret[i] = new T(); return ret; }
    #endregion
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;

// (づ°ω°)づﾐe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    public class Heap<T>
    {
        private readonly List<T> data;
        private readonly Comparison<T> compare;

        public Heap(Comparison<T> compare)
        {
            this.compare = compare;
            data = new List<T> { default(T) };
        }

        public int Count
        {
            get { return data.Count - 1; }
        }

        public T Peek()
        {
            return data[1];
        }

        public void Push(T item)
        {
            data.Add(item);
            var curPlace = Count;
            while (curPlace > 1 && compare(item, data[curPlace / 2]) < 0)
            {
                data[curPlace] = data[curPlace / 2];
                data[curPlace / 2] = item;
                curPlace /= 2;
            }
        }

        public T Pop()
        {
            var ret = data[1];
            data[1] = data[Count];
            data.RemoveAt(Count);
            var curPlace = 1;
            while (true)
            {
                var max = curPlace;
                if (Count >= curPlace * 2 && compare(data[max], data[2 * curPlace]) > 0)
                    max = 2 * curPlace;
                if (Count >= curPlace * 2 + 1 && compare(data[max], data[2 * curPlace + 1]) > 0)
                    max = 2 * curPlace + 1;
                if (max == curPlace)
                    break;
                var item = data[max];
                data[max] = data[curPlace];
                data[curPlace] = item;
                curPlace = max;
            }

            return ret;
        }
    }

    class Edge
    {
        public int to;
        public double weight;
        public Edge(int to, double weight)
        {
            this.to = to;
            this.weight = weight;
        }
    }

    double[] Dijkstra(int start, List<Edge>[] edges)
    {
        int n = edges.Length;
        var dist = Enumerable.Repeat(double.MaxValue / 2, n).ToArray();
        dist[start] = 0;

        var q = new Heap<KeyValuePair<int, double>>((x, y) => x.Value.CompareTo(y.Value));
        q.Push(new KeyValuePair<int, double>(start, 0));

        while (q.Count > 0)
        {
            var t = q.Pop();
            if (t.Value != dist[t.Key])
                continue;

            foreach (var e in edges[t.Key])
            {
                var ndist = e.weight + t.Value;
                if (dist[e.to] > ndist)
                {
                    dist[e.to] = ndist;
                    q.Push(new KeyValuePair<int, double>(e.to, ndist));
                }
            }
        }

        return dist;
    }

    bool NextPerm(int[] a)
    {
        int n = a.Length;
        for (int k = n - 2; k >= 0; k--)
            if (a[k] < a[k + 1])
                for (int l = n - 1; l >= 0; l--)
                    if (a[k] < a[l])
                    {
                        Swap(ref a[k], ref a[l]);
                        for (int i = k + 1, j = n - 1; i < j; i++, j--)
                            Swap(ref a[i], ref a[j]);
                        return true;
                    }
        return false;
    }

    void Swap<T>(ref T a, ref T b)
    {
        T t = a;
        a = b;
        b = t;
    }

    double Dist(int x1, int y1, int x2, int y2)
    {
        return Math.Sqrt(1L * (x1 - x2) * (x1 - x2) + 1L * (y1 - y2) * (y1 - y2));
    }

    public void Solve()
    {
        int n = ReadInt(), m = ReadInt() - 1;
        var x = ReadIntArray();
        int xn = x[n], yn = ReadInt();

        int xm = m < n ? x[m] : 0;
        Array.Sort(x, 0, n);
        if (m < n)
            for (int i = 0; i < n; i++)
                if (x[i] == xm)
                    m = i;

        var o = new HashSet<int> { m, n, 0, n - 1 };
        for (int i = 0; i + 1 < n; i++)
        {
            if (x[i] == xn)
            {
                o.Add(i);
                if (i > 0)
                    o.Add(i - 1);
                o.Add(i + 1);
            }
            else if (x[i] < xn && x[i + 1] > xn)
            {
                o.Add(i);
                o.Add(i + 1);
            }
        }
        if (m > 0)
            o.Add(m - 1);
        if (m + 1 < n)
            o.Add(m + 1);

        var g = Init<List<Edge>>(n + 1);
        for (int i = 0; i < n; i++)
        {
            if (i > 0)
                g[i].Add(new Edge(i - 1, Dist(x[i], 0, x[i - 1], 0)));
            if (i + 1 < n)
                g[i].Add(new Edge(i + 1, Dist(x[i], 0, x[i + 1], 0)));
            g[i].Add(new Edge(n, Dist(x[i], 0, xn, yn)));
            g[n].Add(new Edge(i, Dist(x[i], 0, xn, yn)));
        }

        var d = new double[n + 1][];
        var p = o.ToArray();
        Array.Sort(p);
        foreach (int v in p)
            d[v] = Dijkstra(v, g);

        double ans = double.MaxValue;
        do
        {
            if (p[0] != m)
                continue;

            var f = new bool[n + 1];
            double sum = 0;
            for (int i = 1; i < p.Length; i++)
            {
                sum += d[p[i - 1]][p[i]];
                f[p[i - 1]] = f[p[i]] = true;
                if (p[i - 1] < n && p[i] < n)
                    for (int j = Math.Min(p[i - 1], p[i]); j <= Math.Max(p[i - 1], p[i]); j++)
                        f[j] = true;
            }
            if (f.All(ff => ff))
                ans = Math.Min(ans, sum);
        } while (NextPerm(p));

        Write(ans.ToString(CultureInfo.InvariantCulture));
    }

    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;
    static void Main()
    {
#if DEBUG
        reader = new StreamReader("..\\..\\input.txt");
        //reader = new StreamReader(Console.OpenStandardInput());
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
#else
        reader = new StreamReader(Console.OpenStandardInput());
        writer = new StreamWriter(Console.OpenStandardOutput());
        //reader = new StreamReader("input.txt");
        //writer = new StreamWriter("output.txt");
#endif
        try
        {
            new Solver().Solve();
            //var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);
            //thread.Start();
            //thread.Join();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex);
#if DEBUG
#else
            throw;
#endif
        }
        reader.Close();
        writer.Close();
    }

    #endregion

    #region Read / Write
    private static Queue<string> currentLineTokens = new Queue<string>();
    private static string[] ReadAndSplitLine() { return reader.ReadLine().Split(new[] { ' ', '\t', }, StringSplitOptions.RemoveEmptyEntries); }
    public static string ReadToken() { while (currentLineTokens.Count == 0)currentLineTokens = new Queue<string>(ReadAndSplitLine()); return currentLineTokens.Dequeue(); }
    public static int ReadInt() { return int.Parse(ReadToken()); }
    public static long ReadLong() { return long.Parse(ReadToken()); }
    public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); }
    public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); }
    public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); }
    public static double[] ReadDoubleArray() { return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray(); }
    public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int[numberOfRows][]; for (int i = 0; i < numberOfRows; i++)matrix[i] = ReadIntArray(); return matrix; }
    public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)
    {
        int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][];
        for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++)ret[i][j] = matrix[j][i]; } return ret;
    }
    public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++)lines[i] = reader.ReadLine().Trim(); return lines; }
    public static void WriteArray<T>(IEnumerable<T> array) { writer.WriteLine(string.Join(" ", array)); }
    public static void Write(params object[] array) { WriteArray(array); }
    public static void WriteLines<T>(IEnumerable<T> array) { foreach (var a in array)writer.WriteLine(a); }
    private class SDictionary<TKey, TValue> : Dictionary<TKey, TValue>
    {
        public new TValue this[TKey key]
        {
            get { return ContainsKey(key) ? base[key] : default(TValue); }
            set { base[key] = value; }
        }
    }
    private static T[] Init<T>(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++)ret[i] = new T(); return ret; }
    #endregion
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;

// (づ°ω°)づﾐe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    public class Heap<T>
    {
        private readonly List<T> data;
        private readonly Comparison<T> compare;

        public Heap(Comparison<T> compare)
        {
            this.compare = compare;
            data = new List<T> { default(T) };
        }

        public int Count
        {
            get { return data.Count - 1; }
        }

        public T Peek()
        {
            return data[1];
        }

        public void Push(T item)
        {
            data.Add(item);
            var curPlace = Count;
            while (curPlace > 1 && compare(item, data[curPlace / 2]) < 0)
            {
                data[curPlace] = data[curPlace / 2];
                data[curPlace / 2] = item;
                curPlace /= 2;
            }
        }

        public T Pop()
        {
            var ret = data[1];
            data[1] = data[Count];
            data.RemoveAt(Count);
            var curPlace = 1;
            while (true)
            {
                var max = curPlace;
                if (Count >= curPlace * 2 && compare(data[max], data[2 * curPlace]) > 0)
                    max = 2 * curPlace;
                if (Count >= curPlace * 2 + 1 && compare(data[max], data[2 * curPlace + 1]) > 0)
                    max = 2 * curPlace + 1;
                if (max == curPlace)
                    break;
                var item = data[max];
                data[max] = data[curPlace];
                data[curPlace] = item;
                curPlace = max;
            }

            return ret;
        }
    }

    class Edge
    {
        public int to;
        public double weight;
        public Edge(int to, double weight)
        {
            this.to = to;
            this.weight = weight;
        }
    }

    double[] Dijkstra(int start, List<Edge>[] edges)
    {
        int n = edges.Length;
        var dist = Enumerable.Repeat(double.MaxValue / 2, n).ToArray();
        dist[start] = 0;

        var q = new Heap<KeyValuePair<int, double>>((x, y) => x.Value.CompareTo(y.Value));
        q.Push(new KeyValuePair<int, double>(start, 0));

        while (q.Count > 0)
        {
            var t = q.Pop();
            if (t.Value != dist[t.Key])
                continue;

            foreach (var e in edges[t.Key])
            {
                var ndist = e.weight + t.Value;
                if (dist[e.to] > ndist)
                {
                    dist[e.to] = ndist;
                    q.Push(new KeyValuePair<int, double>(e.to, ndist));
                }
            }
        }

        return dist;
    }

    bool NextPerm(int[] a)
    {
        int n = a.Length;
        for (int k = n - 2; k >= 0; k--)
            if (a[k] < a[k + 1])
                for (int l = n - 1; l >= 0; l--)
                    if (a[k] < a[l])
                    {
                        Swap(ref a[k], ref a[l]);
                        for (int i = k + 1, j = n - 1; i < j; i++, j--)
                            Swap(ref a[i], ref a[j]);
                        return true;
                    }
        return false;
    }

    void Swap<T>(ref T a, ref T b)
    {
        T t = a;
        a = b;
        b = t;
    }

    double Dist(int x1, int y1, int x2, int y2)
    {
        return Math.Sqrt(1L * (x1 - x2) * (x1 - x2) + 1L * (y1 - y2) * (y1 - y2));
    }

    public void Solve()
    {
        int n = ReadInt(), m = ReadInt() - 1;
        var x = ReadIntArray();
        int xn = x[n], yn = ReadInt();

        int xm = m < n ? x[m] : 0;
        Array.Sort(x, 0, n);
        if (m < n)
            for (int i = 0; i < n; i++)
                if (x[i] == xm)
                    m = i;

        var o = new HashSet<int> { m, n, 0, n - 1 };
        for (int i = 0; i + 1 < n; i++)
        {
            if (x[i] == xn)
            {
                o.Add(i);
                if (i > 0)
                    o.Add(i - 1);
                o.Add(i + 1);
            }
            else if (x[i] < xn && x[i + 1] > xn)
            {
                o.Add(i);
                o.Add(i + 1);
            }
        }
        if (m > 0)
            o.Add(m - 1);
        if (m + 1 < n)
            o.Add(m + 1);

        var g = Init<List<Edge>>(n + 1);
        for (int i = 0; i < n; i++)
        {
            if (i > 0)
                g[i].Add(new Edge(i - 1, Dist(x[i], 0, x[i - 1], 0)));
            if (i + 1 < n)
                g[i].Add(new Edge(i + 1, Dist(x[i], 0, x[i + 1], 0)));
            g[i].Add(new Edge(n, Dist(x[i], 0, xn, yn)));
            g[n].Add(new Edge(i, Dist(x[i], 0, xn, yn)));
        }

        var d = new double[n + 1][];
        var p = o.ToArray();
        Array.Sort(p);
        foreach (int v in p)
            d[v] = Dijkstra(v, g);

        double ans = double.MaxValue;
        do
        {
            if (p[0] != m)
                continue;

            var f = new bool[n + 1];
            double sum = 0;
            for (int i = 1; i < p.Length; i++)
            {
                sum += d[p[i - 1]][p[i]];
                f[p[i - 1]] = f[p[i]] = true;
                if (p[i - 1] < n && p[i] < n)
                    for (int j = Math.Min(p[i - 1], p[i]); j <= Math.Max(p[i - 1], p[i]); j++)
                        f[j] = true;
                if (f.All(ff => ff))
                    break;
            }
            if (f.All(ff => ff))
                ans = Math.Min(ans, sum);
        } while (NextPerm(p));

        Write(ans.ToString(CultureInfo.InvariantCulture));
    }

    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;
    static void Main()
    {
#if DEBUG
        reader = new StreamReader("..\\..\\input.txt");
        //reader = new StreamReader(Console.OpenStandardInput());
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
#else
        reader = new StreamReader(Console.OpenStandardInput());
        writer = new StreamWriter(Console.OpenStandardOutput());
        //reader = new StreamReader("input.txt");
        //writer = new StreamWriter("output.txt");
#endif
        try
        {
            new Solver().Solve();
            //var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);
            //thread.Start();
            //thread.Join();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex);
#if DEBUG
#else
            throw;
#endif
        }
        reader.Close();
        writer.Close();
    }

    #endregion

    #region Read / Write
    private static Queue<string> currentLineTokens = new Queue<string>();
    private static string[] ReadAndSplitLine() { return reader.ReadLine().Split(new[] { ' ', '\t', }, StringSplitOptions.RemoveEmptyEntries); }
    public static string ReadToken() { while (currentLineTokens.Count == 0)currentLineTokens = new Queue<string>(ReadAndSplitLine()); return currentLineTokens.Dequeue(); }
    public static int ReadInt() { return int.Parse(ReadToken()); }
    public static long ReadLong() { return long.Parse(ReadToken()); }
    public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); }
    public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); }
    public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); }
    public static double[] ReadDoubleArray() { return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray(); }
    public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int[numberOfRows][]; for (int i = 0; i < numberOfRows; i++)matrix[i] = ReadIntArray(); return matrix; }
    public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)
    {
        int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][];
        for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++)ret[i][j] = matrix[j][i]; } return ret;
    }
    public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++)lines[i] = reader.ReadLine().Trim(); return lines; }
    public static void WriteArray<T>(IEnumerable<T> array) { writer.WriteLine(string.Join(" ", array)); }
    public static void Write(params object[] array) { WriteArray(array); }
    public static void WriteLines<T>(IEnumerable<T> array) { foreach (var a in array)writer.WriteLine(a); }
    private class SDictionary<TKey, TValue> : Dictionary<TKey, TValue>
    {
        public new TValue this[TKey key]
        {
            get { return ContainsKey(key) ? base[key] : default(TValue); }
            set { base[key] = value; }
        }
    }
    private static T[] Init<T>(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++)ret[i] = new T(); return ret; }
    #endregion
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;

// (づ°ω°)づﾐe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    public void Solve()
    {
        int n = ReadInt();
        int s = ReadInt() - 1;
        var x = ReadIntArray();
        int y = ReadInt();

        if (s == n)
        {
            int min = x.Take(n).Min();
            int max = x.Take(n).Max();
            int sh = Math.Min(Math.Abs(x[n] - min), Math.Abs(x[n] - max));
            Write((Math.Sqrt(1L * y * y + 1L * sh * sh) + max - min).ToString(CultureInfo.InvariantCulture));
            return;
        }

        int xs = x[s];
        Array.Sort(x, 0, n);
        for (int i = 0; i < n; i++)
            if (x[i] == xs)
                s = i;

        var d = new double[n];
        for (int i = 0; i < n; i++)
            d[i] = Math.Sqrt(1L * (x[i] - x[n]) * (x[i] - x[n]) + 1L * y * y);

        double ans = d[s];
        int l = 0, r = n - 1;
        if (s == 0)
            l++;
        if (s == n - 1)
            r--;
        if (l <= r)
            ans += Math.Min(d[l], d[r]) + x[r] - x[l];

        for (int i = 0; i < n; i++)
        {
            if (i <= s)
            {
                l = 0;
                r = i - 1;
                double ex = 0;
                if (l <= r)
                    ex = Math.Min(d[l], d[r]) + x[r] - x[l];
                ans = Math.Min(ans, x[s] - x[i] + x[n - 1] - x[i] + d[n - 1] + ex);
                ans = Math.Min(ans, x[n - 1] - x[s] + x[n - 1] - x[i] + d[i] + ex);
            }
            if (i >= s)
            {
                l = i + 1;
                r = n - 1;
                double ex = 0;
                if (l <= r)
                    ex = Math.Min(d[l], d[r]) + x[r] - x[l];
                ans = Math.Min(ans, x[i] - x[s] + x[i] - x[0] + d[0] + ex);
                ans = Math.Min(ans, x[i] - x[0] + x[i] - x[0] + d[i] + ex);
            }
        }

        Write(ans.ToString(CultureInfo.InvariantCulture));
    }

    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;
    static void Main()
    {
#if DEBUG
        reader = new StreamReader("..\\..\\input.txt");
        //reader = new StreamReader(Console.OpenStandardInput());
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
#else
        reader = new StreamReader(Console.OpenStandardInput());
        writer = new StreamWriter(Console.OpenStandardOutput(),Encoding.ASCII);
        //reader = new StreamReader("input.txt");
        //writer = new StreamWriter("output.txt");
#endif
        try
        {
            new Solver().Solve();
            //var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);
            //thread.Start();
            //thread.Join();
        }
        catch (Exception ex)
        {
#if DEBUG
            Console.WriteLine(ex);
#else
            throw;
#endif
        }
        reader.Close();
        writer.Close();
    }

    #endregion

    #region Read / Write
    private static Queue<string> currentLineTokens = new Queue<string>();
    private static string[] ReadAndSplitLine() { return reader.ReadLine().Split(new[] { ' ', '\t', }, StringSplitOptions.RemoveEmptyEntries); }
    public static string ReadToken() { while (currentLineTokens.Count == 0)currentLineTokens = new Queue<string>(ReadAndSplitLine()); return currentLineTokens.Dequeue(); }
    public static int ReadInt() { return int.Parse(ReadToken()); }
    public static long ReadLong() { return long.Parse(ReadToken()); }
    public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); }
    public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); }
    public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); }
    public static double[] ReadDoubleArray() { return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray(); }
    public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int[numberOfRows][]; for (int i = 0; i < numberOfRows; i++)matrix[i] = ReadIntArray(); return matrix; }
    public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)
    {
        int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][];
        for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++)ret[i][j] = matrix[j][i]; } return ret;
    }
    public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++)lines[i] = reader.ReadLine().Trim(); return lines; }
    public static void WriteArray<T>(IEnumerable<T> array) { writer.WriteLine(string.Join(" ", array)); }
    public static void Write(params object[] array) { WriteArray(array); }
    public static void WriteLines<T>(IEnumerable<T> array) { foreach (var a in array)writer.WriteLine(a); }
    private class SDictionary<TKey, TValue> : Dictionary<TKey, TValue>
    {
        public new TValue this[TKey key]
        {
            get { return ContainsKey(key) ? base[key] : default(TValue); }
            set { base[key] = value; }
        }
    }
    private static T[] Init<T>(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++)ret[i] = new T(); return ret; }
    #endregion
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;

// (づ°ω°)づﾐe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    public void Solve()
    {
        int n = ReadInt();
        int s = ReadInt() - 1;
        var x = ReadIntArray();
        int y = ReadInt();

        if (s == n)
        {
            int min = x.Take(n).Min();
            int max = x.Take(n).Max();
            int sh = Math.Min(Math.Abs(x[n] - min), Math.Abs(x[n] - max));
            Write((Math.Sqrt(1L * y * y + 1L * sh * sh) + max - min).ToString(CultureInfo.InvariantCulture));
            return;
        }

        int xs = x[s];
        Array.Sort(x, 0, n);
        for (int i = 0; i < n; i++)
            if (x[i] == xs)
                s = i;

        var d = new double[n];
        for (int i = 0; i < n; i++)
            d[i] = Math.Sqrt(1L * (x[i] - x[n]) * (x[i] - x[n]) + 1L * y * y);

        double ans = d[s];
        int l = 0, r = n - 1;
        if (s == 0)
            l++;
        if (s == n - 1)
            r--;
        if (l <= r)
            ans += Math.Min(d[l], d[r]) + x[r] - x[l];

        for (int i = 0; i < n; i++)
        {
            if (i <= s)
            {
                l = 0;
                r = i - 1;
                double v = x[s] - x[i] + x[n - 1] - x[i] + d[n - 1];
                if (l <= r)
                    v += Math.Min(d[l], d[r]) + x[r] - x[l];
                ans = Math.Min(ans, v);
            }
            if (i >= s)
            {
                l = i + 1;
                r = n - 1;
                double v = x[i] - x[s] + x[i] - x[0] + d[0];
                if (l <= r)
                    v += Math.Min(d[l], d[r]) + x[r] - x[l];
                ans = Math.Min(ans, v);
            }
        }

        Write(ans.ToString(CultureInfo.InvariantCulture));
    }

    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;
    static void Main()
    {
#if DEBUG
        reader = new StreamReader("..\\..\\input.txt");
        //reader = new StreamReader(Console.OpenStandardInput());
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
#else
        reader = new StreamReader(Console.OpenStandardInput());
        writer = new StreamWriter(Console.OpenStandardOutput(),Encoding.ASCII);
        //reader = new StreamReader("input.txt");
        //writer = new StreamWriter("output.txt");
#endif
        try
        {
            new Solver().Solve();
            //var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);
            //thread.Start();
            //thread.Join();
        }
        catch (Exception ex)
        {
#if DEBUG
            Console.WriteLine(ex);
#else
            throw;
#endif
        }
        reader.Close();
        writer.Close();
    }

    #endregion

    #region Read / Write
    private static Queue<string> currentLineTokens = new Queue<string>();
    private static string[] ReadAndSplitLine() { return reader.ReadLine().Split(new[] { ' ', '\t', }, StringSplitOptions.RemoveEmptyEntries); }
    public static string ReadToken() { while (currentLineTokens.Count == 0)currentLineTokens = new Queue<string>(ReadAndSplitLine()); return currentLineTokens.Dequeue(); }
    public static int ReadInt() { return int.Parse(ReadToken()); }
    public static long ReadLong() { return long.Parse(ReadToken()); }
    public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); }
    public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); }
    public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); }
    public static double[] ReadDoubleArray() { return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray(); }
    public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int[numberOfRows][]; for (int i = 0; i < numberOfRows; i++)matrix[i] = ReadIntArray(); return matrix; }
    public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)
    {
        int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][];
        for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++)ret[i][j] = matrix[j][i]; } return ret;
    }
    public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++)lines[i] = reader.ReadLine().Trim(); return lines; }
    public static void WriteArray<T>(IEnumerable<T> array) { writer.WriteLine(string.Join(" ", array)); }
    public static void Write(params object[] array) { WriteArray(array); }
    public static void WriteLines<T>(IEnumerable<T> array) { foreach (var a in array)writer.WriteLine(a); }
    private class SDictionary<TKey, TValue> : Dictionary<TKey, TValue>
    {
        public new TValue this[TKey key]
        {
            get { return ContainsKey(key) ? base[key] : default(TValue); }
            set { base[key] = value; }
        }
    }
    private static T[] Init<T>(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++)ret[i] = new T(); return ret; }
    #endregion
}


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

namespace King_s_Problem
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            int n = Next();
            int k = Next();

            var nn = new int[n];
            for (int i = 0; i < n; i++)
            {
                nn[i] = Next();
            }
            long x = Next(), y = Next();
            double ans;
            if (k == n + 1)
            {
                int min = nn.Min();
                int max = nn.Max();
                ans = max - min + Math.Min(Math.Sqrt((x - min)*(x - min) + y*y), Math.Sqrt((x - max)*(x - max) + y*y));
            }
            else
            {
                int xx = nn[k - 1];

                ans = GM(nn, x, y, xx);
                for (int i = 0; i < nn.Length; i++)
                {
                    nn[i] = 1000000 - nn[i];
                }
                x = 100000 - x;
                xx = 1000000 - xx;
                ans = Math.Min(ans, GM(nn, x, y, xx));
            }

            writer.WriteLine(ans.ToString("#0.0000000", CultureInfo.InvariantCulture));
            writer.Flush();
        }

        private static double GM(int[] nn, long x, long y, int xx)
        {
            double ans;

            int min = nn.Min();
            int max = nn.Max();

            //  ___/___\
            if (xx == min)
            {
                ans = max - xx + Math.Sqrt((x - max)*(x - max) + y*y);
            }
            else
            {
                int mix = nn.Where(e => e < xx).Max();
                ans = max - xx + Math.Sqrt((x - max)*(x - max) + y*y)
                      + Math.Sqrt((x - mix)*(x - mix) + y*y) + mix - min;
            }

            // <- ->\
            if (xx != min)
            {
                ans = Math.Min(ans, xx - min + max - min + Math.Sqrt((x - max)*(x - max) + y*y));
            }

            if (xx < x && xx != max)
            {
                int max1 = nn.Where(e => e < x).Max();
                int max2 = nn.Where(e => e <= x).Max();

                List<int> lmax1 = nn.Where(e => e > max1).ToList();
                if (lmax1.Any())
                {
                    int nmax1 = lmax1.Min();
                    ans = Math.Min(ans, xx - min + max1 - min + Math.Sqrt((x - max1)*(x - max1) + y*y) +
                                        Math.Sqrt((x - nmax1)*(x - nmax1) + y*y) + max - nmax1);

                    if (max1 != max2)
                    {
                        List<int> lmax2 = nn.Where(e => e > max2).ToList();
                        if (lmax2.Any())
                        {
                            int nmax2 = lmax2.Min();
                            ans = Math.Min(ans, xx - min + max2 - min + Math.Sqrt((x - max2)*(x - max2) + y*y) +
                                                Math.Sqrt((x - nmax2)*(x - nmax2) + y*y) + max - nmax2);
                        }
                    }
                }
            }

            return ans;
        }

        private static int Next()
        {
            int c;
            int m = 1;
            do
            {
                c = reader.Read();
                if (c == '-')
                    m = -1;
            } while (c < '0' || c > '9');
            int res = c - '0';
            while (true)
            {
                c = reader.Read();
                if (c < '0' || c > '9')
                    return m*res;
                res *= 10;
                res += c - '0';
            }
        }
    }
}


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

public class HelloWorld {

    static int n;
    static int m;
    static int[] str;
    static int[,,] memo;
    static int[,] memoSol;

    public static void SolveCodeForces() {
        Console.ReadLine();
        str = Console.ReadLine().Select(c => c - 'a').ToArray();
        n = str.Length;
        m = str.Max()+1;

        memo = new int[n, n, m];
        for (var i = 0; i < n; i++)
            for (var j = 0; j < n; j++)
                for (var k = 0; k < m; k++)
                    memo[i,j,k] = -1;

        memoSol = new int[n, n];
        for (var i = 0; i < n; i++)
            for (var j = 0; j < n; j++)
                memoSol[i,j] = -1;

        System.Console.WriteLine(Solve(0, n-1));
    }

    static int Solve(int i, int j) {
        if (i > j) return 0;
        if (i == j) return 1;
        if (memoSol[i, j] >= 0) return memoSol[i, j];

        var ans = 10000;
        for (var sym = 0; sym < m; sym++)
            ans = Math.Min(ans, SolveFun(i, j, sym));
        ans++;
        memoSol[i, j] = ans;
        return ans;
    }

    static int SolveFun(int i, int j, int sym) {
        if (i > j) return 0;
        if (i == j) return str[i] == sym ? 0 : 10000;
        if (memo[i,j,sym] >= 0) return memo[i,j,sym];

        var ans = 10000;

        for (var k = i; k <= j; k++) {
            if (str[k] == sym) {

                var fl = SolveFun(i, k-1, sym);
                var sl = Solve(i, k-1);

                var fr = SolveFun(k+1, j, sym);
                var sr = Solve(k+1, j);

                var sol =
                    Math.Min(fl + fr,
                    Math.Min(sl + sr,
                    Math.Min(fl + sr,
                             sl + fr)));

                ans = Math.Min(ans, sol);
            }
        }

// System.Console.WriteLine(new { i, j, sym, ans });

        memo[i, j, sym] = ans;
        return ans;
    }

    static Scanner cin = new Scanner();
    static StringBuilder cout = new StringBuilder();

    static public void Main () {
        SolveCodeForces();
        // System.Console.Write(cout.ToString());
    }
}

public static class Helpers {
    public static T[] CreateArray<T>(int length, Func<int, T> itemCreate) {
        var result = new T[length];
        for (var i = 0; i < result.Length; i++)
            result[i] = itemCreate(i);
        return result;
    }

    public static IEnumerable<int> IndicesWhere<T>(this IEnumerable<T> seq, Func<T, bool> cond) {
        var i = 0;
        foreach (var item in seq) {
            if (cond(item)) yield return i;
            i++;
        }
    }
}

public class Scanner
{
    private string[] line = new string[0];
    private int index = 0;

    public string Next() {
        if (line.Length <= index) {
            line = Console.ReadLine().Split(' ');
            index = 0;
        }
        var res = line[index];
        index++;
        return res;
    }

    public int NextInt() {
        return int.Parse(Next());
    }

    public long NextLong() {
        return long.Parse(Next());
    }

    public ulong NextUlong() {
        return ulong.Parse(Next());
    }

    public string[] Array() {
        line = Console.ReadLine().Split(' ');
        index = line.Length;
        return line;
    }

    public int[] IntArray(int emptyPrefixLen = 0) {
        var array = Array();
        var result = new int[emptyPrefixLen + array.Length];
        for (int i = 0; i < array.Length; i++)
            result[emptyPrefixLen + i] = int.Parse(array[i]);
        return result;
    }

    public long[] LongArray() {
        var array = Array();
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
            result[i] = long.Parse(array[i]);
        return result;
    }

    public ulong[] UlongArray() {
        var array = Array();
        var result = new ulong[array.Length];
        for (int i = 0; i < array.Length; i++)
            result[i] = ulong.Parse(array[i]);
        return result;
    }
}


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

class Program
{
    class T
    {
        public int X;
        public int Y;

        public T(int x, int y)
        {
            X = x;
            Y = y;
        }
    }

    //////////////////////////////////////////////////

    /// <summary>
    /// Получает следующую перестановку элементов. Элементы не обязаны быть уникальными.
    /// Должно гарантироваться, что на вход подается одна из перестановок.
    /// Возвращает true, если была получена следующая перестановка, иначе - false.
    /// </summary>
    bool NextPermutation(IList<long> a)
    {
        var n = a.Count;
        for (int ind = n - 2; ind >= 0; ind--)
            if (a[ind] < a[ind + 1])
                for (int i = ind + 2; ; i++)
                    if (i == n || a[ind] >= a[i])
                    {
                        swap(a, ind, i - 1);
                        var m = (n - 1 - ind) >> 1;
                        for (int j = 1; j <= m; j++)
                            swap(a, ind + j, n - j);
                        return true;
                    }
        return false;
    }

    int tutu(int[,] a, List<char> s, int from, int to)
    {
        if (a[from, to] == 0)
        {
            var res = int.MaxValue;

            if (s[from] == s[to])
            {
                res = tutu(a, s, from + 1, to);
            }
            else
            {
                for (int i = from; i < to; i++)
                {
                    var l = tutu(a, s, from, i);
                    var r = tutu(a, s, i + 1, to);
                    var z = l + r;
                    if (s[from] == s[i + 1] || s[i] == s[to])
                        z--;
                    res = Math.Min(res, z);
                }
            }
            a[from, to] = res;
        }
        return a[from, to];
    }

    //////////////////////////////////////////////////
    void Solution()
    {
        var n = ri;
        var s = rs;
        var a = new List<char>(n) { s[0] };
        for (int i = 1; i < n; i++)
            if (s[i - 1] != s[i])
                a.Add(s[i]);

        var b = new int[n, n];
        for (int i = 0; i < n; i++)
            b[i, i] = 1;
        wln(tutu(b, a, 0, a.Count - 1));

    }
    //////////////////////////////////////////////////

    struct P : IComparable<P>
    {
        public long X;
        public long Y;

        public P(long x, long y)
        {
            X = x;
            Y = y;
        }

        public int CompareTo(P other) => X != other.X ? X.CompareTo(other.X) : Y.CompareTo(other.Y);
        public static int Comparison(P p1, P p2) => p1.CompareTo(p2);

        public static bool operator ==(P p1, P p2) => (p1.X == p2.X) && (p1.Y == p2.Y);
        public static bool operator !=(P p1, P p2) => (p1.X != p2.X) || (p1.Y != p2.Y);

        public static P operator +(P p1, P p2) => new P(p1.X + p2.X, p1.Y + p2.Y);
        public static P operator -(P p1, P p2) => new P(p1.X - p2.X, p1.Y - p2.Y);
    }

    void swap<T>(ref T o1, ref T o2) { var o = o1; o1 = o2; o2 = o; }
    void swap<T>(IList<T> a, int from, int to) { var buf = a[from]; a[from] = a[to]; a[to] = buf; }
    long gcd(long a, long b) => (b != 0) ? gcd(b, a % b) : a;
    long lcm(long a, long b) => a / gcd(a, b) * b;

    long rast2(long x1, long y1, long x2, long y2) => (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
    long rast2(P p1, P p2) => (p1.X - p2.X) * (p1.X - p2.X) + (p1.Y - p2.Y) * (p1.Y - p2.Y);
    long ccw(P p1, P p2, P p3) => p1.X * p2.Y + p1.Y * p3.X + p2.X * p3.Y - p2.Y * p3.X - p3.Y * p1.X - p1.Y * p2.X;

    StringBuilder _sb = new StringBuilder();
    void wln() { _sb.AppendLine(); }
    void wln<T>(T o) { _sb.AppendLine(o.ToString()); }
    void wsp<T>(T o) { _sb.Append(o).Append(" "); }
    void wrt<T>(T o) { _sb.Append(o); }
    void wln(double o) { _sb.AppendLine(string.Format(CultureInfo.InvariantCulture, "{0:F12}", o)); }
    void wsp(double o) { _sb.Append(string.Format(CultureInfo.InvariantCulture, "{0:F12} ", o)); }
    void wrt(double o) { _sb.Append(string.Format(CultureInfo.InvariantCulture, "{0:F12}", o)); }

    List<P> rpa(int n)
    {
        var res = new List<P>(n);
        for (int i = 0; i < n; i++)
            res.Add(new P(rl, rl));
        return res;
    }

    int ri
    {
        get
        {
            _read(); while (_str[_ind] == ' ') ++_ind;
            int sign = 1; if (_str[_ind] == '-') { sign = -1; ++_ind; }
            int p = 0;
            while (_ind < _count && _str[_ind] != ' ') p = p * 10 + _str[_ind++] - '0';
            while (_ind < _count && _str[_ind] == ' ') ++_ind; return p * sign;
        }
    }
    long rl
    {
        get
        {
            _read(); while (_str[_ind] == ' ') ++_ind;
            int sign = 1; if (_str[_ind] == '-') { sign = -1; ++_ind; }
            long p = 0;
            while (_ind < _count && _str[_ind] != ' ') p = p * 10 + _str[_ind++] - '0';
            while (_ind < _count && _str[_ind] == ' ') ++_ind; return p * sign;
        }
    }
    double rd
    {
        get
        {
            _read(); while (_str[_ind] == ' ') ++_ind; int sign = 1; if (_str[_ind] == '-') { sign = -1; ++_ind; }
            long p = 0, q = 1; while (_ind < _count && _str[_ind] != ' ' && _str[_ind] != '.') p = p * 10 + _str[_ind++] - '0';
            if (_ind < _count && _str[_ind] == '.') { ++_ind; while (_ind < _count && _str[_ind] != ' ') { p = p * 10 + _str[_ind++] - '0'; q *= 10; } }
            while (_ind < _count && _str[_ind] == ' ') ++_ind; return (double)p / q * sign;
        }
    }
    // Читает строку без пробелов
    string rs
    {
        get
        {
            _read(); while (_ind < _count && _str[_ind] == ' ') ++_ind;
            var tmp = _str.IndexOf(' ', _ind);
            if (tmp == -1) { var res = _str.Substring(_ind); _count = 0; _ind = 0; return res; }
            var s = _str.Substring(_ind, tmp - _ind); _ind = tmp + 1;
            while (_ind < _count && _str[_ind] == ' ') ++_ind; return s;
        }
    }

    List<int> ria(int n)
    {
        var res = new List<int>(n);
        for (int i = 0; i < n; i++)
            res.Add(ri);
        return res;
    }
    List<long> rla(int n)
    {
        var res = new List<long>(n);
        for (int i = 0; i < n; i++)
            res.Add(rl);
        return res;
    }
    List<double> rda(int n)
    {
        var res = new List<double>(n);
        for (int i = 0; i < n; i++)
            res.Add(rd);
        return res;
    }
    // Читает строки без пробелов
    List<string> rsa(int n)
    {
        var res = new List<string>(n);
        for (int i = 0; i < n; i++)
            res.Add(rs);
        return res;
    }
    string _str = null; int _count = 0; int _ind = 0;
    void _read() { if (_ind == _count) { _str = Console.ReadLine(); _count = _str.Length; _ind = 0; } }
    static void Main(string[] args) { new Program().Main(); }
    void Main()
    {
        //Console.SetIn(new StreamReader("input.txt")); Console.SetOut(new StreamWriter("output.txt"));
        Solution();
        Console.Write(_sb);
        //Console.In.Close(); Console.Out.Close();
    }
}


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

namespace Algorithm
{
    class Program
    {
        static int N = 500;
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var s = Console.ReadLine();
			int[,] dp = new int[N, N];
            for (int i = 0; i < N; i++)
            {
                for (int j = 0; j < N; j++)
                {
                    dp[i, j] = -1;
                }
            }
            Console.WriteLine(findMinimumDeletion(0, n - 1, dp, s));
        }

        static int findMinimumDeletion(int l, int r,
                                int[,] dp, String s)
        {

            if (l > r)
            {
                return 0;
            }
            if (l == r)
            {
                return 1;
            }
            if (dp[l, r] != -1)
            {
                return dp[l, r];
            }

            // When a single character is deleted
            int res = 1 + findMinimumDeletion(l + 1, r, dp, s);

            // When a group of consecutive characters
            // are deleted if any of them matches
            for (int i = l + 1; i <= r; ++i)
            {

                // When both the characters are same then
                // delete the letters in between them
                if (s[l] == s[i])
                {
                    res = Math.Min(res, findMinimumDeletion(l + 1, i - 1, dp, s)
                            + findMinimumDeletion(i, r, dp, s));
                }
            }

            // Memoize
            return dp[l, r] = res;
        }
    }
}


/*
csc -debug F.cs && mono --debug F.exe <<< "5
abaca"
*/

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

public class HelloWorld {

    static int n;
    static int m;
    static int[] str;
    static int[,,] memo;
    static int[,] memoSol;

    public static void SolveCodeForces() {
        Console.ReadLine();
        str = Console.ReadLine().Select(c => c - 'a').ToArray();
        n = str.Length;
        m = str.Max()+1;

        memo = new int[n, n, m];
        for (var i = 0; i < n; i++)
            for (var j = 0; j < n; j++)
                for (var k = 0; k < m; k++)
                    memo[i,j,k] = -1;

        memoSol = new int[n, n];
        for (var i = 0; i < n; i++)
            for (var j = 0; j < n; j++)
                memoSol[i,j] = -1;

        System.Console.WriteLine(Solve(0, n-1));
    }

    static int Solve(int i, int j) {
        if (i > j) return 0;
        if (i == j) return 1;
        if (memoSol[i, j] >= 0) return memoSol[i, j];

        var ans = 10000;
        for (var sym = 0; sym < m; sym++)
            ans = Math.Min(ans, SolveFun(i, j, sym));
        ans++;
        memoSol[i, j] = ans;
        return ans;
    }

    static int SolveFun(int i, int j, int sym) {
        if (i > j) return 0;
        if (i == j) return str[i] == sym ? 0 : 10000;
        if (memo[i,j,sym] >= 0) return memo[i,j,sym];

        var ans = 10000;

        for (var k = i; k <= j; k++) {
            if (str[k] == sym) {

                var fl = SolveFun(i, k-1, sym);
                var sl = Solve(i, k-1);

                var fr = SolveFun(k+1, j, sym);
                var sr = Solve(k+1, j);

                var sol =
                    Math.Min(fl + fr,
                    Math.Min(sl + sr,
                    Math.Min(fl + sr,
                             sl + fr)));

                ans = Math.Min(ans, sol);
            }
        }

// System.Console.WriteLine(new { i, j, sym, ans });

        memo[i, j, sym] = ans;
        return ans;
    }

    static Scanner cin = new Scanner();
    static StringBuilder cout = new StringBuilder();

    static public void Main () {
        SolveCodeForces();
        // System.Console.Write(cout.ToString());
    }
}

public static class Helpers {
    public static T[] CreateArray<T>(int length, Func<int, T> itemCreate) {
        var result = new T[length];
        for (var i = 0; i < result.Length; i++)
            result[i] = itemCreate(i);
        return result;
    }

    public static IEnumerable<int> IndicesWhere<T>(this IEnumerable<T> seq, Func<T, bool> cond) {
        var i = 0;
        foreach (var item in seq) {
            if (cond(item)) yield return i;
            i++;
        }
    }
}

public class Scanner
{
    private string[] line = new string[0];
    private int index = 0;

    public string Next() {
        if (line.Length <= index) {
            line = Console.ReadLine().Split(' ');
            index = 0;
        }
        var res = line[index];
        index++;
        return res;
    }

    public int NextInt() {
        return int.Parse(Next());
    }

    public long NextLong() {
        return long.Parse(Next());
    }

    public ulong NextUlong() {
        return ulong.Parse(Next());
    }

    public string[] Array() {
        line = Console.ReadLine().Split(' ');
        index = line.Length;
        return line;
    }

    public int[] IntArray(int emptyPrefixLen = 0) {
        var array = Array();
        var result = new int[emptyPrefixLen + array.Length];
        for (int i = 0; i < array.Length; i++)
            result[emptyPrefixLen + i] = int.Parse(array[i]);
        return result;
    }

    public long[] LongArray() {
        var array = Array();
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
            result[i] = long.Parse(array[i]);
        return result;
    }

    public ulong[] UlongArray() {
        var array = Array();
        var result = new ulong[array.Length];
        for (int i = 0; i < array.Length; i++)
            result[i] = ulong.Parse(array[i]);
        return result;
    }
}


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.ReadLine();
            var str = Console.ReadLine();
            var s = str.ToList();

            var a = new int[s.Count, s.Count];
            var res = tutu(a, s, 0, s.Count - 1);
            Console.WriteLine(res);
        }

        // tutu(a, s, 0, s.Count - 1)
        static int tutu(int[,] a, List<char> s, int from, int to)
        {
            if (a[from, to] == 0)
            {
                if (from == to)
                    return 1;
                var res = int.MaxValue;

                if (s[from] == s[to])
                {
                    res = tutu(a, s, from + 1, to);
                }
                else
                {
                    for (int i = from; i < to; i++)
                    {
                        var z = tutu(a, s, from, i) + tutu(a, s, i + 1, to);
                        if (s[from] == s[i + 1] || s[i] == s[to])
                            z--;
                        res = Math.Min(res, z);
                    }
                }
                a[from, to] = res;
            }
            return a[from, to];
        }

    }
}


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

namespace Algorithm
{
    class Program
    {
        static int count = 0;
        static void Main(string[] args)
        {
			var n = Console.ReadLine();
			var s = Console.ReadLine();

            Console.WriteLine(DeleteMinCount(n, s));
        }

        private static int DeleteMinCount(string s, int n)
        {
            if (s.Length == 0)
            {
                return 0;
            }

            int n = s.Length;
            int i = 0;
            Dictionary<char, int> fequence = new Dictionary<char, int>();

            while (i < n)
            {
                char c = s[i];

                int j = i + 1;
                while (j < n)
                {
                    if (c != s[j])
                    {
                        break;
                    }
                    j++;
                }

                i = j;
                if (!fequence.ContainsKey(c))
                {
                    fequence.Add(c, 0);
                }

                fequence[c]++;
            }

            s = RemoveChar(fequence, s);
            count++;
            DeleteMinCount(s, n);

            return count;
        }

        private static string RemoveChar(Dictionary<char, int> fequence, string s)
        {
            int min = Int32.MaxValue;
            char c = ' ';
            foreach (var f in fequence)
            {
                if (f.Value < min)
                {
                    min = f.Value;
                    c = f.Key;
                }
            }

            int n = s.Length;
            int i = 0;
            int j = 0;
            while (i < n)
            {
                if (c == s[i])
                {
                    j = i;
                    while (j < n)
                    {
                        if (c != s[j])
                        {
                            break;
                        }
                        j++;
                    }
                    break;
                }
                i++;
            }

            s = s.Remove(i, j - i);

            return s;
        }
    }
}


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

namespace Algorithm
{
    class Program
    {
        static int count = 0;
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var s = Console.ReadLine();
			int[,] dp = new int[N, N];
            for (int i = 0; i < N; i++)
            {
                for (int j = 0; j < N; j++)
                {
                    dp[i, j] = -1;
                }
            }
            Console.WriteLine(findMinimumDeletion(0, n - 1, dp, s));
        }

        static int findMinimumDeletion(int l, int r,
                                int[,] dp, String s)
        {

            if (l > r)
            {
                return 0;
            }
            if (l == r)
            {
                return 1;
            }
            if (dp[l, r] != -1)
            {
                return dp[l, r];
            }

            // When a single character is deleted
            int res = 1 + findMinimumDeletion(l + 1, r, dp, s);

            // When a group of consecutive characters
            // are deleted if any of them matches
            for (int i = l + 1; i <= r; ++i)
            {

                // When both the characters are same then
                // delete the letters in between them
                if (s[l] == s[i])
                {
                    res = Math.Min(res, findMinimumDeletion(l + 1, i - 1, dp, s)
                            + findMinimumDeletion(i, r, dp, s));
                }
            }

            // Memoize
            return dp[l, r] = res;
        }
    }
}


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

namespace Algorithm
{
    class Program
    {
        static int count = 0;
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var s = Console.ReadLine();

            Console.WriteLine(DeleteMinCount(s, n));
        }

        private static int DeleteMinCount(string s, int length)
        {
            if (s.Length == 0)
            {
                return 0;
            }

            int n = s.Length;
            int i = 0;
            Dictionary<char, int> fequence = new Dictionary<char, int>();

            while (i < n)
            {
                char c = s[i];

                int j = i + 1;
                while (j < n)
                {
                    if (c != s[j])
                    {
                        break;
                    }
                    j++;
                }

                i = j;
                if (!fequence.ContainsKey(c))
                {
                    fequence.Add(c, 0);
                }

                fequence[c]++;
            }

            s = RemoveChar(fequence, s);
            count++;
            DeleteMinCount(s, n);

            return count;
        }

        private static string RemoveChar(Dictionary<char, int> fequence, string s)
        {
            int min = Int32.MaxValue;
            char c = ' ';
            foreach (var f in fequence)
            {
                if (f.Value < min)
                {
                    min = f.Value;
                    c = f.Key;
                }
            }

            int n = s.Length;
            int i = 0;
            int j = 0;
            while (i < n)
            {
                if (c == s[i])
                {
                    j = i;
                    while (j < n)
                    {
                        if (c != s[j])
                        {
                            break;
                        }
                        j++;
                    }
                    break;
                }
                i++;
            }

            s = s.Remove(i, j - i);

            return s;
        }
    }
}


/*
csc -debug F.cs && mono --debug F.exe <<< "5
abaca"
*/

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

public class HelloWorld {

    static int n;
    static int m;
    static int[] str;
    static int[,,] memo;

    public static void SolveCodeForces() {
        Console.ReadLine();
        str = Console.ReadLine().Select(c => c - 'a').ToArray();
        n = str.Length;
        m = str.Max()+1;

        memo = new int[n, n, m];
        for (var i = 0; i < n; i++)
            for (var j = 0; j < n; j++)
                for (var k = 0; k < m; k++)
                    memo[i,j,k] = -1;

        System.Console.WriteLine(Solve(0, n-1));
    }

    static int Solve(int i, int j) {
        if (i > j) return 0;
        if (i == j) return 1;

        var ans = 10000;
        for (var sym = 0; sym < m; sym++)
            ans = Math.Min(ans, SolveFun(i, j, sym));
        return ans + 1;
    }

    static int SolveFun(int i, int j, int sym) {
        if (i > j) return 0;
        if (i == j) return str[i] == sym ? 0 : 10000;
        if (memo[i,j,sym] >= 0) return memo[i,j,sym];

        var ans = 10000;

        for (var k = i; k <= j; k++) {
            if (str[k] == sym) {

                var fl = SolveFun(i, k-1, sym);
                var sl = Solve(i, k-1);

                var fr = SolveFun(k+1, j, sym);
                var sr = Solve(k+1, j);

                var sol =
                    Math.Min(fl + fr,
                    Math.Min(sl + sr,
                    Math.Min(fl + sr,
                             sl + fr)));

                ans = Math.Min(ans, sol);
            }
        }

// System.Console.WriteLine(new { i, j, sym, ans });

        memo[i, j, sym] = ans;
        return ans;
    }

    static Scanner cin = new Scanner();
    static StringBuilder cout = new StringBuilder();

    static public void Main () {
        SolveCodeForces();
        // System.Console.Write(cout.ToString());
    }
}

public static class Helpers {
    public static T[] CreateArray<T>(int length, Func<int, T> itemCreate) {
        var result = new T[length];
        for (var i = 0; i < result.Length; i++)
            result[i] = itemCreate(i);
        return result;
    }

    public static IEnumerable<int> IndicesWhere<T>(this IEnumerable<T> seq, Func<T, bool> cond) {
        var i = 0;
        foreach (var item in seq) {
            if (cond(item)) yield return i;
            i++;
        }
    }
}

public class Scanner
{
    private string[] line = new string[0];
    private int index = 0;

    public string Next() {
        if (line.Length <= index) {
            line = Console.ReadLine().Split(' ');
            index = 0;
        }
        var res = line[index];
        index++;
        return res;
    }

    public int NextInt() {
        return int.Parse(Next());
    }

    public long NextLong() {
        return long.Parse(Next());
    }

    public ulong NextUlong() {
        return ulong.Parse(Next());
    }

    public string[] Array() {
        line = Console.ReadLine().Split(' ');
        index = line.Length;
        return line;
    }

    public int[] IntArray(int emptyPrefixLen = 0) {
        var array = Array();
        var result = new int[emptyPrefixLen + array.Length];
        for (int i = 0; i < array.Length; i++)
            result[emptyPrefixLen + i] = int.Parse(array[i]);
        return result;
    }

    public long[] LongArray() {
        var array = Array();
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
            result[i] = long.Parse(array[i]);
        return result;
    }

    public ulong[] UlongArray() {
        var array = Array();
        var result = new ulong[array.Length];
        for (int i = 0; i < array.Length; i++)
            result[i] = ulong.Parse(array[i]);
        return result;
    }
}


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

namespace CodeForces
{
    static class Reader
    {
        public static int NextInt()
        {
            int ret = 0;
            char c;

            while (!char.IsDigit(c = (char)Console.Read()))
            {
                if (c == '-')
                    return -NextInt();
            }
            do
            {
                ret = ret * 10 + c - '0';
            } while (char.IsDigit(c = (char)Console.Read()));

            return ret;
        }

        public static double NextDouble()
        {
            double ret = 0;
            char c;

            while (!char.IsDigit(c = (char)Console.Read()))
            {
                if (c == '-')
                    return -NextDouble();
            }
            do
            {
                ret = ret * 10 + c - '0';
            } while (char.IsDigit(c = (char)Console.Read()));
            if (c != '.') return ret;

            double p10 = 0.1;
            while (char.IsDigit(c = (char)Console.Read()))
            {
                ret += p10 * (c - '0');
                p10 *= 0.1;
            }

            return ret;
        }

        public static string NextToken()
        {
            StringBuilder ret = new StringBuilder();
            char c;

            while (char.IsWhiteSpace(c = (char)Console.Read())) ;
            do
            {
                ret.Append(c);
            } while (!char.IsWhiteSpace(c = (char)Console.Read()));

            return ret.ToString();
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            int n, t;

            n = Reader.NextInt();
            t = Reader.NextInt();
            long[, , , ,] dp = new long[n, 4, 4, t + 2, t + 2];

            for (int i = 0; i < 4; ++i)
                for (int j = 0; j < 4; ++j)
                    if(i != j)
                        dp[1, i, j, 0, 0] = 1;
            for (int i = 2; i < n; ++i)
                for (int j = 0; j < 4; ++j)
                    for (int k = 0; k < 4; ++k)
                        if (j != k)
                            for (int l = 0; l <= t; ++l)
                                for (int m = 0; m <= t; ++m)
                                    for (int y = 0; y < 4; ++y)
                                        if (k != y)
                                            if (j < k && k > y)
                                                dp[i, k, y, l + 1, m] += dp[i - 1, j, k, l, m];
                                            else if (j > k && k < y)
                                                dp[i, k, y, l, m + 1] += dp[i - 1, j, k, l, m];
                                            else
                                                dp[i, k, y, l, m] += dp[i - 1, j, k, l, m];

            long sol = 0;
            for (int i = 0; i < 4; ++i)
                for (int j = 0; j < 4; ++j)
                    if (i != j)
                        sol += dp[n - 1, i, j, t, t - 1];

            Console.WriteLine(sol);
        }
    }
}