import
java.util.*;
class
GFG{
static
int
MOD =
1000000007
;
static
int
countSubarrays(Integer[]nums,
Integer[] target)
{
int
N = nums.length;
long
ans = N * (N +
1
) /
2
;
HashMap<Integer,Integer> freq =
new
HashMap<Integer,Integer> ();
HashSet<Integer> active =
new
HashSet<Integer>();
active.addAll(Arrays.asList(target));
int
left =
0
;
for
(
int
right =
0
; right < N; right++)
{
if
(active.contains(nums[right]))
if
(freq.containsKey(nums[right])){
freq.put(nums[right], freq.get(nums[right])+
1
);
}
else
{
freq.put(nums[right],
1
);
}
while
(freq.size() == target.length) {
ans -= (N - right);
if
(active.contains(nums[left])) {
if
(freq.get(nums[left])-
1
==
0
)
freq.remove(nums[left]);
}
left++;
}
}
return
(
int
) (ans % MOD);
}
public
static
void
main(String[] args)
{
Integer[] nums = {
1
,
2
,
2
};
Integer[] target = {
1
,
2
};
System.out.print(countSubarrays(nums, target));
}
}