Language: C++

#include <cstdio>
#include <iostream>
#include <string>
#include <set>
#include <vector>
#include <list>
#include <algorithm>

using namespace std;

#define rev(s) (vector<char>((s).rbegin(), (s).rend()))
#define HASH_SIZE 2011
#define a 1049

int hash(vector<char> str)
{
  int n = 0;
  int pow = 1;
  for (unsigned int i = 0; i < str.size(); i++) {
    n += (pow * (str[i] - 'a')) % HASH_SIZE;
    pow *= 26;
    pow %= HASH_SIZE;
  }
  return n % HASH_SIZE;
}

class hash_table {
public:
  vector<vector<char> > h;
  bool operator[](vector<char> str) {
    int key = hash(str);
    //cout << string(str.begin(), str.end()) << ":" << key << endl;
    for (int i = 0; i < HASH_SIZE; i++) {
      if (h[key].empty()) {
	h[key] = str;
	return true;
      } else if (str == h[key]) {
	return false;
      } else {
	//printf("hit!\n");
	key = (key * key + a) % HASH_SIZE;
      }
    }
    //printf("!!\n");
    h[key] = str;
    return true;
  }
  hash_table():h(HASH_SIZE) {}
};

vector<char>operator+(const vector<char>& lhs, const vector<char>& rhs)
{
  vector<char> result = lhs;
  result.insert(result.end(), rhs.begin(), rhs.end());
  return result; 
}

int getline(char* str)
{
  char c;
  int idx = 0;
  while ((c = getchar()) != EOF) {
    //printf("%d\n", idx);
    if (c == '\n') {break;}
    str[idx++] = c;
    //printf("%c\n", str[idx - 1]);
  }
  return idx;
}

int main() {
  int N;
  scanf("%d ", &N);
  hash_table bag;
  char str[100];
  while (N--) {
    //gets(str);
    fgets(str, 100, stdin);
    if (strchr(str, '\n') != NULL) {
      a[strlen(a) - 1] = '\0';
    } else {
      while(getchar() != '\n');
    }

    //int end = getline(str);
    //if (N == 3) {printf("hoge\n");}
    int end;
    for (end = 0; str[end] != '\0'; end++);
    bag.h.clear();
    bag.h.resize(HASH_SIZE);

    int c = 0;
    vector<char> s = vector<char>(str, str + end - 1);
    /*
    printf("%d\n", s.size());
    for (int i = 0; i < s.size(); i++) {
      printf("%c", s[i]);
    }
    printf("\n");
    */
    bag[s];
    c++;
    if (bag[rev(s)]) {c++;}
    for (int i=1; i< end; i++) {
      vector<char> head(str, str + i);
      vector<char> tail(str + i, str + end - 1);
      //if (bag[head + tail]) c++;
      reverse(head.begin(), head.end());
      if (bag[head + tail]) c++;
      if (bag[tail + head]) c++;
      reverse(tail.begin(), tail.end());
      if (bag[head + tail]) c++;
      reverse(head.begin(), head.end());
      if (bag[head + tail]) c++;
      if (bag[tail + head]) c++;
      reverse(tail.begin(), tail.end());
      if (bag[tail + head]) c++;
    }
    printf("%d\n", c);
  }
  return 0;
}

Compiler output:
a.cc: In member function 'bool hash_table::operator[](std::vector<char>)':
a.cc:31:15: error: reference to 'hash' is ambiguous
   31 |     int key = hash(str);
      |               ^~~~
In file included from /usr/include/c++/14/string_view:50,
                 from /usr/include/c++/14/bits/basic_string.h:47,
                 from /usr/include/c++/14/string:54,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:2:
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
   59 |     struct hash;
      |            ^~~~
a.cc:15:5: note:                 'int hash(std::vector<char>)'
   15 | int hash(vector<char> str)
      |     ^~~~
a.cc: In function 'int main()':
a.cc:79:9: error: 'strchr' was not declared in this scope
   79 |     if (strchr(str, '\n') != NULL) {
      |         ^~~~~~
a.cc:8:1: note: 'strchr' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    7 | #include <algorithm>
  +++ |+#include <cstring>
    8 | 
a.cc:80:9: error: 'strlen' was not declared in this scope
   80 |       a[strlen(a) - 1] = '\0';
      |         ^~~~~~
a.cc:80:9: note: 'strlen' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'