update S(n) solution to distinct subsequences