https://www.acmicpc.net/problem/3052 My attempt const input = require ( 'fs' ) . readFileSync ( '/dev/stdin' ) . toString () . split ( ' \n ' ); const arr = [ 39 , 40 , 41 , 42 , 43 , 44 , 82 , 83 , 84 , 85 ]; const newArr = []; for ( let i = 0 ; i < input . length ; i ++ ) { const rest = ( Number ( input [ i ]) % 42 ); newArr . push ( rest ) } let set1 = new Set ( newArr ); console . log ( set1 . size ); This site might not accept Set syntax yet. Others const input = require ( "fs" ) . readFileSync ( "/dev/stdin" ) . toString () . split ( " \n " ); const userNum = []; input . forEach ( ( x ) => { const num = x % 42 ; if ( userNum . indexOf ( num ) === - 1 ) { userNum . push ( num ); } }); console . log ( userNum . length );