Count of elements arriving at a given point at the same time
let count = 1 ; while ( ( i < ( T . length - 1 ) ) && ( T [ i ] == T [ i + 1 ] ) ) { count += 1 ; i += 1 ; } total += ( count * ( count - 1 ) ) / 2 ; i += 1 ; } return total ; }