Pozislav and Minuslav met at a forum on the physics of integers.
It turned out that their research areas are very similar — Pozislav studies energy emissions of positive numbers, while Minuslav studies energy bursts of negative numbers.
The guys decided to combine their efforts and conduct a large-scale study of sign entanglement:
The guys combined their records — now they need to find the number of pairs of events that are entangled by sign.
The first line contains two integers $$$n$$$ and $$$d$$$ $$$(1 \le n \le 3 \cdot 10^5; 1 \le d \le 10^9)$$$ — the number of studied energy events and the maximum time difference for entanglement to exist.
The second line contains $$$n$$$ integers $$$t_i$$$ $$$(1 \le t_i \le 10^9)$$$ — the moment in time when the $$$i$$$-th event occurred.
The third line contains a string $$$S$$$ $$$(|S| = n)$$$ — the signs of the half-axes on which the events occurred:
It is guaranteed that the records are given in chronological order: $$$t_1 \le t_2 \le \ldots \le t_n$$$.
Output a single integer $$$T$$$ $$$(0 \le T \le 10^{18})$$$ — the number of pairs of entangled events by sign.
14 31 1 3 3 3 3 5 5 6 6 6 8 9 11+--+++--+++++-
23
First test example
Events on the positive axis occurred at times $$$[1, 3, 3, 3, 6, 6, 6, 8, 9]$$$. Events on the negative axis occurred at times $$$[1, 3, 5, 5, 11]$$$.
Let's enumerate the entangled pairs of events:
In total, we get $$$1 + 3 + 3 + 6 + 6 + 2 + 1 + 1 = 23$$$ pairs of entangled events.