#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const int INF = 1e9;
const long long IINF = 1e18;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const char dir[4] = {'D', 'R', 'U', 'L'};
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
  for (T &x : v) is >> x;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for (int i = 0; i < v.size(); ++i) {
    os << v[i] << (i + 1 == v.size() ? "" : " ");
  }
  return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  cout << '(' << p.first << ',' << p.second << ')';
  return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &m) {
  os << '{';
  for (auto itr = m.begin(); itr != m.end(); ++itr) {
    os << '(' << itr->first << ',' << itr->second << ')';
    if (++itr != m.end()) os << ',';
    --itr;
  }
  os << '}';
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> &s) {
  os << '{';
  for (auto itr = s.begin(); itr != s.end(); ++itr) {
    os << *itr;
    if (++itr != s.end()) os << ',';
    --itr;
  }
  os << '}';
  return os;
}
void debug_out() { cerr << '\n'; }
template <class Head, class... Tail>
void debug_out(Head &&head, Tail &&...tail) {
  cerr << head;
  if (sizeof...(Tail) > 0) cerr << ", ";
  debug_out(move(tail)...);
}
template <class T1, class T2>
inline bool chmin(T1 &a, T2 b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T1, class T2>
inline bool chmax(T1 &a, T2 b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
struct BinaryIndexedTree {
  vector<T> dat;
  BinaryIndexedTree(int n) : dat(n + 1, 0) {}
  void add(int i, T x) {
    if (i == 0) return;
    for (; i <= dat.size(); i += (i & -i)) dat[i] += x;
  }
  T sum(int i) {
    T res = 0;
    for (; i > 0; i -= (i & -i)) res += dat[i];
    return res;
  }
  T query(int l, int r) { return sum(r - 1) - sum(l - 1); }
  int lower_bound(T x) {
    if (x <= 0) return 0;
    int lb = 0, r = 1;
    while (r < dat.size()) r <<= 1;
    for (; r > 0; r >>= 1) {
      if (lb + r < dat.size() && dat[lb + r] < x) {
        x -= dat[lb + r];
        lb += r;
      }
    }
    return lb + 1;
  }
  void add0(int i, T x) { add(i + 1, x); }
  T sum0(int i) { return sum(i + 1); }
  T query0(int l, int r) { return sum(r) - sum(l); }
};
const int MAX = 2e5 + 10;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> a(n), b(n + 1, 0), c(n + 1, 0), d(n + 1), e(n + 1);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    b[i + 1] = (a[i] <= m ? 1 : 0);
    c[i + 1] = (a[i] <= m - 1 ? 1 : 0);
  }
  for (int i = 0; i <= n; ++i) {
    if (i) {
      b[i] += b[i - 1];
      c[i] += c[i - 1];
    }
    d[i] = 2 * b[i] - i + MAX;
    e[i] = 2 * c[i] - i + MAX;
  }
  BinaryIndexedTree<int> BIT0(MAX * 2), BIT1(MAX * 2);
  long long ans0 = 0, ans1 = 0;
  for (int i = 0; i <= n; ++i) {
    ans0 += BIT0.sum(d[i]);
    ans1 += BIT1.sum(e[i]);
    BIT0.add(d[i], 1);
    BIT1.add(e[i], 1);
  }
  cout << ans0 - ans1 << '\n';
}

### Prompt

Your task is to create a CPP solution to the following problem:

You are given a permutation p_1, p_2, ..., p_n. A permutation of length n is a sequence such that each integer between 1 and n occurs exactly once in the sequence.

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

The median of a sequence is the value of the 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 the median of p_l, p_{l+1}, ..., p_r is exactly the given number m.

Input

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

The second line contains a permutation p_1, p_2, ..., p_n (1 ≤ p_i ≤ n). Each integer between 1 and n occurs in p exactly once.

Output

Print the required number.

Examples

Input

5 4
2 4 5 3 1


Output

4


Input

5 5
1 2 3 4 5


Output

1


Input

15 8
1 15 2 14 3 13 4 8 12 5 11 6 10 7 9


Output

48

Note

In the first example, the suitable pairs of indices are: (1, 3), (2, 2), (2, 3) and (2, 4).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const int INF = 1e9;
const long long IINF = 1e18;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const char dir[4] = {'D', 'R', 'U', 'L'};
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
  for (T &x : v) is >> x;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for (int i = 0; i < v.size(); ++i) {
    os << v[i] << (i + 1 == v.size() ? "" : " ");
  }
  return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  cout << '(' << p.first << ',' << p.second << ')';
  return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &m) {
  os << '{';
  for (auto itr = m.begin(); itr != m.end(); ++itr) {
    os << '(' << itr->first << ',' << itr->second << ')';
    if (++itr != m.end()) os << ',';
    --itr;
  }
  os << '}';
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> &s) {
  os << '{';
  for (auto itr = s.begin(); itr != s.end(); ++itr) {
    os << *itr;
    if (++itr != s.end()) os << ',';
    --itr;
  }
  os << '}';
  return os;
}
void debug_out() { cerr << '\n'; }
template <class Head, class... Tail>
void debug_out(Head &&head, Tail &&...tail) {
  cerr << head;
  if (sizeof...(Tail) > 0) cerr << ", ";
  debug_out(move(tail)...);
}
template <class T1, class T2>
inline bool chmin(T1 &a, T2 b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T1, class T2>
inline bool chmax(T1 &a, T2 b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
struct BinaryIndexedTree {
  vector<T> dat;
  BinaryIndexedTree(int n) : dat(n + 1, 0) {}
  void add(int i, T x) {
    if (i == 0) return;
    for (; i <= dat.size(); i += (i & -i)) dat[i] += x;
  }
  T sum(int i) {
    T res = 0;
    for (; i > 0; i -= (i & -i)) res += dat[i];
    return res;
  }
  T query(int l, int r) { return sum(r - 1) - sum(l - 1); }
  int lower_bound(T x) {
    if (x <= 0) return 0;
    int lb = 0, r = 1;
    while (r < dat.size()) r <<= 1;
    for (; r > 0; r >>= 1) {
      if (lb + r < dat.size() && dat[lb + r] < x) {
        x -= dat[lb + r];
        lb += r;
      }
    }
    return lb + 1;
  }
  void add0(int i, T x) { add(i + 1, x); }
  T sum0(int i) { return sum(i + 1); }
  T query0(int l, int r) { return sum(r) - sum(l); }
};
const int MAX = 2e5 + 10;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> a(n), b(n + 1, 0), c(n + 1, 0), d(n + 1), e(n + 1);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    b[i + 1] = (a[i] <= m ? 1 : 0);
    c[i + 1] = (a[i] <= m - 1 ? 1 : 0);
  }
  for (int i = 0; i <= n; ++i) {
    if (i) {
      b[i] += b[i - 1];
      c[i] += c[i - 1];
    }
    d[i] = 2 * b[i] - i + MAX;
    e[i] = 2 * c[i] - i + MAX;
  }
  BinaryIndexedTree<int> BIT0(MAX * 2), BIT1(MAX * 2);
  long long ans0 = 0, ans1 = 0;
  for (int i = 0; i <= n; ++i) {
    ans0 += BIT0.sum(d[i]);
    ans1 += BIT1.sum(e[i]);
    BIT0.add(d[i], 1);
    BIT1.add(e[i], 1);
  }
  cout << ans0 - ans1 << '\n';
}

```