Simple C, DP, O(1) space, O(n) time
\nint uniqueLetterString(char * s){\n    int64_t total = 0;\n    int prev[128] = { 0 }, prevprev[128] = { 0 };\n    // elc: sum of countUniqueChars for subsrtin
```\nint uniqueLetterString(char * s){\n    int64_t total = 0;\n    int prev[128] = { 0 }, prevprev[128] = { 0 };\n    // elc: sum of countUniqueChars for subsrtings ending on current position\n    for (int i = 0, elc = 0; *s; ++s) {\n        total += elc += ++i + prevprev[*s] - 2 * prev[*s];\n        prevprev[*s] = prev[*s];\n        prev[*s] = i;\n    }\n    return total % 1000000007LL;\n}\n```
['C']