title: Count Substrings With Same First And Last Characters
signature: int countSubstringsWithSameFirstAndLastCharacters(string s) {
test_code: #include <algorithm>
  #include <assert.h>
  #include <cstdlib>
  #include <iostream>
  #include <map>
  #include <set>
  #include <string>
  #include <tuple> 
  #include <unordered_map>
  #include <vector>
  #include <math.h>
  #include <cmath>
  #include <bits/stdc++.h>
  #include <numeric>
  #include <functional>
  
  using namespace std;
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  bool validateSolution(int actual, int expected){
      return actual == expected;
  }
  
  string driver(string s, int expected){
      try
      {
          if (validateSolution(PLACEHOLDER_FN_NAME(s), expected)){
              return "PASSED";
          }
          return "FAILED";
      }
      catch (const std::overflow_error& exception_obj)
      {
          return typeid(exception_obj).name();
      }
      catch (const std::runtime_error& exception_obj)
      {
          return typeid(exception_obj).name();
      }
      catch (const std::exception& exception_obj)
      {
          return typeid(exception_obj).name();
      }
      catch (...)
      {
          return "UNK_ERROR";
      }
  }
  
  int main() {
      string result = "";
  
      result = driver("LZIKA", 5); 
      cout << "TEST-" << 0 << "..."
           <<  result
           << "\n";
  
      result = driver("0556979952", 16); 
      cout << "TEST-" << 1 << "..."
           <<  result
           << "\n";
  
      result = driver("110010", 12); 
      cout << "TEST-" << 2 << "..."
           <<  result
           << "\n";
  
      result = driver("kGaYfd", 6); 
      cout << "TEST-" << 3 << "..."
           <<  result
           << "\n";
  
      result = driver("413567670657", 19); 
      cout << "TEST-" << 4 << "..."
           <<  result
           << "\n";
  
      result = driver("01001", 9); 
      cout << "TEST-" << 5 << "..."
           <<  result
           << "\n";
  
      result = driver("EQPuFa", 6); 
      cout << "TEST-" << 6 << "..."
           <<  result
           << "\n";
  
      result = driver("48848378", 15); 
      cout << "TEST-" << 7 << "..."
           <<  result
           << "\n";
  
      result = driver("110", 4); 
      cout << "TEST-" << 8 << "..."
           <<  result
           << "\n";
  
      result = driver("PLehNeP", 9); 
      cout << "TEST-" << 9 << "..."
           <<  result
           << "\n";
  
      return 0;
  }
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;
  }