A general rearrangement inequality