# 50158. Stop the Sequence

## I'm a slow walker, but I never walk backwards.

Given a sequence of non-negative integers $x$ and a function $C(x)$, find out the first three consecutive $x$'s whose $C(x)$ are also consecutive integers.

The function $C$ is defined as follows. We will be given another function $f(x) = (a x + b) \mod c$, and an interval $\lbrack d, e]$. For a given input $x$, we will repeatedly apply $f$ on it. That is, we will consider the sequence $x$, $f(x)$, $f(f(x))$, $f(f(f(x)))$, ... and so on. We will stop when this process produces a value $y$ between $d$ and $e$ (inclusively). That is, $d \leq y \leq e$. $C(x)$ is deifned as the number of times we need to apply $f$ until it stops, and we guarantee that $C(x)$ is a finite integer for our input $x$. For example, if $x$ is between $d$ and $e$ then $C(x)$ is 0. Also if $f(f(f(x)))$ is between $d$ and $e$, but $f(f(x))$, $f(x)$, and $x$ are not, then $C(x)$ is 3.

You will be given a sequence of $x$'s and you need to compute their $C(x)$. You will stop when the last three $x$'s give three consecutive $C(x)$. Note that three consecutive numbers can appear in any order, like 7, 6, 5.

## Input Format

The first three lines contain $a$, $b$, and $c$. The next two lines contain $d$ and $e$. The sixth line contains $x$'s. You must process all input until EOF.

## Output Format

If you find the three consecutive $C$'s, output the three $x$'s in the order they appear. If you cannot find such numbers, output “Not found”.

• 20 points: The three consecutive $C(x)$ will appear as $C$, $C + 1$, and $C + 2$.
• 80 points: The three consecutive $C(x)$ may appear in any order.

231599203010 21 43 67 140 98 141 5


## Sample Output

43 67 140


231599203010 21 98 110 67 43 140 5 29


## Sample Output

67 43 140


231599203010 21 43 77 140 98 141 5


## Sample Output

Not found