eolymp
bolt
Try our new interface for solving problems
Problems

Genuine Messages

Genuine Messages

To communicate with HQ, spies send electronic messages over the Information Superhighway using a protocol called SMTP (Secret Message Translation Protocol). To ensure that these messages are genuine and have not, for example, been sent by an evil adversary, every message is modified in such a way that it looks like there was noise on the communication line, or the sender was very nervous while typing the message. However, the mutation algorithm is carefully crafted such that an imposter is very unlikely to replicate this particular effect, and it is also easy for field agents to intentionally insert a "mistake" if they are forced at gunpoint to write a message. In a correctly mutated message every third appearance of each letter is duplicated. For example, "\textbf{HELLOTHEREEWELLLBEFINEE}" is the correct mutation if the agent wanted to send "\textbf{HELLOTHEREWELLBEFINE}". For the past few decades these messages have been checked by highly trained monkeys. Since the number of messages arriving at the HQ has greatly increased recently, they have tasked you with writing an automated program that can alert HQ when a message is definitely fake and not sent by our agent. \InputFile On the first line one positive number: the number of test cases, at most \textbf{100}. After that per test case: \begin{itemize} \item one line with a string \textbf{M }(\textbf{1 }≤ \textbf{length(M) }≤ \textbf{100000}), consisting of uppercase letters only: the incoming message to check. \end{itemize} \OutputFile For each test case print one line with either "\textbf{OK}" or "\textbf{FAKE}", indicating whether or not the message \textbf{M }can be the result of a correctly applied mutation to some (unspecified) original message.
Time limit 1 second
Memory limit 64 MiB
Input example #1
3
BAPC
AABA
ABCABCBBAAACC
Output example #1
OK
FAKE
OK
Source 2013 Benelux Algorithm Programming Contest (BAPC), Preliminaries, September 28, Problem G