Trie-Based Autocomplete (easy version)
Implement an autocomplete system using a trie data structure. Support two operations: inserting words and finding all words with a given prefix.
Input
The first line contains n (1 ≤ n ≤ 1000), the number of operations.
Each of the next n lines contains one operation:
INSERT word— addwordto the trie. Duplicate inserts have no effect.AUTOCOMPLETE prefix— find all words in the trie that start withprefix, in lexicographic order.
All words and prefixes are non-empty strings of lowercase English letters, each at most 20 characters.
Output
For each AUTOCOMPLETE query, print the matching words in lexicographic order, one per line. If no words match, print nothing (blank line).
After all queries are processed, print the total number of distinct words inserted (on a single line).
Constraints
- 1 ≤ n ≤ 1000
- Each word and prefix is 1–20 lowercase English letters
- Total length of all words and prefixes ≤ 20000
- Time limit: 1000 ms
- Memory limit: 256 MB