new version with recursive calculation of all values except median