title: Count Substrings With Same First And Last Characters
signature: function countSubstringsWithSameFirstAndLastCharacters($s) {
test_code: <?php
  
  
  // SOLUTION CODE 
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  function validateSolution($actual, $expected){
      return serialize($actual) == serialize($expected);
  }
  
  function driver($s, $expected){
      try{
        if (validateSolution(PLACEHOLDER_FN_NAME($s), $expected)){
          return "PASSED";
        }
        return "FAILED";
      }
      catch (Exception $exception_obj) {
        return get_class($exception_obj);
      }
  }
  
  function main(){
      printf("TEST-0...%s\n",driver(
        "LZIKA", 
        5));
      
      printf("TEST-1...%s\n",driver(
        "0556979952", 
        16));
      
      printf("TEST-2...%s\n",driver(
        "110010", 
        12));
      
      printf("TEST-3...%s\n",driver(
        "kGaYfd", 
        6));
      
      printf("TEST-4...%s\n",driver(
        "413567670657", 
        19));
      
      printf("TEST-5...%s\n",driver(
        "01001", 
        9));
      
      printf("TEST-6...%s\n",driver(
        "EQPuFa", 
        6));
      
      printf("TEST-7...%s\n",driver(
        "48848378", 
        15));
      
      printf("TEST-8...%s\n",driver(
        "110", 
        4));
      
      printf("TEST-9...%s\n",driver(
        "PLehNeP", 
        9));
      
  }
  
  main();
  ?>
source_py: def count_substrings_with_same_first_and_last_characters(s):
      result = 0
      n = len(s)
      for i in range(n):
          for j in range(i, n):
              if (s[i] == s[j]):
                  result = (result + 1)
      return result
source_cpp: int count_substrings_with_same_first_and_last_characters(string s) {
    int result = 0;
    int n = s . length ( );
    for ( int i = 0;
    i < n;
    i ++ ) for ( int j = i;
    j < n;
    j ++ ) if ( s [ i ] == s [ j ] ) result ++;
    return result;
  }