to find the median of the input array