#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
using i64 = int64_t;
using vi64 = vector<i64>;
using vvi64 = vector<vi64>;
using u64 = uint64_t;

#define rep(i, s, n) for (i64 i = (s); i < (n); ++i)

void run() {
  i64 n;
  cin >> n;
  vi64 ps(n);
  rep(i, 0, n) {
    cin >> ps[i];
    --ps[i];
  }
  vi64 ret{};
  i64 p{0};
  while (p < n - 1) {
    if (ps[p] == p) {
      cout << -1 << endl;
      return;
    }
    rep(i, p + 1, n) {
      if (ps[i] == p) {
        for (i64 j{i - 1}; p <= j; --j) {
          if (j < i - 1 && ps[j] != j + 1) {
            cout << -1 << endl;
            return;
          }
          ret.push_back(j);
        }
        ps[i] = ps[i - 1];
        p = i;
      }
    }
  }
  for (const auto x : ret) {
    cout << x + 1 << endl;
  }
}

int main() {
  cin.tie(nullptr);
  cout.precision(std::numeric_limits<double>::max_digits10);
  run();
  return 0;
}

//  Copyright 2021 Nikita Golikov

#include <bits/stdc++.h>

using namespace std;

using i64 = int64_t;
using ui64 = uint64_t;

template <class A, class B>
bool smin(A &x, B &&y) {
  if (y < x) {
    x = y;
    return true;
  }
  return false;
}

template <class A, class B>
bool smax(A &x, B &&y) {
  if (x < y) {
    x = y;
    return true;
  }
  return false;
}

int main() {
#ifdef GOLIKOV
  assert(freopen("in", "rt", stdin));
  auto _clock_start = chrono::high_resolution_clock::now();
#endif
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n;
  cin >> n;
  auto solve = [&](auto&& solve, int n) -> vector<string> {
    if (n == 1) {
      return {"AB"};
    }
    auto res = solve(solve, n - 1);
    auto resSz = int(res.size());
    vector<string> ans;
    for (auto const& s : res) {
      ans.push_back(s + s);
    }
    for (auto const& s : res) {
      auto is = s;
      for (auto& x : is) x = 'A' ^ 'B' ^ x;
      ans.push_back(s + is);
    }
    ans.push_back(string(1 << (n - 1), 'A') + string(1 << (n - 1), 'B'));
    return ans;
  };
  auto ans = solve(solve, n);
  cout << ans.size() << '\n';
  for (auto const& s : ans) cout << s << '\n';

#ifdef GOLIKOV
  cerr << "Executed in " << chrono::duration_cast<chrono::milliseconds>(
      chrono::high_resolution_clock::now()
          - _clock_start).count() << "ms." << endl;
#endif
  return 0;
}
