The formula are equal because we can use use multiplication to group the same number. We can group the same number together and count the sum by using multiplication. Example, $44+46+47+47+47+51=44(1)+46(1)+47(3)+51$. @Swarup
A remark is the notation difference between the formula, the $x_i$ refers to the $i$-th data in the first formula. In the second formula $x_i$ refers to the $i$-th distinct value.