From disorganized equality to efficient hierarchy: how group size drives the evolution of hierarchy in human societies