VIII Olimpiada Informatyczna 2000/2001
|
Task: NAS
|
Author: Adam Malinowski, Wojciech Rytter
|
III stage contest, the first day |
Byteland is known for the gorgeous necklaces made by famous jeweler Byteman. These necklaces are made of gem stones threaded together. The gem stones are divided into 26 distinct sorts, these will be denoted by the lower case Latin letters: a - z (stones of the same sort are indistinguishable). It is a point of honor with Byteman never to produce two identical necklaces, therefore he keeps the descriptions of all the necklaces he had ever produced. Some of the necklaces are really long, that is why their descriptions are kept in a shorten form. Each description consists of fragments of the following form: a sequence of letters (called pattern) followed by an integer denoting the number of times the pattern repeats in the necklace. Every description is a sequence of such fragments. For example, the description:
represents the necklace abcabcxyzaxcaxcaxc (this word is obtained by writing : "abc" - twice, "xyz" - once, and "axc" - 3 times). The problem is more complicated because of the inability to determine the beginning of the necklace (i.e. the necklace can be arbitrarily turned around). Hence some necklaces may have more then one description. For example, the necklace described above may also be described as: cabcxyzaxcaxcaxcab or xcaxcaxcabcabcxyza.
Your program should write in the first and only line of the output file NAS.OUT a word "TAK" ("YES" in Polish), if both descriptions represent the same necklace, and a word "NIE" ("NO" in Polish) if the described necklaces are different.
3 3 abc 2 3 xyz 1 3 axc 3 4 4 cabc 1 4 xyza 1 3 xca 3 1 b 1the correct answer is the output file NAS.OUT:
TAK