| Winter Cup 8.0 Online Mirror Contest |
|---|
| Finished |
Deep inside the ancient Medina of Tunis, among the narrow alleys and whitewashed walls, a respected calligrapher and scholar left behind a mysterious parchment before disappearing during troubled times.
The parchment was discovered in a small shop near the souks. It contains an encrypted message written in lowercase English characters. The message was protected using a Caesar cipher, yet the shift number used to encrypt it is unknown.
Luckily, an old hakim (wise man) from the Medina provides a clue: he is certain that the original message contained at least one word from a given list of important Tunisian words — words such as "carthage", "zitouna", "jasmine", "kasba", or "medina".
A Caesar cipher shifts each letter in the alphabet forward by a fixed number of positions $$$k$$$ ($$$0 \le k \le 25$$$). The shift wraps around at the end of the alphabet. For example, with a shift of $$$1$$$, 'a' becomes 'b', 'b' becomes 'c', and 'z' becomes 'a'.
Your task is to determine the shift number $$$k$$$ that was used to encrypt the message.
In the first example, shifting the original words "treasure" and "madina" forward by $$$k=5$$$ results in the encrypted words "ywjfxzwj" and "rfinsf".
The first line contains a single integer $$$N$$$ ($$$1 \le N \le 1000$$$) — the number of words in the encrypted text.
The second line contains a string $$$S$$$ — the encrypted text. The string contains only lowercase letters and spaces. The length of $$$S$$$ is at most $$$100,000$$$ characters and contains exactly $$$N$$$ words.
The third line contains a single integer $$$M$$$ ($$$1 \le M \le 1000$$$) — the number of words in the known list.
The next $$$M$$$ lines each contain a string — the words that could appear in the decrypted text. Each word contains only lowercase letters and has a length of at most $$$50$$$.
Print a single integer: the shift number($$$0 \le \text{shift} \le 25$$$), or '-1' if it cannot be determined for certain.
6ymj ywjfxzwj nx ns ymj rfinsf2madinatreasure
5
5o ziovx u bcxxyh nlyumoly3agoldtreasure
-1
| Name |
|---|


