[vjudge]
code
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<map>
using namespace std;
#define ll long long
#define vi vector<int>
int win[3][3]={
{0,-1,1},
{1,0,-1},
{-1,1,0}
};
int n,m,a[105][25],b[25];
map<vi,int>M;
ll ans;
void record()
{
vi tmp;tmp.clear();
for (int i=1;i<=m;++i)
{
int x=0;
for (int j=1;j<=n/2;++j) x+=win[b[j]][a[i][j]];
tmp.push_back(x);
}
++M[tmp];
}
void dfs1(int u)
{
if (u==n/2+1) {record();return;}
for (int i=0;i<=2;++i)
b[u]=i,dfs1(u+1);
}
void query()
{
vi tmp;tmp.clear();
for (int i=1;i<=m;++i)
{
int x=0;
for (int j=n/2+1;j<=n;++j) x+=win[b[j]][a[i][j]];
tmp.push_back(-x);
}
ans+=M[tmp];
}
void dfs2(int u)
{
if (u==n/2) {query();return;}
for (int i=0;i<=2;++i)
b[u]=i,dfs2(u-1);
}
ll yyb_solve()
{
dfs1(1);dfs2(n);
return ans;
}
/*
int main()
{
m=42;n=14;
for (int i=1;i<=m;++i)
for (int j=1;j<=n;++j)
{
char ch=getchar();
while (ch!='R'&&ch!='P'&&ch!='S') ch=getchar();
if (ch=='R') a[i][j]=0;
if (ch=='P') a[i][j]=1;
if (ch=='S') a[i][j]=2;
}
printf("%lld\n",yyb_solve());return 0;
}
*/
class EllysRPS{
public:
ll getCount(vector<string>s)
{
m=s.size();n=s[0].size();
for (int i=1;i<=m;++i)
for (int j=1;j<=n;++j)
{
if (s[i-1][j-1]=='R') a[i][j]=0;
if (s[i-1][j-1]=='P') a[i][j]=1;
if (s[i-1][j-1]=='S') a[i][j]=2;
}
return yyb_solve();
}
};