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 ;
}
 

Day3-E-New Year Snowmen CodeForces140C的更多相关文章

  1. 冲刺阶段day3

    day3 项目进展 今天周三,我们五个人难得的一整个下午都能聚在一起.首先我们对昨天的成果一一地查看了一遍,并且坐出了修改.后面的时间则是做出 登录界面的窗体,完善了登录界面的代码,并且实现了其与数据 ...

  2. python笔记 - day3

    python笔记 - day3 参考:http://www.cnblogs.com/wupeiqi/articles/5453708.html set特性: 1.无序 2.不重复 3.可嵌套 函数: ...

  3. python_way,day3 集合、函数、三元运算、lambda、python的内置函数、字符转换、文件处理

    python_way,day3 一.集合 二.函数 三.三元运算 四.lambda 五.python的内置函数 六.字符转换 七.文件处理 一.集合: 1.集合的特性: 特性:无序,不重复的序列 如果 ...

  4. Spark菜鸟学习营Day3 RDD编程进阶

    Spark菜鸟学习营Day3 RDD编程进阶 RDD代码简化 对于昨天练习的代码,我们可以从几个方面来简化: 使用fluent风格写法,可以减少对于中间变量的定义. 使用lambda表示式来替换对象写 ...

  5. Spark Tungsten揭秘 Day3 内存分配和管理内幕

    Spark Tungsten揭秘 Day3 内存分配和管理内幕 恭喜Spark2.0发布,今天会看一下2.0的源码. 今天会讲下Tungsten内存分配和管理的内幕.Tungsten想要工作,要有数据 ...

  6. Catalyst揭秘 Day3 sqlParser解析

    Catalyst揭秘 Day3 sqlParser解析 今天我们会进入catalyst引擎的第一个模块sqlparser,它是catalyst的前置模块. 树形结构 从昨天的介绍我们可以看到sqlPa ...

  7. Kakfa揭秘 Day3 Kafka源码概述

    Kakfa揭秘 Day3 Kafka源码概述 今天开始进入Kafka的源码,本次学习基于最新的0.10.0版本进行.由于之前在学习Spark过程中积累了很多的经验和思想,这些在kafka上是通用的. ...

  8. python s12 day3

    python s12 day3   深浅拷贝 对于 数字 和 字符串 而言,赋值.浅拷贝和深拷贝无意义,因为其永远指向同一个内存地址. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ...

  9. Day3 - Python基础3 函数、递归、内置函数

    Python之路,Day3 - Python基础3   本节内容 1. 函数基本语法及特性 2. 参数与局部变量 3. 返回值 嵌套函数 4.递归 5.匿名函数 6.函数式编程介绍 7.高阶函数 8. ...

随机推荐

  1. ubuntu 16 “无法获得锁”解决方案

    强制解锁,命令 sudo rm /var/cache/apt/archives/lock sudo rm /var/lib/dpkg/lock

  2. ZOJ4114 Flipping Game(2019山东省赛)

    有n个开关,有起始状态和终状态,问如果每次必须选m个开关进行改变状态,一共进行k次,那么有多少种方式可以从起始状态到终状态~ #include<bits/stdc++.h> using n ...

  3. Kubernetes的pod控制器之DaemonSet

    DaemonSet 顶级参数介绍 [root@master manifests]# kubectl explain ds KIND: DaemonSet VERSION: extensions/v1b ...

  4. 在VS2017配置OpenGL开发环境

    这个方法适合初学者使用,较为简单方便.第一,你的VS2017一定要安装了C/C++开发组件可以打开Visual Studio Installer来查看另外,确定你有安装NuGet包管理器,在单个组件中 ...

  5. 并行效果&迭代器

    具体文章:ALEX的文章 https://www.cnblogs.com/alex3714/articles/5765046.html 串行的并行效果: import time def consume ...

  6. Java 基础--移位运算符

    移位运算符就是在二进制的基础上对数字进行平移.按照平移的方向和填充数字的规则分为三种: <<(左移).>>(带符号右移)和>>>(无符号右移). 1.左移 按 ...

  7. C++11常用特性介绍——array容器

    std::array是具有固定大小的数组,支持快速随机访问,不能添加或删除元素,定义于头文件<array>中. 一.概要 array是C++11新引入的容器类型,与内置数组相比,array ...

  8. bat获取当前路径

    @echo off setlocal EnableDelayedExpansion echo 当前正在运行的批处理文件所在路径:!cd! pause @echo off echo 当前目录是:%cd% ...

  9. MySQL中case when的基本用法总结

    MySQL中case when的基本用法总结原创Backcanhave7 最后发布于2018-12-06 15:14:15 阅读数 439 收藏展开MySQL中的case when有用两种用法,官方文 ...

  10. ThinkPHP5 动态生成图片缩略图

    需求场景 不同终端(PC端.手机端.平板),不同界面(列表页.详情页),对图片大小的要求不一样, 如果所有场景下都使用同一尺寸的图片,势必对会网络带宽及服务器性能造成一定的影响,由此需要服务器端能够根 ...