Sensex rises 399 points; pharma stocks surge for third day