eolymp
bolt
Try our new interface for solving problems
Məsələlər

"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 \textbf{А} of length \textbf{N} is a prefix of code \textbf{B} of length \textbf{M} if \textbf{N} < \textbf{M} and first \textbf{N} symbols of code \textbf{B} equal code \textbf{А}. For convenience DNA code is presented by non-empty string of characters '\textbf{a}', '\textbf{b}', '\textbf{c}', '\textbf{d}'. George’s database should correctly process duplicated DNA codes. \InputFile The first input line contains integer \textbf{T} -- number of database operations. Following \textbf{T} lines contain one operation each. Insert operation consists of symbol "\textbf{+}" followed by DNA code to be added to the database, query operation consists of symbol "\textbf{?}" followed by DNA code for which number of codes from the database having this code as prefix needs to be found. \OutputFile For each line at input, which starts from symbol "\textbf{?}" you need to print result into separate line at output. \textbf{Constraints} Total length of codes in George’s database does not exceed \textbf{1000000}.
Zaman məhdudiyyəti 0.4 saniyə
Yaddaşı istafadə məhdudiyyəti 64 MiB
Giriş verilənləri #1
4
+cccdcc
+a
?a
?c
Çıxış verilənləri #1
0
1
Mənbə ACM-ICPC Ukraine 2013, 2nd Stage Ukraine, September 10-12, 2013