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).
import java.io.*;
import java.util.*;

public class E21005{
	
	int n;
	int[] a;

	private void solve() throws Exception {
		n = nextInt();
		int m = nextInt();
		a = new int[n+1];
		for(int i = 1; i <= n; i++) a[i] = nextInt();
		out.println(doit(m) - doit(m+1));
	}
	
	long doit(int m) {
		int[] less = new int[n+1];
		int[] notLess = new int[n+1];
		for(int i = 1; i <= n; i++) {
			less[i] = less[i-1];
			notLess[i] = notLess[i-1];
			if(a[i] < m) less[i]++;
			else notLess[i]++;
		}
		long count = 0;
		AVLTree<Integer> lessMinusNotLess = new AVLTree<Integer>();
		for(int l = n; l >= 0; l--) {
			int val = less[l]-notLess[l];
			count += lessMinusNotLess.countLessThan(val);
			lessMinusNotLess.insert(val);
		}
		return count;
	}
	
	
	
	
	public static void main(String[] args) {
		(new E21005()).run();
	}

	private BufferedReader in;
	private PrintWriter out;
	private StringTokenizer tokenizer;

	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			tokenizer = null;
			out = new PrintWriter(System.out);
			solve();
			in.close();
			out.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	private int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	private long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	private float nextFloat() throws IOException {
		return Float.parseFloat(nextToken());
	}

	private String nextLine() throws IOException {
		return new String(in.readLine());
	}

	private String nextToken() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			tokenizer = new StringTokenizer(in.readLine());
		}
		return tokenizer.nextToken();
	}


}


class AVLTree<E extends Comparable<E>> {
	
	TreeNode<E> root;
	
	public void insert(E data) {
		root = insert(root, data);
	}
	
	public long countLessThan(E val) {
		return countLessThan(root, val);
	}
	
	public long countLessThan(TreeNode<E> node, E val) {
		if(node == null) return 0L;
		else if(val.compareTo(node.data) <= 0) return countLessThan(node.left, val);
		else return (node.left==null?0:node.left.size) + 1 + countLessThan(node.right, val);
	}

	private TreeNode<E> insert(TreeNode<E> node, E data){
		if(node == null) node = new TreeNode<E>(data);
		else {
			if(data.compareTo(node.data) <= 0) node.left = insert(node.left, data);
			else if(data.compareTo(node.data) > 0) node.right = insert(node.right, data);
			node.size = (node.left==null?0:node.left.size)+(node.right==null?0:node.right.size)+1;
		}
		node = checkAVL(node);
		return node;
	}

	private TreeNode<E> checkAVL(TreeNode<E> node){
		if(node != null) {
			int balance = getBalance(node);
			if(balance < -1 || balance > 1) node = rotate(node, balance);
			updateHeight(node);
		}
		return node;
	}

	private TreeNode<E> rotate(TreeNode<E> node, int balance){
		if(balance < -1) {
			if(getBalance(node.left) <= 0) node = rotateLeftLeft(node);
			else node = rotateLeftRight(node);
		}else {
			if(getBalance(node.right) >= 0) node = rotateRightRight(node);
			else node = rotateRightLeft(node);
		}
		return node;
	}
	
	private TreeNode<E> rotateRightLeft(TreeNode<E> node) {
		TreeNode<E> pivot = node.right;
		TreeNode<E> root = pivot.left;
		pivot.left = root.right;
		node.right = root.left;
		root.right = pivot;
		root.left = node;
		updateHeight(pivot);
		updateHeight(node);
		return root;
	}

	private TreeNode<E> rotateRightRight(TreeNode<E> node) {
		TreeNode<E> root = node.right;
		node.right = root.left;
		root.left = node;
		updateHeight(node);
		return root;
	}

	private TreeNode<E> rotateLeftRight(TreeNode<E> node) {
		TreeNode<E> pivot = node.left;
		TreeNode<E> root = pivot.right;
		pivot.right = root.left;
		node.left = root.right;
		root.left = pivot;
		root.right = node;
		updateHeight(pivot);
		updateHeight(node);
		return root;
	}

	private TreeNode<E> rotateLeftLeft(TreeNode<E> node) {
		TreeNode<E> root = node.left;
		node.left = root.right;
		root.right = node;
		updateHeight(node);
		return root;
	}
	
	
	private void updateHeight(TreeNode<E> node) {
		if(node != null) {
			node.height = Math.max(getHeight(node.left), getHeight(node.right))+1;
			node.size = (node.left==null?0:node.left.size)+(node.right==null?0:node.right.size)+1;
		}
	}

	private int getBalance(TreeNode<E> node) {
		return getHeight(node.right) - getHeight(node.left);
	}
	
	private int getHeight(TreeNode<E> node) {
		return node != null? node.height : -1;
	}
		
}

class TreeNode<E extends Comparable<E>>{
	E data;
	int height;
	int size;
	TreeNode<E> left;
	TreeNode<E> right;
	
	public TreeNode(E data){
		this.data = data;
	}
}