favorite Нам необхідно трохи Вашої допомоги щоб сайт продовжував працювати, натисніть на банер щоб дізнатись більше.

"Desoxyribonucleic Acid"

"Desoxyribonucleic Acid"

Science marches on and biology is not an exception. DNA decoding became one of turning points in history of biology. One of last year students of biology faculty, George, decided to make own contribution to this fascinating science. George plans to develop a database to store genetic codes of DNAs. You are assigned to implement a program, which adds codes to the database and returns number of codes for which give code is a prefix.

Code А of length N is a prefix of code B of length M if N < M and first N symbols of code B equal code А. For convenience DNA code is presented by non-empty string of characters 'a', 'b', 'c', 'd'. George’s database should correctly process duplicated DNA codes.


The first input line contains integer T – number of database operations. Following T lines contain one operation each. Insert operation consists of symbol "+" followed by DNA code to be added to the database, query operation consists of symbol "?" followed by DNA code for which number of codes from the database having this code as prefix needs to be found.


For each line at input, which starts from symbol "?" you need to print result into separate line at output.


Total length of codes in George’s database does not exceed 1000000.

Ліміт часу 1 секунда
Ліміт використання пам'яті 64 MiB
Вхідні дані #1
Вихідні дані #1
Джерело ACM-ICPC Ukraine 2013, 2nd Stage Ukraine, September 10-12, 2013