PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#TP0000055. Những con kiến ma (Ghost Ants)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

2 lộ trình

Những con kiến ma (Ghost Ants)

Ghost Ants

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn ants, numbered 11 through nn, on a number line. Ant ii initially stands at integer coordinate XiX_i, and all initial coordinates are distinct. Binary string SS of length nn specifies their directions: Si=0S_i=\texttt{0} means left, while Si=1S_i=\texttt{1} means right.

From time 00, each ant moves at constant speed 11 in its chosen direction until time T+0.1T+0.1. When ants meet, they pass through one another without changing direction or speed. They then stop at that ending time.

Count the pairs of different ants that have met between time 00 and time T+0.1T+0.1, counting each pair once.

Input

  • The first line contains integers n,Tn,T: the number of ants and the time parameter.
  • The second line contains a binary string SS of exactly nn characters, encoding directions.
  • The third line contains exactly nn integers X1,…,XnX_1,\ldots,X_n, the initial positions in ant-number order.

Output

Print one integer: the number of ant pairs meeting within the specified time.

Subtasks

  • Subtask 1 (20 points): 2≤n≤252\le n\le 25; 1≤T≤1091\le T\le10^9; S∈{0,1}nS\in\{0,1\}^n; −109≤Xi≤109-10^9\le X_i\le10^9 for every ii; all XiX_i are pairwise distinct.
  • Subtask 2 (30 points): 2≤n≤20002\le n\le 2000; 1≤T≤1091\le T\le10^9; S∈{0,1}nS\in\{0,1\}^n; −109≤Xi≤109-10^9\le X_i\le10^9 for every ii; all XiX_i are pairwise distinct.
  • Subtask 3 (50 points): 2≤n≤2000002\le n\le 200000; 1≤T≤1091\le T\le10^9; S∈{0,1}nS\in\{0,1\}^n; −109≤Xi≤109-10^9\le X_i\le10^9 for every ii; all XiX_i are pairwise distinct.

Examples

Input

6 3
101010
-5 -1 0 1 2 4

Output

5

Explanation

Exactly five ant pairs meet: (3,4)(3,4) at time 0.50.5, (5,6)(5,6) at 11, (1,2)(1,2) at 22, (3,6)(3,6) at 22, and (1,4)(1,4) at 33. All occur no later than time 3.13.1, giving answer 55.