#include #include #include #include using namespace std; struct node { map child; size_t files = 0; size_t total_children = 0; }; size_t cnt_children(node* cur) { size_t sm = cur->files; for(auto &p : cur->child) { sm += cnt_children(&(p.second)); } cur->total_children = sm; return sm; } int main() { size_t s; cin >> s; node root; size_t total_parts = 0; for(size_t ss=0; ss < s; ss++) { string path; string part; cin >> path; size_t last = 1; size_t next; node* cur = &root; while ((next = path.find('/', last)) != string::npos) { part = path.substr(last, next-last); if(cur->child.count(part) == 0) { cur->child.emplace(part, node()); } cur = &(cur->child[part]); last = next + 1; total_parts++; } cur->files++; total_parts++; } // count children and store in each node cnt_children(&root); // greedily walk from top to pick best node node* cur = &root; size_t before = 0; while(cur->child.size() > 0) { size_t threshold = cur->total_children + before; bool move = false; for(auto &p : cur->child) { if( 2*p.second.total_children > threshold ) { // cerr << "Moving " << threshold << " " << p.second.total_children << " " << before << endl; total_parts -= 2*p.second.total_children - threshold; before = threshold - p.second.total_children; move = true; cur = &(p.second); break; } } if(!move) break; } cout << total_parts << endl; return 0; }