Fix GetNextWorkRequired (part 1)

This patch calculates Median correctly.
Previously target time was just a constrained pseudo-random value, influenced by only one specific block in the look back period.