Improvements.
Input data added; algorithm is corrected.