using System;

class Forma
{
    static void Main()
    {
        string teksts = "kristers turkis;";
        (string vards, string uzvards) = IegutFormatetuVarduUzvardu(teksts);

        Console.WriteLine("Vārds: " + vards);
        Console.WriteLine("Uzvārds: " + uzvards);

        int minKol = 5;
        int minRind = 5;

        int kolonnas = IevadeHelper.SaņemtSkaitli("Cik kolonnas? (>=" + minKol + "): ", minKol);
        int rindas = IevadeHelper.SaņemtSkaitli("Cik rindas? (>=" + minRind + "): ", minRind);

        Console.WriteLine();
        TabulasRenderer.UzzimetTabulu(rindas, kolonnas);
    }

    static (string, string) IegutFormatetuVarduUzvardu(string teksts)
    {
        string[] sadalits = teksts.Split(' ', StringSplitOptions.RemoveEmptyEntries);
        if (sadalits.Length < 2) return ("", "");
        return (Normalizet(sadalits[0]), Normalizet(sadalits[1]));
    }

    static string Normalizet(string teksts)
    {
        if (string.IsNullOrWhiteSpace(teksts)) return "";
        string pirm = teksts[..1].ToUpper();
        string parejie = teksts[1..].ToLower();
        return pirm + parejie;
    }
}

static class IevadeHelper
{
    public static int SaņemtSkaitli(string jautajums, int minimums)
    {
        int sk;
        Console.Write(jautajums);
        while (!int.TryParse(Console.ReadLine(), out sk) || sk < minimums)
        {
            Console.Write("Mēģini vēlreiz (min: " + minimums + "): ");
        }
        return sk;
    }
}

static class TabulasRenderer
{
    public static void UzzimetTabulu(int rindas, int kolonnas)
    {
        const int plata = 3;

        for (int i = 0; i < rindas; i++)
        {
            int skaits = i < kolonnas ? i + 1 : kolonnas;
            int sakums = i < kolonnas ? 1 : i - kolonnas + 2;
            int atstarpe = (kolonnas - skaits) * (plata + 1);

            Console.Write(new string(' ', atstarpe));
            Console.Write("+");
            for (int j = 0; j < skaits; j++) Console.Write(new string('-', plata) + "+");
            Console.WriteLine();

            Console.Write(new string(' ', atstarpe));
            Console.Write("|");
            for (int j = 0; j < skaits; j++) Console.Write((sakums + j).ToString().PadLeft(plata) + "|");
            Console.WriteLine();
        }

        int apaksa = Math.Min(rindas, kolonnas);
        int space = (kolonnas - apaksa) * (plata + 1);

        Console.Write(new string(' ', space));
        Console.Write("+");
        for (int z = 0; z < apaksa; z++) Console.Write(new string('-', plata) + "+");
        Console.WriteLine();
    }
}
