Didn’t find any major issue in your code. A small possible improvement: the fruit sizes are all distinct, so pair is not necessary in ordered set. fast io might also be helpful.