Duminy and Elgar help S Africa build 181-run lead