Prijateljice
InterviewTime limit1sMemory limit1024 MB
Two players alternately say larger words from their own sorted lists, starting with the same or next letter. Decide the winner if Leona opens with her smallest word.
- Level
Medium5 of 10
- Topics
- Game theory, Dynamic programming, Sorting
- Solved
- No attempts yet
Problem
One summer night in Krk, Leona and Zoe went for a walk. On their winding path, they found a pile of words! Excited by that, they quickly started collecting them: Leona collected words, and Zoe words. After admiring them for a while, they decided to play the following game:
In one move a player says a word from her pile. The player chooses the word so that two conditions hold. The word is lexicographically greater than the previous word, and it begins with the same letter as the previous word or with the letter that follows the first letter of the previous word in the English alphabet. If a player cannot make a move, she loses.
They alternate turns, and Leona plays first by saying her lexicographically smallest word. If Leona and Zoe play optimally, determine who wins.
Note: The word A is lexicographically smaller than the word B if A is a prefix of B, or if at the first position where A and B differ, the letter in A comes before the letter in B.
Input
The first line contains integers and (), the number of Leona's words and the number of Zoe's words.
The following lines contain Leona's words. The following lines contain Zoe's words.
Words contain only lowercase English letters, all words are mutually distinct, their total length is at most , and Leona's and Zoe's words are each sorted lexicographically.
Output
Output Leona or Zoe, the name of the winner.
Hint
Clarification of the first example: Leona starts with the word avokado, then Zoe continues with her only word brazil. Leona cannot make any move, so she loses.