Another version of transform, calculates number of ways to make such mask
some changes