define beauty permutation number 1 n p_1 p_2 dot p_n number pair L R 1 le L le R le n number p_l p_L1 dot p_r consecutive RL1 number order for example beauty permutation 1 2 5 3 4 equal 9 segment correspond pair 1 2 5 4 3 1 2 3 4 5 3 4 1 2 5 3 4answer q independent query in query give integer n k Determine exist permutation number 1 n beauty equal k exist output