/*
 * Solution by Christian Kauth - July 2010 - Solves all test cases at 
 * http://ioinformatics.org/locations/ioi08/contest/day1/typ.zip
 * To solve this problem in linear time complexity, we can build a
 * prefix tree (trie). The longest subtree should be traversed last.
 */

#include <iostream>
#include <vector>
#include <string>
using namespace std;

#define NONE 0

struct TNode
{
	vector<TNode*> children;
	bool isEndOfWord;
	char letter;
	unsigned int treeDepth;
};

TNode *root = new TNode;
string answer("");

/*
 * recursively adds a suffix 's' at a node 'parent' of the trie
 */
void add(TNode *parent, string s)		
{
	// mark the end of the word
	if (s=="")
	{
		parent->isEndOfWord = true;
		parent->treeDepth = 1;
		return;
	}

	// s shares a common prefix
	for (unsigned int i=0; i<parent->children.size(); i++)
		if (parent->children[i]->letter == s[0])
		{
			add(parent->children[i],s.substr(1));
			if (parent->treeDepth < s.size())
			{
				swap(parent->children[i],parent->children[parent->children.size()-1]);
				parent->treeDepth = s.size();
			}
			return;
		}

	// s is a new entry to the trie
	TNode *child = new TNode;
	child->letter = s[0];
	child->isEndOfWord = false;
	child->treeDepth = s.size()-1;
	parent->children.push_back(child);
	add(child,s.substr(1));
	if (parent->treeDepth != NONE && parent->treeDepth > s.size())
		swap(parent->children[parent->children.size()-2],parent->children[parent->children.size()-1]);
	else
		parent->treeDepth = s.size();
}

/*
 * builds the trie from the input data
 */
void build_trie()
{
	int N;
	string s;

	root->treeDepth = NONE;
    cin>>N;
    for (int i=0; i<N; i++)
    {
            cin>>s;
            add(root,s);
    }
}

/*
 * traverses the trie and builds the answer
 */
void traverse(TNode* pos)
{
	answer += pos->letter;

	for (unsigned int i=0; i<pos->children.size(); i++)
		traverse(pos->children[i]);

	if (pos->isEndOfWord)
		answer+='P';
	
	answer+='-';
}

/*
 * output the answer
 */
void typewrite()
{
	cout<<answer.size()-root->treeDepth-3<<endl;
	for (unsigned int i=1; i < answer.size()-root->treeDepth-2; i++)
		cout<<answer[i]<<endl;
}

int main()
{
	build_trie();
    traverse(root);
	typewrite();
	return 0;
}
