//static string dictionary =

        /*
         *  "ABCDEFGH" +
         *  "IJKLMNOP" +
         *  "QRSTUVWX" +
         *  "YZ.     " +
         *  "abcdefgh" +
         *  "ijklmnop" +
         *  "qrstuvwx" +
         *  "yz      ";
         * /**/

        static void Main(string[] args)
        {
            Density den = new Density("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz .");

            //Density den = new Density("ACDEFHIJLMNOPQRSTUVWabcdefghijlmnopqrstuvwy .");

            den.CalculatePercentages(lorem);
            Map mapy = new Map(8, 8, "WReQwLTDHj. Ml UJrhcuovEFPbisnapNVdt etgfp .maruOICvulosyASpcdiq");



            Console.WriteLine(mapy.Solve(lorem));

            //loop();
        }
        /**/

        static void Main(string[] args)
        {
            Console.WriteLine(dictionary.Length);
            Map map = new Map(
                8,
                //int.Parse(Console.ReadLine()),
                8,
                //int.Parse(Console.ReadLine()),
                dictionary
                //Console.ReadLine()
                );

            Density den = new Density(dictionary);

            den.CalculatePercentages(lorem);

            //Console.WriteLine(map.Solve(Console.ReadLine()));
            Console.WriteLine(map.Solve(lorem));
        }
        static void loop()
        {
            string dictionary;
            string bestS = "";
            int    best  = int.MaxValue;

            Density den = new Density("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz .");

            //Density den = new Density("ACDEFHIJLMNOPQRSTUVWabcdefghijlmnopqrstuvwy .");

            den.CalculatePercentages(lorem);
            //den.CalculatePercentagesRanked(lorem);

            for (int x = 0; x < 500; x++)
            {
                for (int i = 0; i < 500; i++)
                {
                    char[,] M = new char[8, 8];

                    dictionary = den.FillSpiral(M);

                    Map map = new Map(8, 8, dictionary);

                    int temp = map.Solve(lorem);

                    if (temp < best)
                    {
                        best  = temp;
                        bestS = dictionary;
                    }

                    if (temp < 80000)
                    {
                        Console.WriteLine(temp);
                        Console.WriteLine(dictionary);
                    }
                }

                Console.WriteLine(best);
                Console.WriteLine(bestS);
            }
        }
        //static string dictionary =
        /*
            "ABCDEFGH" +
            "IJKLMNOP" +
            "QRSTUVWX" +
            "YZ.     " +
            "abcdefgh" +
            "ijklmnop" +
            "qrstuvwx" +
            "yz      ";
        /**/
        static void Main(string[] args)
        {
            Density den = new Density("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz .");
            //Density den = new Density("ACDEFHIJLMNOPQRSTUVWabcdefghijlmnopqrstuvwy .");

            den.CalculatePercentages(lorem);
            Map mapy = new Map(8, 8, "WReQwLTDHj. Ml UJrhcuovEFPbisnapNVdt etgfp .maruOICvulosyASpcdiq");

            Console.WriteLine(mapy.Solve(lorem));

            //loop();
        }
        static void loop()
        {
            string dictionary;
            string bestS = "";
            int best = int.MaxValue;

            Density den = new Density("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz .");
            //Density den = new Density("ACDEFHIJLMNOPQRSTUVWabcdefghijlmnopqrstuvwy .");

            den.CalculatePercentages(lorem);
            //den.CalculatePercentagesRanked(lorem);

            for (int x = 0; x < 500; x++)
            {
                for (int i = 0; i < 500; i++)
                {
                    char[,] M = new char[8, 8];

                    dictionary = den.FillSpiral(M);

                    Map map = new Map(8, 8, dictionary);

                    int temp = map.Solve(lorem);

                    if (temp < best)
                    {
                        best = temp;
                        bestS = dictionary;
                    }

                    if (temp < 80000)
                    {
                        Console.WriteLine(temp);
                        Console.WriteLine(dictionary);
                    }
                }

                Console.WriteLine(best);
                Console.WriteLine(bestS);
            }
        }
        /**/
        static void Main(string[] args)
        {
            Console.WriteLine(dictionary.Length);
            Map map = new Map(
                8,
                //int.Parse(Console.ReadLine()),
                8,
                //int.Parse(Console.ReadLine()),
                dictionary
                //Console.ReadLine()
            );

            Density den = new Density(dictionary);
            den.CalculatePercentages(lorem);

            //Console.WriteLine(map.Solve(Console.ReadLine()));
            Console.WriteLine(map.Solve(lorem));
        }