#include <iostream>
#include <cstdio>
#include <cstring>

typedef long long LL;

using namespace std;

const int MAX_N = (int)1e5 + 10;
const int MAX_L = 42;
const LL INF = 1LL << 62;

struct Node {
    int depth;
    char symbol;
    Node * first, * brother;
    bool take;

    LL penalty() {
        return (depth && symbol != '$') ? (1LL << (40 - depth)) : INF;
    }

    Node(int _depth, char _symbol)
        : depth(_depth), symbol(_symbol), first(0), brother(0)
    {
    }
};

LL minPenalty(Node * root) {
    LL result = root->penalty();
    root->take = true;

    if (root->first) {
        LL sum = 0;
        for (Node * child = root->first; child; child = child->brother)
            sum += minPenalty(child);
        if (sum < result) {
            result = sum;
            root->take = false;
        }
    }

#ifdef DBG
    std::cerr << "minPenalty " << result << '\n';
#endif
    return result;
}

void add(Node * root, int depth, char const* cur) {
    if (*cur == '\0')
        return;

    if (!root->first)
        root->first = new Node(depth + 1, *cur);

    for (Node * child = root->first; child; child = child->brother)
        if (child->symbol == *cur) {
            add(child, depth + 1, cur + 1);
            return;
        }

    Node * newFirst = new Node(depth + 1, *cur);
    newFirst->brother = root->first;
    root->first = newFirst;

    add(root->first, depth + 1, cur + 1);
}

int nAns;
char ans [MAX_N][MAX_L];

char path [MAX_L];

void printAns(int depth, Node * root) {
    if (root->take) {
        path[depth] = '\0';
        sprintf(ans[nAns++], "%s\n", path);
        return;
    }

    for (Node * child = root->first; child; child = child->brother) {
        path[depth] = child->symbol;
        printAns(depth + 1, child);
    }
}

int main() {
    Node root(0, '\0');

    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        char buf [MAX_L];
        scanf("%s", buf);

        int len = strlen(buf);
        buf[len] = '$';
        buf[len + 1] = '\0';

        add(&root, 0, buf);
    }

    std::cout << minPenalty(&root) << '\n';
    printAns(0, &root);
    std::cout << nAns << '\n';
    for (int i = 0; i < nAns; i++)
        printf("%s", ans[i]);

    return 0;
}
