Run the code r times and select the best runs' output