An algorithm to count ways to represent changes