#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0, length = n; i < length; i++)
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define ep emplace
#define epb emplace_back
#define scll static_cast<long long> 
#define sz(x) static_cast<int>((x).size())
#define pfll(x) printf("%lld\n", x)
#define ci(x) cin >> x
#define ci2(x, y) cin >> x >> y
#define ci3(x, y, z) cin >> x >> y >> z
#define ci4(w, x, y, z) cin >> w >> x >> y >> z
#define co(x) cout << x << endl
#define co2(x, y) cout << x << " " << y << endl
#define co3(x, y, z) cout << x << " " << y << " " << z << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> PQ;
typedef priority_queue<int, vector<int>, greater<int>> PQG;
typedef priority_queue<P> PQP;
typedef priority_queue<P, vector<P>, greater<P>> PQPG;

const int MAX_N = 2e5, MOD = 1e9 + 7, INF = 1e9;
int n, po[8];
vector<string> s[8];

int main() {
    ci(n);
    po[0] = 1;
    rep(i, n - 1) po[i + 1] = 2 * po[i] + 1;
    s[0].epb("AB");
    rep(i, n - 1) {
        rep(j, po[i]) {
            string tmp1, tmp2;
            for (auto &c: s[i][j]) {
                tmp1.append(2, c);
                tmp2.append(1, c);
                tmp2.append(1, 'A' + (c - 'A' + 1) % 2);
            }
            s[i + 1].epb(tmp1);
            s[i + 1].epb(tmp2);
        }
        string tmp;
        rep(j, po[i] + 1) tmp.append("AB");
        s[i + 1].epb(tmp);
    }
    co(po[n - 1]);
    rep(i, po[n - 1]) co(s[n - 1][i]);
    return 0;
}

#include<bits/stdc++.h>

using namespace std;
using Graph=vector<vector<int>>;

void dfs(int v,vector<bool> &flag,Graph &g){
  if(!flag[v]){return;}
  flag[v]=false;
  for(auto &nx : g[v]){dfs(nx,flag,g);}
}

int main(){
  int n,res=0;
  cin >> n;
  vector<int> a(n);
  vector<bool> flag(200005,false);
  Graph g(200005);
  for(auto &nx : a){
    cin >> nx;
    if(!flag[nx]){flag[nx]=true;res++;}
  }
  int p=0,q=n-1;
  while(p<q){
    g[a[p]].push_back(a[q]);
    g[a[q]].push_back(a[p]);
    p++;q--;
  }
  for(int i=1;i<=200000;i++){
    if(flag[i]){
      res--;
      dfs(i,flag,g);
    }
  }
  cout << res;
}
