## GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

# [Solution] Almost Triple Deletions CodeForces Solution

D. Almost Triple Deletions
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given an integer $n$ and an array ${a}_{1},{a}_{2},\dots ,{a}_{n}$.

In one operation, you can choose an index $i$ ($1\le i) for which ${a}_{i}\ne {a}_{i+1}$ and delete both ${a}_{i}$ and ${a}_{i+1}$ from the array. After deleting ${a}_{i}$ and ${a}_{i+1}$, the remaining parts of the array are concatenated.

For example, if $a=\left[1,4,3,3,6,2\right]$, then after performing an operation with $i=2$, the resulting array will be $\left[1,3,6,2\right]$.

What is the maximum possible length of an array of equal elements obtainable from $a$ by performing

Solution Click Below:-  👉
👇👇👇👇👇

several (perhaps none) of the aforementioned operations?

Input

Each test contains multiple test cases. The first line of input contains one integer $t$ ($1\le t\le 1000$) — the

The Third Three Number Problem Codeforces Solution

Almost Ternary Matrix Codeforces Solution

The Third Problem Codeforces Solution

Almost Triple Deletions CodeForces Solution

Three Days Grace Codeforces Solution

number of test cases. The following lines contain the descriptions of the test cases.

The first line of each test case contains a single integer $n$ ($1\le n\le 5000$) — the length of array $a$.

The second line of each test case contains $n$ integers ${a}_{1},{a}_{2},\dots ,{a}_{n}$ ($1\le {a}_{i}\le n$) — the elements of array $a$.

It is guaranteed that the sum of $n$ across all test cases does not exceed $10\phantom{\rule{thinmathspace}{0ex}}000$.

Output

For each testcase, print a single integer, the maximum possible length of an array of equal elements obtainable from $a$ by performing a sequence of operations.