GHOST is a spelling game played by bored students on long trips. The goal is to build up letters that spell the beginning of some word without ever actually finishing a word. Before the game starts, the players agree on a fixed turn order. Play passes from one player to the next and then wraps back to the first player, repeating until the game ends. On each turn a player must do exactly one of three things: extend the current sequence, bluff, or challenge.
P (secretly thinking of part), the second L (thinking of play), and the third E (thinking of please). A player loses if they actually complete a valid word of 4 or more letters. With only three players, after PLE the first player adding A (aiming for plead) would lose, because plea is already a valid word.Write a program that takes one turn of GHOST as the computer player. A strong player does more than find any legal extension: it weighs every word the sequence might grow into against the number of players, so that it is never forced on some later turn to be the one who completes a word.
The input contains one or more scenarios.
Each scenario is given as follows:
a–z, with no leading, trailing, or internal spaces. An empty line ends the word list.For each scenario, print exactly one line: the current sequence from the input, then a single space, then one of the following.
Challenge — if the current sequence is itself a word in the dictionary, or is not a prefix of any word in the dictionary.c is a valid extension when: the sequence followed by c is a prefix of some word; that extended sequence does not itself complete a word of $4$ or more letters; and there is a dictionary word $W$ beginning with the extended sequence such that, if the remaining letters of $W$ are spelled out one per turn, the first word of $4$ or more letters completed along the way does not land on the computer's turn. If several letters qualify, print the alphabetically smallest one.Bluff — if at least one extension exists but every extension would eventually force the computer itself to complete a word.