Evolutionary selection of proteins with two folds