#P7210. Song Prefix Game

    ID: 20414 Type: Default 1000ms 256MiB

Song Prefix Game

Song Prefix Game

Two players, Nina and Emilija, play a game on paper starting with an empty word. In each turn, the current player appends a single letter to the end of the current word. After the letter is appended, the new word must be a prefix of at least one word in that player's favorite song list. Nina moves first. If a player cannot make a move under these rules, she loses.

Formally, if the current word is \(W\) and the current player appends a letter \(L\), then \(W+L\) must be a prefix of some word in that player's list. Note that the validity check is performed with respect to the current player's favorite song words only; the updated word may or may not be a prefix for the opponent. Assuming both players play optimally, determine who wins the game.

Input Details: Each player’s favorite song is given as a list of words.

inputFormat

The input consists of:

  • An integer \(n\), the number of words in Nina's favorite song.
  • \(n\) lines, each containing a non-empty word of lowercase English letters.
  • An integer \(m\), the number of words in Emilija's favorite song.
  • \(m\) lines, each containing a non-empty word of lowercase English letters.

The game starts with an empty word.

outputFormat

Output a single line with the name of the winning player: either Nina or Emilija.

sample

1
a
1
b
Nina