#P7954. Chili Pepper Dream Swap

    ID: 21138 Type: Default 1000ms 256MiB

Chili Pepper Dream Swap

Chili Pepper Dream Swap

Chef Marin intends to cook with n chili peppers. He will use all peppers with age \(\le x\) days for dish A and the rest for dish B. Each pepper has its own dream: it knows whether it wants to be used in dish A or dish B.

However, the peppers do not know the value of \(x\). In order to maximize the number of peppers that get to realize their dream, they perform the following adjacent swaps exactly once in a left-to-right pass:

  • For \(i=1,2,\dots,n-1\), compare the current ages of pepper \(i\) and pepper \(i+1\).
  • Suppose in the current pair the pepper with the larger age and the one with the smaller age are indexed by \(i\) and \(i+1\) respectively (if the ages differ). If the pepper with the larger age dreams of dish A and the pepper with the smaller age dreams of dish B, they swap their ages.

After these operations, Chef Marin assigns dish A to every pepper whose final age is \(\le x\), and dish B to every pepper with age \(> x\). Your task is to determine the number of peppers that achieve their dream after the swaps.

Note: If the two peppers have equal ages, no swap is performed.

inputFormat

The first line contains two integers \(n\) and \(x\) \((1 \le n \le 10^5, 1 \le x \le 10^9)\) indicating the number of peppers and the age threshold.

The second line contains \(n\) integers \(a_1, a_2, \dots, a_n\) \((1 \le a_i \le 10^9)\) where \(a_i\) is the initial age (in days) of the \(i\)-th pepper.

The third line is a string of length \(n\) consisting only of characters 'A' and 'B'. The \(i\)-th character indicates whether the \(i\)-th pepper dreams of becoming dish A or dish B.

outputFormat

Output a single integer representing the number of peppers that get to realize their dream after performing the swaps.

sample

3 5
3 7 5
AAB
3