The Journey of the King
시간 제한1초메모리 제한2048 MB
서로 다른 단어들의 사전이 주어질 때, 두 카드는 두 연결 순서 중 하나가 사전에 있으면 짝이 되며, 정해진 순서에서 최대 짝 수를 구한다.
문제
You are very close to becoming the King of Games. The only thing left to do is to win in a card game against the incarnation of the King of Nusantara, Anda, whose soul resides inside you as your split personality.
Each player has a deck of cards, each card contains a word. Within each deck, there are no two cards containing the same word. There is also a dictionary consisting of distinct words: .
The game consists of turns. In turn , Anda will play a card with the word . Then, you can either match his card with one of your remaining cards or skip this turn. Two cards, and , match if either the words or exist in the dictionary. The operator represents the concatenation operation. For instance, the concatenation of words AU and RA is AU RA AURA. Once you match a card, you cannot use that card for the rest of the game.
Your deck has cards (numbered from to ); card contains word . You want to maximize the number of turns in which you successfully match Anda’s card.
입력
The first line consists of an integer ().
Each of the next lines consists of a string . String consists of only uppercase English letters. The sum of length of does not exceed . It is guaranteed that for .
The following line consists of an integer ().
Each of the next lines consists of a string . String consists of only uppercase English letters. The sum of length of does not exceed . It is guaranteed that for .
The following line consists of an integer ().
Each of the next lines consists of a string . String consists of only uppercase English letters. The sum of length of does not exceed . It is guaranteed that for .
출력
Output a single integer representing the maximum number of turns you match Anda’s card.