Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Petya and his friend Vasya play an interesting game. Petya randomly chooses an integer p from the interval [pl, pr] and Vasya chooses an integer v from the interval [vl, vr] (also randomly). Both players choose their integers equiprobably. Find the probability that the interval [min(v, p), max(v, p)] contains exactly k lucky numbers.

The single line contains five integers pl, pr, vl, vr and k (1 ≤ pl ≤ pr ≤ 109, 1 ≤ vl ≤ vr ≤ 109, 1 ≤ k ≤ 1000).

On the single line print the result with an absolute error of no more than 10 - 9.

NoteConsider that [a, b] denotes an interval of integers; this interval includes the boundaries. That is, In first case there are 32 suitable pairs: (1, 7), (1, 8), (1, 9), (1, 10), (2, 7), (2, 8), (2, 9), (2, 10), (3, 7), (3, 8), (3, 9), (3, 10), (4, 7), (4, 8), (4, 9), (4, 10), (7, 1), (7, 2), (7, 3), (7, 4), (8, 1), (8, 2), (8, 3), (8, 4), (9, 1), (9, 2), (9, 3), (9, 4), (10, 1), (10, 2), (10, 3), (10, 4). Total number of possible pairs is 10·10 = 100, so answer is 32 / 100.In second case Petya always get number less than Vasya and the only lucky 7 is between this numbers, so there will be always 1 lucky number.

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

class LuckyProbability
{

    static int[] L = new int[1024];
    static int[] st = new int[10];
    static int LPos = 0;

    public static int Main()
    {
        //citire
        string[] citire = Console.ReadLine().Split(' ');
        int x1, x2, y1, y2, k;
        x1 = Convert.ToInt32(citire[0]);
        x2 = Convert.ToInt32(citire[1]);
        y1 = Convert.ToInt32(citire[2]);
        y2 = Convert.ToInt32(citire[3]);
        k = Convert.ToInt32(citire[4]);

        //solve
        back(1); L[1023] = 1000000001;
        Array.Sort(L, 1, 1022); //stocare numere Lucky

        int i, j; long Rez = 0;
        for (i = 1; i <= (1023 - k); i++)
        {
            j = i + k - 1;
            Rez += (long)Intersectie(x1, x2, L[i - 1] + 1, L[i]) * (long)Intersectie(y1, y2, L[j], L[j + 1] - 1);
            Rez += (long)Intersectie(y1, y2, L[i - 1] + 1, L[i]) * (long)Intersectie(x1, x2, L[j], L[j + 1] - 1);
            if (k == 1 && x1 <= L[i] && L[i] <= x2 && y1 <= L[i] && L[i] <= y2) Rez--;
        }

        long Posibilitati = (long)(x2 - x1 + 1) * (long)(y2 - y1 + 1);
        decimal Afis = (decimal)Rez / (decimal)Posibilitati;
        Console.WriteLine(Afis.ToString("N12"));
        Console.ReadKey();

        return 0;
    }

    public static void back(int k)
    {
        int i, j, x;
        for (i = 4; i <= 7; i += 3)
        {
            st[k] = i;
            if (k < 9) back(k + 1);
            x = 0;
            for (j = 1; j <= k; j++) x = x * 10 + st[j];
            L[++LPos] = x;
         }
    }

    public static long Intersectie(int stA, int drA, int stB, int drB)
    {
        if (drA < stB || drB < stA) return 0;
        if (stA <= stB && drB <= drA) return drB - stB + 1;
        if (stB <= stA && drA <= drB) return drA - stA + 1;
        if (stA <= stB && drA <= drB) return drA - stB + 1;
        if (stB <= stA && drB <= drA) return drB - stA + 1;
        return 0;
    }
}

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

namespace D
{
    class Program
    {
        static double p_select(int l, int r, int inl, int inr)
        {
            inl = Math.Max(inl, l);
            inr = Math.Min(inr, r);
            if (inl > inr)
                return 0.0;

            return (double)(inr - inl + 1) / (double)(r - l + 1);
        }

        static void Main(string[] args)
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            List<int>[] lucky = new List<int>[10];
            for (int i = 0; i < 10; i++)
                lucky[i] = new List<int>();
            lucky[1].Add(4);
            lucky[1].Add(7);

            int m = 10;
            for (int i = 2; i < 10; i++)
            {
                foreach (int x in lucky[i - 1])
                {
                    int y4 = m * 4 + x;
                    int y7 = m * 7 + x;
                    lucky[i].Add(y4);
                    lucky[i].Add(y7);
                }
                m *= 10;
            }

            lucky[0].Add(-1); // stop value
            lucky[0].Add(int.MaxValue - 1); // stop value
            int[] luckyAll = lucky[0].Union(lucky[1]).Union(lucky[2]).Union(lucky[3]).Union(lucky[4]).Union(lucky[5]).Union(lucky[6]).Union(lucky[7]).Union(lucky[8]).Union(lucky[9]).ToArray();
            Array.Sort(luckyAll);

            string[] line = Console.ReadLine().Split();
            int pl = int.Parse(line[0]);
            int pr = int.Parse(line[1]);
            int vl = int.Parse(line[2]);
            int vr = int.Parse(line[3]);
            int k = int.Parse(line[4]);

            double S = 0.0;

            int p = pl;
            while (p <= pr)
            {
                int fp = Array.BinarySearch(luckyAll, p);
                int q;
                if (fp < 0)
                {
                    fp = ~fp;
                    q = luckyAll[fp] - 1;
                    q = Math.Min(q, pr);

                    int idx1 = fp + k - 1;
                    int idx2 = fp + k;
                    int q1 = idx1 < luckyAll.Length ? luckyAll[idx1] : int.MaxValue;
                    int q2 = idx2 < luckyAll.Length ? luckyAll[idx2] - 1 : int.MaxValue;

                    S += p_select(pl, pr, p, q) * p_select(vl, vr, q1, q2);
                }
                else
                {
                    q = p;
                    int idx1 = fp + k - 1;
                    int idx2 = fp + k;
                    int q1 = idx1 < luckyAll.Length ? luckyAll[idx1] : int.MaxValue;
                    if (k == 1)
                    {
                        q1 = p + 1;
                    }
                    int q2 = idx2 < luckyAll.Length ? luckyAll[idx2] - 1 : int.MaxValue;

                    S += p_select(pl, pr, p, q) * p_select(vl, vr, q1, q2);
                }

                p = q + 1;
            }

            p = vl;
            while (p <= vr)
            {
                int fp = Array.BinarySearch(luckyAll, p);
                int q;
                if (fp < 0)
                {
                    fp = ~fp;
                    q = luckyAll[fp] - 1;
                    q = Math.Min(q, vr);

                    int idx1 = fp + k - 1;
                    int idx2 = fp + k;
                    int q1 = idx1 < luckyAll.Length ? luckyAll[idx1] : int.MaxValue;
                    int q2 = idx2 < luckyAll.Length ? luckyAll[idx2] - 1 : int.MaxValue;

                    S += p_select(vl, vr, p, q) * p_select(pl, pr, q1, q2);
                }
                else
                {
                    q = p;
                    int idx1 = fp + k - 1;
                    int idx2 = fp + k;
                    int q1 = idx1 < luckyAll.Length ? luckyAll[idx1] : int.MaxValue;
                    if (k == 1)
                    {
                        q1 = p + 1;
                    }
                    int q2 = idx2 < luckyAll.Length ? luckyAll[idx2] - 1 : int.MaxValue;

                    S += p_select(vl, vr, p, q) * p_select(pl, pr, q1, q2);
                }

                p = q + 1;
            }

            if (k == 1)
            {
                for (int i = 1; i < luckyAll.Length - 1; i++)
                {
                    int a = luckyAll[i];
                    if(a >= pl && a <= pr && a >= vl && a <= vr)
                        S += p_select(pl, pr, a, a) * p_select(vl, vr, a, a);
                }
            }

            Console.WriteLine("{0:0.000000000}", S);
        }
    }
}

using System;
using System.IO;
//using System.Reflection;
//using System.Collections;
using System.Collections.Generic;
using System.Linq;
//using System.Text;
//using System.Text.RegularExpressions;
using System.Threading;

namespace ConsoleApplication1
{
    class Program
    {
        static class Scanner
        {
            readonly static IEnumerator<string> Tokens;
            static Scanner()
            {
                Tokens = Enumerable.Range(Int32.MinValue, Int32.MaxValue).
                    Select(s => Console.ReadLine()).
                    TakeWhile(s => s != null).
                    SelectMany(s => s.Split(new[] { ' ', '\r', '\n', '\t' }, StringSplitOptions.RemoveEmptyEntries)).
                    Concat(Enumerable.Repeat(0, 1).Select(_ => (string)null)).
                    GetEnumerator();
            }

            public static string NextToken()
            {
                Tokens.MoveNext();
                return Tokens.Current;
            }
        }

        int nextInt()
        {
            return int.Parse(Scanner.NextToken());
        }

        bool GoodValue(int a)
        {
            if (a <= 0) return false;
            while (a != 0)
            {
                if (a % 10 != 7 && a % 10 != 4) return false;
                a /= 10;
            }
            return true;
        }

        int[] GenSequence()
        {
            var l = new List<int>();
            var q = new Queue<int>();
            q.Enqueue(0);
            while (q.Count != 0)
            {
                int cur = q.Dequeue();
                l.Add(cur);
                if (GoodValue(cur * 10 + 4)) q.Enqueue(cur * 10 + 4);
                if (GoodValue(cur * 10 + 7)) q.Enqueue(cur * 10 + 7);
            }
            return l.Concat(Enumerable.Range(1111111111, 1)).OrderBy(c => c).ToArray();
        }

        int LowerBound(int v, int[] a)
        {
            int x = 0, y = a.Length;
            while (y - x > 1)
            {
                int z = (x + y) / 2;
                if (a[z] <= v) x = z;
                else y = z;
            }
            return x;
        }

        int Len(int x, int y, int[] a, int p)
        {
            if (p < 1 || p >= a.Length) return 0;
            int tx = Math.Max(x, a[p - 1]), ty = Math.Min(y, a[p]);
            if (GoodValue(tx)) tx++;
            if (GoodValue(ty)) ty--;
            return Math.Max(ty - tx + 1, 0);
        }

        void Solve()
        {
            var values = GenSequence();
            int pl = nextInt(), pr = nextInt(),
                vl = nextInt(), vr = nextInt(),
                k = nextInt();
            long res = 0;
            for (int x = 1; x < values.Length; x++)
            {
                long pc = Len(pl, pr, values, x);
                long rc1 = Len(vl, vr, values, x + k),
                    rc2 = Len(vl, vr, values, x - k);
                res += pc * (rc1 + rc2);
                if (x + k - 1 < values.Length && values[x + k - 1] >= vl && values[x + k - 1] <= vr) res += pc;
                if (x - k > 0 && values[x - k] >= vl && values[x - k] <= vr) res += pc;

                if (values[x] >= pl && values[x] <= pr)
                {
                    res += Len(vl, vr, values, x - k + 1);
                    res += Len(vl, vr, values, x + k);

                    res += new[] { x + k - 1, x - k + 1 }.Distinct().Where(
                        c => c > 0 && c < values.Length &&
                            values[c] >= vl && values[c] <= vr
                        ).Count();
                }
            }
            long all = (pr - pl + 1);
            all *= (vr - vl + 1);
            Console.Write("{0:F12}", (double)res / (double)(all));
        }

        static void Main()
        {
#if MY_SUPER_PUPER_ONLINE_JUDGE
            string dir = Directory.GetCurrentDirectory();
            dir = Directory.GetParent(dir).FullName;
            dir = Directory.GetParent(dir).FullName;
            Console.SetIn(new StreamReader(dir + "\\input.txt"));
            Console.SetOut(new StreamWriter(dir + "\\output.txt"));
#endif
            Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
            new Program().Solve();
#if MY_SUPER_PUPER_ONLINE_JUDGE
            Console.In.Close();
            Console.Out.Close();
#endif
        }
    }
}

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

namespace tc_cf_c_sharp
{
    class MyIO
    {
        TextReader reader;
        TextWriter writer=Console.Out;
        string[] tokens;
        int pointer;
        public MyIO(TextReader rd)
        {
            reader = rd;
        }
        public string NextLine()
        {
            try
            {
                return reader.ReadLine();
            }
            catch (IOException)
            {
                return null;
            }
        }
        public string NextString()
        {
            try
            {
                while (tokens == null || pointer >= tokens.Length)
                {
                    tokens = NextLine().Split(new char[]{' '},System.StringSplitOptions.RemoveEmptyEntries);
                    pointer = 0;
                }
                return tokens[pointer++];
            }
            catch (IOException)
            {
                return null;
            }
        }
        public int NextInt()
        {
            return int.Parse(NextString());
        }
        public long NextLong()
        {
            return long.Parse(NextString());
        }
        public double NextDouble()
        {
            return double.Parse(NextString());
        }
        public void Write(string format, params object[] args)
        {
            writer.Write(format, args);
        }
        public void WriteLine(string format, params object[] args)
        {
            writer.WriteLine(format, args);
        }
    }
    class Program
    {
        static List<long> li;
        static void gen(long r)
        {
            if (r > 10000000000) return;
            li.Add(r);
            gen(r * 10 + 4);
            gen(r * 10 + 7);

        }
        static void Main(string[] args)
        {
            MyIO myio = new MyIO(Console.In);
            //MyIO myio = new MyIO(new StreamReader(File.OpenRead(@"D:\project\tc cf c sharp\tc cf c sharp\in.txt")));
            li = new List<long>();
            li.Add(0);
            gen(4); gen(7);
            li.Sort();
            long ct = 0;
            long v1 = myio.NextLong(), v2 = myio.NextLong(), p1 = myio.NextLong(), p2 = myio.NextLong();
            int k = myio.NextInt();
            for (int i = 0; i + k + 1 < li.Count; i++)
            {
                long mmin = li[i] + 1, mmax = li[i + 1];
                long nmin = li[i + k], nmax = li[i + k + 1] - 1;
                mmin = Math.Max(mmin, v1); mmax = Math.Min(mmax, v2);
                nmin = Math.Max(nmin, p1); nmax = Math.Min(nmax, p2);
                long t1 = Math.Max(0, mmax - mmin + 1);
                long t2 = Math.Max(0, nmax - nmin + 1);
                ct += t1 * t2;
            }
            for (int i = 0; i + k + 1 < li.Count; i++)
            {
                long mmin = li[i] + 1, mmax = li[i + 1];
                long nmin = li[i + k], nmax = li[i + k + 1] - 1;
                mmin = Math.Max(mmin, p1); mmax = Math.Min(mmax, p2);
                nmin = Math.Max(nmin, v1); nmax = Math.Min(nmax, v2);
                long t1 = Math.Max(0, mmax - mmin + 1);
                long t2 = Math.Max(0, nmax - nmin + 1);

                ct += t1 * t2;
            }
            for (int i = 0; i < li.Count; i++)
            {
                if (k==1&&li[i] >= v1 && li[i] <= v2 && li[i] >= p1 && li[i] <= p2) ct--;
            }
            long ct2 = (p2 - p1 + 1) * (v2 - v1 + 1);
            myio.WriteLine("{0}",(double)ct/ct2);
        }
    }
}

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

namespace ProgrammingContest.Codeforces.Round84 {
    class B {
        static List<int> v = new List<int>();
        const int MAX = 1000000000;

        static void dfs(long x) {
            if (x > MAX) return;
            v.Add((int)x);
            dfs(x * 10 + 4);
            dfs(x * 10 + 7);
        }

        static double choiceProb(int l1, int r1, int l2, int r2) {
            int low = Math.Max(l1, l2),
                high = Math.Min(r1, r2);
            if (low > high) {
                //Console.WriteLine("{0} {1} {2} {3}: {4}", l1, r1, l2, r2, 0);
                return 0;
            }
            //Console.WriteLine("{0} {1} {2} {3}: {4}", l1, r1, l2, r2, (high - low + 1) / (double)(r1 - l1 + 1));
            return (high - low + 1) / (double)(r1 - l1 + 1);
        }

        static void Main() {
            dfs(0);
            v.Add(MAX + 1);
            v.Sort();
            var xs = Array.ConvertAll<string, int>(Console.ReadLine().Split(' '), int.Parse);
            int pl = xs[0],
                pr = xs[1],
                vl = xs[2],
                vr = xs[3],
                k = xs[4];

            double res = 0;
            for (int i = 1; i < v.Count; i++) {
                int j = i + k;
                if (j >= v.Count) {
                    break;
                }

                res += choiceProb(pl, pr, v[i - 1] + 1, v[i]) * choiceProb(vl, vr, v[j - 1], v[j] - 1);
                res += choiceProb(vl, vr, v[i - 1] + 1, v[i]) * choiceProb(pl, pr, v[j - 1], v[j] - 1);
                if(k == 1 && pl <= v[i] && v[i] <= pr && vl <= v[i] && v[i] <= vr) {
                    res -= 1.0/(pr-pl+1)/(vr-vl+1);
                }
            }

            Console.WriteLine("{0:F12}", res);
        }
    }
}

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

namespace Task
{
    class MyIo
    {
        char[] separators = new char[] { ' ', '\t' };

#if TEST
        TextReader inputStream = new StreamReader("..\\..\\input.txt");
#else
        TextReader inputStream = System.Console.In;
#endif
        TextWriter outputStream = Console.Out;

        string[] tokens;
        int pointer;

        public string NextLine()
        {
            try
            {
                return inputStream.ReadLine();
            }
            catch (IOException)
            {
                return null;
            }
        }

        public string NextString()
        {
            try
            {
                while (tokens == null || pointer >= tokens.Length)
                {
                    tokens = NextLine().Split(separators, StringSplitOptions.RemoveEmptyEntries);
                    pointer = 0;
                }
                return tokens[pointer++];
            }
            catch (IOException)
            {
                return null;
            }
        }

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

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

        public void Print(string format, params object[] args)
        {
            outputStream.Write(format, args);
        }

        public void PrintLine(string format, params object[] args)
        {
            outputStream.WriteLine(format, args);
        }

        public void Print<T>(T o)
        {
            outputStream.Write(o);
        }

        public void PrintLine<T>(T o)
        {
            outputStream.WriteLine(o);
        }

        public void Close()
        {
            inputStream.Close();
            outputStream.Close();
        }
    }

    class Program
    {
        MyIo io = new MyIo();

        const int Limit = 1000000000;

        void Populate(List<int> list, long curNum)
        {
            if (curNum > Limit)
            {
                return;
            }
            if (curNum != 0)
            {
                list.Add((int)curNum);
            }
            Populate(list, curNum * 10 + 4);
            Populate(list, curNum * 10 + 7);
        }

        double Fp(int low, int high, int tLow, int tHigh)
        {
            if (low > high || tLow > tHigh)
            {
                return 0;
            }

            int iLow = Math.Max(low, tLow);
            int iHigh = Math.Min(high, tHigh);

            if (iLow > iHigh)
            {
                return 0;
            }

            double res = (iHigh - iLow + 1D) / (high - low + 1D);
            return res;
        }

        void Solve()
        {
            // Place your code here
            int pL = io.NextInt();
            int pR = io.NextInt();
            int vL = io.NextInt();
            int vR = io.NextInt();
            int k = io.NextInt();

            List<int> list = new List<int>();
            Populate(list, 0);
            list.Sort();

            double ans = 0;

            for (int a = 0; a < list.Count; a++)
            {
                int b = a + k - 1;
                if (b >= list.Count)
                {
                    break;
                }

                int beforeLow = a == 0 ? 1 : list[a - 1] + 1;
                int beforeHigh = list[a];

                int afterLow = list[b];
                int afterHigh = b + 1 == list.Count ? Limit : list[b + 1] - 1;

                double r1 = Fp(pL, pR, beforeLow, beforeHigh);
                double r2 = Fp(vL, vR, afterLow, afterHigh);

                double r3 = Fp(vL, vR, beforeLow, beforeHigh);
                double r4 = Fp(pL, pR, afterLow, afterHigh);

                double res = r1 * r2 + r3 * r4;

                if (k == 1 && pL <= list[a] && list[a] <= pR && vL <= list[a] && list[a] <= vR)
                {
                    double r5 = Fp(vL, vR, list[a], list[a]);
                    double r6 = Fp(pL, pR, list[a], list[a]);
                    res -= r5 * r6;
                }

                ans += res;
            }

            io.PrintLine(ans);
        }

        static void Main(string[] args)
        {
            var p = new Program();

            p.Solve();
            p.io.Close();
        }
    }
}

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

class LuckyProbability
{

    static int[] L = new int[1024];
    static int[] st = new int[10];
    static int LPos = 0;

    public static int Main()
    {
        //citire
        string[] citire = Console.ReadLine().Split(' ');
        int x1, x2, y1, y2, k;
        x1 = Convert.ToInt32(citire[0]);
        x2 = Convert.ToInt32(citire[1]);
        y1 = Convert.ToInt32(citire[2]);
        y2 = Convert.ToInt32(citire[3]);
        k = Convert.ToInt32(citire[4]);

        //solve
        back(1); L[1023] = 1000000001;
        Array.Sort(L, 1, 1022); //stocare numere Lucky

        int i, j; long Rez = 0;
        for (i = 1; i <= (1023 - k); i++)
        {
            j = i + k - 1;
            Rez += Intersectie(x1, x2, L[i - 1] + 1, L[i]) * Intersectie(y1, y2, L[j], L[j+1]-1);
            Rez += Intersectie(y1, y2, L[i - 1] + 1, L[i]) * Intersectie(x1, x2, L[j], L[j+1]-1);
        }

        long Posibilitati = (x2 - x1 + 1) * (y2 - y1 + 1);
        decimal Afis = (decimal)Rez / (decimal)Posibilitati;
        Console.WriteLine(Afis.ToString("N12"));
        Console.ReadKey();

        return 0;
    }

    public static void back(int k)
    {
        int i, j, x;
        for (i = 4; i <= 7; i += 3)
        {
            st[k] = i;
            if (k < 9) back(k + 1);
            x = 0;
            for (j = 1; j <= k; j++) x = x * 10 + st[j];
            L[++LPos] = x;
         }
    }

    public static int Intersectie(int stA, int drA, int stB, int drB)
    {
        if (drA < stB || drB < stA) return 0;
        if (stA <= stB && drB <= drA) return drB - stB + 1;
        if (stB <= stA && drA <= drB) return drA - stA + 1;
        if (stA <= stB && drA <= drB) return drA - stB + 1;
        if (stB <= stA && drB <= drA) return drB - stA + 1;
        return 0;
    }
}

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

class LuckyProbability
{

    static int[] L = new int[1024];
    static int[] st = new int[10];
    static int LPos = 0;

    public static int Main()
    {
        //citire
        string[] citire = Console.ReadLine().Split(' ');
        int x1, x2, y1, y2, k;
        x1 = Convert.ToInt32(citire[0]);
        x2 = Convert.ToInt32(citire[1]);
        y1 = Convert.ToInt32(citire[2]);
        y2 = Convert.ToInt32(citire[3]);
        k = Convert.ToInt32(citire[4]);

        //solve
        back(1); L[1023] = 1000000001;
        Array.Sort(L, 1, 1022); //stocare numere Lucky

        int i, j; long Rez = 0;
        for (i = 1; i <= (1023 - k); i++)
        {
            j = i + k - 1;
            Rez += Intersectie(x1, x2, L[i - 1] + 1, L[i]) * Intersectie(y1, y2, L[j], L[j+1]-1);
            Rez += Intersectie(y1, y2, L[i - 1] + 1, L[i]) * Intersectie(x1, x2, L[j], L[j+1]-1);
        }

        long Posibilitati = (x2 - x1 + 1) * (y2 - y1 + 1);
        decimal Afis = (decimal)Rez / (decimal)Posibilitati;
        Console.WriteLine(Afis.ToString("N12"));
        Console.ReadKey();

        return 0;
    }

    public static void back(int k)
    {
        int i, j, x;
        for (i = 4; i <= 7; i += 3)
        {
            st[k] = i;
            if (k < 9) back(k + 1);
            x = 0;
            for (j = 1; j <= k; j++) x = x * 10 + st[j];
            L[++LPos] = x;
         }
    }

    public static int Intersectie(int stA, int drA, int stB, int drB)
    {
        if (drA < stB || drB < stA) return 0;
        if (stA <= stB && drB <= drA) return drB - stB + 1;
        if (stB <= stA && drA <= drB) return drA - stA + 1;
        if (stA <= stB && drB >= drA) return drA - stB + 1;
        if (stB <= stA && drA >= drB) return stA - drB + 1;
        return 0;
    }
}

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

class LuckyProbability
{

    static int[] L = new int[1024];
    static int[] st = new int[10];
    static int LPos = 0;

    public static int Main()
    {
        //citire
        string[] citire = Console.ReadLine().Split(' ');
        int x1, x2, y1, y2, k;
        x1 = Convert.ToInt32(citire[0]);
        x2 = Convert.ToInt32(citire[1]);
        y1 = Convert.ToInt32(citire[2]);
        y2 = Convert.ToInt32(citire[3]);
        k = Convert.ToInt32(citire[4]);

        //solve
        back(1); L[1023] = 1000000001;
        Array.Sort(L, 1, 1022); //stocare numere Lucky

        int i, j; long Rez = 0;
        for (i = 1; i <= (1023 - k); i++)
        {
            j = i + k - 1;
            Rez += (long)Intersectie(x1, x2, L[i - 1] + 1, L[i]) * (long)Intersectie(y1, y2, L[j], L[j + 1] - 1);
            Rez += (long)Intersectie(y1, y2, L[i - 1] + 1, L[i]) * (long)Intersectie(x1, x2, L[j], L[j + 1] - 1);
        }

        long Posibilitati = (long)(x2 - x1 + 1) * (long)(y2 - y1 + 1);
        decimal Afis = (decimal)Rez / (decimal)Posibilitati; if (Afis > 1) Afis = 1M;
        Console.WriteLine(Afis.ToString("N12"));
        Console.ReadKey();

        return 0;
    }

    public static void back(int k)
    {
        int i, j, x;
        for (i = 4; i <= 7; i += 3)
        {
            st[k] = i;
            if (k < 9) back(k + 1);
            x = 0;
            for (j = 1; j <= k; j++) x = x * 10 + st[j];
            L[++LPos] = x;
         }
    }

    public static long Intersectie(int stA, int drA, int stB, int drB)
    {
        if (drA < stB || drB < stA) return 0;
        if (stA <= stB && drB <= drA) return drB - stB + 1;
        if (stB <= stA && drA <= drB) return drA - stA + 1;
        if (stA <= stB && drA <= drB) return drA - stB + 1;
        if (stB <= stA && drB <= drA) return drB - stA + 1;
        return 0;
    }
}

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

class LuckyProbability
{

    static int[] L = new int[1024];
    static int[] st = new int[10];
    static int LPos = 0;

    public static int Main()
    {
        //citire
        string[] citire = Console.ReadLine().Split(' ');
        int x1, x2, y1, y2, k;
        x1 = Convert.ToInt32(citire[0]);
        x2 = Convert.ToInt32(citire[1]);
        y1 = Convert.ToInt32(citire[2]);
        y2 = Convert.ToInt32(citire[3]);
        k = Convert.ToInt32(citire[4]);

        //solve
        back(1); L[1023] = 1000000001;
        Array.Sort(L, 1, 1022); //stocare numere Lucky

        int i, j; long Rez = 0;
        for (i = 1; i <= (1023 - k); i++)
        {
            j = i + k - 1;
            Rez += (long)Intersectie(x1, x2, L[i - 1] + 1, L[i]) * (long)Intersectie(y1, y2, L[j], L[j + 1] - 1);
            Rez += (long)Intersectie(y1, y2, L[i - 1] + 1, L[i]) * (long)Intersectie(x1, x2, L[j], L[j + 1] - 1);
        }

        long Posibilitati = (long)(x2 - x1 + 1) * (long)(y2 - y1 + 1);
        decimal Afis = (decimal)Rez / (decimal)Posibilitati;
        Console.WriteLine(Afis.ToString("N12"));
        Console.ReadKey();

        return 0;
    }

    public static void back(int k)
    {
        int i, j, x;
        for (i = 4; i <= 7; i += 3)
        {
            st[k] = i;
            if (k < 9) back(k + 1);
            x = 0;
            for (j = 1; j <= k; j++) x = x * 10 + st[j];
            L[++LPos] = x;
         }
    }

    public static long Intersectie(int stA, int drA, int stB, int drB)
    {
        if (drA < stB || drB < stA) return 0;
        if (stA <= stB && drB <= drA) return drB - stB + 1;
        if (stB <= stA && drA <= drB) return drA - stA + 1;
        if (stA <= stB && drA <= drB) return drA - stB + 1;
        if (stB <= stA && drB <= drA) return drB - stA + 1;
        return 0;
    }
}

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

class LuckyProbability
{

    static int[] L = new int[1024];
    static int[] st = new int[10];
    static int LPos = 0;

    public static int Main()
    {
        //citire
        string[] citire = Console.ReadLine().Split(' ');
        int x1, x2, y1, y2, k;
        x1 = Convert.ToInt32(citire[0]);
        x2 = Convert.ToInt32(citire[1]);
        y1 = Convert.ToInt32(citire[2]);
        y2 = Convert.ToInt32(citire[3]);
        k = Convert.ToInt32(citire[4]);

        //solve
        back(1); L[1023] = 1000000001;
        Array.Sort(L, 1, 1022); //stocare numere Lucky

        int i, j; long Rez = 0;
        for (i = 1; i <= (1023 - k); i++)
        {
            j = i + k - 1;
            Rez += Intersectie(x1, x2, L[i - 1] + 1, L[i]) * Intersectie(y1, y2, L[j], L[j+1]-1);
            Rez += Intersectie(y1, y2, L[i - 1] + 1, L[i]) * Intersectie(x1, x2, L[j], L[j+1]-1);
        }

        long Posibilitati = (long)(x2 - x1 + 1) * (long)(y2 - y1 + 1);
        decimal Afis = (decimal)Rez / (decimal)Posibilitati;
        Console.WriteLine(Afis.ToString("N12"));
        Console.ReadKey();

        return 0;
    }

    public static void back(int k)
    {
        int i, j, x;
        for (i = 4; i <= 7; i += 3)
        {
            st[k] = i;
            if (k < 9) back(k + 1);
            x = 0;
            for (j = 1; j <= k; j++) x = x * 10 + st[j];
            L[++LPos] = x;
         }
    }

    public static int Intersectie(int stA, int drA, int stB, int drB)
    {
        if (drA < stB || drB < stA) return 0;
        if (stA <= stB && drB <= drA) return drB - stB + 1;
        if (stB <= stA && drA <= drB) return drA - stA + 1;
        if (stA <= stB && drA <= drB) return drA - stB + 1;
        if (stB <= stA && drB <= drA) return drB - stA + 1;
        return 0;
    }
}

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

class LuckyProbability
{

    static int[] L = new int[1024];
    static int[] st = new int[10];
    static int LPos = 0;

    public static int Main()
    {
        //citire
        string[] citire = Console.ReadLine().Split(' ');
        int x1, x2, y1, y2, k;
        x1 = Convert.ToInt32(citire[0]);
        x2 = Convert.ToInt32(citire[1]);
        y1 = Convert.ToInt32(citire[2]);
        y2 = Convert.ToInt32(citire[3]);
        k = Convert.ToInt32(citire[4]);

        //solve
        back(1); L[1023] = 1000000001;
        Array.Sort(L, 1, 1022); //stocare numere Lucky

        int i, j; long Rez = 0;
        for (i = 1; i <= (1023 - k); i++)
        {
            j = i + k - 1;
            Rez += Intersectie(x1, x2, L[i - 1] + 1, L[i]) * Intersectie(y1, y2, L[j], L[j+1]-1);
            Rez += Intersectie(y1, y2, L[i - 1] + 1, L[i]) * Intersectie(x1, x2, L[j], L[j+1]-1);
        }

        long Posibilitati = (x2 - x1 + 1) * (y2 - y1 + 1);
        decimal Afis = (decimal)Rez / (decimal)Posibilitati;
        Console.WriteLine(Afis.ToString("N12"));
        Console.ReadKey();

        return 0;
    }

    public static void back(int k)
    {
        int i, j, x;
        for (i = 4; i <= 7; i += 3)
        {
            st[k] = i;
            if (k < 9) back(k + 1);
            x = 0;
            for (j = 1; j <= k; j++) x = x * 10 + st[j];
            L[++LPos] = x;
         }
    }

    public static int Intersectie(int stA, int drA, int stB, int drB)
    {
        if (drA < stB || drB < stA) return 0;
        if (stA <= stB && drB <= drA) return drB - stB + 1;
        if (stB <= stA && drA <= stB) return drA - stA + 1;
        if (stA <= stB && drB >= drA) return drA - stB + 1;
        if (stB <= stA && drA >= drB) return stA - drB + 1;
        return 0;
    }
}

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

namespace D
{
    class Program
    {
        static double p_select(int l, int r, int inl, int inr)
        {
            inl = Math.Max(inl, l);
            inr = Math.Min(inr, r);
            if (inl > inr)
                return 0.0;

            return (double)(inr - inl + 1) / (double)(r - l + 1);
        }

        static void Main(string[] args)
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            List<int>[] lucky = new List<int>[10];
            for (int i = 0; i < 10; i++)
                lucky[i] = new List<int>();
            lucky[1].Add(4);
            lucky[1].Add(7);

            int m = 10;
            for (int i = 2; i < 10; i++)
            {
                foreach (int x in lucky[i - 1])
                {
                    int y4 = m * 4 + x;
                    int y7 = m * 7 + x;
                    lucky[i].Add(y4);
                    lucky[i].Add(y7);
                }
                m *= 10;
            }

            lucky[0].Add(-1); // stop value
            lucky[0].Add(int.MaxValue - 1); // stop value
            int[] luckyAll = lucky[0].Union(lucky[1]).Union(lucky[2]).Union(lucky[3]).Union(lucky[4]).Union(lucky[5]).Union(lucky[6]).Union(lucky[7]).Union(lucky[8]).Union(lucky[9]).ToArray();
            Array.Sort(luckyAll);

            string[] line = Console.ReadLine().Split();
            int pl = int.Parse(line[0]);
            int pr = int.Parse(line[1]);
            int vl = int.Parse(line[2]);
            int vr = int.Parse(line[3]);
            int k = int.Parse(line[4]);

            double S = 0.0;

            int p = pl;
            while (p <= pr)
            {
                int fp = Array.BinarySearch(luckyAll, p);
                int q;
                if (fp < 0)
                {
                    fp = ~fp;
                    q = luckyAll[fp] - 1;
                    q = Math.Min(q, pr);

                    int idx1 = fp + k - 1;
                    int idx2 = fp + k;
                    int q1 = idx1 < luckyAll.Length ? luckyAll[idx1] : int.MaxValue;
                    int q2 = idx2 < luckyAll.Length ? luckyAll[idx2] - 1 : int.MaxValue;

                    S += p_select(pl, pr, p, q) * p_select(vl, vr, q1, q2);
                }
                else
                {
                    q = p;
                    int idx1 = fp + k - 1;
                    int idx2 = fp + k;
                    int q1 = idx1 < luckyAll.Length ? luckyAll[idx1] : int.MaxValue;
                    if (k == 1)
                    {
                        q1 = p + 1;
                    }
                    int q2 = idx2 < luckyAll.Length ? luckyAll[idx2] - 1 : int.MaxValue;

                    S += p_select(pl, pr, p, q) * p_select(vl, vr, q1, q2);
                }

                p = q + 1;
            }

            p = vl;
            while (p <= vr)
            {
                int fp = Array.BinarySearch(luckyAll, p);
                int q;
                if (fp < 0)
                {
                    fp = ~fp;
                    q = luckyAll[fp] - 1;
                    q = Math.Min(q, vr);

                    int idx1 = fp + k - 1;
                    int idx2 = fp + k;
                    int q1 = idx1 < luckyAll.Length ? luckyAll[idx1] : int.MaxValue;
                    int q2 = idx2 < luckyAll.Length ? luckyAll[idx2] - 1 : int.MaxValue;

                    S += p_select(vl, vr, p, q) * p_select(pl, pr, q1, q2);
                }
                else
                {
                    q = p;
                    int idx1 = fp + k - 1;
                    int idx2 = fp + k;
                    int q1 = idx1 < luckyAll.Length ? luckyAll[idx1] : int.MaxValue;
                    if (k == 1)
                    {
                        q1 = p + 1;
                    }
                    int q2 = idx2 < luckyAll.Length ? luckyAll[idx2] - 1 : int.MaxValue;

                    S += p_select(vl, vr, p, q) * p_select(pl, pr, q1, q2);
                }

                p = q + 1;
            }

            if (k == 1)
            {
                for (int i = 1; i < luckyAll.Length - 1; i++)
                {
                    int a = luckyAll[i];
                    if(a >= pl && a <= pr && a >= vl && a <= vl)
                        S += p_select(pl, pr, a, a) * p_select(vl, vr, a, a);
                }
            }

            Console.WriteLine("{0:0.000000000}", S);
        }
    }
}

using System;
using System.IO;
//using System.Reflection;
//using System.Collections;
using System.Collections.Generic;
using System.Linq;
//using System.Text;
//using System.Text.RegularExpressions;
using System.Threading;

namespace ConsoleApplication1
{
    class Program
    {
        static class Scanner
        {
            readonly static IEnumerator<string> Tokens;
            static Scanner()
            {
                Tokens = Enumerable.Range(Int32.MinValue, Int32.MaxValue).
                    Select(s => Console.ReadLine()).
                    TakeWhile(s => s != null).
                    SelectMany(s => s.Split(new[] { ' ', '\r', '\n', '\t' }, StringSplitOptions.RemoveEmptyEntries)).
                    Concat(Enumerable.Repeat(0, 1).Select(_ => (string)null)).
                    GetEnumerator();
            }

            public static string NextToken()
            {
                Tokens.MoveNext();
                return Tokens.Current;
            }
        }

        int nextInt()
        {
            return int.Parse(Scanner.NextToken());
        }

        bool GoodValue(int a)
        {
            if (a <= 0) return false;
            while (a != 0)
            {
                if (a % 10 != 7 && a % 10 != 4) return false;
                a /= 10;
            }
            return true;
        }

        int[] GenSequence()
        {
            var l = new List<int>();
            var q = new Queue<int>();
            q.Enqueue(0);
            while (q.Count != 0)
            {
                int cur = q.Dequeue();
                l.Add(cur);
                if (GoodValue(cur * 10 + 4)) q.Enqueue(cur * 10 + 4);
                if (GoodValue(cur * 10 + 7)) q.Enqueue(cur * 10 + 7);
            }
            return l.OrderBy(c => c).ToArray();
        }

        int LowerBound(int v, int[] a)
        {
            int x = 0, y = a.Length;
            while (y - x > 1)
            {
                int z = (x + y) / 2;
                if (a[z] <= v) x = z;
                else y = z;
            }
            return x;
        }

        int Len(int x, int y, int[] a, int p)
        {
            if (p < 1 || p >= a.Length) return 0;
            int tx = Math.Max(x, a[p - 1]), ty = Math.Min(y, a[p]);
            if (GoodValue(tx)) tx++;
            if (GoodValue(ty)) ty--;
            return Math.Max(ty - tx + 1, 0);
        }

        void Solve()
        {
            var values = GenSequence();
            int pl = nextInt(), pr = nextInt(),
                vl = nextInt(), vr = nextInt(),
                k = nextInt();
            long res = 0;
            for (int x = 1; x < values.Length; x++)
            {
                long pc = Len(pl, pr, values, x);
                long rc1 = Len(vl, vr, values, x + k),
                    rc2 = Len(vl, vr, values, x - k);
                res += pc * (rc1 + rc2);
                if (x + k - 1 < values.Length && values[x + k - 1] >= vl && values[x + k - 1] <= vr) res += pc;
                if (x - k > 0 && values[x - k] >= vl && values[x - k] <= vr) res += pc;

                if (values[x] >= pl && values[x] <= pr)
                {
                    res += Len(vl, vr, values, x - k + 1);
                    res += Len(vl, vr, values, x + k);

                    res += new[] { x + k - 1, x - k + 1 }.Distinct().Where(
                        c => c > 0 && c < values.Length &&
                            values[c] >= vl && values[c] <= vr
                        ).Count();
                }
            }
            long all = (pr - pl + 1);
            all *= (vr - vl + 1);
            Console.Write("{0:F12}", (double)res / (double)(all));
        }

        static void Main()
        {
#if MY_SUPER_PUPER_ONLINE_JUDGE
            string dir = Directory.GetCurrentDirectory();
            dir = Directory.GetParent(dir).FullName;
            dir = Directory.GetParent(dir).FullName;
            Console.SetIn(new StreamReader(dir + "\\input.txt"));
            Console.SetOut(new StreamWriter(dir + "\\output.txt"));
#endif
            Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
            new Program().Solve();
#if MY_SUPER_PUPER_ONLINE_JUDGE
            Console.In.Close();
            Console.Out.Close();
#endif
        }
    }
}

using System;
using System.IO;
//using System.Reflection;
//using System.Collections;
using System.Collections.Generic;
using System.Linq;
//using System.Text;
//using System.Text.RegularExpressions;
using System.Threading;

namespace ConsoleApplication1
{
    class Program
    {
        static class Scanner
        {
            readonly static IEnumerator<string> Tokens;
            static Scanner()
            {
                Tokens = Enumerable.Range(Int32.MinValue, Int32.MaxValue).
                    Select(s => Console.ReadLine()).
                    TakeWhile(s => s != null).
                    SelectMany(s => s.Split(new[] { ' ', '\r', '\n', '\t' }, StringSplitOptions.RemoveEmptyEntries)).
                    Concat(Enumerable.Repeat(0, 1).Select(_ => (string)null)).
                    GetEnumerator();
            }

            public static string NextToken()
            {
                Tokens.MoveNext();
                return Tokens.Current;
            }
        }

        int nextInt()
        {
            return int.Parse(Scanner.NextToken());
        }

        bool GoodValue(int a)
        {
            if (a <= 0) return false;
            while (a != 0)
            {
                if (a % 10 != 7 && a % 10 != 4) return false;
                a /= 10;
            }
            return true;
        }

        int[] GenSequence()
        {
            var l = new List<int>();
            var q = new Queue<int>();
            q.Enqueue(0);
            while (q.Count != 0)
            {
                int cur = q.Dequeue();
                l.Add(cur);
                if (GoodValue(cur * 10 + 4)) q.Enqueue(cur * 10 + 4);
                if (GoodValue(cur * 10 + 7)) q.Enqueue(cur * 10 + 7);
            }
            return l.OrderBy(c => c).ToArray();
        }

        int LowerBound(int v, int[] a)
        {
            int x = 0, y = a.Length;
            while (y - x > 1)
            {
                int z = (x + y) / 2;
                if (a[z] <= v) x = z;
                else y = z;
            }
            return x;
        }

        int Len(int x, int y, int[] a, int p)
        {
            if (p < 1 || p >= a.Length) return 0;
            int tx = Math.Max(x, a[p - 1]), ty = Math.Min(y, a[p]);
            if (GoodValue(tx)) tx++;
            if (GoodValue(ty)) ty--;
            return Math.Max(ty - tx + 1, 0);
        }

        void Solve()
        {
            var values = GenSequence();
            int pl = nextInt(), pr = nextInt(),
                vl = nextInt(), vr = nextInt(),
                k = nextInt();
            long res = 0;
            for (int x = 1; x < values.Length; x++)
            {
                long pc = Len(pl, pr, values, x);
                long rc1 = Len(vl, vr, values, x + k),
                    rc2 = Len(vl, vr, values, x - k);
                res += pc * (rc1 + rc2);
                if (x + k - 1 < values.Length && values[x + k - 1] >= vl && values[x + k - 1] <= vr) res += pc;
                if (x - k > 0 && values[x - k] >= vl && values[x - k] <= vr) res += pc;

                if (values[x] >= pl && values[x] <= pr)
                {
                    res += Len(vl, vr, values, x - k + 1);
                    res += Len(vl, vr, values, x + k);

                    res += new[] { x + k - 1, x - k + 1 }.Distinct().Where(
                        c => c > 0 && c < values.Length &&
                            values[c] >= vl && values[c] <= vr
                        ).Count();
                }
            }
            long all = (pr - pl + 1);
            all *= (vr - vl + 1);
            Console.Write("{0:F7}", (double)res / (double)(all));
        }

        static void Main()
        {
#if MY_SUPER_PUPER_ONLINE_JUDGE
            string dir = Directory.GetCurrentDirectory();
            dir = Directory.GetParent(dir).FullName;
            dir = Directory.GetParent(dir).FullName;
            Console.SetIn(new StreamReader(dir + "\\input.txt"));
            Console.SetOut(new StreamWriter(dir + "\\output.txt"));
#endif
            Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
            new Program().Solve();
#if MY_SUPER_PUPER_ONLINE_JUDGE
            Console.In.Close();
            Console.Out.Close();
#endif
        }
    }
}

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

namespace tc_cf_c_sharp
{
    class MyIO
    {
        TextReader reader;
        TextWriter writer=Console.Out;
        string[] tokens;
        int pointer;
        public MyIO(TextReader rd)
        {
            reader = rd;
        }
        public string NextLine()
        {
            try
            {
                return reader.ReadLine();
            }
            catch (IOException)
            {
                return null;
            }
        }
        public string NextString()
        {
            try
            {
                while (tokens == null || pointer >= tokens.Length)
                {
                    tokens = NextLine().Split(new char[]{' '},System.StringSplitOptions.RemoveEmptyEntries);
                    pointer = 0;
                }
                return tokens[pointer++];
            }
            catch (IOException)
            {
                return null;
            }
        }
        public int NextInt()
        {
            return int.Parse(NextString());
        }
        public long NextLong()
        {
            return long.Parse(NextString());
        }
        public double NextDouble()
        {
            return double.Parse(NextString());
        }
        public void Write(string format, params object[] args)
        {
            writer.Write(format, args);
        }
        public void WriteLine(string format, params object[] args)
        {
            writer.WriteLine(format, args);
        }
    }
    class Program
    {
        static List<long> li;
        static void gen(long r)
        {
            if (r > 10000000000) return;
            li.Add(r);
            gen(r * 10 + 4);
            gen(r * 10 + 7);

        }
        static void Main(string[] args)
        {
            MyIO myio = new MyIO(Console.In);
            //MyIO myio = new MyIO(new StreamReader(File.OpenRead(@"D:\project\tc cf c sharp\tc cf c sharp\in.txt")));
            li = new List<long>();
            li.Add(0);
            gen(4); gen(7);
            li.Sort();
            long ct = 0;
            long v1 = myio.NextLong(), v2 = myio.NextLong(), p1 = myio.NextLong(), p2 = myio.NextLong();
            int k = myio.NextInt();
            for (int i = 0; i + k + 1 < li.Count; i++)
            {
                long mmin = li[i] + 1, mmax = li[i + 1];
                long nmin = li[i + k], nmax = li[i + k + 1] - 1;
                mmin = Math.Max(mmin, v1); mmax = Math.Min(mmax, v2);
                nmin = Math.Max(nmin, p1); nmax = Math.Min(nmax, p2);
                long t1 = Math.Max(0, mmax - mmin + 1);
                long t2 = Math.Max(0, nmax - nmin + 1);
                ct += t1 * t2;
            }
            for (int i = 0; i + k + 1 < li.Count; i++)
            {
                long mmin = li[i] + 1, mmax = li[i + 1];
                long nmin = li[i + k], nmax = li[i + k + 1] - 1;
                mmin = Math.Max(mmin, p1); mmax = Math.Min(mmax, p2);
                nmin = Math.Max(nmin, v1); nmax = Math.Min(nmax, v2);
                long t1 = Math.Max(0, mmax - mmin + 1);
                long t2 = Math.Max(0, nmax - nmin + 1);

                ct += t1 * t2;
            }
            for (int i = 0; i < li.Count; i++)
            {
                if (li[i] >= v1 && li[i] <= v2 && li[i] >= p1 && li[i] <= p2) ct--;
            }
            long ct2 = (p2 - p1 + 1) * (v2 - v1 + 1);
            myio.WriteLine("{0}",(double)ct/ct2);
        }
    }
}

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

namespace ProgrammingContest.Codeforces.Round84 {
    class B {
        static List<int> v = new List<int>();
        const int MAX = 1000000000;

        static void dfs(long x) {
            if (x > MAX) return;
            v.Add((int)x);
            dfs(x * 10 + 4);
            dfs(x * 10 + 7);
        }

        static double choiceProb(int l1, int r1, int l2, int r2) {
            int low = Math.Max(l1, l2),
                high = Math.Min(r1, r2);
            if (low > high) {
                //Console.WriteLine("{0} {1} {2} {3}: {4}", l1, r1, l2, r2, 0);
                return 0;
            }
            //Console.WriteLine("{0} {1} {2} {3}: {4}", l1, r1, l2, r2, (high - low + 1) / (double)(r1 - l1 + 1));
            return (high - low + 1) / (double)(r1 - l1 + 1);
        }

        static void Main() {
            dfs(0);
            v.Add(MAX + 1);
            v.Sort();
            var xs = Array.ConvertAll<string, int>(Console.ReadLine().Split(' '), int.Parse);
            int pl = xs[0],
                pr = xs[1],
                vl = xs[2],
                vr = xs[3],
                k = xs[4];
            if(pl == pr && pl == vl && vl == vr && k == 1) {
                Console.WriteLine("{0:F12}", v.Contains(pl) ? 1 : 0);
            }

            double res = 0;
            for (int i = 1; i < v.Count; i++) {
                int j = i + k;
                if (j >= v.Count) {
                    break;
                }

                res += choiceProb(pl, pr, v[i - 1] + 1, v[i]) * choiceProb(vl, vr, v[j - 1], v[j] - 1);
                res += choiceProb(vl, vr, v[i - 1] + 1, v[i]) * choiceProb(pl, pr, v[j - 1], v[j] - 1);
            }

            Console.WriteLine("{0:F12}", res);
        }
    }
}

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

namespace ProgrammingContest.Codeforces.Round84 {
    class B {
        static List<int> v = new List<int>();
        const int MAX = 1000000000;

        static void dfs(long x) {
            if (x > MAX) return;
            v.Add((int)x);
            dfs(x * 10 + 4);
            dfs(x * 10 + 7);
        }

        static double choiceProb(int l1, int r1, int l2, int r2) {
            int low = Math.Max(l1, l2),
                high = Math.Min(r1, r2);
            if (low > high) {
                //Console.WriteLine("{0} {1} {2} {3}: {4}", l1, r1, l2, r2, 0);
                return 0;
            }
            //Console.WriteLine("{0} {1} {2} {3}: {4}", l1, r1, l2, r2, (high - low + 1) / (double)(r1 - l1 + 1));
            return (high - low + 1) / (double)(r1 - l1 + 1);
        }

        static void Main() {
            dfs(0);
            v.Add(MAX + 1);
            v.Sort();
            var xs = Array.ConvertAll<string, int>(Console.ReadLine().Split(' '), int.Parse);
            int pl = xs[0],
                pr = xs[1],
                vl = xs[2],
                vr = xs[3],
                k = xs[4];

            double res = 0;
            for (int i = 1; i < v.Count; i++) {
                int j = i + k;
                if (j >= v.Count) {
                    break;
                }

                res += choiceProb(pl, pr, v[i - 1] + 1, v[i]) * choiceProb(vl, vr, v[j - 1], v[j] - 1);
                res += choiceProb(vl, vr, v[i - 1] + 1, v[i]) * choiceProb(pl, pr, v[j - 1], v[j] - 1);
            }

            Console.WriteLine("{0:F12}", res);
        }
    }
}

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

namespace ProgrammingContest.Codeforces.Round84 {
    class B {
        static List<int> v = new List<int>();
        const int MAX = 1000000000;

        static void dfs(long x) {
            if (x > MAX) return;
            v.Add((int)x);
            dfs(x * 10 + 4);
            dfs(x * 10 + 7);
        }

        static double choiceProb(int l1, int r1, int l2, int r2) {
            int low = Math.Max(l1, l2),
                high = Math.Min(r1, r2);
            if (low > high) {
                //Console.WriteLine("{0} {1} {2} {3}: {4}", l1, r1, l2, r2, 0);
                return 0;
            }
            //Console.WriteLine("{0} {1} {2} {3}: {4}", l1, r1, l2, r2, (high - low + 1) / (double)(r1 - l1 + 1));
            return (high - low + 1) / (double)(r1 - l1 + 1);
        }

        static void Main() {
            dfs(0);
            v.Add(MAX + 1);
            v.Sort();
            var xs = Array.ConvertAll<string, int>(Console.ReadLine().Split(' '), int.Parse);
            int pl = xs[0],
                pr = xs[1],
                vl = xs[2],
                vr = xs[3],
                k = xs[4];

            double res = 0;
            for (int i = 1; i < v.Count; i++) {
                int j = i + k;
                if (j >= v.Count) {
                    break;
                }

                res += choiceProb(pl, pr, v[i - 1] + 1, v[i]) * choiceProb(vl, vr, v[j - 1], v[j] - 1);
                if(k > 1) res += choiceProb(vl, vr, v[i - 1] + 1, v[i]) * choiceProb(pl, pr, v[j - 1], v[j] - 1);
            }

            Console.WriteLine("{0:F12}", res);
        }
    }
}

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

namespace ProgrammingContest.Codeforces.Round84 {
    class B {
        static List<int> v = new List<int>();
        const int MAX = 1000000000;

        static void dfs(long x) {
            if (x > MAX) return;
            v.Add((int)x);
            dfs(x * 10 + 4);
            dfs(x * 10 + 7);
        }

        static double choiceProb(int l1, int r1, int l2, int r2) {
            int low = Math.Max(l1, l2),
                high = Math.Min(r1, r2);
            if (low > high) {
                //Console.WriteLine("{0} {1} {2} {3}: {4}", l1, r1, l2, r2, 0);
                return 0;
            }
            //Console.WriteLine("{0} {1} {2} {3}: {4}", l1, r1, l2, r2, (high - low + 1) / (double)(r1 - l1 + 1));
            return (high - low + 1) / (double)(r1 - l1 + 1);
        }

        static void Main() {
            dfs(0);
            v.Add(MAX + 1);
            v.Sort();
            var xs = Array.ConvertAll<string, int>(Console.ReadLine().Split(' '), int.Parse);
            int pl = xs[0],
                pr = xs[1],
                vl = xs[2],
                vr = xs[3],
                k = xs[4];
            if(pl == pr && pl == vl && vl == vr && k == 1) {
                Console.WriteLine("{0:F12}", v.Contains(pl) ? 1 : 0);
                return;
            }

            double res = 0;
            for (int i = 1; i < v.Count; i++) {
                int j = i + k;
                if (j >= v.Count) {
                    break;
                }

                res += choiceProb(pl, pr, v[i - 1] + 1, v[i]) * choiceProb(vl, vr, v[j - 1], v[j] - 1);
                res += choiceProb(vl, vr, v[i - 1] + 1, v[i]) * choiceProb(pl, pr, v[j - 1], v[j] - 1);
            }

            Console.WriteLine("{0:F12}", res);
        }
    }
}


There are $$$n$$$ benches in the Berland Central park. It is known that $$$a_i$$$ people are currently sitting on the $$$i$$$-th bench. Another $$$m$$$ people are coming to the park and each of them is going to have a seat on some bench out of $$$n$$$ available.Let $$$k$$$ be the maximum number of people sitting on one bench after additional $$$m$$$ people came to the park. Calculate the minimum possible $$$k$$$ and the maximum possible $$$k$$$.Nobody leaves the taken seat during the whole process.

The first line contains a single integer $$$n$$$ $$$(1 \le n \le 100)$$$ — the number of benches in the park. The second line contains a single integer $$$m$$$ $$$(1 \le m \le 10\,000)$$$ — the number of people additionally coming to the park. Each of the next $$$n$$$ lines contains a single integer $$$a_i$$$ $$$(1 \le a_i \le 100)$$$ — the initial number of people on the $$$i$$$-th bench.

Print the minimum possible $$$k$$$ and the maximum possible $$$k$$$, where $$$k$$$ is the maximum number of people sitting on one bench after additional $$$m$$$ people came to the park.

NoteIn the first example, each of four benches is occupied by a single person. The minimum $$$k$$$ is $$$3$$$. For example, it is possible to achieve if two newcomers occupy the first bench, one occupies the second bench, one occupies the third bench, and two remaining — the fourth bench. The maximum $$$k$$$ is $$$7$$$. That requires all six new people to occupy the same bench.The second example has its minimum $$$k$$$ equal to $$$15$$$ and maximum $$$k$$$ equal to $$$15$$$, as there is just a single bench in the park and all $$$10$$$ people will occupy it.

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

namespace Benches
{
    class Program
    {
        static void Main(string[] args)
        {
            var numberBenches = int.Parse(Console.ReadLine());
            var incomingPeople = int.Parse(Console.ReadLine());
            List<int> startingSeats = new List<int>();
            for (int i = 0; i < numberBenches; i++)
            {
                startingSeats.Add(int.Parse(Console.ReadLine()));
            }
            var startMax = startingSeats.Max();
            var startIncomingPeople = incomingPeople;

            while(incomingPeople>0)
            {
                var min = startingSeats.Min();
                var index = startingSeats.IndexOf(min);
                startingSeats[index] += 1;
                incomingPeople--;
            }

            Console.WriteLine("{0} {1}", startingSeats.Max(), startMax+startIncomingPeople);
        }
    }
}

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

namespace Achill
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int m = int.Parse(Console.ReadLine());
            List<int> a = new List<int>(), b;
            for(int i = 0; i < n; ++i)
            {
                a.Add(int.Parse(Console.ReadLine()));
            }
            int res = 0;
            a.ForEach(item => res += a.Max() - item);
            Console.Write((res >= m ? a.Max() : a.Max() + (m - res)/n + ((m-res)%n == 0 ? 0 : 1))  + " ");
            Console.WriteLine(a.Max() + m);
        }
    }
}

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

namespace codeforces
{
    class Program
    {

        static void Main(string[] args)
        {

            int n = Convert.ToInt32(Console.ReadLine());
            int m = Convert.ToInt32(Console.ReadLine());
            int[] mas = new int[n];

            for (int i = 0; i < n; i++)
            {
                mas[i] = Convert.ToInt32(Console.ReadLine());
            }
            int a = mas.Max()+m;
            for (int i = 0; i < m; i++)
            {
                int min = 0;
                for (int j = 0; j < n; j++)
                {
                    if (mas[j] < mas[min])
                        min = j;
                }
                mas[min]++;
            }
            Console.WriteLine(mas.Max()+" "+a);

        }
    }
}

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

internal class Console1
{
    /*
    static int[] ReadInt()
    {
        return Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
    }

    private static ulong GCD(ulong a, ulong b)
    {
        while (a != 0 && b != 0)
        {
            if (a > b)
                a %= b;
            else
                b %= a;
        }

        return a == 0 ? b : a;
    }
    */

    static void Main()
    {
        int n = 0, m = 0;
        Int32.TryParse(Console.ReadLine(), out n);
        Int32.TryParse(Console.ReadLine(), out m);

        int[] benches = new int[n];
        for (int i = 0; i < n; ++i)
        {
            Int32.TryParse(Console.ReadLine(), out benches[i]);
        }

        int maxOnBench = benches.Max();
        int maxValue = m + maxOnBench;

        for (int i = 0; i < n; i++)
        {
            m -= (maxOnBench - benches[i]);
        }

        if (m < 0)
            m = 0;

        double minValue = maxOnBench + Math.Ceiling((double)m / n);

        Console.WriteLine($"{minValue} {maxValue}");
    }
}

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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {

            int n = Convert.ToInt16(Console.ReadLine());
            int m = Convert.ToInt16(Console.ReadLine());
            int[] mas = new int[n];

            for (int i =0;i<n;i++)
            {
                mas[i] = Convert.ToInt16(Console.ReadLine());
            }
            int max = 0;
            for (int i = 0; i < n; i++)
            {
                if (max < mas[i])
                {
                    max = mas[i];
                }
            }
            int min1;
            int minInd;
            for (int i = 0; i < m; i++)
            {
                min1 = mas[0];
                minInd = 0;
                for (int j = 0;j < n; j++)
                {
                    if (min1 > mas[j])
                    {
                        min1 = mas[j];
                        minInd = j;
                    }
                }
                mas[minInd]++;
            }
            int min = mas[0];
            for (int i = 1; i<n;i++)
            {
                if (min < mas[i])
                {
                    min = mas[i];
                }
            }
            for (int i = 0; i<m;i++)
            {
                max++;
            }
            Console.WriteLine(min+ " "+max);

        }
    }
}

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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n =Convert.ToInt32(Console.ReadLine());
            int m = Convert.ToInt32(Console.ReadLine());
            List<int> peoples = new List<int>();

            for (int i = 0; i < n; i++)
            {
                peoples.Add(Convert.ToInt32(Console.ReadLine()));
            }
            int maxK = peoples.Max() + m;

            for (int i = 0; i < m; i++)
            {
                peoples[peoples.IndexOf(peoples.Min())]++;
            }

            int minK = peoples.Max();

            Console.WriteLine(minK + " " + maxK);
        }
    }
}

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

namespace EhWasByDetstvoVspomnit
{

    class Program
    {
        private static int[] ReadIntArray => Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        private static long[] ReadLongArray => Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        private static char[] ReadCharArray => Console.ReadLine().Split(' ').Select(char.Parse).ToArray();
        private static int ReadInt => int.Parse(Console.ReadLine());
        private static string ReadString => Console.ReadLine();

        static void Main()
        {
            int n = ReadInt;
            //int[] n = ReadIntArray;
            int m = ReadInt;
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = ReadInt;
            Array.Sort(a);
            int max = a[a.Count() - 1] + m;
            int temp = 0;
            for (int i = 0; i < a.Count(); i++)
            {
                temp += a[a.Count() - 1] - a[i];
            }
            if (temp >= m)
                Console.WriteLine(a[a.Count() - 1] + " " + max);
            else
            {
                m -= temp;
                if (m % n == 0)
                    Console.WriteLine(a[a.Count() - 1] + (m / n) + " " + max);
                else
                    Console.WriteLine(a[a.Count() - 1] + (m / n) + 1 + " " + max);
            }
            Console.ReadLine();
        }
    }
}

using System;
using System.Linq;

namespace CSharp
{
    public class _1042A
    {
        public static void Main()
        {
            int n = int.Parse(Console.ReadLine());
            int m = int.Parse(Console.ReadLine());
            int[] a = new int[n];

            for (int i = 0; i < n; i++)
            {
                a[i] = int.Parse(Console.ReadLine());
            }

            int minK = Math.Max(0, (m - n * a.Max() + a.Sum() + n - 1) / n) + a.Max();
            int maxK = a.Max() + m;

            Console.WriteLine($"{minK} {maxK}");
        }
    }
}

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, c;
            a = Convert.ToInt32(Console.ReadLine());
            b = Convert.ToInt32(Console.ReadLine());
            int per1 = 0;
            int per;
            c = 0;

            int[] mas = new int[a];

            for (int i = 0; i < mas.Length; i++)
            {
                mas[i]= Convert.ToInt32(Console.ReadLine());
            }

            Array.Sort(mas);
            per = mas[a - 1] + b;

            for (int i = 0; i < b; i++)
            {
                Array.Sort(mas);
                mas[0] = mas[0] + 1;
            }

            for (int i = 0; i < mas.Length; i++)
            {
                if (mas[i] > per1)
                {
                    per1 = mas[i];
                }
            }

            Console.WriteLine(per1 +" "+ per);
        }
    }
}

using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		long N = long.Parse(Console.ReadLine());
		long M = long.Parse(Console.ReadLine());
		long[] A = new long[N];
		long max = 0;
		for(var i=0;i<N;i++){
			A[i] = long.Parse(Console.ReadLine());
			max = Math.Max(A[i],max);
		}
		long M2 = M;
		for(var i=0;i<N;i++){
			M2 -= Math.Max(0,max-A[i]);
		}
		long min = 0;
		if(M2>0){
			min = (M2-1)/N+1+max;
		} else {
			min = max;
		}
		max += M;
		Console.WriteLine(min+" "+max);
	}
}

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

namespace Лавочки
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            int m = Convert.ToInt32(Console.ReadLine());
            int max = 0, min = 0;
            int d, sum = 0, maxa = 0;
            for (int i = 0; i < n; i++)
            {
                int z = Convert.ToInt32(Console.ReadLine());
                sum += z;
                if (z>maxa)
                {
                    maxa = z;
                }
            }
            sum = sum - maxa;
            max = maxa + m;
            d = ((n - 1) * maxa) - sum;
            if (d>=m)
            {
                min = maxa;
            }
            else
            {
                if ((m - d) % n == 0)
                {
                    min = maxa + (m - d) / n;
                }
                else
                {
                    min = maxa + (m - d) / n  +1;
                }

            }
            Console.Write(min);
            Console.Write(' ');
            Console.Write(max);
        }
    }
}

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

namespace ProjectEuler
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int m = int.Parse(Console.ReadLine());
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = int.Parse(Console.ReadLine());
            }
            Array.Sort(a);
            int max = a.Max() + m;

            while (m>0)
            {
                a[0]++;
                m--;
                Array.Sort(a);

            }

            int minmax = a.Max();
            Console.WriteLine($"{minmax} {max}");

        }
    }
}

using System;
using System.Linq;

namespace Median
{
    class Program
    {
        static void Main(string[] args)
        {
            // var line = Console.ReadLine();
            // string[] tokens = line.Split(' ');
            // int[] numbers = Array.ConvertAll(tokens, int.Parse);
            // int proposedMedian = numbers[1];
            // int n = numbers[0];

            // //Read array numbers
            // line = Console.ReadLine();
            // tokens = line.Split(' ');
            // numbers = Array.ConvertAll(tokens, int.Parse);
            // int[] arr = numbers;

            // int count = ForceMedian(arr, proposedMedian, n);
            // Console.WriteLine(count);
            //Console.ReadLine();
            //Benches.Run();

            var benches = int.Parse(Console.ReadLine());
            var m = int.Parse(Console.ReadLine());

            int[] numbers = new int[benches];
            for (int i = 0; i < benches; i++)
            {
                numbers[i] = int.Parse(Console.ReadLine()); ;
            }

            //Find Max
            var max = numbers.Max();
            var kMax = max + m;

            Array.Sort(numbers);

            //Find the Min
            while (m > 0)
            {
                if(numbers.Length == 1)
                {
                    numbers[0] += m;
                    break;
                }
                var min = numbers[0];
                var secondMin = numbers[1];
                var diff = (secondMin - min) + 1;
                if (m - diff < 0)
                {
                    numbers[0] += m;
                    m = 0;
                }
                else
                {
                    numbers[0] += diff;
                    m -= diff;
                }

                Array.Sort(numbers);

            }

            //Console.WriteLine(kMax);
            Console.WriteLine("{0} {1}", numbers.Max(), kMax);
            Console.ReadLine();
        }

        public static int  ForceMedian (int [] arr, int proposedMedian, int n)
        {
            Array.Sort(arr);
          //  int median = Median(arr);
            int count = 0;
            int mid = (arr.Length / 2);

            for (int i = mid; i < n && arr[i] <= proposedMedian; i++)
            {
                count += proposedMedian - arr[i];
            }

            for (int i = mid; i >= 0 && arr[i] > proposedMedian; i--)
            {
                count += arr[i] - proposedMedian;
            }

            // do
            // {
            //     if (median < proposedMedian)
            //         median++;
            //     else if (median > proposedMedian)
            //         median--;
            //     arr[mid] = median;

            //     Array.Sort(arr);
            //     median = Median(arr);
            //     count++;
            // } while (median != proposedMedian);
            //// Console.WriteLine(median);
            return count;
        }

    }
}

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

namespace _2
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Int32.Parse(Console.ReadLine());
            int m = Int32.Parse(Console.ReadLine());
            int[] mas = new int[n];
            int N = 0;
            for (int i = 0; i < n; i++)
            {
                mas[i] = Int32.Parse(Console.ReadLine());
                if (mas[i] > N) N = mas[i];
            }
            int N1 = N + m;//максимальный максимум
            for (int i = 0; i < n; i++)
            {
                while (m > 0 && mas[i] < N)
                {
                    mas[i] += 1;
                    m -= 1;
                }
                //Console.WriteLine(mas[i]);
            }
            int N2 = m / n;
            m = m - N2 * n;
            if (N2 != 0)
            {
                for (int i = 0; i < n; i++) mas[i] += N2;
            }
            while (m > 0)
            {
            for (int i = 0; i < n; i++)
            {
                if (m != 0)
                {
                    mas[i] += 1;
                    m -= 1;
                }
            }
            }
            int N3 = mas[0];
            for (int i = 0; i < n; i++)
            {
                if (N3 < mas[i]) N3 = mas[i];
            }

            Console.WriteLine(N3 + " " + N1);
            //Console.ReadKey();

        }
    }
}

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int k = int.Parse(Console.ReadLine());
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = int.Parse(Console.ReadLine());
            }
            int max = 0;
            int min = 0;
            Array.Sort(a);

            max = a[a.Length - 1];
            max += k;
            for (int i = 0; i < k; i++)
            {
                a[0]++;
                Array.Sort(a);
                //for (int j = 0; j < n; j++)
                //{
                //    Console.Write("{0} ", a[j]);

                //}
                //Console.WriteLine();
            }
            min = a[a.Length-1];
            //min++;
            Console.WriteLine("{0} {1}", min, max);
            //Console.ReadKey();
        }
    }
}

using System;

namespace Test1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int m = int.Parse(Console.ReadLine());
            int[] a = new int[n];
            int max = -1;

            for (int i = 0; i < n; i++)
            {
                a[i] = int.Parse(Console.ReadLine());
                if (a[i] > max)
                    max = a[i];
            }
            int k2 = m + max;
            for (int i = 0; i < n; i++)
            {
                if (m > 0)
                {
                    int k = max - a[i];
                    a[i] = a[i] + Math.Min(k, m);
                    m = m - Math.Min(k, m);
                }
                else break;
            }

            int k1;

            if (m % n == 0)
            {
                k1 = max + m / n;
            }
            else
                k1 = max + m / n + 1;

            Console.WriteLine("{0} {1}", k1, k2);
        }
    }
}

using System;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int m = int.Parse(Console.ReadLine());
            int[] a = new int[n];

            int max = 0;

            for (int i = 0; i < n; i++)
            {
                a[i] = int.Parse(Console.ReadLine());
                if (a[i] > max)
                    max = a[i];
            }

            int b = m + max;

            for (int i = 0; i < n; i++)
            {
                if (m > 0)
                {
                    int k = Math.Min(max - a[i], m);
                    a[i] += k;
                    m -= k;
                }
                else
                    break;
            }

            Console.Write("{1} {0}", b, max + m / n + (m % n == 0 ? 0 : 1));
        }
    }
}

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

namespace Benches
{
    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)
        {
            Solve(args);
            writer.Flush();
        }

        private static void Solve(string[] args)
        {
            int n = Next();
            int m = Next();

            var nn = new int[n];
            for (int i = 0; i < n; i++)
            {
                nn[i] = Next();
            }
            Array.Sort(nn);
            int max = m + nn[n - 1];

            for (int i = n - 1; i > 0; i--)
            {
                m -= nn[i] - nn[i - 1];
                nn[i - 1] = nn[i];
            }

            if (m > 0)
            {
                nn[0] += (m + n - 1)/n;
            }

            writer.Write(nn[0]);
            writer.Write(' ');
            writer.WriteLine(max);
        }

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

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

   class MinHeap
    {
        public IList<int> m_array;

        public MinHeap()
        {
            m_array = new List<int>();
        }
        public int GetRoot()
        {
            return m_array[0];
        }

        public int ExtractMin()
        {
            var result = m_array[0];
            m_array[0] = m_array[Count - 1];
            m_array.RemoveAt(m_array.Count - 1);
            ShiftDown(0);

            return result;
        }

        public void Remove(int index)
        {

        }

        public void ShiftDown(int index)
        {
            int left = 2 * index + 1;
            int right = 2 * index + 2;
            int Index = index;

            if (left < Count && m_array[index] > m_array[left])
            {
                index = left;
            }

            if (right < Count && m_array[index] > m_array[right])
            {
                index = right;
            }

            if (index != Index)
            {
                var temp = m_array[Index];
                m_array[Index] = m_array[index];
                m_array[index] = temp;

                ShiftDown(index);
            }
        }

        public int Count
        {
            get
            {
                return m_array.Count();
            }
        }

        private void Balance(int index)
        {
            if (index < 0)
            {
                return;
            }

            int parent = (index - 1) / 2;

            if (m_array[parent] > m_array[index])
            {
                var temp = m_array[parent];
                m_array[parent] = m_array[index];
                m_array[index] = temp;
                Balance(parent);
            }
        }

        public void Add(int number)
        {
            m_array.Add(number);
            //BuildHeap();
            Balance(m_array.Count - 1);
        }

        private void BuildHeap()
        {
            for (int i = Count / 2; i >= 0; i--)
            {
                Heapify(m_array, i);
            }
        }
        private void Heapify(IList<int> array, int index)
        {
            int N = array.Count;

            int Index = index;
            int left = 2 * index + 1;
            int right = 2 * index + 2;

            if (left < N && array[left] < array[index])
            {
                index = left;
            }

            if (right < N && array[right] < array[index])
            {
                index = right;
            }

            if (index != Index)
            {
                var temp = array[Index];
                array[Index] = array[index];
                array[index] = temp;

                Heapify(array, index);
            }

        }
    }

 class cf
 {

 public static void Main()
        {
            int n = int.Parse(Console.ReadLine());
            int m = int.Parse(Console.ReadLine());
            int max = 0;
            int M = m;

            var pq = new MinHeap();

            for (int t = 1; t <= n; t++)
            {
                int num = int.Parse(Console.ReadLine());
                max = Math.Max(max, num);
                pq.Add(num);
            }

            while (m > 0)
            {
                var num = pq.ExtractMin();
                num++;
                m--;
                pq.Add(num);
            }

            while(pq.Count > 1)
            {
                pq.ExtractMin();
            }

            Console.WriteLine(string.Format("{0} {1}", pq.ExtractMin(), max + M));
        }
 }

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

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){

		int max = A.Max() + M;
		for(int i=0;i<M;i++){
			int mi = (int) 1e9;
			int midx = -1;
			for(int j=0;j<N;j++){
				if(A[j] < mi){
					mi = A[j];
					midx = j;
				}
			}
			A[midx]++;
		}
		int min = A.Max();

		Console.WriteLine("{0} {1}", min, max);
	}
	int N,M;
	int[] A;
	public Sol(){
		N = ri();
		M = ri();
		A = new int[N];
		for(int i=0;i<N;i++) A[i] = ri();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(System.Console.ReadLine());
            int m = int.Parse(System.Console.ReadLine());
            int[] benches = new int[n];
            for(int i=0;i<n;i++)
            {
                benches[i] = int.Parse(System.Console.ReadLine());
            }
            int mx=0;
            int mn=0, bn = -1;
            for(int i=0;i<m;i++)
            {
                bn=-1;
                for(int j=0;j<n;j++)
                {
                    if(bn==-1 || benches[j] < mn)
                    {
                        bn = j;
                        mn = benches[j];
                    }
                    if(i==0 && benches[j]>mx)
                    {
                        mx = benches[j];
                    }
                }
                benches[bn]++;
            }
            bn=-1;
            for(int j=0;j<n;j++)
            {
                if(bn==-1 || benches[j] > mn)
                {
                    bn = j;
                    mn = benches[j];
                }
            }
            System.Console.WriteLine(String.Format("{0} {1}", mn, mx + m));
        }
    }
}

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

public class HelloWorld {
    static public void Main () {
        SolveCodeForces();
    }

    public static void SolveCodeForces() {
        var n = long.Parse(Console.ReadLine());
        var m = long.Parse(Console.ReadLine());
        var A = new long[n];
        for (var i = 0; i < A.Length; i++)
            A[i] = long.Parse(Console.ReadLine());

        var maxK = A.Max() + m;
        var z = A.Sum() + m;
        var minK = z / n;
        if (minK * n != z)
            minK++;
        minK = Math.Max(A.Max(), minK);
        System.Console.WriteLine("{0} {1}", minK, maxK);
    }
}

/*
5       n
10      m
68
87
14
68
23

--> actual 54 97
--> expected 87 97
 */

/* Date: 27.10.2018 * Time: 21:45 */
// *

/*
�	fflush(stdout) � ����� C++;
�	System.out.flush() � Java;
�	stdout.flush() � Python;
�	flush(output) � Pascal;

*/

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

class Example
{
	public static void Main (string[] args)
	{
# if ( ! ONLINE_JUDGE )
		StreamReader sr = new StreamReader ("C:\\TRR\\2018\\Task\\07 Codeforces\\034\\A.TXT");
		StreamWriter sw = new StreamWriter ("C:\\TRR\\2018\\Task\\07 Codeforces\\034\\A.OUT");
# endif

		NumberFormatInfo nfi = NumberFormatInfo.InvariantInfo;

		int n, m;

# if ( ONLINE_JUDGE )
		n = int.Parse (Console.ReadLine ());
		m = int.Parse (Console.ReadLine ());
# else
		n = int.Parse (sr.ReadLine ());
		m = int.Parse (sr.ReadLine ());
		sw.WriteLine (n + " *** " + m);
# endif

		string s;

		int amax = 0;
		int [] a = new int [n];
		for ( int i=0; i < n; i++ )
		{

# if ( ONLINE_JUDGE )
			a [i] = int.Parse (Console.ReadLine ());
# else
			a [i] = int.Parse (sr.ReadLine ());
# endif
			if ( a [i] > amax )
				amax = a [i];
		}

		int delta = 0;
		for ( int i=0; i < n; i++ )
			delta += amax - a [i];

		int maxk = amax + m, mink = amax;
		if ( delta < m )
			mink = amax + (m -  delta + n - 1) / n;

# if ( ! ONLINE_JUDGE )
		sw.WriteLine (delta + " *** " + amax);
# endif

# if ( ONLINE_JUDGE )
		Console.WriteLine (mink + " " + maxk);
# else
		sw.WriteLine (mink + " " + maxk);
		sw.Close ();
# endif
	}
}

using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int numBenches = Convert.ToInt32(Console.ReadLine());
            int numExtraPeople = Convert.ToInt32(Console.ReadLine());
            int modifiedNumExtraPeople = numExtraPeople;
            int[] benches = new int[numBenches];
            for (int i = 0; i < numBenches; i++) benches[i] = Convert.ToInt32(Console.ReadLine());
            int maxPeopleCount = FindMax(benches);
            foreach (var i in benches) modifiedNumExtraPeople -= maxPeopleCount - i;
            modifiedNumExtraPeople = Math.Max(0, modifiedNumExtraPeople);
            Console.WriteLine("{0} {1}", maxPeopleCount + Math.Ceiling((double)modifiedNumExtraPeople / numBenches), numExtraPeople + maxPeopleCount);
        }

        static int FindMax(int[] array)
        {
            int max = Int32.MinValue;
            foreach(var i in array)
            {
                if (i > max) max = i;
            }
            return max;
        }
    }
}

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

namespace TestingGround
{
    class P_1042A
    {
        static void Main(string[] args)
        {
            var n = IO.Line().In<int>();
            var m = IO.Line().In<int>();
            var a = new List<int>();
            for (int i = 0; i < n; i++)
            {
                a.Add(IO.Line().In<int>());
            }

            var avg = (int)Math.Ceiling((a.Sum() + m) / (double)n);
            if (avg < a.Max()) avg = a.Max();

            Console.WriteLine(avg + " " + (a.Max() + m));
        }
    }

    public class IO
    {
        private readonly string[] _splitted;
        private int _current = 0;

        private IO()
        {
            _splitted = Console.ReadLine().Split(' ');
        }

        public static IO Line()
        {
            return new IO();
        }

        public T In<T>()
        {
            if (_current >= _splitted.Length)
                throw new IndexOutOfRangeException();

            return (T) Convert.ChangeType(_splitted[_current++], typeof(T));
        }
    }
}

using System;
using System.Linq;
namespace Cows.And.Poker
{
    class Program
    {
        static void Main(string[] args)
        {
            var players = int.Parse(Console.ReadLine());
            var status = Console.ReadLine().ToCharArray();
            var allInOrIn = status.Where(s => s != 'F');
            if (allInOrIn.Count(s => s == 'I') == 0) Console.WriteLine(allInOrIn.Count());
            else if (allInOrIn.Count(s => s == 'I') == 1) Console.WriteLine(1);
            else Console.WriteLine(0);
        }
    }
}

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

namespace codeforces
{
    class Program
    {

        static void Main(string[] args)
        {

            int n = Convert.ToInt32(Console.ReadLine());
            int m = Convert.ToInt32(Console.ReadLine());
            int[] mas = new int[n];
            for (int i = 0; i < n; i++)
            {
                mas[i] = Convert.ToInt32(Console.ReadLine());
            }
            if(n == 1)
                Console.WriteLine((mas[0]+m)+" "+(mas[0]+m));
            else
            Console.WriteLine(((m % n)+mas.Max())+" "+(mas.Max()+m));

        }
    }
}

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

internal class Console1
{
    /*
    static int[] ReadInt()
    {
        return Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
    }

    private static ulong GCD(ulong a, ulong b)
    {
        while (a != 0 && b != 0)
        {
            if (a > b)
                a %= b;
            else
                b %= a;
        }

        return a == 0 ? b : a;
    }
    */

    static void Main()
    {
        int n = 0, m = 0;
        Int32.TryParse(Console.ReadLine(), out n);
        Int32.TryParse(Console.ReadLine(), out m);

        int[] benches = new int[n];
        for (int i = 0; i < n; ++i)
        {
            Int32.TryParse(Console.ReadLine(), out benches[i]);
        }

        int maxOnBench = benches.Max();
        int maxValue = m + maxOnBench;

        for (int i = 0; i < n; i++)
        {
            m -= (maxOnBench - benches[i]);
        }

        double minValue = maxOnBench + Math.Ceiling((double)m / n);

        Console.WriteLine($"{minValue} {maxValue}");
    }
}

using System;

namespace Test1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int m = int.Parse(Console.ReadLine());
            int[] a = new int[n];
            int max = -1;

            for (int i = 0; i < n; i++)
            {
                a[i] = int.Parse(Console.ReadLine());
                if (a[i] > max)
                    max = a[i];
            }

            for (int i = 0; i < n; i++)
            {
                if (m > 0)
                {
                    int k = max - a[i];
                    a[i] = a[i] + Math.Min(k, m);
                    m = m - Math.Min(k, m);
                }
                else break;
            }

            int k1,k2;

            if (m % n == 0)
            {
                k1 = max + m / n;
            }
            else
                k1 = max + m / n + 1;

            k2 = m + max;

            Console.WriteLine("{0} {1}", k1, k2);
        }
    }
}

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

public class HelloWorld {
    static public void Main () {
        SolveCodeForces();
    }

    public static void SolveCodeForces() {
        var n = long.Parse(Console.ReadLine());
        var m = long.Parse(Console.ReadLine());
        var A = new long[n];
        for (var i = 0; i < A.Length; i++)
            A[i] = long.Parse(Console.ReadLine());

        var maxK = A.Max() + m;
        var z = A.Sum() + m;
        var minK = z / n;
        if (minK * n != z)
            minK++;
        System.Console.WriteLine("{0} {1}", minK, maxK);
    }
}

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

public class HelloWorld {
    static public void Main () {
        SolveCodeForces();
    }

    public static void SolveCodeForces() {
        var n = long.Parse(Console.ReadLine());
        var m = long.Parse(Console.ReadLine());
        var A = new long[n];
        for (var i = 0; i < A.Length; i++)
            A[i] = long.Parse(Console.ReadLine());

        var maxK = A.Max() + m;
        var z = A.Sum() + m;
        var minK = z / n;
        if (minK * n != z)
            minK++;
        minK = Math.Max(A.Min(), minK);
        System.Console.WriteLine("{0} {1}", minK, maxK);
    }
}

/* Date: 27.10.2018 * Time: 21:45 */
// *

/*
�	fflush(stdout) � ����� C++;
�	System.out.flush() � Java;
�	stdout.flush() � Python;
�	flush(output) � Pascal;

*/

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

class Example
{
	public static void Main (string[] args)
	{
# if ( ! ONLINE_JUDGE )
		StreamReader sr = new StreamReader ("C:\\TRR\\2018\\Task\\07 Codeforces\\034\\A.TXT");
		StreamWriter sw = new StreamWriter ("C:\\TRR\\2018\\Task\\07 Codeforces\\034\\A.OUT");
# endif

		NumberFormatInfo nfi = NumberFormatInfo.InvariantInfo;

		int n, m;

# if ( ONLINE_JUDGE )
		n = int.Parse (Console.ReadLine ());
		m = int.Parse (Console.ReadLine ());
# else
		n = int.Parse (sr.ReadLine ());
		m = int.Parse (sr.ReadLine ());
# endif

		string s;

		int amax = 0;
		int [] a = new int [n];
		for ( int i=0; i < n; i++ )
		{

# if ( ONLINE_JUDGE )
			a [i] = int.Parse (Console.ReadLine ());
# else
			a [i] = int.Parse (sr.ReadLine ());
# endif
			if ( a [i] > amax )
				amax = a [i];
		}

		int delta = 0;
		for ( int i=0; i < n; i++ )
			delta += amax - a [i];

		int maxk = amax + m, mink = amax;
		if ( delta >= m )
			mink = amax + (m -  delta + n - 1) / n;

# if ( ONLINE_JUDGE )
		Console.WriteLine (mink + " " + maxk);
# else
		sw.WriteLine (mink + " " + maxk);
		sw.Close ();
# endif
	}
}

using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int numBenches = Convert.ToInt32(Console.ReadLine());
            int numExtraPeople = Convert.ToInt32(Console.ReadLine());
            int modifiedNumExtraPeople = numExtraPeople;
            int[] benches = new int[numBenches];
            for (int i = 0; i < numBenches; i++) benches[i] = Convert.ToInt32(Console.ReadLine());
            int maxPeopleCount = FindMax(benches);
            foreach (var i in benches) modifiedNumExtraPeople -= maxPeopleCount - i;
            Console.WriteLine("{0} {1}", maxPeopleCount + Math.Ceiling((double)modifiedNumExtraPeople / numBenches), numExtraPeople + maxPeopleCount);
        }

        static int FindMax(int[] array)
        {
            int max = Int32.MinValue;
            foreach(var i in array)
            {
                if (i > max) max = i;
            }
            return max;
        }
    }
}