using System;

class Program
{
    static void Main()
    {
        int r, c;
        Console.Write("Rindu skaits: ");
        while (!int.TryParse(Console.ReadLine(), out r) || r <= 0)
            Console.Write("Ievadiet pozitīvu skaitli: ");
        Console.Write("Kolonnu skaits: ");
        while (!int.TryParse(Console.ReadLine(), out c) || c <= 0)
       Console.Write("Ievadiet pozitīvu skaitli: ");

        Random rnd = new Random();
        int[,] m = new int[r, c];

        for (int i = 0; i < r; i++)
            for (int j = 0; j < c; j++)
                m[i, j] = rnd.Next(-100, 101);

        int choice;

        do
        {
            Console.WriteLine("\n1 – Izdrukāt matricu");
            Console.WriteLine("2 – Min un Max");
            Console.WriteLine("3 – Kolonnu summas");
            Console.WriteLine("4 – Galvenās diagonāles summa");
            Console.WriteLine("5 – Blakus diagonāles summa");
            Console.WriteLine("6 – Transponēt");
            Console.WriteLine("7 – Meklēt skaitli");
            Console.WriteLine("0 – Iziet");
            Console.Write("Izvēle: ");

            int.TryParse(Console.ReadLine(), out choice);

            if (choice == 1)
            {
                for (int i = 0; i < r; i++)
                {
                    for (int j = 0; j < c; j++)
                        Console.Write(m[i, j] + "\t");
                    Console.WriteLine();
                }
            }
            else if (choice == 2)
            {
                int min = m[0, 0], max = m[0, 0];
                foreach (int x in m)
                {
                    if (x < min) min = x;
                    if (x > max) max = x;
                }
                Console.WriteLine($"Min: {min}, Max: {max}");
            }
            else if (choice == 3)
            {
                for (int j = 0; j < c; j++)
                {
                    int sum = 0;
                    for (int i = 0; i < r; i++) sum += m[i, j];
                    Console.WriteLine($"Kolonna {j + 1}: {sum}");
                }
            }
            else if (choice == 4)
            {
                int sum = 0;
                int min = Math.Min(r, c);
                for (int i = 0; i < min; i++)
                    sum += m[i, i];
                Console.WriteLine("Galvenā diagonāle: " + sum);
            }
            else if (choice == 5)
            {
                int sum = 0;
                int min = Math.Min(r, c);
                for (int i = 0; i < min; i++)
                    sum += m[i, c - 1 - i];
                Console.WriteLine("Blakus diagonāle: " + sum);
            }
            else if (choice == 6)
            {
                int[,] t = new int[c, r];
                for (int i = 0; i < r; i++)
                    for (int j = 0; j < c; j++)
                        t[j, i] = m[i, j];

                m = t;
                int temp = r; r = c; c = temp;
                Console.WriteLine("Transponēts!");
            }
            else if (choice == 7)
            {
                Console.Write("Meklējamais skaitlis: ");
                int x = int.Parse(Console.ReadLine());
                bool atrasts = false;

                for (int i = 0; i < r; i++)
                    for (int j = 0; j < c; j++)
                        if (m[i, j] == x)
                        {
                            Console.WriteLine($"Atrasts ({i + 1}, {j + 1})");
                            atrasts = true;
                        }
                if (!atrasts) Console.WriteLine("Nav atrasts.");
            }

        } while (choice != 0);
    }
}
