#include<bits/stdc++.h>
#define pb push_back
using namespace std;
#define G getchar()
int read()
{
	int x=0; bool flg=false; char ch=G;
	for (;!isdigit(ch);ch=G) if (ch=='-') flg=true;
	for (;isdigit(ch);ch=G) x=(x<<3)+(x<<1)+(ch^48);
	return flg?-x:x;
}
#undef G
#define fi first
#define se second
typedef long long ll;
/*
const int mod=;
inline int upd(const int &x){return x+(x>>31&mod);}
inline void add(int &x,int y){x=upd(x+y-mod);}
inline void iadd(int &x,int y){x=upd(x-y);}
int qpow(int x,int y){
	int res=1;
	for (;y;y>>=1,x=1LL*x*x%mod)
		if (y&1) res=1LL*res*x%mod;
	return res;
}
*/
/*
typedef pair<int,int> P;
*/
#define rep(i,l,r) for (int i(l);i<=(r);i++)
#define per(i,l,r) for (int i(r);i>=(l);i--)

int n;
void solve(){
	n=read();
	printf("%d\n",(1<<n)-1);
	rep(i,1,(1<<n)-1){
		rep(j,0,(1<<n)-1) putchar("AB"[__builtin_parity(i&j)]);
		puts("");
	}
}
int main()
{
	for (int T=1;T--;) solve();
}
#include <cstdio>
#include <queue>
using namespace std;

int main(){
	int n;
	scanf("%d", &n);
	vector<int> a(n*2);
	for(int& i: a)
		scanf("%d", &i);
	priority_queue<int> q;
	long long ans=0;
	for(int i = 0;i < n;i ++){
		q.push(a[i]);
		q.push(a[n*2-1-i]);
		ans+=q.top();
		q.pop();
	}
	printf("%lld\n", ans);
}