#include #define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i)) #define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i)) #define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i)) #define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i)) #define ALL(x) std::begin(x), std::end(x) using namespace std; struct item_t { int length; int64_t min; bool duplicated; }; int64_t solve2(int64_t k, vector l, vector r) { sort(ALL(l), [&](item_t x1, item_t x2) { return x1.min > x2.min; }); sort(ALL(r), [&](item_t y1, item_t y2) { return y1.min > y2.min; }); int64_t ans = 0; int64_t y_count = 0; int64_t y_sum_length = 0; auto y = r.begin(); for (auto x : l) { for (; y != r.end() and x.min < y->min; ++ y) { y_count += 1; y_sum_length += y->length; } if (not x.duplicated) { ans += x.length * y_count + y_sum_length; } } return ans; } template map > solve1(InputIterator first, InputIterator last) { map > f; int length = 0; int64_t x = INT64_MAX; bool duplicated = false; for (; first != last; ++ first) { length += 1; if (*first == x) { duplicated = true; } else if (*first < x) { x = *first; duplicated = false; } f[*first].push_back(item_t{length, x, duplicated}); } return f; } int64_t solve(int n, int64_t k, const vector & a) { int64_t ans = 0; auto go = [&](auto && go, int l, int r) -> void { if (r - l == 0) return; if (r - l == 1) { if (2 * a[l] == k) { ans += 1; } return; } int m = (r + l) / 2; auto f = solve1(a.rbegin() + (n - m), a.rbegin() + (n - l)); auto g = solve1(a.begin() + m, a.begin() + r); for (auto && it1 : f) { auto it2 = g.find(k - it1.first); if (it2 != g.end()) { ans += solve2(k, it1.second, it2->second); ans += solve2(k, it2->second, it1.second); } } go(go, l, m); go(go, m, r); }; go(go, 0, n); return ans; } int main() { int n; int64_t k; scanf("%d%" SCNd64, &n, &k); vector a(n); REP (i, n) { scanf("%" SCNd64, &a[i]); } int64_t ans = solve(n, k, a); printf("%" PRId64 "\n", ans); return 0; }