Language: C++

#include <bits/stdc++.h>
using namespace std;
#define N 32
#define INF 0x3f3f3f3f
string s[N],str[N],col[N],col2[N];
int hash[N],hash2[N];
vector <string> Hash[N<<15];
vector <string> Hash2[N<<15];
map <string,bool> vis;
map <string,bool> vis2;
int main()
{
	//freopen("qc.in","r",stdin);
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		cin>>s[i];
		for(int j=0;j<m;j++)
		{
			hash[i]+=s[i][j];
		}
		Hash[hash[i]].push_back(s[i]);
	}
	int cnt1=0,cnt2=0;
	for(int i=1;i<=n;i++)
	{
		if(Hash[hash[i]].size()%2==0)cnt2++;
		else cnt1++;
	}
	if(cnt1>=2)
	{
		puts("NO");
		return 0;
	}
	if(n%2==1)
	{
		for(int i=1;i<=n;i++)
		{
			if(Hash[hash[i]].size()%2==1)
			{
				str[n/2+1]=Hash[hash[i]][0];
				Hash[hash[i]].erase(Hash[hash[i]].begin());
				break;
			}
		}
	}
	int t=1;
	for(int i=1;i<=n;i++)
	{
		int len=Hash[hash[i]].size();
		for(int j=0;j<len;j++)
		{
			if(vis[Hash[hash[i]][j]])continue;
			vis[Hash[hash[i]][j]]=1;
			str[t]=Hash[hash[i]][j];
			str[n-t+1]=Hash[hash[i]][len-j-1];
			vis[Hash[hash[i]][len-j-1]]=1;
			t++;
		}
	}
	/*for(int i=1;i<=n;i++)
	{
		cout<<str[i]<<endl;
	}
	puts("");*/
	for(int j=1;j<=m;j++)
	{
		for(int i=1;i<=n;i++)
		{
			col[j]=col[j]+str[i][j-1];
		}
	}
	/*for(int j=1;j<=m;j++)
	{
		cout<<col[j]<<endl;
	}
	puts("");*/
	for(int j=1;j<=m;j++)
	{
		for(int i=0;i<n;i++)
		{
			hash2[j]+=col[j][i];
		}
		Hash2[hash2[j]].push_back(col[j]);
	}
	cnt1=0,cnt2=0;
	for(int i=1;i<=m;i++)
	{
		if(Hash2[hash2[i]].size()%2==0)cnt2++;
		else cnt1++;
	}
	if(cnt1>=2)
	{
		puts("NO");
		return 0;
	}
	if(m%2==1)
	{
		for(int i=1;i<=m;i++)
		{
			if(Hash2[hash2[i]].size()%2==1)
			{
				col2[n/2+1]=Hash2[hash2[i]][0];
				Hash2[hash2[i]].erase(Hash2[hash2[i]].begin());
				break;
			}
		}
	}
	t=1;
	for(int i=1;i<=m;i++)
	{
		int len=Hash2[hash2[i]].size();
		for(int j=0;j<len;j++)
		{
			if(vis2[Hash2[hash2[i]][j]])continue;
			vis2[Hash2[hash2[i]][j]]=1;
			col2[t]=Hash2[hash2[i]][j];
			col2[m-t+1]=Hash2[hash2[i]][len-j-1];
			vis2[Hash2[hash2[i]][len-j-1]]=1;
			t++;
		}
	}
	/*for(int i=1;i<=m;i++)
	{
		cout<<col2[i]<<endl;
	}*/
	/*for(int i=1;i<=m;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(col2[i][j]!=col2[m-i+1][n-j-1])
			{
				//printf("<%d,%d>[%c]<%d,%d>[%c]\n",i,j,col2[i][j],m-i+1,n-j-1,col2[m-i+1][n-j-1]);
				puts("NO");
				return 0;
			}
		}
	}*/
	puts("YES");
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:21:25: error: reference to 'hash' is ambiguous
   21 |                         hash[i]+=s[i][j];
      |                         ^~~~
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/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:1:
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
   59 |     struct hash;
      |            ^~~~
a.cc:6:5: note:                 'int hash [32]'
    6 | int hash[N],hash2[N];
      |     ^~~~
a.cc:23:22: error: reference to 'hash' is ambiguous
   23 |                 Hash[hash[i]].push_back(s[i]);
      |                      ^~~~
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
   59 |     struct hash;
      |            ^~~~
a.cc:6:5: note:                 'int hash [32]'
    6 | int hash[N],hash2[N];
      |     ^~~~
a.cc:28:25: error: reference to 'hash' is ambiguous
   28 |                 if(Hash[hash[i]].size()%2==0)cnt2++;
      |                         ^~~~
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
   59 |     struct hash;
      |            ^~~~
a.cc:6:5: note:                 'int hash [32]'
    6 | int hash[N],hash2[N];
      |     ^~~~
a.cc:40:33: error: reference to 'hash' is ambiguous
   40 |                         if(Hash[hash[i]].size()%2==1)
      |                                 ^~~~
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
   59 |     struct hash;
      |            ^~~~
a.cc:6:5: note:                 'int hash [32]'
    6 | int hash[N],hash2[N];
      |     ^~~~
a.cc:42:49: error: reference to 'hash' is ambiguous
   42 |                                 str[n/2+1]=Hash[hash[i]][0];
      |                                                 ^~~~
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
   59 |     struct hash;
      |            ^~~~
a.cc:6:5: note:                 'int hash [32]'
    6 | int hash[N],hash2[N];
      |     ^~~~
a.cc:43:38: error: reference to 'hash' is ambiguous
   43 |                                 Hash[hash[i]].erase(Hash[hash[i]].begin());
      |                                      ^~~~
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
   59 |     struct hash;
      |            ^~~~
a.cc:6:5: note:                 'int hash [32]'
    6 | int hash[N],hash2[N];
      |     ^~~~
a.cc:43:58: error: reference to 'hash' is ambiguous
   43 |                                 Hash[hash[i]].erase(Hash[hash[i]].begin());
      |                                                          ^~~~
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
   59 |     struct hash;
      |            ^~~~
a.cc:6:5: note:                 'int hash [32]'
    6 | int hash[N],hash2[N];
      |     ^~~~
a.cc:51:30: error: reference to 'hash' is ambiguous
   51 |                 int len=Hash[hash[i]].size();
      |                              ^~~~
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
   59 |     struct hash;
      |            ^~~~
a.cc:6:5: note:                 'int hash [32]'
    6 | int hash[N],hash2[N];
      |     ^~~~
a.cc:54:37: error: reference to 'hash' is ambiguous
   54 |                         if(vis[Hash[hash[i]][j]])continue;
      |                                     ^~~~
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
   59 |     struct hash;
      |            ^~~~
a.cc:6:5: note:                 'int hash [32]'
    6 | int hash[N],hash2[N];
      |     ^~~~
a.cc:55:34: error: reference to 'hash' is ambiguous
   55 |                         vis[Hash[hash[i]][j]]=1;
      |                                  ^~~~
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
   59 |     struct hash;
      |            ^~~~
a.cc:6:5: note:                 'int hash [32]'
    6 | int hash[N],hash2[N];
      |     ^~~~
a.cc:56:37: error: reference to 'hash' is ambiguous
   56 |                         str[t]=Hash[hash[i]][j];
      |                                     ^~~~
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
   59 |     struct hash;
      |            ^~~~
a.cc:6:5: note:                 'int hash [32]'
    6 | int hash[N],hash2[N];
      |     ^~~~
a.cc:57:41: error: reference to 'hash' is ambiguous
   57 |                         str[n-t+1]=Hash[hash[i]][len-j-1];
      |                                         ^~~~
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
   59 |     struct hash;
      |            ^~~~
a.cc:6:5: note:                 'int hash [32]'
    6 | int hash[N],hash2[N];
      |     ^~~~
a.cc:58:34: error: reference to 'hash' is ambiguous
   58 |                         vis[Hash[hash[i]][len-j-1]]=1;
      |                                  ^~~~
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
   59 |     struct hash;
      |            ^~~~
a.cc:6:5: note:                 'int hash [32]'
    6 | int hash[N],hash2[N];
      |     ^~~~