title: Count Substrings With Same First And Last Characters
signature: function count_substrings_with_same_first_and_last_characters(s)
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;
  }
question_info.entry_fn_name: count_substrings_with_same_first_and_last_characters
question_info.entry_cls_name: Solution
question_info.test_case_ids: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
question_info.test_code: 
  
  -- SOLUTION CODE
  -- ============================================
  PLACEHOLDER_CODE_BODY
  
  -- TESTING CODE 
  -- ============================================
  function isCorrect(actual, expected)
      if type(expected) ~= type(actual) then
          return false
      end
      
      if type(expected) == 'table' then
          for k,v_expected in pairs(expected) do
              
              if actual[k] == nil then
                  return false
              end
              local v_actual = actual[k]
              if not isCorrect(v_actual, v_expected) then
                  return false
              end
              actual[k]=nil
          end
      
          if next(actual) then 
              return false
          end
          return true
      else
          return actual == expected
      end
  end
  
  function validateSolution(actual, expected)
      return isCorrect(actual,expected)
  end
  
  function driver(s, expected)
      local exec_result;
      local status, error_msg = pcall(function () 
          exec_result=PLACEHOLDER_FN_NAME(s) 
      end)
      if status then
          if validateSolution(exec_result,expected) then
              return "PASSED"
          end
          return "FAILED"
      else
          return string.format("ERROR=%s",string.gsub(error_msg,".*:[%d]+: ",""))
      end
  end
      
  function main()
      result = driver("LZIKA", 5)
      print(string.format("TEST-0...%s",result))
  
      result = driver("0556979952", 16)
      print(string.format("TEST-1...%s",result))
  
      result = driver("110010", 12)
      print(string.format("TEST-2...%s",result))
  
      result = driver("kGaYfd", 6)
      print(string.format("TEST-3...%s",result))
  
      result = driver("413567670657", 19)
      print(string.format("TEST-4...%s",result))
  
      result = driver("01001", 9)
      print(string.format("TEST-5...%s",result))
  
      result = driver("EQPuFa", 6)
      print(string.format("TEST-6...%s",result))
  
      result = driver("48848378", 15)
      print(string.format("TEST-7...%s",result))
  
      result = driver("110", 4)
      print(string.format("TEST-8...%s",result))
  
      result = driver("PLehNeP", 9)
      print(string.format("TEST-9...%s",result))
  
  end
  
  main()
question_info.test_list: [{"idx": 0, "outputs": 5, "inputs": {"s": "LZIKA"}}, {"idx": 1, "outputs": 16, "inputs": {"s": "0556979952"}}, {"idx": 2, "outputs": 12, "inputs": {"s": "110010"}}, {"idx": 3, "outputs": 6, "inputs": {"s": "kGaYfd"}}, {"idx": 4, "outputs": 19, "inputs": {"s": "413567670657"}}, {"idx": 5, "outputs": 9, "inputs": {"s": "01001"}}, {"idx": 6, "outputs": 6, "inputs": {"s": "EQPuFa"}}, {"idx": 7, "outputs": 15, "inputs": {"s": "48848378"}}, {"idx": 8, "outputs": 4, "inputs": {"s": "110"}}, {"idx": 9, "outputs": 9, "inputs": {"s": "PLehNeP"}}]