404999: GYM101733 E Good Snippets

Memory Limit:512 MB Time Limit:3 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

E. Good Snippetstime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard output

One of the most important component of a good search engine is the informative snippets of the documents.

Snippet management is a feature of some text editors, program source code editors, IDEs, and related software. It allows the user to avoid repetitive typing in the course of routine edit operations.

Vladimir is working on a snippets project. Vladimir's algorithm selects the most appropriate snippet for the document, but it only considers such parts of the document that contain words that occur in the query.

You are given a sequence of words w1, w2, ..., wn and the set of words s1, s2, ..., sk (different words from the query). Find the number of pairs of indices (l, r) (1 ≤ l ≤ r ≤ n) such that among the words wl, wl + 1, ..., wr there are all query words si. We say that word si occurs on the segment from l to r if and only if there exits j, such that wj = si and l ≤ j ≤ r. That is, we count only exact matches and do not consider substrings.

Input

The first input line contains two integers n and k (1 ≤ n, k ≤ 100 000), the number of words in the document and the number of words in the query, respectively. The second line contains n words wi (1 ≤ |wi| ≤ 10). The third line contains k different words si (1 ≤ |si| ≤ 10).

The words in the lines are separated by single spaces. The words consist of lowercase English letters.

Output

In a single line print the number of pairs of indices satisfying the problem.

ExamplesInput
6 2
yandex search engine algorithm is powerful
yandex algorithm
Output
3
Input
9 1
the best solution is trying to find better solution
solution
Output
27
Input
7 2
a b a c a b a
b a
Output
18

加入题单

算法标签: