Language: C++

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

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:32:15: error: reference to 'hash' is ambiguous
   32 |     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:16:5: note:                 'int hash(std::vector<char>)'
   16 | int hash(vector<char> str)
      |     ^~~~
a.cc: In function 'int main()':
a.cc:14:11: error: invalid conversion from 'int' to 'const char*' [-fpermissive]
   14 | #define a 1049
      |           ^~~~
      |           |
      |           int
a.cc:81:16: note: in expansion of macro 'a'
   81 |       a[strlen(a) - 1] = '\0';
      |                ^
In file included from /usr/include/c++/14/cstring:43,
                 from a.cc:8:
/usr/include/string.h:407:35: note:   initializing argument 1 of 'size_t strlen(const char*)'
  407 | extern size_t strlen (const char *__s)
      |                       ~~~~~~~~~~~~^~~
a.cc:81:8: error: invalid types 'int[size_t {aka long unsigned int}]' for array subscript
   81 |       a[strlen(a) - 1] = '\0';
      |        ^