Solving equations with unknowns on both sides