First note that, taking any non-empty subset of gives us a subsequence, namely the subsequence indices from that set. So we first count the subsequences containing only one distinct value. Suppose the array has value at indices, then any non-empty subset of those indices will create a subsequence containing only . Hence number of subsequence containing only one value is where is the count of occurrences of .
For the subsequences containing exactly two distinct values, we take all possible pairwise product of and sum them. All of this needs to be done modulo