trying algebraic approach to the combinatorial problem