← Home
package main

import (
	"fmt"
	"io"
	"os"
)

func main() {
	buf, _ := io.ReadAll(os.Stdin)
	pos := 0

	nextInt := func() int {
		for pos < len(buf) && (buf[pos] < '0' || buf[pos] > '9') && buf[pos] != '-' {
			pos++
		}
		if pos == len(buf) {
			return 0
		}
		sign := 1
		if buf[pos] == '-' {
			sign = -1
			pos++
		}
		res := 0
		for pos < len(buf) && buf[pos] >= '0' && buf[pos] <= '9' {
			res = res*10 + int(buf[pos]-'0')
			pos++
		}
		return res * sign
	}

	n := nextInt()
	if n == 0 {
		return
	}
	m := nextInt()

	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextInt()
	}

	countGreaterEqual := func(mVal int) int64 {
		cnt := make([]int, 2*n+2)
		offset := n + 1

		var ans int64 = 0
		curr := 0
		cnt[curr+offset] = 1
		smallerCount := 0

		for i := 0; i < n; i++ {
			if a[i] >= mVal {
				curr++
				smallerCount += cnt[curr-1+offset]
			} else {
				curr--
				smallerCount -= cnt[curr+offset]
			}
			ans += int64(smallerCount)
			cnt[curr+offset]++
		}

		return ans
	}

	ans := countGreaterEqual(m) - countGreaterEqual(m+1)
	fmt.Println(ans)
}