当前位置:   article > 正文

B. Merge it!_given an array consisting of integers a1, a2,...,

given an array consisting of integers a1, a2,..., an make a1+a2+...+an=0 . y

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given an array aa consisting of nn integers a1,a2,…,ana1,a2,…,an.

In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array [2,1,4][2,1,4] you can obtain the following arrays: [3,4][3,4], [1,6][1,6] and [2,5][2,5].

Your task is to find the maximum possible number of elements divisible by 33 that are in the array after performing this operation an arbitrary (possibly, zero) number of times.

You have to answer tt independent queries.

Input

The first line contains one integer tt (1≤t≤10001≤t≤1000) — the number of queries.

The first line of each query contains one integer nn (1≤n≤1001≤n≤100).

The second line of each query contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109).

Output

For each query print one integer in a single line — the maximum possible number of elements divisible by 33 that are in the array after performing described operation an arbitrary (possibly, zero) number of times.

Example

input

Copy

2
5
3 1 2 3 1
7
1 1 1 1 1 2 2

output

Copy

3
3

Note

In the first query of the example you can apply the following sequence of operations to obtain 33 elements divisible by 33: [3,1,2,3,1]→[3,3,3,1][3,1,2,3,1]→[3,3,3,1].

In the second query you can obtain 33 elements divisible by 33 with the following sequence of operations: [1,1,1,1,1,2,2]→[1,1,1,1,2,3]→[1,1,1,3,3]→[2,1,3,3]→[3,3,3]

解题说明:此题是一道贪心题,将数列按被3除的余数分为三组,然后将余1组和余2组组合为3的倍数,然后将剩下的余1或余2组中的数字3个相加再次得到3的倍数,这样确保3的倍数的数字最多。

  1. #include<cstdio>
  2. #include<iostream>
  3. #include<string>
  4. #include<cstring>
  5. #include<cmath>
  6. #include<algorithm>
  7. using namespace std;
  8. int main()
  9. {
  10. int t, y, q, m;
  11. scanf("%d", &t);
  12. while (t--)
  13. {
  14. scanf("%d", &y);
  15. int nt = 0, wq[5] = { 0 };
  16. while (y--)
  17. {
  18. scanf("%d", &q);
  19. wq[q % 3]++;
  20. }
  21. nt = wq[0];
  22. m = min(wq[1], wq[2]);
  23. nt += m;
  24. wq[1] -= m;
  25. wq[2] -= m;
  26. nt += (wq[1] / 3 + wq[2] / 3);
  27. printf("%d\n", nt);
  28. }
  29. return 0;
  30. }

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/酷酷是懒虫/article/detail/745313
推荐阅读
相关标签
  

闽ICP备14008679号