As meticulous Gerald sets the table and caring Alexander sends the postcards, Sergey makes snowmen. Each showman should consist of three snowballs: a big one, a medium one and a small one. Sergey's twins help him: they've already made n snowballs with radii equal to r1r2, ..., rn. To make a snowman, one needs any three snowballs whose radii are pairwise different. For example, the balls with radii 1, 2 and 3 can be used to make a snowman but 2, 2, 3 or 2, 2, 2 cannot. Help Sergey and his twins to determine what maximum number of snowmen they can make from those snowballs.

Input

The first line contains integer n (1 ≤ n ≤ 105) — the number of snowballs. The next line contains n integers — the balls' radii r1r2, ..., rn (1 ≤ ri ≤ 109). The balls' radii can coincide.

Output

Print on the first line a single number k — the maximum number of the snowmen. Next k lines should contain the snowmen's descriptions. The description of each snowman should consist of three space-separated numbers — the big ball's radius, the medium ball's radius and the small ball's radius. It is allowed to print the snowmen in any order. If there are several solutions, print any of them.

Examples

Input
7
1 2 3 4 5 6 7
Output
2
3 2 1
6 5 4
Input
3
2 2 3
Output
0

思路:贪心,每次选出还剩的最大的三个组成一个雪人,用优先队列为数据结构,代码如下:
struct Node {
int id, sum;
Node(int _id = , int _sum = ) : id(_id), sum(_sum){}
bool operator<(const Node &a) const {
return sum < a.sum;
}
}; struct Snowman {
int a, b, c;
Snowman(int _a, int _b, int _c) : a(_a), b(_b), c(_c){}
}; bool comp(int a,int b) {
return a > b;
}
map<int, int> Cache;
vector<Snowman> res;
int n; int main() {
scanf("%d", &n);
priority_queue<Node> q;
for (int i = ; i < n; ++i) {
int tmp;
scanf("%d", &tmp);
Cache[tmp]++;
}
for(auto i = Cache.begin(); i != Cache.end(); ++i)
q.push(Node(i->first,i->second));
while(q.size() > ) {
Node t1, t2, t3;
t1 = q.top(), q.pop();
t2 = q.top(), q.pop();
t3 = q.top(), q.pop();
res.push_back(Snowman(t1.id, t2.id, t3.id));
t1.sum--, t2.sum--, t3.sum--;
if(t1.sum > ) q.push(t1);
if(t2.sum > ) q.push(t2);
if(t3.sum > ) q.push(t3);
}
printf("%d\n", res.size());
for (int i = ; i < res.size(); ++i) {
int tmp[];
tmp[] = res[i].a, tmp[] = res[i].b, tmp[] = res[i].c;
sort(tmp, tmp + , comp);
for(int j = ; j < ; ++j) {
if(j)
printf(" ");
printf("%d", tmp[j]);
}
printf("\n");
}
return ;
}
 

最新文章

  1. Bzoj1305 [CQOI2009]dance跳舞
  2. Android中处理OnClick和OnTouch方法冲突的解决方案
  3. iOS UISlider的使用
  4. WebMatrix之WebMatrix.Data
  5. ubuntu安装LAMP环境
  6. 《大话》之第三者家族 代理 Vs 中介者
  7. android自动填写短信验证码
  8. UVALive 7148 LRIP【树分治+线段树】
  9. NSAssert用法
  10. Oracle数据库的启动与停止
  11. .net 浏览器请求过程(图)
  12. mysql中文乱码解决
  13. css3 -&amp;gt; 多栏布局
  14. 【Demo 0007】Android 信使(Intent)
  15. Calico搭建配置
  16. linux进程管理总结
  17. Wireshark抓包实例诊断TCP连接问题
  18. python全栈开发 * 36知识点汇总 * 180721
  19. ES6 Reflect的认识
  20. servlet 高级知识之Filter

热门文章

  1. SpringBoot RESTful API 架构风格实践
  2. IoT协议LwM2M MQTT与CoAP
  3. USER 指定当前用户,希望以某个已经建立好的用户来运行某个服务进程,不要使用 su 或者 sudo,这些都需要比较麻烦的配置,而且在 TTY 缺失的环境下经常出错。建议使用 gosu
  4. 吴裕雄--天生自然Numpy库学习笔记:NumPy 字符串函数
  5. git 使用点
  6. 【原】Django问题总结
  7. 使用Gogs搭建自己的Git服务--windows
  8. 疫情对国内5G发展的影响
  9. 反射实现定位Servlet中的方法
  10. opencv人脸识别提取手机相册内人物充当数据集,身份识别学习(草稿)