#P17057. [NWERC 2022] Interview Question

[NWERC 2022] Interview Question

Problem Description

Fizz Buzz is a party game that is often used as a programming exercise in job interviews. In the game, there are two positive integers aa and bb, and the game consists of counting up through the positive integers, replacing any number by Fizz if it is a multiple of aa, by Buzz if it is a multiple of bb, and by FizzBuzz if it is a multiple of both aa and bb. The most common form of the game has a=3a=3 and b=5b=5, but other parameters are allowed.

Your task here is to solve the reverse problem: given a transcript of part of the game, not necessarily starting at 11, find possible values of aa and bb that could have been used to generate it.

The original statement shows some sample sequences for various values of aa and bb.

:::align{center} :::

Figure: Fizz Buzz implemented in Hexagony.

Input Format

The input consists of:

  • One line with two integers cc and dd (1cd1051 \leq c \leq d \leq 10^5), indicating that your transcript starts at cc and ends at dd.
  • One line with dc+1d-c+1 integers and strings, the contents of the transcript.

It is guaranteed that the transcript is valid for some integers aa and bb with 1a,b1061 \leq a,b \leq 10^6, according to the rules laid out above.

Output Format

Output two positive integers aa and bb (1a,b1061 \leq a,b \leq 10^6) that are consistent with the given transcript.

If there are multiple valid solutions, you may output any one of them.

7 11
7 8 Fizz Buzz 11
3 5
49999 50002
49999 FizzBuzz 50001 Fizz
2 125
8 11
Buzz Buzz FizzBuzz Buzz
10 1 
10 15
10 11 12 13 14 15
8 23