Solving a system of equations by substitution