#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long
#define P pair<int,ll>
#define MOD 1000000007

using namespace std;

ll n, a,b,c, m;

int main(){
    cin >> n;
    m = n+1;
    rep(i, 60){
        a = (n >> i);
        b = i;
        c = n - (a << b);
        m = min(m, a+b+c);
    }
    cout << m<<endl;
}
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <cassert>
#include <stack>
#include <numeric>

typedef int64_t ll;
typedef std::pair<int, int> Pii;
typedef std::pair<ll, ll> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, _s) for (int i = (_s);i < (int)( n ); i++)
#define all(_l) _l.begin(), _l.end()
#define rall(_l) _l.rbegin(), _l.rend()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<typename T>
inline bool chmax(T &_l, const T b) {
    if (_l < b) {
        _l = b;
        return true;
    }
    return false;
}
template<typename T>
inline bool chmin(T &_l, const T b) {
    if (_l > b) {
        _l = b;
        return true;
    }
    return false;
}

# ifdef LOCAL_DEBUG
template<typename T>
void vdeb(const std::vector<T> &bb) {
    for (unsigned int i = 0;i < bb.size();i++) {
        if (i == bb.size() - 1) std::cout << bb[i];
        else std::cout << bb[i] << ' ';
    }
    std::cout << '\n';
}
template<typename T>
void vdeb(const std::vector<std::vector<T>> &bb) {
    for (unsigned int i = 0;i < bb.size();i++) {
        std::cout << i << ' ';
        vdeb(bb[i]);
    }
    std::cout << '\n';
}
# endif

using namespace std;

int main() {
    int n; cin >> n;
    cout << (1<<n)-1  << endl;
    rip(i,1<<n,1) {
        rip(j,1<<n,0) {
            if(__builtin_popcount(j&i)&1) cout << 'A';
            else cout << 'B';
        }
        cout << '\n';
    }
}