Given several integer patterns and one shade array, count every occurrence where a contiguous block equals a pattern scaled by a positive real factor.
Hard8String matchingMathNo attempts yetTime limit1sMemory limit1024 MBA long time ago, in a galaxy far away, there was a town. The town is gone and only its shade is left.
Assume that every building in the town stood on a single line at equal spacing. All buildings had the same width and differed only in height. The buildings are gone and only their shadows remain. A shadow length does not have to equal the original building height. All shadows may have been scaled by the same positive constant.
We want to know the architecture of the civilization that lived on this planet. You are given several sequences of building heights, called patterns. For each pattern, find every place where it appears in the original row of buildings.
You are given a sequence of positive integers, the lengths of the preserved shadows. You are also given several queries, and one query gives one pattern. A pattern is a sequence of positive integers, the heights of some buildings. A pattern appears in the shade if some contiguous block of the shadow sequence is exactly the pattern multiplied by a positive real factor.
Compute the total number of appearances over all patterns. Appearances are allowed to overlap. A pattern of length 1 can be scaled to any value, so it appears at every position of the shade.
The first line contains the number of patterns n.
Each of the next n lines describes one pattern. The line starts with the pattern length li, followed by li positive integers separated by spaces.
The last line describes the shade. It starts with the shade length m, followed by m positive integers separated by spaces.
Constraints:
Print the total number of appearances of all patterns in the shade as a single integer on one line.