use std::stable_sort instead of std::sort in AIM

Requested there: #6325