title: Count Substrings With Same First And Last Characters
signature: count_substrings_with_same_first_and_last_characters <- function(s) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(s, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(s), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          "LZIKA", 
          5L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          "0556979952", 
          16L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          "110010", 
          12L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          "kGaYfd", 
          6L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          "413567670657", 
          19L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          "01001", 
          9L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          "EQPuFa", 
          6L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          "48848378", 
          15L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          "110", 
          4L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          "PLehNeP", 
          9L
      )))
  
  }
  
  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;
  }