// 2d massivi - Maksims Gutovs
// Lai bija intersantak darit so uzdevuma no jaunas, letoju tikay System (Bez LINQ)
using System;
class HelloWorld {
  static void Main()
  {
    string vards = ("");
    string uzvards = ("");

    Console.Write("Ievadiet vardu: ");
    vards = Console.ReadLine();
    Console.Write("Ievadiet uzvardu: ");
    uzvards = Console.ReadLine();
    
    char[] vardschar = vards.ToCharArray();
    char[] uzvardschar = uzvards.ToCharArray();
    int [,] array2 = new int [vards.Length,uzvards.Length];
    int [,] array1 = new int [uzvards.Length,vards.Length];
    int sum = 0;
    int min = vards.Length+uzvards.Length+1;
    int max = vards.Length;
    int [] sumh = new int[vards.Length+uzvards.Length];
    int [] sumv = new int[vards.Length+uzvards.Length];
    int [] minh = new int[vards.Length+uzvards.Length];
    int [] minv = new int[vards.Length+uzvards.Length];
    int [] maxh = new int[vards.Length+uzvards.Length];
    int [] maxv = new int[vards.Length+uzvards.Length];
    Random rnd = new Random();
    
    for (int i = 0;i<4+vards.Length;i++)
    {
        Console.Write("*===============");
    }
    Console.WriteLine("*");
    Console.Write("|\tX\t|");
    for (int i = 0;i<vards.Length;i++)
    {
        if (i % 2 == 0)
        Console.Write($"\t{char.ToUpper(vardschar[i])}\t|");
        else
        Console.Write($"\t{vardschar[i]}\t|");
    }
    Console.WriteLine("\tsum\t|\tmin\t|\tmax\t|");
    for (int i = 0;i<4+vards.Length;i++)
    {
        Console.Write("*===============");
    }
    Console.WriteLine("*");
    
    for (int i = 0;i<uzvards.Length+vards.Length;i++)
    {
        maxh[i]=vards.Length-1;
        minh[i]=vards.Length+uzvards.Length+2;
        maxv[i]=vards.Length-1;
        minv[i]=vards.Length+uzvards.Length+2;
    }
    for (int i = uzvards.Length-1;i>=0;i--)
    {
        if (i % 2 == 0)
        Console.Write($"\t{char.ToUpper(uzvardschar[i])}\t|");
        else
        Console.Write($"\t{uzvardschar[i]}\t|");
        for (int j = 0;j<vards.Length;j++)
        {
            array1[i,j] = rnd.Next(vards.Length, vards.Length+uzvards.Length+1);
            array2[j,i] = array1[i,j];
            Console.Write($"\t{array1[i,j]}\t|");
            sumh[i] += array1[i,j];
            sumv[j] += array1[i,j];
            
            if (array1[i, j] < minh[i])
                minh[i] = array1[i,j];
            if (array1[i, j] > maxh[i])
                maxh[i] = array1[i,j];
                
            if (array1[i, j] < minv[j])
                minv[j] = array1[i,j];
            if (array1[i, j] > maxv[j])
                maxv[j] = array1[i,j];
        }

        Console.Write($"\t{sumh[i]}\t|");
        Console.Write($"\t{minh[i]}\t|");
        Console.WriteLine($"\t{maxh[i]}\t|");
        if (i == 0)
        {
        for (int j = 0;j<4+vards.Length;j++)
        {
        Console.Write("*===============");
        }
        Console.WriteLine("*");
        }
    else
    {
        for (int j = 0;j<=vards.Length;j++)
        {
            Console.Write("+---------------");
        }
        Console.WriteLine("*===============*===============*===============*");
    }
        // P.S. Viss leja (Prieks sitas tabulas) ir saistis tiesi ar vertikalu stabinu (Pec ta notiek parbaudes uz min, max un sum ka piemera)
    }
    Console.Write("|\tsum\t");
        for (int j = 0;j<vards.Length;j++)
        {
            Console.Write($"|\t{sumv[j]}\t");
            sum += sumv[j];
        }
    Console.WriteLine($"|\t{sum}\t|\t*\t|\t*\t|");
    for (int j = 0;j<4+vards.Length;j++)
        {
        Console.Write("*===============");
        }
        Console.WriteLine("*");
        
    Console.Write($"|\tmin\t");
    for (int j = 0;j<vards.Length;j++)
        {
            Console.Write($"|\t{minv[j]}\t");
            if (minv[j] < min)
            min = minv[j];
        }
        
    Console.WriteLine($"|\t*\t|\t{min}\t|\t*\t|");
    for (int j = 0;j<4+vards.Length;j++)
        {
        Console.Write("*===============");
        }
        Console.WriteLine("*");
    Console.Write($"|\tmax\t");
    
    for (int j = 0;j<vards.Length;j++)
        {
            Console.Write($"|\t{maxv[j]}\t");
            if (maxv[j] > max)
            max = maxv[j];
        }
    Console.WriteLine($"|\t*\t|\t*\t|\t{max}\t|");
    for (int j = 0;j<4+vards.Length;j++)
        {
        Console.Write("*===============");
        }
        Console.WriteLine("*");
        Console.WriteLine("");
    
    //Apgriezta tabula
    for (int i = 0;i<4+uzvards.Length;i++)
    {
        Console.Write("*===============");
    }
    Console.WriteLine("*");
    Console.Write("|\tX\t|");
    for (int i = uzvards.Length-1;i>=0;i--)
    {
        if (i % 2 == 0)
        Console.Write($"\t{char.ToUpper(uzvardschar[i])}\t|");
        else
        Console.Write($"\t{uzvardschar[i]}\t|");
    }
    Console.WriteLine("\tsum\t|\tmin\t|\tmax\t|");
    for (int i = 0;i<4+uzvards.Length;i++)
    {
        Console.Write("*===============");
    }
    Console.WriteLine("*");
    for (int i = vards.Length-1;i>=0;i--)
    {
        Console.Write($"|\t{vardschar[i]}\t|");
        for (int j = uzvards.Length-1;j>=0;j--)
        {
            Console.Write($"\t{array2[i,j]}\t|");
        }
        Console.Write($"\t{sumv[i]}\t|");
        Console.Write($"\t{minv[i]}\t|");
        Console.WriteLine($"\t{maxv[i]}\t|");
        for (int j = 0;j<=uzvards.Length;j++)
        {
            Console.Write("+---------------");
        }
        
        Console.WriteLine("*===============*===============*===============*");
        
    }    
    Console.Write("|\tsum\t");
        for (int j = uzvards.Length-1;j>=0;j--)
        {
            Console.Write($"|\t{sumh[j]}\t");
        }
    Console.WriteLine($"|\t{sum}\t|\t*\t|\t*\t|");
    for (int j = 0;j<4+uzvards.Length;j++)
        {
        Console.Write("*===============");
        }
        Console.WriteLine("*");
        
    Console.Write($"|\tmin\t");
    for (int j = uzvards.Length-1;j>=0;j--)
        {
            Console.Write($"|\t{minh[j]}\t");
        }
        
    Console.WriteLine($"|\t*\t|\t{min}\t|\t*\t|");
    for (int j = 0;j<4+uzvards.Length;j++)
        {
        Console.Write("*===============");
        }
        Console.WriteLine("*");
    Console.Write($"|\tmax\t");
    
    for (int j = uzvards.Length-1;j>=0;j--)
        {
            Console.Write($"|\t{maxh[j]}\t");
        }
    Console.WriteLine($"|\t*\t|\t*\t|\t{max}\t|");
    for (int j = 0;j<4+uzvards.Length;j++)
        {
        Console.Write("*===============");
        }
        Console.WriteLine("*");
        Console.WriteLine("");
    
  }
  
}