#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
#define ull unsigned long long
void testcase(){
    ll n,ans=0;
    cin>>n;
    for(int i=1;i<=n;i++){
        bool st=true;
        int j=i;
        while(j){
            if(j%10==7){
                st=false;
                break;
            }
            j/=10;
        }
        j=i;
        while(j){
            if(j%8==7){
                st=false;
                break;
            }
            j/=8;
        }
        if(st){
            ans++;
        }
    }
    cout<<ans;
}
int main() {
    ll t=1;
    //cin>>t;
    while(t--){
        testcase();
        //cout<<'\n';
    }
}

#include <bits/stdc++.h>
using namespace std;

int main() {
  ios::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);

  int n;
  cin >> n;

  cout << (1<<n) - 1 << '\n';
  vector<string> ans = {"AB"};

  for (int i = 1; i < n; ++i) {
    for (int j = 0; j < (1<<i) - 1; ++j) {
      string tmp = ans[j];
      for (int k = 0; k < (int)tmp.size(); ++k) {
        tmp[k] = (tmp[k] == 'A' ? 'B' : 'A');
      }
      ans.push_back(ans[j] + tmp);
      ans[j] += ans[j];
    }
    ans.push_back(string ((1<<i), 'A') + string ((1<<i), 'B'));
  }

  for (auto i : ans) cout << i << '\n';
}
