You need to provide a strict weak ordering, but
bool sort_by_n( tc a, tc b )
{
return a.n <= b.n;
}
is only a weak order. A strict weak order must return false
if the elements are the same. You need to change it to:
bool sort_by_n( tc a, tc b )
{
return a.n < b.n;
}