title: Count Substrings With Same First And Last Characters
signature: function count_substrings_with_same_first_and_last_characters(s)
test_code: using Printf
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  function validate_solution(actual, expected)
      return actual == expected
  end
  
  function driver(s, expected)
      try
  
          if validate_solution(PLACEHOLDER_FN_NAME(s), expected)
              return "PASSED";
          end
          return "FAILED";
      catch exception_obj
          return string(Base.typename(typeof(exception_obj)).wrapper);
      end
  end
  
  function main()
      
      result = driver("LZIKA", 5);
      @printf("TEST-0...%s\n",result);
      
      result = driver("0556979952", 16);
      @printf("TEST-1...%s\n",result);
      
      result = driver("110010", 12);
      @printf("TEST-2...%s\n",result);
      
      result = driver("kGaYfd", 6);
      @printf("TEST-3...%s\n",result);
      
      result = driver("413567670657", 19);
      @printf("TEST-4...%s\n",result);
      
      result = driver("01001", 9);
      @printf("TEST-5...%s\n",result);
      
      result = driver("EQPuFa", 6);
      @printf("TEST-6...%s\n",result);
      
      result = driver("48848378", 15);
      @printf("TEST-7...%s\n",result);
      
      result = driver("110", 4);
      @printf("TEST-8...%s\n",result);
      
      result = driver("PLehNeP", 9);
      @printf("TEST-9...%s\n",result);
      
  end
  
  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;
  }