eolymp
bolt
Try our new interface for solving problems

Exam

Many universities use scoring system where students can earn up to \textbf{100} points, out of which up to \textbf{75} --- during the semester, and up to \textbf{25} --- during the final exam. The final mark is determined depending on the sum of semester and examination points by the following table: If a student gets strictly less than \textbf{35} points during the semester, they are not allowed to pass the examination; let’s assume in this case that those student’s names have been excluded from the list. If you read the column of European marks in examination list from top to bottom, you can find various "\textbf{words"}. For example, if there are consecutive sums of points \textbf{92}, \textbf{75} and \textbf{66}, they are marked as \textbf{A}, \textbf{C} and \textbf{E} respectively, and form the "\textbf{word}" \textbf{ACE}. In case of \textbf{FX}, both letters (first \textbf{F}, then \textbf{X}) appear in the "\textbf{word}". An exam is a risky thing, it’s impossible to know its results beforehand. But the lecturer knows both the approximate level of knowledge of each student and the list of exam tasks. So the lecturer can estimate the percentage probabilities for each student to earn at the exam every possible number of points: what is the probability that the student gets \textbf{0} points, \textbf{1} point, ..., \textbf{25} points -- totally \textbf{26} nonnegative integers, whose sum equals \textbf{100}. Points, obtained by every student during the semester, are also known (as fixed numbers from \textbf{35} to \textbf{75}, without any probabilities). The lecturer is a great esthete and dislikes situations when the "\textbf{word}", produced by European marks, contains any "\textbf{unpleasant}" substring (just as substring, i.e. when the letters are consecutive). Your task is to write a program to find the probability that this lecturer the esthete will be satisfied because none of the "\textbf{unpleasant}" substrings will occur. \InputFile The first line of the input contains the number of test cases. In each test case, the first line contains the number of students \textbf{N} (\textbf{3} ≤ \textbf{N} ≤ \textbf{100}). Each of the following \textbf{N} lines contains \textbf{27} space-separated integers --- the number of semester points (from \textbf{35} to \textbf{75}), and \textbf{26} probabilities corresponding to \textbf{0}, \textbf{1}, \textbf{2}, ..., \textbf{25} examination points (each probability is non-negative, their total sum is \textbf{100}). The next line of the test case contains number \textbf{K} (\textbf{1} ≤ \textbf{K} ≤ \textbf{100}) of "\textbf{unpleasant}" words according to lecturer’s opinion. Each of the following \textbf{K} test case lines contains an "\textbf{unpleasant}" word. It’s guaranteed that each of these \textbf{K} lines contains only capital Roman letters (any letters, not only \textbf{A-F} and \textbf{X}). Number of letters in each line is from \textbf{2} to \textbf{15} and it ends with the end-of-line symbol. \OutputFile Your program should write to output exactly one floating-point number in a single line -- calculated probability (in percent) that the lecturer will be satisfied. Floating-point format may be any of the standard ones (using decimal point, not decimal comma). \textit{The answer will be accepted if its relative error does not exceed }\textit{\textbf{1e--6}}\textit{.} \textbf{Note for sample}\textit{\textbf{:}}\textit{ }The \textbf{1}st student’s sum will be at least \textbf{72}+\textbf{10}=\textbf{82} points, so his mark can’t be \textbf{D}. Thus, "\textbf{unpleasant}" word \textbf{DE} will occur if and only if the \textbf{2}nd student gets from \textbf{13} to \textbf{19} points (the probability is \textbf{8}\%+\textbf{8}\%+\textbf{7}\%+\textbf{6}\%+\textbf{5}\%+\textbf{4}\%+\textbf{3}\%=\textbf{41}\%) and the \textbf{3}rd -- from \textbf{5} to \textbf{12} (the probability \textbf{3}\%+\textbf{4}\%+\textbf{5}\%+\textbf{6}\%+\textbf{7}\%+\textbf{8}\%+\textbf{8}\%+\textbf{9}\%=\textbf{50}\%). So, the word \textbf{DE} will appear with probability \textbf{0.41}*\textbf{0.5}=\textbf{0.205}, and will not appear with probability \textbf{1}--\textbf{0.205}=\textbf{0.795} (i.e. \textbf{79.5}\%).
Time limit 2 seconds
Memory limit 64 MiB
Input example #1
1
3
72 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 2 3 5 7 9 14 16 21 12 5 1
55 0 0 0 1 2 3 4 5 6 7 8 8 9 8 8 7 6 5 4 3 2 2 1 1 0 0
55 0 0 0 1 2 3 4 5 6 7 8 8 9 8 8 7 6 5 4 3 2 2 1 1 0 0
2
DE
WOW
Output example #1
7.950000000e+001
Source All-Ukrainian Collegiate Programming Contest Semi-Final 2010