parameters: (self, S)
return_statement: return result % M
docstring: :type S: str
          :rtype: int
docstring_summary: :type S: str
          :rtype: int
docstring_tokens: : type S : str : rtype : int
function: def uniqueLetterString(self, S):
          """
          :type S: str
          :rtype: int
          """
          M = 10**9 + 7
          index = {c: [-1, -1] for c in string.ascii_uppercase}
          result = 0
          for i, c in enumerate(S):
              k, j = index[c]
              result += (i-j) * (j-k)
              index[c] = [j, i]
          for c in index:
              k, j = index[c]
              result += (len(S)-j) * (j-k)
          return result % M
function_tokens: def uniqueLetterString ( self , S ) : M = 10 ** 9 + 7 index = { c : [ - 1 , - 1 ] for c in string . ascii_uppercase } result = 0 for i , c in enumerate ( S ) : k , j = index [ c ] result += ( i - j ) * ( j - k ) index [ c ] = [ j , i ] for c in index : k , j = index [ c ] result += ( len ( S ) - j ) * ( j - k ) return result % M