#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}



int main() {
	int n = ri();
	printf("%d\n", (1 << n) - 1);
	for (int i = 1; i < 1 << n; i++) {
		std::string res;
		for (int j = 0; j < 1 << n; j++) {
			if (__builtin_popcount(i & j) & 1) res.push_back('A');
			else res.push_back('B');
		}
		std::cout << res << std::endl;
	}
	
	return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

int main() {
  int n; cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> b[i];

  int max_a = *max_element(a.begin(), a.end());
  int min_b = *min_element(b.begin(), b.end());
  int ans;
  if (max_a > min_b)  ans = 0;
  else ans = min_b - max_a + 1;

  cout << ans << endl;
  return 0;
}