This algorithm uses the same input and output conventions
as Algorithm A.
The lines 31--51 are identical to the lines
25--45 of Algorithm A and the lines 104--113 are identical
to lines 103--112 of Algorithm A.

The algorithm needs without input and output
$(B+G+2H+2J+L+P+4R+2S+T)\mems + (9+A+6B+E+2F+3G+5H+7J+4K+4L+4Q+7R+9S+2T)\oops$.

This time Kirchhoff's law gives the following equations
$$
\eqalign{
    A&=1+B-D;\cr
    E&=D-L;\cr
    G&=F-H;\cr}
\qquad\eqalign{
    J&=H+G-F+E=E=D-L;\cr
    P&=1+S;\cr
    T&=Q-1.\cr}
$$
Applying the equations to the used mems and oops several variables are eliminated:
$(B+2D+F+H-L+Q+4R+3S)\mems + (8+7B+7D+5F+2H+4K-4L+6Q+7R+9S)\oops$.
And most of the other values are already known:
$$
\eqalign{
    B &= \rb{number of words of input;}\cr
    D &= \rb{number of words of input without right parentheses;}\cr
    H &= \rb{number of distinct elements in input;}\cr
  K=L &= \rb{number of cycles in input;}\cr
Q-1=R &= \rb{number of distinct elements in output;}\cr
    S &= \rb{number of cycles in output (inlusive singletons).}\cr}
$$
Of course $H=R$; only the variable $F$ cannot be easily resolved.

With the variables of \eq(19) the profile of the algorithm is
$(3Y+6N-3M+3U+F+1)\mems + (14Y+15N-7M+9U+5F+14)\oops$.

Running the program with \eq(6) as input the \MMIX-simulator shows at the end:
{\tt 838 instructions, 204 mems, 964 oops; 201 good guesses, 45 bad}.
With this input it follows that $Y=29$, $N=7$, $M=5$, and $U=3$.
The algorithm itself needs
{\tt 801 instructions, 198 mems, 887 oops; 197 good guesses, 43 bad}.
The value of $F$ is 74.
As expected the following equations hold:
$3*29+42-15+9+74+1=198$ and $14*29+15*7-35+27+5*74+14=887$.
