sum of absolute differences efficient solution