Fizz and Buzz
Time limit2sMemory limit256 MB
Given a sequence of numbers each divisible by 3 or 5, guess for each position whether Fizz (divisible by 3) or Buzz (divisible by 5) produced it, allowing at most 1200 errors.
- Level
Medium6 of 10
- Topics
- Probability, Math, Greedy, Implementation
- Solved
- No attempts yet
Statement
Two dwarves, Fizz and Buzz, build a sequence of integers. Each element is constructed as follows. First, the friends toss a fair coin to choose who creates the next number: with probability it is Fizz, and with probability it is Buzz. Then, if the toss favors Fizz, he considers all integers from to that are divisible by and selects one of them at random. All these integers are equally likely to be selected. If the toss favors Buzz, he considers all integers from to that are divisible by and selects one of them at random. All these integers are equally likely to be selected as well. All coin tosses and all integer selections are independent events.
The dwarves built a sequence of integers by the rules above. Given the resulting sequence, guess who created which number, without making too many errors.
Input
The first line contains an integer , the length of the sequence (). The second line contains the sequence itself: the integers , , , (). It is guaranteed that the sequence was built according to the statement using a random number generator.
Output
Print a single line with characters, each of which is either "F" or "B". In the perfect answer, the character at position must be "F" if the number was created by Fizz, or "B" if the number was created by Buzz. Your answer may contain at most errors. In other words, it may differ from the perfect answer at no more than positions.
Notes
The example above shows the perfect answer. In this example a solution cannot make more than ten errors, so any correctly formatted answer is accepted.