Longest Unfriendly Subsequence
시간 제한1초메모리 제한1024 MB
고른 원소 중 인덱스 차이가 2 이하인 어떤 두 원소도 서로 다른, 수열 a의 가장 긴 부분수열의 길이를 구한다.
문제
Let's call sequence unfriendly, if the following condition holds:
- If and , then .
In other words, a sequence is unfriendly if any two elements on the distance at most are different.
You are given a sequence . Find the length of its longest unfriendly subsequence.
A sequence is a subsequence of a sequence if can be obtained from by deletion of several (possibly, zero or all) elements. For example, is a subsequence of while is not.
입력
The first line contains a single integer () - the number of test cases. The description of test cases follows.
The first line of each test case contains a single integer () - the length of the sequence.
The second line of each test case contains integers () - the elements of the sequence .
It's guaranteed that the sum of over all test cases doesn't exceed .
출력
For each test case, output a single integer - the length of the longest unfriendly subsequence of .
힌트
In the first test case, the longest unfriendly subsequences are and . The subsequence , for example, is not unfriendly, as its -st and -rd elements are equal.
In the second test case, the longest unfriendly subsequence is . It's clear that the subsequence which consists of the whole sequence is not unfriendly, so the answer is .
In the third test case, the longest unfriendly subsequence is .