New Year Snowmen

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 r 1, r 2, ..., r n. 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 r 1, r 2, ..., r n (1 ≤ r i ≤ 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

题意:给你n个已知半径的小球,半径互不相同的三个雪球可以堆成一个雪人,每个雪球只能用一次,求最多可以堆几个雪人并从大到小输出雪球的半径。

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#define rush() int T;cin>>T;while(T--)
#define go(a) while(cin>>a)
#define ms(a,b) memset(a,b,sizeof a)
#define E 1e-8
using namespace std;
typedef __int64 ll;
const int idata=1e5+5;

int n,m,t,_;
int i,j,k;
int cnt,num;
int minn,maxx;
struct Node
{
    int r,num;
    const bool operator<(const Node &a)//数量多,半径大的先出队
    const{
        return num==a.num ? r<a.r : num<a.num;
    }
}node[idata];

priority_queue<Node>q;
map<int,int>mp;
vector<int>v[3];

void clear()
{
    priority_queue<Node>temp;
    swap(temp,q);
    return ;
}
int main()
{
    cin.tie(0);
    iostream::sync_with_stdio(false);
    while(cin>>n)
    {
        clear();
        for(i=0;i<3;i++){
            v[i].clear();
        }


        for(i=0;i<n;i++){
            cin>>_;
            mp[_]++;
        }
        cnt=0;
        map<int,int>::iterator it;
        for(it=mp.begin();it!=mp.end();it++){
            node[cnt].r = it->first;
            node[cnt].num = it->second;
            cnt++;
        }
        for(i=0;i<cnt;i++){
            q.push(node[i]);
        }


        while(!q.empty()){
            Node a=q.top();
            q.pop();
            if(q.empty()) break;
            Node b=q.top();
            q.pop();
            if(q.empty()) break;
            Node c=q.top();
            q.pop();

            int temp[3]={a.r,b.r,c.r};
            sort(temp,temp+3);
            v[0].push_back(temp[0]);
            v[1].push_back(temp[1]);
            v[2].push_back(temp[2]);

            a.num--,b.num--,c.num--;
            if(a.num) q.push(a);
            if(b.num) q.push(b);
            if(c.num) q.push(c);
        }
        cout<<v[0].size()<<endl;
        for(i=0;i<v[0].size();i++){
            cout<<v[2][i]<<" "<<v[1][i]<<" "<<v[0][i]<<endl;
        }
    }
    return 0;
}
原创文章 410 获赞 16 访问量 3万+

猜你喜欢

转载自blog.csdn.net/C_Dreamy/article/details/106013851