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的倍数的数字最多。

#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;int main()
{int t, y, q, m;scanf("%d", &t);while (t--) {scanf("%d", &y);int nt = 0, wq[5] = { 0 };while (y--) {scanf("%d", &q);wq[q % 3]++;}nt = wq[0];m = min(wq[1], wq[2]);nt += m;wq[1] -= m;wq[2] -= m;nt += (wq[1] / 3 + wq[2] / 3);printf("%d\n", nt);}return 0;
}

B. Merge it!相关推荐

  1. GitHub 中 Merge pull request 的 3 中选项说明

    Merge pull request 提供了 3 种 merge 方法: Create a merge commit:GitHub 的底层操作是 git merge --no-ff.feature 分 ...

  2. Android布局优化之include、merge、ViewStub

    include:引入重复使用的相同布局 merge:减少include布局的层级,将子元素直接添加到merge标签的parent中 ViewStub:其实就是一个宽高都为0的一个View,它默认是不可 ...

  3. SQL 利用merge 同步数据库之间表的数据

    同步两个数据库之间两表的数据也许的数据库管理员偶尔需要做的一件事情,下面来记录一下常用的两种方法: 方法一:使用delete.truncate 方法二:使用 merge into  ,Merge是在S ...

  4. update 改写 merge into

    update语句改写成merge into有时会提高运行速度 看两个案例 1.根据业务将两个嵌套子查询改写成max,速度有3min提升到3s UPDATE OPER_792.LL_SCB_YDKB_2 ...

  5. 分离颜色通道(split)和多通道融合(merge)

    //通道的拆分 Mat srcImg=imread("1.jpg"); Mat ImgBChannel,ImgGChannel,ImgRChannel,mergeImg; vect ...

  6. LeetCode刷题记录15——21. Merge Two Sorted Lists(easy)

    LeetCode刷题记录15--21. Merge Two Sorted Lists(easy) 目录 LeetCode刷题记录15--21. Merge Two Sorted Lists(easy) ...

  7. Oracle中的MERGE语句

    转自http://blog.chinaunix.net/space.php?uid=16981447&do=blog&cuid=430716 做了简单的格式整理,加入了一点点原创的东西 ...

  8. MYSQL的MERGE存储引擎

    MYSQL的引擎不是一般的多,这次说到的是MERGE,这个引擎有很多特殊的地方: MERGE引擎类型允许你把许多结构相同的表合并为一个表.然后,你可以执行查询,从多个表返回的结果就像从一个表返回的结果 ...

  9. OpenCV代码提取:merge/split函数的实现

    对OpenCV中的merge/split函数进行了实现,经测试,与OpenCV3.1结果完全一致. merge实现代码merge.hpp: // fbc_cv is free software and ...

  10. Oracle中merge into的使用

    http://blog.csdn.net/yuzhic/article/details/1896878 http://blog.csdn.net/macle2010/article/details/5 ...

最新文章

  1. 业务高峰期不小心拔掉了服务器电源!!
  2. Conficker蠕虫新动作 P2P更新5月份关闭
  3. 怎么给vue定义全局方法
  4. 走近分形与混沌(part13)--自然现象就其本质来说,是复杂而非线性的
  5. Github客户端使用教程
  6. modulenotfounderror python_python程序在命令行执行提示ModuleNotFoundError: No module named 'XXX' 解决方法...
  7. Python压缩图片到指定大小
  8. python ipaddr库_python访问纯真IP数据库的代码
  9. google浏览器添加抓包插件
  10. 有了这十五款编程游戏,谁都可以学编程!
  11. 计算机怎么看事件管理,用事件查看器查看电脑使用记录
  12. 国庆长假来啦!这些消遣目的地最适合程序员
  13. EIGRP优化—末节路由简介
  14. mysql sql where or_SQL的WHERE子句中包含多个AND和OR
  15. 信捷原创程序,8个伺服轴。 PLC:信捷XDM-60T10 HMI:信捷TG765 总体I/O在200个点之内
  16. 基础C语言代码(10题)
  17. c语言源代码万年历,万年历-C语言源代码.pdf
  18. 【编译原理】符号表的实现C语言
  19. 饭店 火锅店无线网络覆盖 案例
  20. VMware安装win10遇到的一个错误及解决方式

热门文章

  1. 【面向对象】电梯与多线程的是非故事——第二单元课程总结
  2. VS2013 TeeChart_v5 MFC C++ 使用手册干货(二)TeeChart 实时数据图表
  3. yii框架学习(一)yii框架介绍
  4. linux如何取消分区加密,linux下分区与加密详解
  5. 兼容IE7、IE8、IE9的input type=number插件
  6. udp包为什么最好不要大于1472字节
  7. 图解如何计算结构体大小
  8. 丁磊:别把不吭声的鳄鱼当壁虎 没觉得马云多了不起
  9. Python学习日记(四) 集合和元祖
  10. 记一枚蒟蒻的数模国赛参赛经历