Codeforces Round 1098 (Div. 2)
A
Marisa Steals Reimu's Takeout
Codeforces
800
原题
←B →
翻译中…

The Darkness Brought In by Swallowstone Naturalis Historia— Dateless Bar "Old Adam"

翻译中…

Marisa is a girl of integrity who always helps others safeguard their belongings. Over a period of $n$ days, she comes each day to take one of Reimu's takeouts. The $i$-th takeout is described by its deliciousness value — an integer $w_i$ ($0\le w_i\le 2$), forming a sequence $w$ of length $n$.

翻译中…

Marisa has a special fondness for the number $3$. She can perform the following operation zero or more times:

翻译中…
  • Select a non-empty subsequence$^{\text{∗}}$ of $w$ whose sum is divisible by $3$, and remove the elements of the subsequence from $w$.
翻译中…

Determine the maximum number of operations Marisa can perform.

翻译中…

$^{\text{∗}}$A sequence $a$ is a subsequence of a sequence $b$ if $a$ can be obtained from $b$ by the deletion of several (possibly, zero or all) element from arbitrary positions.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 500$). The description of the test cases follows.

翻译中…

The first line of each test case contains a single integer $n$ ($1\le n \le 100$).

翻译中…

The second line contains $n$ integers $w_1, w_2, \ldots, w_n$ ($0\leq w_i \leq 2$), denoting the deliciousness values of the takeouts.

翻译中…

Output

翻译中…

For each test case, output the maximum number of operations Marisa can perform.

翻译中…

Note

翻译中…

In the first test case, Marisa can perform four operations: $$[\underline{0},0,0,0]\to[\underline{0},0,0]\to[\underline{0},0]\to[\underline{0}]\to [].$$

翻译中…

In the second test case, Marisa can perform two operations: $$[\underline{1},\underline{2},0]- \gt [\underline{0}]- \gt [].$$

翻译中…

In the third test case, Marisa can perform two operations: $$[\underline{1},2,1,\underline{2},1]- \gt [\underline{2},1,\underline{1}]- \gt [1].$$

翻译中…

样例

Input #1
3
4
0 0 0 0
3
1 2 0
5
1 2 1 2 1
Output #1
4
2
2
InputCopy OutputCopy
题目信息
题号
2228A
时间限制
1 s
内存限制
256 MB
标签
贪心
模拟

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。