using System;

class Program
{
    static void Main()
    {
        // 1. 2D masivs 3x4
        Console.WriteLine("1. 2D masivs (3x4):");
        int[,] array2D = {
            {1, 2, 3, 4},
            {5, 6, 7, 8},
            {9, 10, 11, 12}
        };

        for (int i = 0; i < array2D.GetLength(0); i++)
        {
            for (int j = 0; j < array2D.GetLength(1); j++)
            {
                Console.Write(array2D[i, j] + " ");
            }
            Console.WriteLine();
        }
        Console.WriteLine();

        // 2. Robotais masivs (jagged array)
        Console.WriteLine("2. Robotais masivs:");
        int[][] jaggedArray = new int[3][];
        jaggedArray[0] = new int[] {1, 2};
        jaggedArray[1] = new int[] {3, 4, 5};
        jaggedArray[2] = new int[] {6};

        for (int i = 0; i < jaggedArray.Length; i++)
        {
            for (int j = 0; j < jaggedArray[i].Length; j++)
            {
                Console.Write(jaggedArray[i][j] + " ");
            }
            Console.WriteLine();
        }
        Console.WriteLine();

        // 3. 2D masivs - rindu summa
        Console.WriteLine("3. 2D masivs - rindu summa:");
        int[,] array2DSum = {
            {1, 2, 3, 4, 5},
            {6, 7, 8, 9, 10},
            {11, 12, 13, 14, 15},
            {16, 17, 18, 19, 20}
        };

        for (int i = 0; i < array2DSum.GetLength(0); i++)
        {
            int rowSum = 0;
            for (int j = 0; j < array2DSum.GetLength(1); j++)
            {
                rowSum += array2DSum[i, j];
            }
            Console.WriteLine("Rindas " + i + " summa = " + rowSum);
        }
        Console.WriteLine();

        // 4. Robotais masivs - elementa meklesana
        Console.WriteLine("4. Robotais masivs - elementa meklesana:");
        int[][] jaggedSearch = new int[3][];
        jaggedSearch[0] = new int[] {1, 5};
        jaggedSearch[1] = new int[] {2, 3, 4};
        jaggedSearch[2] = new int[] {6};

        Console.Write("Ievadi skaitli meklesanai: ");
        int num = int.Parse(Console.ReadLine());
        bool found = false;

        for (int i = 0; i < jaggedSearch.Length; i++)
        {
            for (int j = 0; j < jaggedSearch[i].Length; j++)
            {
                if (jaggedSearch[i][j] == num)
                {
                    Console.WriteLine("Skaitlis " + num + " atrasts rinda " + i + ", kolonna " + j);
                    found = true;
                }
            }
        }
        if (!found)
            Console.WriteLine("Skaitlis " + num + " netika atrasts masiva.");
        Console.WriteLine();

        // 5. Robotais masivs - rindu sakartosana
        Console.WriteLine("5. Robotais masivs - rindu sakartosana:");
        int[][] jaggedSort = new int[3][];
        jaggedSort[0] = new int[] {9, 3};
        jaggedSort[1] = new int[] {5, 1, 4};
        jaggedSort[2] = new int[] {2, 8, 7, 6};

        for (int i = 0; i < jaggedSort.Length; i++)
        {
            Array.Sort(jaggedSort[i]);
        }

        for (int i = 0; i < jaggedSort.Length; i++)
        {
            for (int j = 0; j < jaggedSort[i].Length; j++)
            {
                Console.Write(jaggedSort[i][j] + " ");
            }
            Console.WriteLine();
        }
    }
}
