Check if count of substrings in S with string S1 as prefix and S2 as suffix is equal to that with S2 as prefix and S1 as suffix

#include using namespace std;  int countSubstrings(string S, string S1,                    string S2){        int N = S.length();    int N1 = S1.length();    int N2 = S2.length();              int count = 0, totalcount = 0;          for (int i = 0; i < N; i++) {                  string prefix = S.substr(i, N1);                  string suffix = S.substr(i, N2);                  if (S1 == prefix)            count++;                  if (S2 == suffix)            totalcount += count;    }          return totalcount;}  void checkSubstrings(string S, string S1,                     string S2){          int x = countSubstrings(S, S1, S2);    int y = countSubstrings(S, S2, S1);          if (x == y)        cout