You are given an integer sequence a_1, a_2, ..., a_n.

Find the number of pairs of indices (l, r) (1 ≤ l ≤ r ≤ n) such that the value of median of a_l, a_{l+1}, ..., a_r is exactly the given number m.

The median of a sequence is the value of an element which is in the middle of the sequence after sorting it in non-decreasing order. If the length of the sequence is even, the left of two middle elements is used.

For example, if a=[4, 2, 7, 5] then its median is 4 since after sorting the sequence, it will look like [2, 4, 5, 7] and the left of two middle elements is equal to 4. The median of [7, 1, 2, 9, 6] equals 6 since after sorting, the value 6 will be in the middle of the sequence.

Write a program to find the number of pairs of indices (l, r) (1 ≤ l ≤ r ≤ n) such that the value of median of a_l, a_{l+1}, ..., a_r is exactly the given number m.

Input

The first line contains integers n and m (1 ≤ n,m ≤ 2⋅10^5) — the length of the given sequence and the required value of the median.

The second line contains an integer sequence a_1, a_2, ..., a_n (1 ≤ a_i ≤ 2⋅10^5).

Output

Print the required number.

Examples

Input

5 4
1 4 5 60 4


Output

8


Input

3 1
1 1 1


Output

6


Input

15 2
1 2 3 1 2 3 1 2 3 1 2 3 1 2 3


Output

97

Note

In the first example, the suitable pairs of indices are: (1, 3), (1, 4), (1, 5), (2, 2), (2, 3), (2, 5), (4, 5) and (5, 5).
#include <bits/stdc++.h>
using namespace std;
int n, m;
int arr[200003];
void read() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> arr[i];
}
class bit {
 public:
  unordered_map<int, unordered_map<int, int> > tr;
  void add(int a, int b) {
    a += n + 2;
    b += n + 2;
    for (int i = a; i < 3 * 200003; i += i & (-i))
      for (int j = b; j < 3 * 200003; j += j & (-j)) tr[i][j]++;
  }
  int get_prefix(int a, int b) {
    a += n + 2;
    b += n + 2;
    int ans = 0;
    for (int i = a; i > 0; i -= i & (-i))
      if (tr.count(i))
        for (int j = b; j > 0; j -= j & (-j))
          if (tr[i].count(j)) ans += tr[i][j];
    return ans;
  }
  int get(int a, int b) {
    return get_prefix(a, 3 * 200003) - get_prefix(a, b - 1);
  }
};
bit even, odd;
void solve() {
  for (int i = 1; i <= n; i++) {
    if (arr[i] < m)
      arr[i] = 0;
    else if (arr[i] == m)
      arr[i] = 1;
    else
      arr[i] = 2;
  }
  int a = 0, b = 0, c = 0;
  even.add(0, 0);
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    if (arr[i] == 0)
      a++;
    else if (arr[i] == 1)
      b++;
    else
      c++;
    if (i % 2 == 0) {
      int first = a + b - c;
      int second = a - b - c + 1;
      ans += even.get(first, second);
      first--;
      ans += odd.get(first, second);
      even.add(a + b - c, a - b - c);
    } else {
      int first = a + b - c;
      int second = a - b - c + 1;
      ans += odd.get(first, second);
      first--;
      ans += even.get(first, second);
      odd.add(a + b - c, a - b - c);
    }
  }
  cout << ans << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  read();
  solve();
}
