Description

Suppose that "n" persons that are each given a number from 1 through "n" are playing a game of English word relay. English word relay is played based on the following rules.

  1. Starting from person number 1, each person says a word in turn.
  2. After the last person says a word, person number 1 starts again.
  3. A person should say a word that starts with the last character of the previously said word.
  4. A person cannot say a word that has already been said.
  5. Words with one character are not valid.

The following shows a situation where 3 persons are playing English word relay.

tank → kick → know → wheel → land → dream → mother → robot → tank

The procedure of the word relay above is as follows.

  • Person number 1 says tank at the first turn.
  • Person number 2 says kick at the first turn.
  • Person number 3 says know at the first turn.
  • Person number 1 says wheel at the second turn.
  • (Continued)

As the word relay continues, person number 3 is eliminated because the word tank, said on the third turn, had already appeared.

With the number of people "n" and the words said "words" as parameters, write a function "solution" to return the number given to the first dropout and in which turn he is eliminated.

Constraints
  • The number of participants in the word relay "n" is a natural number between 2 and 10.
  • "words" is an array containing words said in the word relay and its length is more than "n" and less than 100.
  • The length of the words is between 2 and 50.
  • All words consist of lower-case letters only.
  • You do not need to consider the meaning of the words used in the word relay.
  • Return an answer in [ number, turn ] format.
  • If there is no dropout with the given words, return [0, 0].
Example
n words result
3 ["tank", "kick", "know", "wheel", "land", "dream", "mother", "robot", "tank"] [3,3]
5 ["hello", "observe", "effect", "take", "either", "recognize", "encourage", "ensure", "establish", "hang", "gather", "refer", "reference", "estimate", "executive"] [0,0]
2 ["hello", "one", "even", "never", "now", "world", "draw"] [1,3]

Example #1
3 persons participate in the word relay.

  • Person number 1 : tank, wheel, mother
  • Person number 2 : kick, land, robot
  • Person number 3 : know, dream, tank

The sequence of words said is shown above. Since the word tank, said at the third turn of person number 3, is the same with the tank said at the first turn of person number 1, person number 3 is the first dropout and is eliminated at the third turn.

Example #2
5 persons participate in the word relay.

  • Person number 1 : hello, recognize, gather
  • Person number 2 : observe, encourage, refer
  • Person number 3 : effect, ensure, reference
  • Person number 4 : take, establish, estimate
  • Person number 5 : either, hang, executive

The sequence of words said is shown above. In this case, no dropout appears within the given words. Therefore, return [0, 0].

Example #3
2 persons participate in the word relay.

  • Person number 1 : hello, even, now, draw
  • Person number 2 : one, never, world

The sequence of words said is shown above. Since person number 1 said the word now at the third turn, which starts with 'n', instead of 'r', the first dropout appears at this point.

Result Stop
Result of [Run] or [Submit] will be displayed here