Let S=S1S2⋯SN be a string. Every string of the form Si1Si2⋯Sik with 0≤k≤N and 1≤i1<i2<⋯<ik≤N is called a subsequence of S. The empty string, of length 0, is also a subsequence of S. For example, the string ioi has 7 distinct subsequences: the empty string, i, o, ii, io, oi, and ioi.
Given a string S, find the number of distinct subsequences of S.