Colorful Subsequence

AtCoder
IDagc031_a
Time2000ms
Memory256MB
Difficulty
You are given a string $S$ of length $N$. Among its subsequences, count the ones such that all characters are different, modulo $10^9+7$. Two subsequences are considered different if their characters come from different positions in the string, even if they are the same as strings. Here, a subsequence of a string is a concatenation of **one or more** characters from the string without changing the order. ## Constraints * $1 \leq N \leq 100000$ * $S$ consists of lowercase English letters. * $|S|=N$ ## Input Input is given from Standard Input in the following format: $N$ $S$ [samples]
Samples
Input #1
4
abcd
Output #1
15

Since all characters in $S$ itself are different, all its subsequences satisfy the condition.
Input #2
3
baa
Output #2
5

The answer is five: `b`, two occurrences of `a`, two occurrences of `ba`. Note that we do not count `baa`, since it contains two `a`s.
Input #3
5
abcab
Output #3
17
API Response (JSON)
{
  "problem": {
    "name": "Colorful Subsequence",
    "description": {
      "content": "You are given a string $S$ of length $N$. Among its subsequences, count the ones such that all characters are different, modulo $10^9+7$. Two subsequences are considered different if their characters ",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "agc031_a"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You are given a string $S$ of length $N$. Among its subsequences, count the ones such that all characters are different, modulo $10^9+7$. Two subsequences are considered different if their characters ...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments