Space efficient Python3 program to count all substrings with same first and last characters .
def countSubstringWithEqualEnds ( s ) : NEW_LINE INDENT result = 0 ; NEW_LINE n = len ( s ) ; NEW_LINE DEDENT