func_code_string: #include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   int n, m, num[40][40], len = 0, stat[20], sv[20], ans = 0;   bool vis[10][10], vis2[10][10], usedr[10], have = false;   string s[40];   vector<pair<int, int> > coo[400];   vector<int> pr[20];   bool stane = false;   bool check(int pos) {     map<pair<int, int>, int> mp;     mp.clear();     for (int i = 0; i < pr[pos].size(); ++i) {       int x = stat[pos], y = stat[pr[pos][i]];       if (vis[x][y] || mp[make_pair(x, y)]) return false;       mp[make_pair(x, y)] = mp[make_pair(y, x)] = true;     }     return true;   }   void add(int pos, bool val) {     for (int i = 0; i < pr[pos].size(); ++i) {       int x = stat[pos], y = stat[pr[pos][i]];       vis[x][y] = vis[y][x] = val;     }   }   void dfs(int pos, int curc) {     if (pos == 14) {       ++ans;       if (!have) {         have = true;         for (int i = 0; i < 14; ++i) sv[i] = stat[i];       }       return;     }     if (curc < 7) {       stat[pos] = curc;       if (check(pos)) {         add(pos, true);         dfs(pos + 1, curc + 1);         add(pos, false);       }     }     for (int i = 0; i < curc; ++i) {       if (usedr[i]) continue;       stat[pos] = i;       if (check(pos)) {         usedr[i] = true;         add(pos, true);         dfs(pos + 1, curc);         usedr[i] = false;         add(pos, false);       }     }   }   int main() {     cin >> n >> m;     for (int i = 0; i < n; ++i) {       cin >> s[i];       for (int j = 0; j < m; ++j)         if (s[i][j] ==  A )           s[i][j] =  z  + 1;         else if (s[i][j] ==  B )           s[i][j] =  z  + 2;     }     for (int i = 0; i < n + 5; ++i)       for (int j = 0; j < m + 5; ++j) num[i][j] = -1;     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j)         if ( a  <= s[i][j] && s[i][j] <=  z  + 2) {           coo[s[i][j]].push_back(make_pair(i, j));           if (num[i][j] == -1) {             for (int k = i; k < i + 2; ++k)               for (int p = j; p < j + 2; ++p) num[k][p] = len;             ++len;           }         }     for (int i =  a ; i <=  z  + 2; ++i) {       int x = coo[i][0].first, y = coo[i][0].second, xx = coo[i][1].first,           yy = coo[i][1].second;       pr[max(num[x][y], num[xx][yy])].push_back(min(num[x][y], num[xx][yy]));     }     dfs(0, 0);     cout << ans * 5040 << endl;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         if (!( a  <= s[i][j] && s[i][j] <=  z  + 2))           cout <<  . ;         else           cout << sv[num[i][j]];       }       cout << endl;     }     return 0;   }   