#include <bits/stdc++.h>

using namespace std;

#define           REP(i, n)  for (int i = 0, _n = (n); i < _n; ++i)
#define          FORE(i, v)  for (__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++i)
#define          file(name)  if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }

struct Node {
	Node *child[26];
	int terminal;
	Node() {
		REP(i, 26) child[i] = nullptr;
		terminal = 0;
	}
};

int N;
string maxS;
Node *root = new Node();

void addString(const string &s) {
	Node *p = root;
	FORE(it, s) {
		if (p->child[*it - 'a'] == nullptr) p->child[*it - 'a'] = new Node();
		p = p->child[*it - 'a'];
	}
	p->terminal++;
}

void init(void) {
	cin >> N;
	REP(i, N) {
		string s; cin >> s;
		if (maxS.size() < s.size()) maxS = s;
		addString(s);
	}
}

string res;

void dfs(Node *p, int depth, bool type) {
	REP(i, p->terminal) res += 'P';
	if (depth == maxS.size()) return;
	if (type) {
		REP(i, 26) if (p->child[i] != nullptr && i != maxS[depth] - 'a') {
			res += char(i + 'a');
			dfs(p->child[i], depth + 1, 0);
			res += '-';
		}
		res += maxS[depth];
		dfs(p->child[maxS[depth] - 'a'], depth + 1, 1);
	} else {
		REP(i, 26) if (p->child[i] != nullptr) {
			res += char(i + 'a');
			dfs(p->child[i], depth + 1, 0);
			res += '-';
		}
	}
}

void process(void) {
	dfs(root, 0, 1);
	cout << res.size() << '\n' << res;
}

int main(void) {
	ios_base::sync_with_stdio(false); cin.tie(nullptr); // cout.tie(nullptr);
	file("type-printer");
	init();
	process();
	return (0^0);
}