#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/hash_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define LL long long
#define int long long
#define ull unsigned long long
#define fi first
#define se second
#define pll pair<LL, LL>
#define pii pair<int, int>
#define fastio ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define SZ(x) ((int)(x.size()))
#define LC (id<<1)
#define RC (id<<1|1)

constexpr int N = 1e6+9;
constexpr int M = 1e9+7;
#ifdef int
constexpr int INF = 0x3f3f3f3f3f3f3f3f;
constexpr int INF2 = 0xcfcfcfcfcfcfcfcf;
#else
constexpr int INF = 0x3f3f3f3f;
constexpr int INF2 = 0xcfcfcfcf;
#endif



signed main() {
    fastio;
    int n;
    cin >> n;
    vector<int> fa(n, -1);
    vector<vector<int>> ch(n);
    for (int i = 1; i < n; i++) {
        cin >> fa[i];
        fa[i]--;
        ch[fa[i]].emplace_back(i);
    }
    vector<int> sz(n, 1);
    // sz*2 + sz-1
    vector<int> dp(n, 0);
    function<void(int)> dfs = [&](int u) {
        dp[u] = 1;
        array<vector<pii>, 2> sub;
        for (int v: ch[u]) {
            dfs(v);
            sz[u] += sz[v];
            sub[sz[v]&1].emplace_back(dp[v], sz[v]-dp[v]);
        }
        sort(sub[0].begin(), sub[0].end(), [](const pii& p1, const pii& p2) {
            return p1.fi-p1.se > p2.fi-p2.se;
        });
        sort(sub[1].begin(), sub[1].end(), [](const pii& p1, const pii& p2) {
            return p1.fi-p1.se < p2.fi-p2.se;
        });
        while (!sub[0].empty() && sub[0].back().fi <= sub[0].back().se) {
            dp[u] += sub[0].back().fi;
            sub[0].pop_back();
        }
        while (!sub[0].empty()) {
            if (SZ(sub[1]) & 1)
                dp[u] += sub[0].back().se;
            else
                dp[u] += sub[0].back().fi;
            sub[0].pop_back();
        }
        for (int i = 0; i < SZ(sub[1]); i++) {
            if (i & 1) dp[u] += sub[1][i].se;
            else dp[u] += sub[1][i].fi;
        }
    };
    dfs(0);
    cout << dp[0] << "\n";
    return 0;
}
#pragma region head
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using pi = pair<int, int>;
using pll = pair<ll, ll>;
template <class T>
using vv = vector<vector<T>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rrepi(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define bit(n) (1LL << (n))
template <class T>
inline bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
const int INF = 1002003004;
const ll LINF = 1002003004005006007ll;
struct preprocess {
    preprocess() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} ____;
#pragma endregion head

#pragma region library
#pragma endregion library
string inv(const string &s) {
    string res = "";
    rep(i, s.size()) {
        if (s[i] == 'A') {
            res += 'B';
        } else {
            res += 'A';
        }
    }
    return res;
}
int main() {
    int n;
    cin >> n;
    vector<string> ans = {"AB"};
    rep(i, n - 1) {
        vector<string> nxt;
        rep(i, ans.size()) {
            nxt.emplace_back(ans[i] + ans[i]);
            nxt.emplace_back(ans[i] + inv(ans[i]));
        }
        nxt.emplace_back(string(ans[i].size(), 'A') + string(ans[i].size(), 'B'));
        swap(nxt, ans);
    }
    cout << ans.size() << '\n';
    rep(i, ans.size()) {
        cout << ans[i] << '\n';
    }
}