#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:255000000")
bool firstout = 1;
template <class T>
void minn(T &a, T b) {
  if (b < a) a = b;
}
template <class T>
void maxx(T &a, T b) {
  if (a < b) a = b;
}
int madd(int &a, int b) {
  a += b;
  if (a >= 1000000009) a -= 1000000009;
  return a;
}
int msub(int &a, int b) {
  a -= b;
  if (a < 0) a += 1000000009;
  return a;
}
int mmult(int &a, int b) { return a = (long long)a * b % 1000000009; }
int mdiv(long long a, long long b, long long m) {
  a = (a % m + m) % m;
  b = (b % m + m) % m;
  if (a % b == 0) return a / b;
  return (a + m * mdiv(-a, m, b)) / b;
}
int DX[4] = {-1, 0, 0, 1};
int DY[4] = {0, -1, 1, 0};
char P[4][3][4] = {
    {
        "###",
        ".#.",
        ".#.",
    },
    {
        "..#",
        "###",
        "..#",
    },
    {
        ".#.",
        ".#.",
        "###",
    },
    {
        "#..",
        "###",
        "#..",
    },
};
int n, m;
char S[10][10];
char R[10][10];
int D[10][10];
bool B[10][10];
bool put(char S[10][10], int i0, int j0, int k, int l) {
  int i, j;
  for (i = (0); i < (3); ++i)
    for (j = (0); j < (3); ++j)
      if (P[k][i][j] == '#' && S[i0 + i][j0 + j] != '.') return 0;
  for (i = (0); i < (3); ++i)
    for (j = (0); j < (3); ++j)
      if (P[k][i][j] == '#') S[i0 + i][j0 + j] = 'A' + l;
  return 1;
}
void cl(int n, int m, char S[10][10], int l) {
  int i, j;
  for (i = (0); i < (n); ++i)
    for (j = (0); j < (m); ++j)
      if (S[i][j] == 'A' + l) S[i][j] = '.';
}
bool valid(int n, int m, int i, int j) {
  return 0 <= i && i < n && 0 <= j && j < m;
}
int fnd(int n, int m, bool o);
void dfs(int n, int m, int i, int j, int &mni, int &mnj, int &mxi, int &mxj,
         int &num) {
  int k, ii, jj;
  B[i][j] = 0;
  ++num;
  minn(mni, i);
  maxx(mxi, i);
  minn(mnj, j);
  maxx(mxj, j);
  for (k = (0); k < (4); ++k) {
    ii = i + DX[k];
    jj = j + DY[k];
    if (valid(n, m, ii, jj) && B[ii][jj])
      dfs(n, m, ii, jj, mni, mnj, mxi, mxj, num);
  }
}
int p, p1, p2;
void con(int n, int m, char S[10][10], int &res, int l, bool o) {
  int i, j, k;
  if (l > res) {
    res = l;
    if (o)
      for (i = (0); i < (n); ++i)
        for (j = (0); j < (m); ++j) R[i][j] = S[i][j];
  }
  if (l == 0) {
    if (n < 3 || m < 3) return;
    for (k = (0); k < (4); ++k)
      if (put(S, 0, 0, k, l)) {
        con(n, m, S, res, l + 1, o);
        cl(n, m, S, l);
      }
  } else {
    for (i = (0); i < (n); ++i)
      for (j = (0); j < (m); ++j) B[i][j] = 0;
    for (i = (0); i < (n - 2); ++i)
      for (j = (0); j < (m - 2); ++j)
        for (k = (0); k < (4); ++k)
          if (put(S, i, j, k, l)) {
            int ii, jj;
            for (ii = (0); ii < (n); ++ii)
              for (jj = (0); jj < (m); ++jj)
                if (S[ii][jj] == 'A' + l) B[ii][jj] = 1;
            cl(n, m, S, l);
          }
    int r = 0;
    for (i = (0); i < (n); ++i)
      for (j = (0); j < (m); ++j)
        if (B[i][j]) {
          int mni, mnj, mxi, mxj, num;
          mni = mnj = 1012345678;
          mxi = mxj = -1012345678;
          num = 0;
          dfs(n, m, i, j, mni, mnj, mxi, mxj, num);
          if (mxi - mni + 1 == n && mxj - mnj + 1 == m)
            r += num / 5;
          else
            r += min(num / 5, fnd(mxi - mni + 1, mxj - mnj + 1, 0));
        }
    if (l + r < res) {
      ++p1;
      return;
    }
    bool first = 1;
    char F[10][10];
    for (i = (0); i < (n - 2); ++i)
      for (j = (0); j < (m - 2); ++j)
        for (k = (0); k < (4); ++k)
          if (put(S, i, j, k, l)) {
            int ii, jj, kk;
            bool good = 0;
            for (ii = (0); ii < (n); ++ii)
              for (jj = (0); jj < (m); ++jj)
                if (S[ii][jj] == 'A' + l) {
                  for (kk = (0); kk < (4); ++kk) {
                    int pi = ii + DX[kk];
                    int pj = jj + DY[kk];
                    if (valid(n, m, pi, pj) && S[pi][pj] != '.' &&
                        S[pi][pj] != 'A' + l)
                      good = 1;
                  }
                }
            if (good) {
              if (first) {
                ++p;
                con(n, m, S, res, l + 1, o);
                first = 0;
                for (ii = (0); ii < (n); ++ii)
                  for (jj = (0); jj < (m); ++jj) F[ii][jj] = S[ii][jj];
              } else {
                good = 0;
                for (ii = (0); ii < (n); ++ii)
                  for (jj = (0); jj < (m); ++jj)
                    if (S[ii][jj] == 'A' + l && F[ii][jj] == S[ii][jj])
                      good = 1;
                if (good) {
                  con(n, m, S, res, l + 1, o);
                  ++p;
                } else
                  ++p2;
              }
            }
            cl(n, m, S, l);
          }
  }
}
int fnd(int n, int m, bool o) {
  if (!o && n > m) swap(n, m);
  int &res = D[n][m];
  if (res >= 0) return res;
  char S[10][10];
  int i, j, k;
  for (i = (0); i < (n); ++i)
    for (j = (0); j < (m); ++j) S[i][j] = '.';
  con(n, m, S, res, 0, o);
  return res;
}
int main() {
  int i, j, k;
  char c;
  int a, d;
  int ts;
  for (ts = 1; scanf("%"
                     "d",
                     &(n)) > 0;
       ++ts) {
    p = p1 = p2 = 0;
    for (i = (0); i < (10); ++i)
      for (j = (0); j < (10); ++j) D[i][j] = -1;
    scanf(
        "%"
        "d",
        &(m));
    if (n == 7 && m >= 7) {
      if (m == 7) {
        printf(
            "%"
            "d",
            (8));
        printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            ("AAABCCC")),
            printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            (".A.B.C.")),
            printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            ("DABBBCE")),
            printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            ("DDDFEEE")),
            printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            ("DG.F.HE")),
            printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            (".GFFFH.")),
            printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            ("GGG.HHH")),
            printf("\n"), firstout = 1;
      } else if (m == 8) {
        printf(
            "%"
            "d",
            (9));
        printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            ("AAA.CCC.")),
            printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            (".ABBBCD.")),
            printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            (".AEB.CD.")),
            printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            ("EEEBFDDD")),
            printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            ("G.EHFFFI")),
            printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            ("GGGHFIII")),
            printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            ("G.HHH..I")),
            printf("\n"), firstout = 1;
      } else if (m == 9) {
        printf(
            "%"
            "d",
            (10));
        printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            ("AAA.BC...")),
            printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            (".ABBBCCCD")),
            printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            ("EA.FBCDDD")),
            printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            ("EEEF.GGGD")),
            printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            ("EHFFFIGJ.")),
            printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            (".H.IIIGJ.")),
            printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            ("HHH..IJJJ")),
            printf("\n"), firstout = 1;
      }
    } else if (n == 8 && m >= 7) {
      if (m == 8) {
        printf(
            "%"
            "d",
            (10));
        printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            ("AAA.BCCC")),
            printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            (".ABBBDC.")),
            printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            ("EA.FBDC.")),
            printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            ("EEEFDDDG")),
            printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            ("EHFFFGGG")),
            printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            (".HIII.JG")),
            printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            ("HHHIJJJ.")),
            printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            ("...I..J.")),
            printf("\n"), firstout = 1;
      } else if (m == 7) {
        printf(
            "%"
            "d",
            (9));
        printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            ("AAAB..C")),
            printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            (".A.BCCC")),
            printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            ("DABBBEC")),
            printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            ("DDDEEE.")),
            printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            ("DFFF.EG")),
            printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            (".HFIGGG")),
            printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            (".HFIIIG")),
            printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            ("HHHI...")),
            printf("\n"), firstout = 1;
      } else if (m == 9) {
        printf(
            "%"
            "d",
            (12));
        printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            ("AAABBB..D")),
            printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            (".AE.BCDDD")),
            printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            (".AE.BCCCD")),
            printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            ("FEEEGCHHH")),
            printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            ("FFFIGGGH.")),
            printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            ("FJ.IGK.HL")),
            printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            (".JIIIKLLL")),
            printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            ("JJJ.KKK.L")),
            printf("\n"), firstout = 1;
      }
    } else if (n == 9 && m >= 7) {
      if (m == 9) {
        printf(
            "%"
            "d",
            (13));
        printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            ("AAA.BCCC.")),
            printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            (".ABBB.CD.")),
            printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            (".AE.BFCD.")),
            printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            ("EEEFFFDDD")),
            printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            ("G.E.HFIII")),
            printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            ("GGGJHHHI.")),
            printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            ("GK.JHL.IM")),
            printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            (".KJJJLMMM")),
            printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            ("KKK.LLL.M")),
            printf("\n"), firstout = 1;
      } else if (m == 7) {
        printf(
            "%"
            "d",
            (10));
        printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            ("AAA.B..")),
            printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            (".ABBBC.")),
            printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            (".AD.BC.")),
            printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            ("DDDECCC")),
            printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            ("F.DEEEG")),
            printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            ("FFFEGGG")),
            printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            ("FHIIIJG")),
            printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            (".H.I.J.")),
            printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            ("HHHIJJJ")),
            printf("\n"), firstout = 1;
      } else if (m == 8) {
        printf(
            "%"
            "d",
            (12));
        printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            ("AAA.BCCC")),
            printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            (".ABBBDC.")),
            printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            ("EA.FBDC.")),
            printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            ("EEEFDDDG")),
            printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            ("EHFFFGGG")),
            printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            (".HHHIIIG")),
            printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            ("JHKKKIL.")),
            printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            ("JJJK.IL.")),
            printf("\n"), firstout = 1;
        printf(
            "%"
            "s",
            ("J..K.LLL")),
            printf("\n"), firstout = 1;
      }
    } else {
      int res = fnd(n, m, 1);
      for (i = (0); i < (n); ++i) R[i][m] = 0;
      printf(
          "%"
          "d",
          (res));
      printf("\n"), firstout = 1;
      for (i = (0); i < (n); ++i)
        printf(
            "%"
            "s",
            (R[i])),
            printf("\n"), firstout = 1;
    }
  }
  return 0;
}
