using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MaxNumber
{
	public class Matrix
	{
		public int[,] numbers;
		public int N { get { return numbers.GetLength(0); } }
		public int M { get { return numbers.GetLength(1); } }
		public readonly int MaxNumber;
		public readonly Random Rnd;

		public Matrix(int n, int m, int maxNumber, int seed)
		{
			if (n < 1 || n > 100)
				throw new ArgumentException();
			if (m < 1 || m > 100)
				throw new ArgumentException();
			if (maxNumber < 0 || maxNumber > 9)
				throw new ArgumentException();
			numbers = new int[n, m];
			MaxNumber = maxNumber;
			Rnd = new Random(seed);
		}

		public void FillRandom(int maxNumberPercent = 0)
		{
			for (int i = 0; i < N; i++)
			{
				for (int j = 0; j < M; j++)
				{
					if (maxNumberPercent > 0)
					{
						if (Rnd.Next(100) < maxNumberPercent)
							numbers[i, j] = MaxNumber;
						else
							numbers[i, j] = Rnd.Next(MaxNumber);
					}
					else
					{
						numbers[i, j] = Rnd.Next(MaxNumber+1);
					}
				}
			}
		}

		public void Write()
		{
			Console.WriteLine("{0} {1}", N, M);
			for (int i = 0; i < N; i++)
			{
				for (int j = 0; j < M; j++)
				{
					Console.Write(numbers[i, j]);
				}
				Console.WriteLine();
			}
		}
	}

	class MaxNumberGen
	{
		static void Main(string[] args)
		{
			var seed = int.Parse(args[0]);
			var n = int.Parse(args[1]);
			var m = int.Parse(args[2]);
			var maxNumber = int.Parse(args[3]);
			var matrix = new Matrix(n, m, maxNumber, seed);
			var maxNumberPercent = 0;
			if (args.Length > 4)
				maxNumberPercent = int.Parse(args[4]);
			matrix.FillRandom(maxNumberPercent);
			matrix.Write();
		}
	}
}
