乐逍遥xwl

导航

Codeforces Round #565 (Div. 3) B. Merge it!

Codeforces Round #565 (Div. 3) 

 

B. Merge it!

You are given an array aa consisting of nn integers a1,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 t independent queries.

Input

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

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

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

Output

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

Example

input

2

5

3 1 2 3 1

7

1 1 1 1 1 2 2

output

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][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整除的数。

思路:这显然是一道数学题,可以用三个变量记录数组中被3整除、余1、余2的个数,

然后考虑到最大,则最好每个余1的都跟余2的组合,剩下的余1的或余2的如果满足3个则又能组成一组......

 

 

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<cmath>
 5 #include<algorithm>
 6 #include<map>
 7 #include<set>
 8 #include<vector>
 9 using namespace std;
10 #define ll long long
11 //const int maxn=;
12 int main()
13 {
14     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
15     int T;
16     cin>>T;
17     int n,num;
18     while(T--)
19     {
20         cin>>n;
21         ll int a=0,b=0,c=0;
22         for(int i=0;i<n;i++)
23         {
24             cin>>num;
25             if(num%3==0)
26                 a++;
27             else if(num%3==1)
28                 b++;
29             else if(num%3==2)
30                 c++;
31         }
32         ll int ans=0;
33         ans+=a;//第一部分 
34         ans+=min(b,c);//第二部分 
35         ans+=(b-min(b,c))/3+(c-min(b,c))/3;//第三部分 
36         cout<<ans<<endl;
37     }
38     return 0;
39 }

 

posted on 2019-06-10 21:45  乐逍遥xwl  阅读(393)  评论(0编辑  收藏  举报