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

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章