Given an unsorted array **A[]** of** distinct integers** and size **N**, and an element **X**, you need to find the **Minimum Number of Elements** required to be added to this array so the new median of array becomes X.

Median of array is middle element of array in its sorted form. For odd number of elements N it is the element at position (N-1)/2. For even number of elements N, it is (A[N/2] + A[(N/2) - 1])/2.

**Input:** The first line contains number of testcases **T.** Every testcase consists of 2 lines, first line contains **N** - no of element of arrays and **X**, and second line contains Array elements in *unsorted* manner.

**Output:** You need to find total number of elements to be added to array so that the new median becomes equal to X.

**Constraints:**

1 <= **T** <= 100

1 <= **N** <= 10^{6}

1 <= **X** <= 10^{6}

1 <= **A[i]** <= 10^{6}

**Example:
Input: **

2

6 30

10 20 30 100 150 200

5 50

10 20 30 100 150

1

1

**Explanation:
Testcase 1: **Only 1 element before 30 is required to be added to the array, to make median of array 30.

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

d_Coder00 | 134 |

Astikeysingh | 128 |

dungeon_master1299 | 126 |

rajendrashekhawat063 | 115 |

VivSisMMM | 112 |

Pulkit__Sharma__ | 646 |

Anirban166 | 531 |

abducodes | 508 |

Found_me | 474 |

Sathvik Avasarala | 418 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4559 |

Login to report an issue on this page.