Learning foreach.h, and counted sorting using Maps