Cats Substrings
Practice
4 (15 votes)
Arrays
Data structures
Medium
Problem
67% Success 353 Attempts 50 Points 4s Time Limit 256MB Memory 1024 KB Max Code
  • Russian version of the problem can be read here.

There are two cats playing, and each of them has a set of strings consisted of lower case English letters.

The first cat has N strings, while the second one has M strings. Both the first and the second cat will choose one of it's strings and give it to you. After receiving two strings, you will count the number of pairs of equal substrings that you can choose in both strings, and send this number back to the cats. (Note that two occurences of the same substring are considered different. For example, strings "bab" and "aba" have 6 such pairs.)

The cats are going to give you all N * M possible pairs. They are interested in the total sum of numbers received from you. Your task is to find this number.

Input format

The first line of the input contains the integer N. The next N lines contain the first cat's strings, one string per line. The next line contain the integer M, and after that the next M lines contain the second cat's strings, one string per line as well.

Output format

In one line print the answer to the problem.

Constraints

1 ≤ N, M ≤ 100,000 , the total length of each cat strings set will not exceed 100,000. All strings in the input will be non-empty.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:50
19 votes
Tags:
ArraysData StructuresMedium
Points:50
2 votes
Tags:
ApprovedArraysData StructuresMediumSegment Trees
Points:50
3 votes
Tags:
Advanced Data StructuresArraysData StructuresString Manipulation