A theory of efficient cooperation and competition