How are khayr and sharr used here?

Ism al-Tafḍīl: Formation, Comparison, Agreement and Parsing