#include <bits/stdc++.h>
using namespace std;
// Adjacency list for the filesystem
map<string, vector<string>> children;
// Counters for directories and files
int dir_count = 0, file_count = 0;
// Recursive function to print the tree
// node: current node name
// depth: depth in the tree (root = 0)
// last_branch: for each ancestor level, true if that ancestor was the last child
void print_tree(const string& node, int depth, vector<bool>& last_branch) {
if (depth == 0) {
// Print the root directory
cout << node << "\n";
dir_count++;
} else {
// Print indentation for each ancestor level
for (int i = 0; i < depth - 1; i++) {
if (last_branch[i]) {
// no more siblings at this level
cout << " ";
} else {
// still have siblings → draw vertical bar
cout << "| ";
}
}
// Print the branch symbol for this node
bool is_last = last_branch[depth - 1];
cout << (is_last ? "|__ " : "|-- ");
cout << node << "\n";
// Count directory or file
if (!children.count(node)) {
file_count++;
return;
} else {
dir_count++;
}
}
// Recurse into children (already sorted)
auto &vec = children[node];
for (size_t i = 0; i < vec.size(); i++) {
last_branch.push_back(i + 1 == vec.size());
print_tree(vec[i], depth + 1, last_branch);
last_branch.pop_back();
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
string root;
int N;
cin >> root >> N;
// Read filesystem
for (int i = 0; i < N; i++) {
string parent, child;
cin >> parent >> child;
children[parent].push_back(child);
// leave child out of map if it's a file (no children)
}
// Sort each directory's contents
for (auto &p : children) {
sort(p.second.begin(), p.second.end());
}
// Print tree
vector<bool> last_branch;
print_tree(root, 0, last_branch);
// Blank line then counts
cout << "\n"
<< dir_count << " directories, "
<< file_count << " files\n";
return 0;
}