#include <bits/stdc++.h>
using namespace std;
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define forr(a,b,c) for(int a=b;a<c;a++)
#define forrev(a,b,c) for(int a=b;a>c;a--)
#define all(v) v.begin(),v.end()
#define revall(v) v.rbegin(),v.rend()
#define allk(v,k) v.begin()+k,v.end()
#define revallk(v,k) v.rbegin()+k,v.rend()
#define allkj(v,k,j) v.begin()+k,v.end()-j
#define revallkj(v,k,j) v.rbegin()+j,v.rend()-k
#define ff first
#define ss second
////////////////////////// non-modifiable /////////////////////////////////
#define mod 1000000007
#define eps 1e-9
#define inf INT_MAX
#define infl LONG_LONG_MAX
ll power(ll a,ll n)
{
if(a==0)return 0;
if(a==1 || n==0)return 1;
if(n==1)return a%mod;//can remove mod?
ll t=power(a,n/2);
t=t*t%mod;
if(n&1)return t*a%mod;
return t;
}
#define P (int)(2e6)+9
#define FACTORIZE 1
#define DETERMINE 2
/*int primes[P];
void sieve(int prime=2)//2->detects prime, 1->max prime in factorization
{
forr(i,2,P-3)
{
if(!primes[i])
for(int j=prime*i;j<P-3;j+=i)primes[j]=i;
}
//forr(i,1,21)cout<<primes[i]<<" ";cout<<endl;
if(prime==2)
{
forr(i,1,P-3)
{
primes[i] = ( primes[i] == 0 );
}
}
else
primes[1] = 1;
}*/
int popcount(ll a)
{
int c=0;
while(a)
{
c++;
a-=a&-a;
}
return c;
}
void factorize(int a)
{
}
void update(int tree[],int idx,int val,int maxval)
{
for(;idx<=maxval;idx+=idx&-idx)
{
tree[idx]+=val;
//tree[idx]%=mod;
}
}
int read(int tree[],int idx)
{
ll sum=0;
for(;idx>0;idx-=idx&-idx)
{
sum+=tree[idx];
//sum%=mod;
}
return sum;
}
////////////////////////// MODIFIABLE /////////////////////////////////////
struct node2
{
int id,val;
node2()
{
static int ctx=1;
id=ctx++;
};
node2(int a,int b=0,int c=0,int d=0,int e=0,int f=0)
{
val=a;
}
};
struct comp2
{
bool operator()(int a,int b)
{
//return a<b;
return b<a; //min heap
}
};
bool cmp2(int a,int b)
{
//return a<b;
return b<a;
}
struct node
{
bool present;
node * child[26];
node()
{
present = 0;
forr(i,0,26) child[i] = NULL;
};
node(int a,int b=0,int c=0,int d=0,int e=0,int f=0)
{
//val=a;
}
};
struct comp
{
bool operator()(int a,int b)
{
//return a<b;
return b<a; //min heap
}
};
bool cmp(int a,int b)
{
//return a<b;
return b<a;
}
////////////////////////// custom-defined /////////////////////////////////
#define N 500009
int n,m,a,b,c,d,k,h,w,x,y,p,q,t,ans,res,ma,mi,T,act=0,pas=1,cur,flag,now;
int len[N];
string s[N];
node * root;
//vector<string> s;
double e,f,z;
vector<int> v[1], vec;
set<int> sett;
typedef map<int,int> Mapp;
Mapp mapp;
////////////////////////// variable declarations //////////////////////////
void print()//for detailed output of [a data structure]
{
}
void print2()//for detailed output of [a data structure]
{
}
void input()
{
ios_base::sync_with_stdio(false);cin.tie(NULL);
cin >> n;
//scanf("%d",&n);
//cout << "n=" << n << endl;
forr(i,1,n+1) cin >> s[i];
//scanf("%s",s[i]);
//forr(i,1,n+1) cout << s[i] << endl;
//cout << " lol " << endl;
}
node * insert( node * root, string& s, int idx, int length, int sid )
{
if( root -> present == 1 )
{
len[ sid ] = idx;
cout << "2sid=" << sid << " len[sid]=" << len[sid] << " idx=" << idx << endl;
return root;
}
if( idx == length )
{
root -> present = 1;
return root;
}
forr(i,0,s[idx]-'a')
if( root->child[i] != NULL )
{
len[ sid ] = idx;
cout << "sid=" << sid << " len[sid]=" << len[sid] << " i=" << i << endl;
cout << root->child[i] << endl;
root -> present = 1;
return root;
}
//if( root->child[ s[idx] - 'a' ] != NULL && )
if( root->child[ s[idx] - 'a' ] == NULL )
root->child[ s[idx] - 'a' ] = (node*) malloc( sizeof( node ) );
root->child[ s[idx] - 'a' ] = insert( root->child[ s[idx] - 'a' ], s, idx+1, length, sid );
return root;
}
void solve()
{
forr(i,1,n+1) len[i] = s[i].length();
forr(i,1,n+1) cout << len[i] << " "; cout << endl;
root = (node*) malloc( sizeof( node ) );
root->present = 0;
forrev(i,n,0)
{
root = insert( root, s[i], 1, len[i], i );
}
forr(i,1,n+1) cout << len[i] << " "; cout << endl;
}
char buff[500009] = {0};
int id = 0;
void output()
{
forr(i,1,n+1) cout << len[i] << " "; cout << endl;
forr(i,1,n+1)
{
forr(j,0,len[i])
//buffer[id++] = s[i][j];
printf("%c",s[i][j]);
//buffer[id++] = '\n';
printf("\n");
//cout << string( s[i].begin(), s[i].begin() + len[i] ) << endl;
}
//printf("%s\n",buffer);
buff[ id-1 ] = 0;
//cout << buffer;
}
///////////////////////////// my functions ////////////////////////////////
int main()
{
input();
solve();
output();
return 0;
}
//// MAIN //// MAIN //// MAIN //// MAIN //// MAIN //// MAIN //// MAIN ////
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgcGIoYSkgcHVzaF9iYWNrKGEpCiNkZWZpbmUgbXAoYSxiKSBtYWtlX3BhaXIoYSxiKQojZGVmaW5lIGxsIGxvbmcgbG9uZwojZGVmaW5lIHBpaSBwYWlyPGludCxpbnQ+CiNkZWZpbmUgcGxsIHBhaXI8bGwsbGw+CiNkZWZpbmUgZm9ycihhLGIsYykgZm9yKGludCBhPWI7YTxjO2ErKykKI2RlZmluZSBmb3JyZXYoYSxiLGMpIGZvcihpbnQgYT1iO2E+YzthLS0pCiNkZWZpbmUgYWxsKHYpIHYuYmVnaW4oKSx2LmVuZCgpCiNkZWZpbmUgcmV2YWxsKHYpIHYucmJlZ2luKCksdi5yZW5kKCkKI2RlZmluZSBhbGxrKHYsaykgdi5iZWdpbigpK2ssdi5lbmQoKQojZGVmaW5lIHJldmFsbGsodixrKSB2LnJiZWdpbigpK2ssdi5yZW5kKCkKI2RlZmluZSBhbGxraih2LGssaikgdi5iZWdpbigpK2ssdi5lbmQoKS1qCiNkZWZpbmUgcmV2YWxsa2oodixrLGopIHYucmJl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