title: Count Palindromic Subsequence Given String
signature: def count_palindromic_subsequence_given_string(str):
source_py: def count_palindromic_subsequence_given_string(str):
      N = len(str)
      cps = [[0 for i in range((N + 2))] for j in range((N + 2))]
      for i in range(N):
          cps[i][i] = 1
      for L in range(2, (N + 1)):
          for i in range(N):
              k = ((L + i) - 1)
              if (k < N):
                  if (str[i] == str[k]):
                      cps[i][k] = ((cps[i][(k - 1)] + cps[(i + 1)][k]) + 1)
                  else:
                      cps[i][k] = ((cps[i][(k - 1)] + cps[(i + 1)][k]) - cps[(i + 1)][(k - 1)])
      return cps[0][(N - 1)]
source_cpp: int count_palindromic_subsequence_given_string(string str) {
    int N = str . length ( );
    int cps [ N + 1 ] [ N + 1 ];
    memset ( cps, 0, sizeof ( cps ) );
    for ( int i = 0;
    i < N;
    i ++ ) cps [ i ] [ i ] = 1;
    for ( int L = 2;
    L <= N;
    L ++ ) {
      for ( int i = 0;
      i < N;
      i ++ ) {
        int k = L + i - 1;
        if ( str [ i ] == str [ k ] ) cps [ i ] [ k ] = cps [ i ] [ k - 1 ] + cps [ i + 1 ] [ k ] + 1;
        else cps [ i ] [ k ] = cps [ i ] [ k - 1 ] + cps [ i + 1 ] [ k ] - cps [ i + 1 ] [ k - 1 ];
      }
    }
    return cps [ 0 ] [ N - 1 ];
  }
question_info.test_code: import array
  import bisect
  import collections
  import datetime
  import functools
  import heapq
  import itertools
  import math
  import queue
  import re
  import string
  import sys
  from typing import Any, Dict, List, Optional, Set
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  def validate_solution(actual, expected):
      return actual == expected
  
  def driver(str, expected):
      try:
          if validate_solution(PLACEHOLDER_FN_NAME(
              str),
              expected
          ):
              return "PASSED"
          return "FAILED"
      except Exception as exception_obj:
          return type(exception_obj).__name__
      
  if __name__ == "__main__":
      result = driver("R", 1)
      print(f"TEST-0...{result}")
  
      result = driver("2956350", 10)
      print(f"TEST-1...{result}")
  
      result = driver("11100111110101", 2798)
      print(f"TEST-2...{result}")
  
      result = driver("TZTDLIIfAD", 20)
      print(f"TEST-3...{result}")
  
      result = driver("98", 2)
      print(f"TEST-4...{result}")
  
      result = driver("1100100001", 270)
      print(f"TEST-5...{result}")
  
      result = driver("oKwGeatf", 8)
      print(f"TEST-6...{result}")
  
      result = driver("19", 2)
      print(f"TEST-7...{result}")
  
      result = driver("00010110100", 563)
      print(f"TEST-8...{result}")
  
      result = driver("Cyq", 3)
      print(f"TEST-9...{result}")
  
      sys.exit(0)
question_info.test_case_ids: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
question_info.entry_fn_name: count_palindromic_subsequence_given_string
question_info.test_list: [{"idx": 0, "outputs": 1, "inputs": {"str": "R"}}, {"idx": 1, "outputs": 10, "inputs": {"str": "2956350"}}, {"idx": 2, "outputs": 2798, "inputs": {"str": "11100111110101"}}, {"idx": 3, "outputs": 20, "inputs": {"str": "TZTDLIIfAD"}}, {"idx": 4, "outputs": 2, "inputs": {"str": "98"}}, {"idx": 5, "outputs": 270, "inputs": {"str": "1100100001"}}, {"idx": 6, "outputs": 8, "inputs": {"str": "oKwGeatf"}}, {"idx": 7, "outputs": 2, "inputs": {"str": "19"}}, {"idx": 8, "outputs": 563, "inputs": {"str": "00010110100"}}, {"idx": 9, "outputs": 3, "inputs": {"str": "Cyq"}}]
question_info.entry_cls_name: Solution