#include <iostream>
using namespace std;
char input[200];
char heap[200];
int cnt_1=0;
int cusor = 1;
int depth_cnt = 1;
int depth_check = 0;
int depth_temp;
int depth = 0;
int k_1 = 1;
int k = 1;//초기값 1
void print_1(int _n);
void print_2(int _n);
int jegop(int _n)
{
int k = 1;
int n = _n;
for(int i = 0 ; i < n; i++)
k *= 2;
return k;
}
void ancestor_sort(int _i, int _j)
{
int i = _i; //i보내는거
int n = _j; //cusor 보내는거
int cnt=0;
char temp;
if(cusor != 0)
{
if((i%2) == 1) //홀수고 왼쪽 노드
{
cusor = ((i-1)/2);
if(heap[i] < heap[cusor])
{
temp = heap[cusor];
heap[cusor] = heap[i];
heap[i] = temp;
ancestor_sort(cusor, cusor);
}
}
else if((i%2) == 0) //짝수고 오른쪽 노드
{
cusor = ((i-2)/2);
if(heap[i] < heap[cusor])
{
temp = heap[cusor];
heap[cusor] = heap[i];
heap[i] = temp;
ancestor_sort(cusor, cusor);
}
}
}
cusor = 1;
}
void sort(char *_c,int _arr_size) //'A'랑 'D'는 없는 상태
{
int arr_size = _arr_size;
int n = (arr_size/3)+1;
for(int i = n-1 ; i >= 0; i--)
{
ancestor_sort(i,1);
}
}
void insert(char *_c, int _arr_size) //들어온게 input
{
char *c = _c;
int arr_size = _arr_size;
int count = 0;
for(int i = 0; i < arr_size; i++)
{
if(c[i] == 'A')
{
if(c[i+1] != ' '){
heap[count] = c[i+1];
count ++;
}
}
else if (c[i] == 'D')
{
if(c[i+1] != ' ')
for(int j=0; j <arr_size; j++)
if(c[i+1] == heap[j])
heap[j] = NULL;
}
}
sort(heap, arr_size);
}
void main()
{
int n;
cin >> n;
// char input[500]; //입력받은 문자열들이 저장되는 배열
int i_int; //getchar를 받기 위해 있는 변수
int arr_size = (n * 3)-1;
int cnt=0;
fflush(stdin);
while((i_int=getchar()) != '\n')
{
input[cnt] = i_int;
cnt++;
}
insert(input, arr_size); //cnt 안받기로 했음
cout<<"Original Form"<<endl;
print_1(n);
}
void print_1(int _n)
{
int n = _n;
for(int i = 0; i < n; i++)
{
if(jegop(i) <= n)
depth = i;
}
cout << depth <<endl;
int depth_save = depth;
int arr_count=0;
int count = 0;
char **arr = new char *[jegop((depth+1))-1];
for(int i = 0; i < (jegop(depth+1))-1; i++)
arr[i] = new char[depth];
for(int i = 0 ; i <= depth; i++)
for(int j =0; j<= jegop(depth+1)-1; j++)
arr[i][j] = ' ';
int cnt=0;
int depth_check = 0;
int d1, d2, d3;
d1 = jegop(depth) -1;
for(int i = 0; i < n ; i++)
{
if(depth_check == 0)
{
arr[count][d1] = heap[i];
cnt++;
depth_check ++;
}
else
{
arr[count][d1+d2] = heap[i];
d2 = d2 + d3;
cnt++;
}
if(cnt == k)
{
d2 = d1+1;
d3 = d2;
depth--;
d1 = jegop(depth)-1;
depth_check = 0;
cnt = 0;
count++;
k = jegop(k);
}
}
/* cout << endl;
char **arr_1 = new char *[depth];
for(int i = 0; i < depth; i++)
arr_1[i] = new char[jegop((depth+1))-1];
*/
for(int i = 0 ; i <= depth_save; i++)
{
for(int j =0; j<= jegop(depth_save+1)-1; j++)
{
cout << arr[i][j];
}
cout << endl;
}
cout << endl;
cout << "Lotation Form" << endl;
for(int i = 0 ; i <= jegop(depth_save+1)-1; i++)
{
for(int j =0; j<= depth_save; j++)
{
cout<< arr[j][i];
}
cout << endl;
}
}