Evil Subsequence

배열 a의 부분수열 중 배열 b와 매칭되는 것의 개수를 구한다.

어려움8동적 계획법조합론해시맵아직 제출이 없습니다시간 제한3초메모리 제한512 MB

문제

It’s just a problem to waste your time.

You are given two sequences a1, a2, . . . , an and b1, b2, . . . , bm.

Two sequences (x1, x2, . . . , xp) and (y1, y2, . . . , yq) match iff p = q and xi = xj ⇔ yi = yj for every possible pair 1 ≤ i, j ≤ p.

Output the number of subsequences of a1, a2, . . . , an that match b1, b2, . . . , bm.

입력

The first line contains two integers n, m (1 ≤ n ≤ 3000, 1 ≤ m ≤ min(5, n)).

The second line contains n integers a1, a2, . . . , an (1 ≤ ai ≤ n).

The third line contains m integers b1, b2, . . . , bm (1 ≤ bi ≤ m).

출력

Output one integer: the answer.