The subroutine \mb{:Farey} costs $(2A+4)\mems+(92A+18)\oops$.
Let the length of a Farey series of order $n$ be $f_n$. Then
the following relation holds: $A = f_n - 2$.
The value of $f_1$ is 2 as there are just the two entries 0/1 and 1/1. The Farey series of order 2 has
one more element as the only quotient to be added is 1/2. So $f_2 = 3$.
In general the step from $f_{n-1}$ to $f_n$ adds all quotients of the form $x/n$ in which
the $x$ is relatively prim to $n$. So $f_n = f_{n-1} + \varphi(n)$.
Therefore $A = 2 + \varphi(2) + \varphi(3) + \cdots + \varphi(n) - 2$.
For test runs with $n=7$, 13, and 39 the answers are $f_7 = 19$, $f_{13} = 59$, and $f_{39} = 475$. So
in the subroutine the value of $A$ has to be $17 + 57 + 473 = 547$.
The first call to Farey starts with {\tt 7 instructions, 1 mem, 11 oops; 0 good guesses, 0 bad}
and ends with {\tt 276 instructions, 39 mems, 1593 oops; 16 good guesses, 1 bad}. Therefore
the subroutine needs 38\mems\ and 1582\oops.
The second and third calls have $118\mems + 5262\oops$ and $950\mems + 43534\oops$.
The measured data agree with the above stated cost function.