« first day (1074 days earlier)      last day (401 days later) » 

19:04
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
19:17
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.

« first day (1074 days earlier)      last day (401 days later) »