#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   int n;   int mt[256][256];   int xy[256], yx[256];   int lx[256], ly[256], slk[256], slkx[256], prv[256];   char S[256], T[256];   void updtree(int x) {     for (int y = 0; y < (int)(n); y++)       if (lx[x] + ly[y] - mt[x][y] < slk[y]) {         slk[y] = lx[x] + ly[y] - mt[x][y];         slkx[y] = x;       }   }   int hungar() {     for (int i = 0; i < (int)(n); i++) {       ly[i] = 0;       lx[i] = *max_element(mt[i], mt[i] + n);     }     memset(xy, -1, sizeof(xy));     memset(yx, -1, sizeof(yx));     for (int m = 0; m < (int)(n); m++) {       memset(S, 0, sizeof(S));       memset(T, 0, sizeof(T));       memset(prv, -1, sizeof(prv));       memset(slk, 0x7f, sizeof(slk));       queue<int> q;       for (int i = 0; i < (int)(n); i++)         if (xy[i] == -1) {           {             q.push(i);             prv[i] = -2;             S[i] = 1;             updtree(i);           };           break;         }       int x = 0, y = -1;       while (y == -1) {         while (!q.empty() && y == -1) {           x = q.front();           q.pop();           for (int j = 0; j < (int)(n); j++)             if (mt[x][j] == lx[x] + ly[j] && !T[j]) {               if (yx[j] == -1) {                 y = j;                 break;               }               T[j] = 1;               {                 q.push(yx[j]);                 prv[yx[j]] = x;                 S[yx[j]] = 1;                 updtree(yx[j]);               };             }         }         if (y != -1) break;         int dlt = 0x7f7f7f7f;         for (int j = 0; j < (int)(n); j++)           if (!T[j]) dlt = min(dlt, slk[j]);         for (int k = 0; k < (int)(n); k++) {           if (S[k]) lx[k] -= dlt;           if (T[k]) ly[k] += dlt;           if (!T[k]) slk[k] -= dlt;         }         for (int j = 0; j < (int)(n); j++)           if (!T[j] && !slk[j]) {             if (yx[j] == -1) {               x = slkx[j];               y = j;               break;             } else {               T[j] = 1;               if (!S[yx[j]]) {                 q.push(yx[j]);                 prv[yx[j]] = slkx[j];                 S[yx[j]] = 1;                 updtree(yx[j]);               };             }           }       }       if (y != -1) {         for (int p = x; p != -2; p = prv[p]) {           yx[y] = p;           int ty = xy[p];           xy[p] = y;           y = ty;         }       } else         break;     }     int res = 0;     for (int i = 0; i < (int)(n); i++) res += mt[i][xy[i]];     return res;   }   string s, t;   int f(char c) {     if ( A  <= c && c <=  Z )       return (int)(c -  A  + 26);     else       return (int)(c -  a );   }   char invf(int i) {     if (i < 26)       return (char)(i +  a );     else       return (char)(i - 26 +  A );   }   int main() {     int N;     cin >> N >> n;     cin >> s >> t;     memset(mt, 0, sizeof(mt));     for (int i = 0; i < (int)(N); i++) {       mt[f(s[i])][f(t[i])]++;     }     cout << hungar() << endl;     for (int i = 0; i < (int)(n); i++) {       cout << invf(xy[i]);     }     cout << endl;     return 0;   }   