Problem:
Problem B:
Organize Your Train part II
RJ Freight, a Japanese railroad company for freight operations
has recently constructed exchange lines at Hazawa, Yokohama.
The layout of the lines is shown in Figure B-1.
Figure B-1: Layout of the exchange lines
A freight train consists of 2 to 72 freight cars.  There are 26
types of freight cars, which are denoted by 26 lowercase letters
from "a" to "z".  The cars of the same type are indistinguishable from
each other, and each car's direction doesn't matter either.
Thus, a string of lowercase letters of length 2 to 72 is sufficient
to completely express the configuration of a train.
Upon arrival at the exchange lines, a train is divided into two
sub-trains at an arbitrary position (prior to entering the
storage lines).  Each of the sub-trains may have its direction
reversed (using the reversal line).  Finally, the two sub-trains
are connected in either order to form the final configuration.
Note that the reversal operation is optional for each of the
sub-trains.
For example, if the arrival configuration is "abcd", the train
is split into two sub-trains of either 3:1, 2:2 or 1:3 cars.
For each of the splitting, possible final configurations are
as follows ("+" indicates final concatenation position):
[3:1]
    abc+d  cba+d  d+abc  d+cba
  [2:2]
    ab+cd  ab+dc  ba+cd  ba+dc  cd+ab  cd+ba  dc+ab  dc+ba
  [1:3]
    a+bcd  a+dcb  bcd+a  dcb+a
Excluding duplicates, 12 distinct configurations are possible.
Given an arrival configuration, answer 
the number of distinct configurations which can be
constructed using the exchange lines described above.
Input
The entire input looks like the following.
the number of datasets = m
1st dataset
2nd dataset
...
m-th dataset
Each dataset represents an arriving train, and is a string of
2 to 72 lowercase letters in an input line.
Output
For each dataset, output the number of possible train configurations
in a line.  No other characters should appear in the output.
Sample Input
4
aa
abba
abcd
abcde
Output for the Sample Input
1
6
12
18

Submitted solutions:

code_snippet: #include <iostream>
#include <algorithm>
#include <string>
#include <set>
using namespace std;

int main() {
    int N;
    cin >> N;
    for (int i=0; i<N; ++i) {
        string word;
        set<string> S;
        cin >> word;
        for (size_t j=0; j<=word.size(); ++j) {
            string l = word.substr(0, j);
            string r = word.substr(j);
            S.insert(l + r);
            S.insert(r + l);
            string reversed_l = l;
            reverse(reversed_l.begin(), reversed_l.end());
            string reversed_r = r;
            reverse(reversed_r.begin(), reversed_r.end());
            S.insert(l + reversed_r);
            S.insert(r + reversed_l);
            S.insert(reversed_l + r);
            S.insert(reversed_r + l);
            S.insert(reversed_l + reversed_r);
            S.insert(reversed_r + reversed_l);
        }
        cout << S.size() << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3540
final_rank: 9

code_snippet: #include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <cmath>
#include <map>
#include <queue>
#define N 75
using namespace std;
struct node
{
   char a[N];
}q[N*N];
int cnt;
bool judge(char s[])
{
    if(cnt == 0) return true;
    for(int i=0;i<cnt;i++)
    {
        if(strcmp(q[i].a,s)==0)
            return false;
    }
    return true;
}
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        char s[N];
        scanf("%s",s);
       int len=strlen(s);
       int ans=0;
       cnt=0;
       for(int i=0;i<len-1;i++)
       {

           char b1[80],b2[80];     // 如果四部分分别为 a1 a2 a3 a4
           int c1=0,c2=0;          // 其中 a3是a1的反串  a4是a2的反串
           for(int j=0;j<=i;j++)    //b1 = a1 + a4 
           {                        //b2 = a4 + a1
               b1[c1++]= s[j];    
           }
           for(int j=len-1;j>i;j--)
           {
               b1[c1++] = s[j];
               b2[c2++]= s[j];
           }
           for(int j=0;j<=i;j++)
           {
              b2[c2++] = s[j];
           }
           b1[c1]='\0';
           b2[c2]='\0';
           if(judge(b1))          //判断b1是否已经存在
           {
            strcpy(q[cnt++].a,b1);    //不存在记录下b1
               ans++;
           }
           if(judge(b2))
           {
             strcpy(q[cnt++].a,b2);
               ans++;
           }
           c1=0;
           c2=0;
           for(int j=0;j<=i;j++)    //b1 = a1 + a2
           {
              b1[c1++] = s[j];       //b2 = a2 + a1

           }
           for(int j=i+1;j<len;j++)
           {
               b1[c1++] = s[j];
               b2[c2++]= s[j];
           }
           for(int j=0;j<=i;j++)
           {
               b2[c2++]= s[j];
           }
          if(judge(b1))
           {
               strcpy(q[cnt++].a,b1);
               ans++;
           }
           if(judge(b2))
           {
             strcpy(q[cnt++].a,b2);
               ans++;
           }
           c1=0;
           c2=0;
           for(int j=i+1;j<len;j++)     //b1 = a2 + a3
           {
              b1[c1++] = s[j];          // b2 = a3 + a2
           }
           for(int j=i;j>=0;j--)
           {
               b1[c1++] = s[j];
               b2[c2++]= s[j];
           }
           for(int j=i+1;j<len;j++)
           {

               b2[c2++]= s[j];
           }
           if(judge(b1))
           {
               strcpy(q[cnt++].a,b1);
               ans++;
           }
           if(judge(b2))
           {
             strcpy(q[cnt++].a,b2);
               ans++;
           }
           c1=0;
           c2=0;
           for(int j=i;j>=0;j--)     //b1 = a3 + a4
           {
              b1[c1++] = s[j];       //b2 = a4 + a3

           }
           for(int j=len-1;j>i;j--)
           {
              b1[c1++] = s[j];
               b2[c2++]= s[j];
           }
           for(int j=i;j>=0;j--)
           {

               b2[c2++]= s[j];
           }
           if(judge(b1))
           {
               strcpy(q[cnt++].a,b1);
               ans++;
           }
           if(judge(b2))
           {
             strcpy(q[cnt++].a,b2);
               ans++;
           }
       }
       printf("%d\n",ans);
    }
    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3280
final_rank: 18

code_snippet: #include <map>
#include <string>
#include <iostream>
using namespace std;
string s;
map<string,int>t;
int TS;
int main(){
    cin >> TS;
    for(int O=1; O<=TS; O++){
        cin >> s;
        t.clear();
        int ANS = 0;
        int N = (int)s.length();
        for(int i=1; i<N; i++){
            string a = "";
            for(int j=0; j<i; j++)
                a+= s[j];
            string b = "";
            for(int j=i-1; j>=0; j--)
                b+= s[j];
            string c = "";
            for(int j=i; j<N; j++)
                c+= s[j];
            string d = "";
            for(int j=N-1; j>=i; j--)
                d+= s[j];
            if(!t[a+c]){
                t[a+c] = 1;
                ANS++;
            }
            if(!t[a+d]){
                t[a+d] = 1;
                ANS++;
            }
            if(!t[b+c]){
                t[b+c] = 1;
                ANS++;
            }
            if(!t[b+d]){
                t[b+d] = 1;
                ANS++;
            }
            if(!t[c+a]){
                t[c+a] = 1;
                ANS++;
            }
            if(!t[d+a]){
                t[d+a] = 1;
                ANS++;
            }
            if(!t[c+b]){
                t[c+b] = 1;
                ANS++;
            }
            if(!t[d+b]){
                t[d+b] = 1;
                ANS++;
            }
        }
        cout << ANS << endl;
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3396
final_rank: 5

code_snippet: #include <iostream>
#include <cstring>
#include <set>

using namespace std;

set<string> s;
string t;
int n, len;

string reverse(const string &s) {
	string res = "";
	for (int i = s.length() - 1; ~i; i--)
		res += s[i];
	return res;
}

string x, y, _x, _y;
int main() {
	ios::sync_with_stdio(0);
	cin >> n;
	while (n--) {
		cin >> t;
		s.clear();
		len = t.length();
		for (int i = 1; i < len; i++) {
			x = t.substr(0, i);
			y = t.substr(i, len);
			_x = reverse(x);
			_y = reverse(y);
			s.insert(x + y);
			s.insert(x + _y);
			s.insert(_x + y);
			s.insert(_x + _y);
		}
		t = reverse(t);
		for (int i = 1; i < len; i++) {
			x = t.substr(0, i);
			y = t.substr(i, len);
			_x = reverse(x);
			_y = reverse(y);
			s.insert(x + y);
			s.insert(x + _y);
			s.insert(_x + y);
			s.insert(_x + _y);
		}
		cout << s.size() << endl;
	}
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3360
final_rank: 2

code_snippet: #include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<map>
#include<string> 
using namespace std;
map<string,bool>m;
string a,b,c,d;
char s[200];
int n;
int main(){
	scanf("%d",&n);
	long long sol;
	for(int i=1;i<=n;i++){ 
		memset(s,0,sizeof(s));
		scanf("%s",s); 
		m.clear();
		sol=0;
		for(int j=1;j<strlen(s);j++){
			a=b=c=d="";
			for(int k=0;k<j;k++){
				a=a+s[k];
				b=s[k]+b;
			}
			for(int k=j;k<strlen(s);k++){
				c=c+s[k];
				d=s[k]+d;
			}
			if(m[a+c]==0)sol++;
			m[a+c]=1;
			if(m[a+d]==0)sol++;
			m[a+d]=1;
			if(m[b+c]==0)sol++;
			m[b+c]=1;
			if(m[b+d]==0)sol++;
			m[b+d]=1;
			if(m[c+a]==0)sol++;
			m[c+a]=1;
			if(m[d+a]==0)sol++;
			m[d+a]=1;
			if(m[c+b]==0)sol++;
			m[c+b]=1;
			if(m[d+b]==0)sol++;
			m[d+b]=1; 
		}
		printf("%lld\n",sol);
	}
	return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 3556
final_rank: 19

code_snippet: #include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <tr1/unordered_set>
#include <set>
using namespace std;
using namespace tr1;
#define fromto(from,to,i) for(int i=(from);i<=(to);++i)
const int MAXN = 108;

int main()
{
	int case_cnt;
	scanf("%d",&case_cnt);
	while(case_cnt--) {
		char str[MAXN];
		scanf("%s",str);
		int N = strlen(str);
		unordered_set<string> tset;
		fromto(1,N-1,i) { //[0,i)[i,N)
			fromto(0,1,t1) fromto(0,1,t2) fromto(0,1,t3) {
				char str2[MAXN];
				strcpy(str2,str);
				if(t1) {
					reverse(str2,str2+i);
				}
				if(t2) {
					reverse(str2+i,str2+N);
				}
				if(t3) {
					char tstr[MAXN];
					strcpy(tstr,str2);
					copy(str2+i,str2+N,tstr);
					copy(str2,str2+i,tstr+N-i);
					strcpy(str2,tstr);
				}
				tset.insert(string(str2));
			}
		}
		printf("%d\n",tset.size());
	}
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3388
final_rank: 3

code_snippet: #include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <set>
using namespace std;
#define fromto(from,to,i) for(int i=(from);i<=(to);++i)
const int MAXN = 108;

int main()
{
	int case_cnt;
	scanf("%d",&case_cnt);
	while(case_cnt--) {
		char str[MAXN];
		scanf("%s",str);
		int N = strlen(str);
		set<string> tset;
		fromto(1,N-1,i) { //[0,i)[i,N)
			fromto(0,1,t1) fromto(0,1,t2) fromto(0,1,t3) {
				char str2[MAXN];
				strcpy(str2,str);
				if(t1) {
					reverse(str2,str2+i);
				}
				if(t2) {
					reverse(str2+i,str2+N);
				}
				if(t3) {
					char tstr[MAXN];
					strcpy(tstr,str2);
					copy(str2+i,str2+N,tstr);
					copy(str2,str2+i,tstr+N-i);
					strcpy(str2,tstr);
				}
				tset.insert(string(str2));
			}
		}
		printf("%d\n",tset.size());
	}
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3468
final_rank: 8

code_snippet: #include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <set>
using namespace std;
#define fromto(from,to,i) for(int i=(from);i<=(to);++i)
const int MAXN = 108;
int main()
{
	int case_cnt;
	scanf("%d",&case_cnt);
	while(case_cnt--) {
		char str[MAXN];
		scanf("%s",str+1);
		int N = strlen(str+1);
		set<string> tset;
		fromto(1,N-1,i) { //[1,i][i+1,N]
			fromto(0,1,t1) fromto(0,1,t2) fromto(0,1,t3) {
				string newstr(str+1); //[0,i-1][i,N-1]
				if(t1) {
					reverse(newstr.begin(),newstr.begin()+i);
				}
				if(t2) {
					reverse(newstr.begin()+i,newstr.begin()+N);
				}
				if(t3) {
					string tstr=newstr;
					copy(newstr.begin()+i,newstr.begin()+N,tstr.begin());
					copy(newstr.begin(),newstr.begin()+i,tstr.begin()+N-i);
					newstr = tstr;
				}
				tset.insert(newstr);
			}
		}
		printf("%d\n",tset.size());
	}
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3552
final_rank: 10

code_snippet: #include <cstdio>
#include <iostream>
#include <algorithm>
#include <map>
#include <cstring>
#include <string>
using namespace std;
int cases,n,tot;
char s[1010];
map<string,int> hashh;
string temp;
int main()
{
	cin >> cases;
	while (cases--)
	{
		scanf("%s",s+1);
		int n = strlen(s+1);
		tot++;int ans = 0;
		//cout << n << endl;
		for (int i = 1;i < n;i++)
		{
			temp = "";
			for (int j = 1;j <= i;j++) temp+=s[j];
			for (int j = i + 1;j <= n;j++) temp+=s[j];
			if (hashh[temp] != tot) ans++,hashh[temp] = tot;

			temp = "";
			for (int j = i;j >= 1;j--) temp+=s[j];
			for (int j = i + 1;j <= n;j++) temp+=s[j];
			if (hashh[temp] != tot) ans++,hashh[temp] = tot;

			temp = "";
			for (int j = 1;j <= i;j++) temp+=s[j];
			for (int j = n;j >= i + 1;j--) temp+=s[j];
			if (hashh[temp] != tot) ans++,hashh[temp] = tot;

			temp = "";
			for (int j = i;j >= 1;j--) temp+=s[j];
			for (int j = n;j >= i + 1;j--) temp+=s[j];
			if (hashh[temp] != tot) ans++,hashh[temp] = tot;


			temp = "";
			for (int j = i + 1;j <= n;j++) temp+=s[j];
			for (int j = 1;j <= i;j++) temp+=s[j];
			if (hashh[temp] != tot) ans++,hashh[temp] = tot;

			temp = "";
			for (int j = i + 1;j <= n;j++) temp+=s[j];
			for (int j = i;j >= 1;j--) temp+=s[j];
			if (hashh[temp] != tot) ans++,hashh[temp] = tot;

			temp = "";
			for (int j = n;j >= i + 1;j--) temp+=s[j];
			for (int j = 1;j <= i;j++) temp+=s[j];
			if (hashh[temp] != tot) ans++,hashh[temp] = tot;

			temp = "";
			for (int j = n;j >= i + 1;j--) temp+=s[j];
			for (int j = i;j >= 1;j--) temp+=s[j];
			if (hashh[temp] != tot) ans++,hashh[temp] = tot;

		}
		cout << ans << endl;
	}
}
accuracy: 1
time_ms: 20
memory_kb: 8628
final_rank: 20

code_snippet: #include<cstdio>
#include<string>
#include<map>
#include<iostream>
using namespace std;
string s,pre[4];
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
      cin>>s;
      map<string,int>mp;
      int l = s.size(),ans = 0;
      for(int i=1;i<l;i++)
          {
            pre[0] = s.substr(0,i);
            pre[1] = pre[0];
            for(int j=0;j<i;j++)
                pre[1].at(j) = s.at(i-j-1);
            pre[2] = s.substr(i,l-i);
            pre[3] = pre[2];
            for(int j=i;j<l;j++)
                pre[3].at(j-i) = s.at(l-j+i-1);
            for(int j=0;j<=1;j++)
                for(int k=2;k<=3;k++)
                {
                   mp[pre[j]+pre[k]]++;
                   mp[pre[k]+pre[j]]++;
                }
          }
        cout<<mp.size()<<endl;
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3608
final_rank: 12

code_snippet: //#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<map>
#include<cmath>
#include<queue>
#include<stack>
#include<ctime>
#include<vector>
#include<set>
#include<cfloat>

using namespace std;

const int maxn=1500;
const int INF=999999999;
const float eps = 0.00000001;
const int mod=100000007;
const int prime=100003;
const int VM=60;
const int EM=10020;

typedef pair<int,int> P;
//int dir[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
//int dir[4][2]={{0,1},{0,-1},{-1,0},{1,0}};
//int dir[4][2]={{1,0},{0,-1},{-1,0},{0,1}};
//int dir[8][2]={{-2,-1},{-1,-2},{1,-2},{2,-1},{-2,1},{-1,2},{1,2},{2,1}};
//int dir[8][2]={{-1,-2},{-2,-1},{-2,1},{-1,2},{1,-2},{2,-1},{2,1},{1,2}};
//int dir[8][2]={{-1,-2},{1,-2},{-2,-1},{2,-1},{-2,1},{2,1},{-1,2},{1,2}};
//int dir[8][2]={{-1,-2},{1,-2},{-2,-1},{2,-1},{-2,1},{2,1},{-1,2},{1,2}};
int dir[6][3]={{-1,0,0},{1,0,0},{0,-1,0},{0,1,0},{0,0,1},{0,0,-1}};

char str[120];
char s1[120],s2[120];
char t1[120],t2[120];
char res[120];

void splitStr(char s[],int x,int len){
    int c1=0,c2=0;
    for(int i=0;i<x;i++){
        s1[c1++]=s[i];
    }
    s1[c1]='\0';
    for(int i=x;i<len;i++){
        s2[c2++]=s[i];
    }
    s2[c2]='\0';
}

void unionStr(char a[],char b[],char ans[]){
    int c1=strlen(a);
    int c2=strlen(b);
    int c3=0;
    for(int i=0;i<c1;i++){
        ans[c3++]=a[i];
    }
    for(int i=0;i<c2;i++){
        ans[c3++]=b[i];
    }
    ans[c3]='\0';
}

void reverseStr(char tmp[]){
    int len=strlen(tmp);
    char c;
    for(int i=len-1;i>=len/2;i--){
        c=tmp[i];
        tmp[i]=tmp[len-1-i];
        tmp[len-1-i]=c;
    }
}

int main(){

    //freopen("input.txt","r",stdin);

    //freopen("out.txt","w",stdout);

    int t;
    scanf("%d",&t);
    while(t--){
        scanf("%s",str);
        int len=strlen(str);
        map<string,int > mp;
        map<string,int>::iterator it;
        for(int i=1;i<len;i++){
            splitStr(str,i,len);

            unionStr(s1,s2,res);
            mp[res]=1;
            unionStr(s2,s1,res);
            mp[res]=1;

            strcpy(t1,s1);
            strcpy(t2,s2);
            reverseStr(t1);
            reverseStr(t2);

            unionStr(s1,t2,res);
            mp[res]=1;
            unionStr(t2,s1,res);
            mp[res]=1;
            unionStr(t1,s2,res);
            mp[res]=1;
            unionStr(t1,t2,res);
            mp[res]=1;
            unionStr(s2,t1,res);
            mp[res]=1;
            unionStr(t2,t1,res);
            mp[res]=1;
        }

        //strcpy(res,"sss");

        printf("%d\n",mp.size());
    }


    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3672
final_rank: 14

code_snippet: #include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<algorithm>
#include<set>
using namespace std;

const int mod = 10007;
const int maxn = 200;
bool has1[mod],has2[mod];
set<string> has;

/*
int h1(string s){
	int cnt=0;
	for(int i=0;i<s.size();++i){
		cnt=(31*cnt+s[i]-'a')%mod;
	}
	return cnt;
}

int h2(string s){
	int cnt=0;
	for(int i=0;i<s.size();++i){
		cnt=(37*cnt+s[i]-'a')%mod;
	}
	return cnt;
}
*/

int deal(string s){
	if(has.find(s)!=has.end()) return 0;
	has.insert(s);
	return 1;
}

inline string rev(string s){
	reverse(s.begin(),s.end());
	return s;
}

int solve(char* s){
	has.clear();
	int ans=1;
	string s1,s2(s);
	s1.clear();
	has.insert(s2);
	for(int i=0;i<strlen(s)-1;++i){
		s1.push_back(s[i]);
		s2.erase(s2.begin());
//		cout<<s1<<" "<<s2<<endl;

		ans+=deal(rev(s1)+s2);
		ans+=deal(s1+rev(s2));
		ans+=deal(rev(s1)+rev(s2));

		ans+=deal(s2+s1);
		ans+=deal(rev(s2)+s1);
		ans+=deal(s2+rev(s1));
		ans+=deal(rev(s2)+rev(s1));
	}
	return ans;
}

int main()
{
	//freopen("test.txt","r",stdin);
	int m;
	char s[maxn];
	scanf("%d",&m);
	for(int i=0;i<m;++i){
		scanf("%s",s);
		printf("%d\n",solve(s));	
	}
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3556
final_rank: 11

code_snippet: #include<cstdio>
#include<cstring>
#include<string>
#include<set>
#include<iostream>

using namespace std;

const int maxn = 80;

set<string> has;

int deal(string s){
	if(has.find(s)!=has.end()) return 0;
	has.insert(s);
	return 1;
}

string rev(string s){
	for(int i=0;i<s.size()/2;++i) swap(s[i],s[s.size()-i-1]);
	return s;
}

int solve(char* ss){
	int ans=1;
	string s(ss);
	has.clear();
	string s1,s2(s);
	s1.clear();
	has.insert(s);
	for(int i=0;i<s.size();++i){
		s1.push_back(s[i]);
		s2.erase(s2.begin());
		ans+=deal(rev(s1)+s2);
		ans+=deal(s1+rev(s2));
		ans+=deal(rev(s1)+rev(s2));

		ans+=deal(s2+s1);
		ans+=deal(rev(s2)+s1);
		ans+=deal(s2+rev(s1));
		ans+=deal(rev(s2)+rev(s1));
	}
	return ans;
}

int main()
{
//	freopen("test.txt","r",stdin);
	int m;
	char s[maxn];
	scanf("%d",&m);
	for(int i=0;i<m;++i){
		scanf("%s",s);
		printf("%d\n",solve(s));	
	}
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3648
final_rank: 13

code_snippet: #include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<set>
#include<iostream>
using namespace std;

string save;
int len;
set<string> vis;
int cnt;

void insert(string& s)
{
    if(vis.find(s) == vis.end())
    {
     //   cout << s << endl;
        vis.insert(s);
        cnt++;
    }
}
void solve()
{
    vis.clear();
    cnt = 0;
    for(int i = 1;i <= len-1;++i)
    {
        string a = save.substr(0,i);
        string b = save.substr(i,len-i);
      //  cout << a << "    " << b << endl;
        string ra = a; reverse(ra.begin(),ra.end());
        string rb = b; reverse(rb.begin(),rb.end());
        for(int j = 0;j < 2;++j)
        {
            string t1 = a +  b , t2 = ra + b;
            string t3 = a + rb , t4 = ra + rb;
        //    cout << t1 << "  " << t2 << "  " << t3 << "  " << t4 << endl;
            insert(t1);
            insert(t2);
            insert(t3);
            insert(t4);
            if(j == 0)
            {
                swap(a,b);
                swap(ra,rb);
            }
        }
    }
}



int main()
{
  //  freopen("./test.txt","r",stdin);
    int kase;
    cin >> kase;
    while(kase--)
    {
        cin >> save;
        len = save.length();
        solve();
        cout << cnt << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3436
final_rank: 7

code_snippet: #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
using namespace std;

char save[80];
char a[80];
char b[80];
typedef pair<string,int> psi;

int main()
{
    int t;
    scanf("%d",&t);
    while (t--)
    {
        scanf("%s",save);
        int len = strlen(save);
        int i;
        map<string,int> m;
        int cnt = 0;
        for (i = 1; i < len; i++)
        {
            sprintf(a,save);
            sprintf(b,save+i);
            a[i] = 0;

            string tmp = string(a) + string(b);
            if (m.find(tmp) == m.end())
            {
                cnt++;
                m.insert(psi(string(tmp),cnt));
            }
            tmp = string (b) + string (a);
            if (m.find(tmp) == m.end())
            {
                cnt++;
                m.insert (psi(string(tmp),cnt));
            }

            reverse (a,a+i);
            tmp = string(a) + string(b);
            if (m.find(tmp) == m.end())
            {
                cnt++;
                m.insert(psi(string(tmp),cnt));
            }
            tmp = string (b) + string (a);
            if (m.find(tmp) == m.end())
            {
                cnt++;
                m.insert (psi(string(tmp),cnt));
            }

            reverse (b,b+len-i);
            tmp = string(a) + string(b);
            if (m.find(tmp) == m.end())
            {
                cnt++;
                m.insert(psi(string(tmp),cnt));
            }
            tmp = string (b) + string (a);
            if (m.find(tmp) == m.end())
            {
                cnt++;
                m.insert (psi(string(tmp),cnt));
            }

            reverse (a,a+i);
            tmp = string(a) + string(b);
            if (m.find(tmp) == m.end())
            {
                cnt++;
                m.insert(psi(string(tmp),cnt));
            }
            tmp = string (b) + string (a);
            if (m.find(tmp) == m.end())
            {
                cnt++;
                m.insert (psi(string(tmp),cnt));
            }

        }
        printf("%d\n",cnt);
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3676
final_rank: 15

code_snippet: #include<stdio.h>
#include<algorithm>
#include<string.h>
#include<map>
#include<string>
#include<iostream>
using namespace std ;

map<string,int> mp ;
char s[111] ;
char s1[111] , s2[111] , f[1111] ;

void reverse ( char *s , int len ) {
    int i ;
    for ( i = 0 ; i < (len+1) / 2 ; i ++ )
        swap ( s[i] , s[len-i-1] ) ;
}

void jion ( char *s , char *s1 , char *s2 , int l1 , int l2 ) {
    int len = 0 ;
    int i ;
    for ( i = 0 ; i < l1 ; i ++ ) s[len++] = s1[i] ;
    for ( i = 0 ; i < l2 ; i ++ ) s[len++] = s2[i] ;
    s[len] = 0 ;
}

int main () {
    int t , i ;
    scanf ( "%d" , &t ) ;
    while ( t -- ) {
        scanf ( "%s" , s ) ;
        int len = strlen ( s ) ;
        mp.clear () ;
        int ans = 0 ;
        for ( i = 0 ; i < len - 1 ; i ++ ) {
            s1[i] = s[i] , s1[i+1] = 0 ;
            strcpy ( s2 , s + i + 1  ) ;
            int l1 = i + 1 , l2 = len - l1 ;
            jion ( f , s1 , s2 , l1 , l2 ) ;
            if ( !mp.count ( f ) ) ans ++ , mp[f] = 1 ;
            jion ( f , s2 , s1 , l2 , l1 ) ;
            if ( !mp.count ( f ) ) ans ++ , mp[f] = 1 ;
            reverse ( s2 , l2 ) ;
            jion ( f , s1 , s2 , l1 , l2 ) ;
            if ( !mp.count ( f ) ) ans ++ , mp[f] = 1 ;
            jion ( f , s2 , s1 , l2 , l1 ) ;
            if ( !mp.count ( f ) ) ans ++ , mp[f] = 1 ;
            reverse ( s1 , l1 ) ;
            jion ( f , s1 , s2 , l1 , l2 ) ;
            if ( !mp.count ( f ) ) ans ++ , mp[f] = 1 ;
            jion ( f , s2 , s1 , l2 , l1 ) ;
            if ( !mp.count ( f ) ) ans ++ , mp[f] = 1 ;
            reverse ( s2 , l2 ) ;
            jion ( f , s1 , s2 , l1 , l2 ) ;
            if ( !mp.count ( f ) ) ans ++ , mp[f] = 1 ;
            jion ( f , s2 , s1 , l2 , l1 ) ;
            if ( !mp.count ( f ) ) ans ++ , mp[f] = 1 ;
            reverse ( s1 ,  l1 ) ;
        }
        printf ( "%d\n" , ans ) ;
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3424
final_rank: 6

code_snippet: #include<stdio.h>
#include<algorithm>
#include<string.h>
#include<map>
#include<string>
#include<iostream>
using namespace std ;

map<string,int> mp ;
char s[111] ;
char s1[111] , s2[111] ;

void reverse ( char *s , int len ) {
    int i ;
    for ( i = 0 ; i < (len+1) / 2 ; i ++ )
        swap ( s[i] , s[len-i-1] ) ;
}

int main () {
    int t , i ;
    scanf ( "%d" , &t ) ;
    while ( t -- ) {
        scanf ( "%s" , s ) ;
        int len = strlen ( s ) ;
        mp.clear () ;
        int ans = 0 ;
        string t = "" ;
        for ( i = 0 ; i < len - 1 ; i ++ ) {
            s1[i] = s[i] , s1[i+1] = 0 ;
            strcpy ( s2 , s + i + 1  ) ;
            int l1 = i + 1 , l2 = len - l1 ;
            t = "" ;
            t = t + s1 + s2 ;
       //     cout << t << endl ;
            if ( !mp.count ( t ) ) ans ++ , mp[t] = 1 ;
            t = "" ;
            t = t + s2 + s1 ;
            if ( !mp.count ( t ) ) ans ++ , mp[t] = 1 ;
            reverse ( s2 , l2 ) ;
            t = "" ;
            t = t + s1 + s2 ;
       //     cout << t << endl ;
            if ( !mp.count ( t ) ) ans ++ , mp[t] = 1 ;
            t = "" ;
            t = t + s2 + s1 ;
            if ( !mp.count ( t ) ) ans ++ , mp[t] = 1 ;
            reverse ( s1 , l1 ) ;
            t = "" ;
            t = t + s1 + s2 ;
      //      cout << t << endl ;
            if ( !mp.count ( t ) ) ans ++ , mp[t] = 1 ;
            t = "" ;
            t = t + s2 + s1 ;
            if ( !mp.count ( t ) ) ans ++ , mp[t] = 1 ;
            reverse ( s2 , l2 ) ;
            t = "" ;
            t = t + s1 + s2 ;
            if ( !mp.count ( t ) ) ans ++ , mp[t] = 1 ;
            t = "" ;
            t = t + s2 + s1 ;
            if ( !mp.count ( t ) ) ans ++ , mp[t] = 1 ;
            reverse ( s1 ,  l1 ) ;
        }
        printf ( "%d\n" , ans ) ;
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3696
final_rank: 17

code_snippet: #include<stdio.h>
#include<algorithm>
#include<string.h>
#include<map>
#include<string>
#include<iostream>
using namespace std ;

map<string,int> mp ;
char s[111] ;
char s1[111] , s2[111] ;

int main () {
    int t , i ;
    scanf ( "%d" , &t ) ;
    while ( t -- ) {
        scanf ( "%s" , s ) ;
        int len = strlen ( s ) ;
        mp.clear () ;
        int ans = 0 ;
        string t = "" ;
        for ( i = 0 ; i < len - 1 ; i ++ ) {
            s1[i] = s[i] , s1[i+1] = 0 ;
            strcpy ( s2 , s + i + 1  ) ;
            int l1 = i + 1 , l2 = len - l1 ;
            t = "" ;
            t = t + s1 + s2 ;
       //     cout << t << endl ;
            if ( !mp.count ( t ) ) ans ++ , mp[t] = 1 ;
            t = "" ;
            t = t + s2 + s1 ;
            if ( !mp.count ( t ) ) ans ++ , mp[t] = 1 ;
            reverse ( s2 , s2 + l2 ) ;
            t = "" ;
            t = t + s1 + s2 ;
       //     cout << t << endl ;
            if ( !mp.count ( t ) ) ans ++ , mp[t] = 1 ;
            t = "" ;
            t = t + s2 + s1 ;
            if ( !mp.count ( t ) ) ans ++ , mp[t] = 1 ;
            reverse ( s1 , s1 + l1 ) ;
            t = "" ;
            t = t + s1 + s2 ;
      //      cout << t << endl ;
            if ( !mp.count ( t ) ) ans ++ , mp[t] = 1 ;
            t = "" ;
            t = t + s2 + s1 ;
            if ( !mp.count ( t ) ) ans ++ , mp[t] = 1 ;
            reverse ( s2 , s2 + l2 ) ;
            t = "" ;
            t = t + s1 + s2 ;
            if ( !mp.count ( t ) ) ans ++ , mp[t] = 1 ;
            t = "" ;
            t = t + s2 + s1 ;
            if ( !mp.count ( t ) ) ans ++ , mp[t] = 1 ;
            reverse ( s1 , s1 + l1 ) ;
        }
        printf ( "%d\n" , ans ) ;
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3680
final_rank: 16

code_snippet: #include<iostream>
#include<string>
#include<set>
#include<functional>
std::set<size_t> set;
int main() {
  int testCount;
  std::cin>>testCount;
  while(testCount--) {
    std::string s;
    std::cin>>s;
    set.clear();
    std::hash<std::string> hash_fn;
    for(int i=1; i<s.size(); ++i) {
      std::string a=s.substr(0,i);
      std::string b=s.substr(i,s.size()-i);
      std::string ra,rb;
      for(int j=0; j<a.size(); ++j) {
        ra=a[j]+ra;
      }
      for(int j=0; j<b.size(); ++j) {
        rb=b[j]+rb;
      }
      set.insert(hash_fn(a+b));
      set.insert(hash_fn(b+a));
      set.insert(hash_fn(ra+b));
      set.insert(hash_fn(b+ra));
      set.insert(hash_fn(a+rb));
      set.insert(hash_fn(rb+a));
      set.insert(hash_fn(ra+rb));
      set.insert(hash_fn(rb+ra));
    }
    std::cout<<set.size()<<std::endl;
  }
}
accuracy: 1
time_ms: 10
memory_kb: 3320
final_rank: 1

code_snippet: #include<iostream>
#include<string>
#include<set>
std::set<std::string> set;
int main() {
  int testCount;
  std::cin>>testCount;
  while(testCount--) {
    std::string s;
    std::cin>>s;
    set.clear();
    for(int i=1; i<s.size(); ++i) {
      std::string a=s.substr(0,i);
      std::string b=s.substr(i,s.size()-i);
      std::string ra,rb;
      for(int j=0; j<a.size(); ++j) {
        ra=a[j]+ra;
      }
      for(int j=0; j<b.size(); ++j) {
        rb=b[j]+rb;
      }
      set.insert(a+b);
      set.insert(b+a);
      set.insert(ra+b);
      set.insert(b+ra);
      set.insert(a+rb);
      set.insert(rb+a);
      set.insert(ra+rb);
      set.insert(rb+ra);
    }
    std::cout<<set.size()<<std::endl;
  }
}
accuracy: 1
time_ms: 10
memory_kb: 3392
final_rank: 4