const NOT_FOUND = - 1 ;

const NUM_OF_ITERATIONS = 1e6 ;

var multiples_of_three = new Array ( ) ;

var multiples_of_five = new Array ( ) ;

Array . prototype . swap = function ( x , y ) {

var temp = this [ x ] ; this [ x ] = this [ y ] ; this [ y ] = temp ;

} ;

Array . prototype . my_sort = function ( from , to ) {

if ( isFinite ( from ) == false || isFinite ( to ) == false ) return this . sort ( 0 , this . length - 1 ) ;

if ( this [ from ] > this [ to ] ) this . swap ( from , to ) ;

if ( to - from + 1 >= 3 ) {

var t = Math . floor ( ( to - from + 1 ) / 3 ) ;

this . my_sort ( from , to - t ) ;

this . my_sort ( from + t , to ) ;

this . my_sort ( from , to - t ) ;

}

return this ;

} ;

function union_two_arrays ( A , B ) {

var result = [ ] ;

for ( var index = 0 ; index < A. length ; index = index + 1 ) result. push ( A [ index ] ) ;

for ( var index = 0 ; index < B. length ; index = index + 1 ) if ( result. indexOf ( B [ index ] ) == NOT_FOUND ) result. push ( B [ index ] ) ;

return result ;

}

function generate_random_number_between ( from , to ) {

var random_number = Math . random ( ) ;

return Math . floor ( random_number * ( to - from + 1 ) ) + from ;

}

for ( var num_of_iterations = NUM_OF_ITERATIONS ; num_of_iterations --> 0 ; ) {

var random_number = generate_random_number_between ( 1 , 999 ) ;

if ( random_number % 3 == 0 && multiples_of_three. indexOf ( random_number ) == NOT_FOUND ) multiples_of_three. push ( random_number ) ;

if ( random_number % 5 == 0 && multiples_of_five. indexOf ( random_number ) == NOT_FOUND ) multiples_of_five. push ( random_number ) ;

}

var multiples_of_three_sorted = multiples_of_three. my_sort ( ) ;

var multiples_of_five_sorted = multiples_of_five. my_sort ( ) ;

var multiples_of_three_or_five = union_two_arrays ( multiples_of_three_sorted , multiples_of_five_sorted ) ;

for ( var result = 0 , index = 0 ; index < multiples_of_three_or_five. length ; index = index + 1 ) {

result = result + multiples_of_three_or_five [ index ] ;

}