let look follow process initially stack array s length l you try push array element stack order s_1 s_2 s_3 dot s_l moreover stack element stack equal current element push current element stack otherwise do not push current element stack pop element stack if process stack remain array s consider stack exterminablethere sample stack exterminable array 1 1 2 1 1 2 1 1 2 2 1 3 3 1 2 2 3 1 3 3 1 3 3 3 3 3 3 3 5 1 2 2 1 4 4 5 Lets consider change stack detail s 5 1 2 2 1 4 4 5 stack highlight push s_1 5 stack turn textbf5 push s_2 1 stack turn 5 textbf1 push s_3 2 stack turn 5 1 textbf2 push s_4 2 stack turn 5 textbf1 push s_5 1 stack turn textbf5 push s_6 4 stack turn 5 textbf4 push s_7 4 stack turn textbf5 push s_8 5 stack you give array a_1 a_2 ldot a_n you calculate number subarray stack exterminablenote answer q independent query