ENG  RUSTimus Online Judge
Online Judge
Online contests
About Online Judge
Frequently asked questions
Site news
Problem set
Submit solution
Judge status
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests

Ural Regional School Programming Contest 2012

About     Problems     Submit solution     Judge status     Standings
Contest is over

B. Chaos and Order

Time limit: 2.0 second
Memory limit: 64 MB
The world is in danger! Far, far away on the Extreme West there is a temple of Chaos and Order. Each of these two forces could destroy the world if you give one of them a freedom, that’s why world's peace depends on subtle balance between them. This balance is supported by Monks of Balance.
Floor of the temple is divided into equal squares, so that it turns into the field n × m. In each square the Monks of Balance draw one of the k runes to keep the balance. Incantation of t-th level is t identical successive runes in the same line, in the same column or in the same diagonal of the field.
Once in a thousand years the Order and the Chaos meet each other on the Earth and agree what should be the balance l in this millennium. And after one day and two seconds after this meeting the monks must fill the floor of the temple of Chaos and Order in the way that will contain at least one incantation of (l − 1)-th level (otherwise Chaos will destroy the world) without incantations of l-th level (otherwise the world will be destroyed by Order).
Please help the monks to find the correct arrangement of runes to save the universe. They need the whole day to write runes, that’s why your program must work only for two seconds.


There are integers n, m, k and l (1 ≤ n, m ≤ 100; 1 ≤ k ≤ 26; 2 ≤ l ≤ 100) in the only line of input data.


If drawing the runes correctly is impossible output “NO” in the only line. Otherwise output “YES” in the first line and write m characters in each of the next n lines –– floor, which is filled with runes. Each rune should be represented by the Latin capital letter; different runes should be represented by different letters, the same runes — by the same letters. You are allowed to use only first k letters of Latin alphabet to mark runes.


3 4 4 2
2 2 1 2
Problem Author: Grigoriy Nazarov
Problem Source: Ural Regional School Programming Contest 2012
To submit the solution for this problem go to the Problem set: 1921. Chaos and Order