using System;

namespace program
{
    class Program
    {
        static void Main(string[] args)
        {
            // pieprasu lietotājam vārdu
            Console.Write("Ievadi vardu: ");
            string firstName = Console.ReadLine();

            // pieprasu lietotājam uzvārdu
            Console.Write("Ievadi uzvardu: ");
            string lastName = Console.ReadLine();

            // veidoju pirmā un otrā vārda pārmaiņus lielos/mazos burtus
            string styledFirst = ApplyAlternatingCase(firstName);
            string styledLast  = ApplyAlternatingCase(lastName);

            // aprēķinu sākotnējās tabulas izmērus
            int rowsA = lastName.Length + 2;
            int colsA = firstName.Length + 1;
            int[,] matrixA = new int[rowsA, colsA];

            // aizpildīju datu laukumu ar random skaitļiem noteiktā intervālā
            var rng = new Random();
            for (int r = 1; r < rowsA - 1; r++)
                for (int c = 1; c < colsA; c++)
                    matrixA[r, c] = rng.Next(firstName.Length,
                                              firstName.Length + lastName.Length + 1);

            // izdrukāju sākotnējo tabulu
            RenderMatrix(matrixA, styledFirst, styledLast, firstName.Length);

            // gatavoju transponētās tabulas izmērus
            int rowsB = firstName.Length + 2;
            int colsB = lastName.Length + 1;
            int[,] matrixB = new int[rowsB, colsB];

            // pārcel datus, lai kolonnas kļūtu par rindām un otrādi
            for (int r = 1; r <= firstName.Length; r++)
                for (int c = 1; c <= lastName.Length; c++)
                    matrixB[r, c] = matrixA[c, r];

            // pagriežu virsrakstus otrādi
            string revLast  = ReverseString(styledLast);
            string revFirst = ReverseString(styledFirst);

            // izdrukāju transponēto tabulu
            RenderMatrix(matrixB, revLast, revFirst, lastName.Length);
        }

        // pārveido katru otro burtu uz lielo, pārējos uz mazo
        static string ApplyAlternatingCase(string input)
        {
            var arr = input.ToCharArray();
            for (int i = 0; i < arr.Length; i++)
                arr[i] = (i % 2 == 0)
                         ? char.ToUpper(arr[i])
                         : char.ToLower(arr[i]);
            return new string(arr);
        }

        // pagriež ievadīto tekstu otrādi
        static string ReverseString(string input)
        {
            var arr = input.ToCharArray();
            Array.Reverse(arr);
            return new string(arr);
        }

        // izveido un izdrukā tabulu ar rindu un kolonnu apkopojumiem
        static void RenderMatrix(int[,] data,
                                 string colHeaders,
                                 string rowHeaders,
                                 int headerLen)
        {
            int totalRows = data.GetLength(0);
            int totalCols = data.GetLength(1);

            // veido augšējo un starplīniju rakstu
            string topLine = "*";
            string midLine = "";
            for (int i = 0; i < headerLen + 1; i++)
            {
                topLine += "-----*";
                midLine += "+-----";
            }
            topLine += "-----*-----*-----*";
            midLine += "*-----*-----*-----*";

            // drukā virsrakstu rindu
            Console.WriteLine(topLine);
            Console.Write("|  *  ");
            foreach (char ch in colHeaders)
                Console.Write($"|  {ch}  ");
            Console.WriteLine("| sum | min | max |");
            Console.WriteLine(topLine);

            // drukā datus pa rindām ar sum, min, max
            for (int r = 1; r < totalRows - 1; r++)
            {
                Console.Write("| ");
                int sumR = 0, minR = int.MaxValue, maxR = int.MinValue;
                Console.Write($" {rowHeaders[rowHeaders.Length - r]}  | ");

                for (int c = 1; c < totalCols; c++)
                {
                    int v = data[r, c];
                    sumR += v;
                    if (v < minR) minR = v;
                    if (v > maxR) maxR = v;
                    Console.Write($"{v,3} | ");
                }

                Console.WriteLine($"{sumR,3} | {minR,3} | {maxR,3} |");
                if (r < totalRows - 2) Console.WriteLine(midLine);
            }

            // apakšējās rindas ar kolonnām sum, min, max
            Console.WriteLine(topLine);
            Console.Write("| sum |");
            int totalSum = 0;
            for (int c = 1; c < totalCols; c++)
            {
                int cs = 0;
                for (int r = 1; r < totalRows - 1; r++) cs += data[r, c];
                Console.Write($" {cs,3} |");
                totalSum += cs;
            }
            Console.WriteLine($" {totalSum,3} |  *  |  *  |");
            Console.WriteLine(topLine);

            Console.Write("| min |");
            int globalMin = int.MaxValue;
            for (int c = 1; c < totalCols; c++)
            {
                int cm = int.MaxValue;
                for (int r = 1; r < totalRows - 1; r++)
                    if (data[r, c] < cm) cm = data[r, c];
                Console.Write($" {cm,3} |");
                if (cm < globalMin) globalMin = cm;
            }
            Console.WriteLine($"  *  | {globalMin,3} |  *  |");
            Console.WriteLine(topLine);

            Console.Write("| max |");
            int globalMax = int.MinValue;
            for (int c = 1; c < totalCols; c++)
            {
                int cM = int.MinValue;
                for (int r = 1; r < totalRows - 1; r++)
                    if (data[r, c] > cM) cM = data[r, c];
                Console.Write($" {cM,3} |");
                if (cM > globalMax) globalMax = cM;
            }
            Console.WriteLine($"  *  |  *  | {globalMax,3} |");
            Console.WriteLine(topLine);
        }
    }
}
