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] you can obtain the following arrays: [3,4], [1,6] and [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,…,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]

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

任何数%3结果只有0,1,2三种,三个1可以组成一组,三个2可以组成一组。

#include<iostream>
#include<stdio.h>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxx = 1e5+10;
int dp[110];



int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        int i,j;
        int count = 0;
        dp[1] = 0;
        dp[2] = 0;
        for(i=0; i<n; i++)
        {
            int x;
            scanf("%d",&x);
            if(x%3==0)
                count++;
            else
            {
                dp[x%3]++;
            }
        }
        int t = min(dp[1],dp[2]);
        count +=t;
        dp[1] -=t;
        dp[2] -=t;
        if(dp[1])
        {
            count +=dp[1]/3;
        }
        if(dp[2])
        {
            count +=dp[2]/3;
        }
        printf("%d\n",count);
    }
    return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值