/*
    In the name of
        "ALLAH"
    And say "AL-HAMD-U-LILLAH"
*/

#include<bits/stdc++.h>
#define   ll   long long
#define   llu  unsigned long long
#define   _    printf("\n")
int      take() {
    int n;
    scanf("%d",&n);
    return n;

}
double  ttake() {
    double n;
    scanf("%lf",&n);
    return n;
}
ll     takes() {
    ll n;
    scanf("%lld",&n);
    return n;

}

#define  Int             take()
#define  Dnt             ttake()
#define  LL              takes()
#define  done            {return 0;}
#define  fr(i,x,n,a)     for(int i=x;i<=n;i+=a)
#define  FR(a,b,x)       for(int i=(a);i<=(b);i+=(x))
#define  rfr(i,x,n,a)    for(int i=x;i>=n;i--)
int      cas;
#define  print           printf("Case %d:",++cas)
#define  vi              vector<int>
#define  vs              vector<string>
#define  vl              vector<ll>
#define  pb              push_back
#define  pii             pair<int,int>
#define  vii             vector<pii>
#define  pll             pair<ll,ll>
#define  pil             pair<int,ll>
#define  pli             pair<ll,int>
#define  pipii           pair<int,pii>
#define  piipi           pair<pii,int>
#define  mk              make_pair
#define  fill(x,v)       memset(x,v,sizeof x)

using    namespace       std;

bool     approximatelyEqual(float a, float b, float epsilon) {
    return fabs(a - b) <= ( (fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}

bool     essentiallyEqual(float a, float b, float epsilon) {
    return fabs(a - b) <= ( (fabs(a) > fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}

bool     definitelyGreaterThan(float a, float b, float epsilon) {
    return (a - b) > ( (fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}

bool     definitelyLessThan(float a, float b, float epsilon) {
    return (b - a) > ( (fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}
#define  STR             {struct info}
#define  dbg(x)          {cout<<"ekhane"<<x<<endl;}
#define  SS              second
#define  FF              first
#define  PQ              priority_queue
#define  great           greatest
#define  less            lesser
#define  mii             map<int,int>
#define  mil             map<int,ll>
#define  mll             map<ll,ll>
#define  msb             map<string,bool>
#define  V               vector
#define  M               200005
#define  pf              printf
#define  inf             INT_MAX
//////////////////////////////////////////

int main(){
    int tc = 1 ;
    while( tc-- ){
        int n = Int ; multiset<int>ms ;
        set<pipii>s1 ;
        fr( i , 1 , n , 1 ){
            ms.insert( Int ) ;
        }
        int ans = 0 ; vi v1 ;
        while( n-- && ms.size() > 2 ){
            int u = *ms.begin() ;
            auto id1 = ( ms.upper_bound( u  ) ) ;
            auto id2 = ( ms.upper_bound( (*id1 ) ) ) ;
           // cout<<u<<"  "<<*id1<<"  "<<*id2<<endl;

            if( id1 != ms.end() && id2 != ms.end() &&   s1.find( mk( u , mk( *id1 , *id2 ) ) ) == s1.end() ){
         //    cout<<u<<"  "<<*id1<<" "<<*id2<<endl;
               s1.insert( mk( u , mk( *id1 , *id2 ) ) ) ;
                ans++ ; //cout<<s1.size()<<endl;
                ms.erase( id2 ) ;
                ms.erase( id1 ) ;
            }
            ms.erase( ms.begin() ) ;
        }
        pf("%d\n",s1.size()) ;
        auto x = s1.begin() ;
        fr( i , 1 , s1.size() , 1 ){
            pipii u = *x ;
            pf("%d %d %d\n",u.SS.SS , u.SS.FF , u.FF ) ;
            x++ ;
        }
    }
 done ;
}


#include <bits/stdc++.h>
#include <string.h>
using namespace std;

#define mp make_pair
#define show(a, i) cout << " a[ " << i << " ] = " << a[i] << endl;
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define pli pair<long long, int>
#define Long long long
#define ld long double
#define si(x) scanf("%d", &x)
#define out(x) printf("%d\n", x);

const Long inf = 1LL << 60;
const int me = 400005;
const int fixx = 216;
const int mod = 1.e9 + 7;

set< pair<int, int> > s;
unordered_map<int, int> m;
int n, r;
vector< vector<int> > v;
vector<int> g;
void add(set< pair<int, int> > :: iterator it){
    g.push_back((*it).first);
    if((*it).second > 1)
        s.insert(mp((*it).first, (*it).second - 1));
    s.erase(it);
}
int main()
{
    ios_base:: sync_with_stdio(false);
    cin.tie(false);

    cin >> n;
    for(int i = 0 ; i < n ; i ++){
        cin >> r;
        if(m.count(r))
            s.erase(mp(r, m[r]));
        s.insert(mp(r, ++m[r]));
    }
    s.insert(mp(-1, -1));
    while(s.size() > 3){
        g.resize(0);
        auto it = --s.end();
        add(it);
        if(s.size() < 2)
            break;

        it = --s.end();
        while((*it).first != -1 && (*it).first == g.back())
            -- it;
        add(it);

        it = --s.end();
        while((*it).first != -1 && (*it).first == g.back())
            -- it;
        add(it);
        v.push_back(g);
    }
    cout << v.size() << endl;
    for(auto i : v){
        for(int j : i)
            cout << j << " ";
        cout << endl;
    }

    ///cout << "Elapsed time is: " << clock() / CLOCKS_PER_SEC << endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define mp make_pair
#define all(x) x.begin(), x.end()
#define Long long long
#define pii pair<int, int>
#define pli pair<Long, Long>
#define ld long double
#define si(x) scanf("%d", &x)
#define out(x) printf("%d\n", x);
/// Me 3nc4nta Soli
const Long inf = 140101008;
const int me = 100005;
const Long fixx = 2;
const Long mod = 1.e9 + 7;

int n, ptr;
map<int, int> m;
map<int, int> :: iterator it;
int a[me];
int main()
{
    ios_base:: sync_with_stdio(false);
    cin.tie(false);

    cin >> n;
    for(int i = 0 ; i < n ; i ++){
        int x;
        cin >> x;
        m[x] ++;
    }
    while(1){
        while(!m.empty() && (it = --m.end()) -> second == 0)
            m.erase(it);
        if(m.size() < 3)
            break;
        a[++ptr] = it -> first;
        it -> second --; it --;
        a[++ptr] = it -> first;
        it -> second --; it --;
        a[++ptr] = it -> first;
        it -> second --; it --;
    }
    cout << ptr / 3 << endl;
    for(int i = 1 ; i <= ptr ; i ++){
        cout << a[i] << " ";
        if(i % 3 == 0) cout << endl;
    }

    ///cout << "Elapsed time is: " << clock() / CLOCKS_PER_SEC << endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define mp make_pair
#define all(x) x.begin(), x.end()
#define Long long long
#define pii pair<int, int>
#define pli pair<Long, Long>
#define ld long double
#define si(x) scanf("%d", &x)
#define out(x) printf("%d\n", x);
/// Me 3nc4nta Soli
const Long inf = 140101008;
const int me = 100005;
const Long fixx = 2;
const Long mod = 1.e9 + 7;

int n, ptr;
map<int, int> m;
map<int, int> :: iterator it;
int a[me];
int main()
{
    ios_base:: sync_with_stdio(false);
    cin.tie(false);

    cin >> n;
    for(int i = 0 ; i < n ; i ++){
        int x;
        cin >> x;
        m[x] ++;
    }
    while(1){
        while(!m.empty() && (it = --m.end()) -> second == 0)
            m.erase(it);
        if(m.size() < 3)
            break;
        a[++ptr] = it -> first;
        it -> second --; it --;
        a[++ptr] = it -> first;
        it -> second --; it --;
        a[++ptr] = it -> first;
        it -> second --; it --;

        if(m[ a[ptr] ] == 0) m.erase(a[ptr]);
        if(m[ a[ptr - 1] ] == 0) m.erase(a[ptr - 1]);
        if(m[ a[ptr - 2] ] == 0) m.erase(a[ptr - 2]);
    }
    cout << ptr / 3 << endl;
    for(int i = 1 ; i <= ptr - ptr % 3; i ++){
        cout << a[i] << " ";
        if(i % 3 == 0) cout << endl;
    }

    ///cout << "Elapsed time is: " << clock() / CLOCKS_PER_SEC << endl;

    return 0;
}


#include <bits/stdc++.h>
#include <string.h>
using namespace std;

#define mp make_pair
#define show(a, i) cout << " a[ " << i << " ] = " << a[i] << endl;
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define pli pair<long long, int>
#define Long long long
#define ld long double
#define si(x) scanf("%d", &x)
#define out(x) printf("%d\n", x);

const Long inf = 1LL << 60;
const int me = 400005;
const int fixx = 216;
const int mod = 1.e9 + 7;

set< pair<int, int> > s;
unordered_map<int, int> m;
int n, r;
vector< vector<int> > v;
int main()
{
    ios_base:: sync_with_stdio(false);
    cin.tie(false);

    cin >> n;
    for(int i = 0 ; i < n ; i ++){
        cin >> r;
        if(m.count(r))
            s.erase(mp(r, m[r]));
        s.insert(mp(r, ++m[r]));
    }
    while(s.size() > 2){
        vector<int> g(0);
        auto it = --s.end();
        g.push_back((*it).first);
        if((*it).second > 1)
            s.insert(mp((*it).first, (*it).second - 1));
        s.erase(it);

        if(s.size() < 2)
            break;
        it = --s.end(); --it;
        g.push_back((*it).first);
        if((*it).second > 1)
            s.insert(mp((*it).first, (*it).second - 1));
        s.erase(it);

        if(s.empty())
            break;
        it = --s.end(); --it; --it;
        g.push_back((*it).first);
        if((*it).second > 1)
            s.insert(mp((*it).first, (*it).second - 1));
        s.erase(it);
        v.push_back(g);
    }
    cout << v.size() << endl;
    for(auto i : v){
        for(int j : i)
            cout << j << " ";
        cout << endl;
    }

    ///cout << "Elapsed time is: " << clock() / CLOCKS_PER_SEC << endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define Long long long
#define ld long double
#define pii pair<int, int>
#define pli pair<Long, int>

const int me = 200005;
const int fix = 26;
const int mod = 1.e9 + 9;
const Long big = 1LL << 55;

pii a[me], v[me][4];
int n;
int main()
{
    ios_base:: sync_with_stdio(0);
    cin.tie(0);

    cin >> n;
    for(int i = 1 ; i <= n ; i ++){
        cin >> a[i].first;
        a[i].second = i;
    }
    sort(a + 1, a + n + 1);

    int low = 0, high = n / 3, mid, best = 0;
    while(low <= high){
        mid = (low + high + 1) / 2;
        for(int i = 1 ; i <= mid ; i ++)
            v[i][1] = a[i];
        int ptr = 1, level = 2;
        for(int i = mid + 1 ; i <= n ; i ++){
            if(level == 4)
                break;
            if(a[i].first > v[ptr][level - 1].first){
                v[ptr][level] = a[i];
                if(ptr == mid){
                    ptr = 1;
                    level ++;
                }
                else ptr ++;
            }
        }
        if(level == 4){
            best = mid;
            low = mid + 1;
        }
        else high = mid - 1;
    }
    cout << best << endl;
    for(int i = 1 ; i <= best ; i ++)
        cout << v[i][3].first << " " << v[i][2].first << " " << v[i][1].first << endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define mp make_pair
#define all(x) x.begin(), x.end()
#define Long long long
#define pii pair<int, int>
#define pli pair<Long, Long>
#define ld long double
#define si(x) scanf("%d", &x)
#define out(x) printf("%d\n", x);
/// Me 3nc4nta Soli
const Long inf = 140101008;
const int me = 100005;
const Long fixx = 2;
const Long mod = 1.e9 + 7;

int n, ptr;
map<int, int> m;
map<int, int> :: iterator it;
int a[me];
int main()
{
    ios_base:: sync_with_stdio(false);
    cin.tie(false);

    cin >> n;
    for(int i = 0 ; i < n ; i ++){
        int x;
        cin >> x;
        m[x] ++;
    }
    while(1){
        while(!m.empty() && (it = --m.end()) -> second == 0)
            m.erase(it);
        if(m.size() < 3)
            break;
        assert(it == --m.end());
        a[++ptr] = it -> first;
        it -> second --; it --;
        a[++ptr] = it -> first;
        it -> second --; it --;
        a[++ptr] = it -> first;
        it -> second --; it --;

        if(m[ a[ptr] ] == 0) m.erase(a[ptr]);
        if(m[ a[ptr - 1] ] == 0) m.erase(a[ptr - 1]);
        if(m[ a[ptr - 2] ] == 0) m.erase(a[ptr - 2]);
    }
    cout << ptr / 3 << endl;
    for(int i = 1 ; i <= ptr - ptr % 3; i ++){
        cout << a[i] << " ";
        if(i % 3 == 0) cout << endl;
    }

    ///cout << "Elapsed time is: " << clock() / CLOCKS_PER_SEC << endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define Long long long
#define ld long double
#define pii pair<int, int>
#define pli pair<Long, int>

const int me = 200005;
const int fix = 26;
const int mod = 1.e9 + 9;
const Long big = 1LL << 55;

pii a[me], v[me][4];
int n;
int main()
{
    ios_base:: sync_with_stdio(0);
    cin.tie(0);

    cin >> n;
    for(int i = 1 ; i <= n ; i ++){
        cin >> a[i].first;
        a[i].second = i;
    }
    sort(a + 1, a + n + 1);

    int low = 0, high = n / 3, mid, best = 0;
    while(low <= high){
        mid = (low + high + 1) / 2;
        for(int i = 1 ; i <= mid ; i ++)
            v[i][1] = a[i];
        int ptr = 1, level = 2;
        for(int i = mid + 1 ; i <= n ; i ++){
            if(level == 4)
                break;
            if(a[i].first > v[ptr][level - 1].first){
                v[ptr][level] = a[i];
                if(ptr == mid){
                    ptr = 1;
                    level ++;
                }
                else ptr ++;
            }
        }
        if(level == 4){
            best = mid;
            low = mid + 1;
        }
        else high = mid - 1;
    }
    cout << best << endl;
    for(int i = 1 ; i <= best ; i ++)
        cout << v[i][3].second << " " << v[i][2].second << " " << v[i][1].second << endl;

    return 0;
}


#include <bits/stdc++.h>
#include <string.h>
using namespace std;

#define mp make_pair
#define show(a, i) cout << " a[ " << i << " ] = " << a[i] << endl;
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define pli pair<long long, int>
#define Long long long
#define ld long double
#define si(x) scanf("%d", &x)
#define out(x) printf("%d\n", x);

const Long inf = 1LL << 60;
const int me = 400005;
const int fixx = 216;
const int mod = 1.e9 + 7;

set< pair<int, int> > s;
unordered_map<int, int> m;
int n, r;
vector< vector<int> > v;
vector<int> g;
void add(set< pair<int, int> > :: iterator it){
    g.push_back((*it).first);
    if((*it).second > 1)
        s.insert(mp((*it).first, (*it).second - 1));
    s.erase(it);
}
int main()
{
    ios_base:: sync_with_stdio(false);
    cin.tie(false);

    cin >> n;
    for(int i = 0 ; i < n ; i ++){
        cin >> r;
        if(m.count(r))
            s.erase(mp(r, m[r]));
        s.insert(mp(r, ++m[r]));
    }
    s.insert(mp(-1, -1));
    while(s.size() > 3){
        g.resize(0);
        auto it = --s.end();
        add(it);
        if(s.size() < 2)
            break;

        it = --s.end();
        while((*it).first != -1 && (*it).first == g.back())
            -- it;
        add(it);

        it = --s.end();
        while((*it).first != -1 && (*it).first == g.back() || (*it).first == g[0])
            -- it;
        add(it);
        v.push_back(g);
    }
    cout << v.size() << endl;
    for(auto i : v){
        for(int j : i)
            cout << j << " ";
        cout << endl;
    }

    ///cout << "Elapsed time is: " << clock() / CLOCKS_PER_SEC << endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define Long long long
#define ld long double
#define pii pair<int, int>
#define pli pair<Long, int>

const int me = 200005;
const int fix = 26;
const int mod = 1.e9 + 9;
const Long big = 1LL << 55;

pii a[me], v[me][4];
int n;
int main()
{
    ios_base:: sync_with_stdio(0);
    cin.tie(0);

    cin >> n;
    for(int i = 1 ; i <= n ; i ++){
        cin >> a[i].first;
        a[i].second = i;
    }
    sort(a + 1, a + n + 1);

    int low = 0, high = n / 3, mid, best = 0;
    while(low <= high){
        mid = (low + high + 1) / 2;
        for(int i = 1 ; i <= mid ; i ++)
            v[i][1] = a[i];
        int ptr = 1, level = 2;
        for(int i = mid + 1 ; i <= n ; i ++){
            if(level == 4)
                break;
            if(a[i].first > v[ptr][level - 1].first){
                v[ptr][level] = a[i];
                if(ptr == mid){
                    ptr = 1;
                    level ++;
                }
                else ptr ++;
            }
        }
        if(level == 4){
            best = mid;
            low = mid + 1;
        }
        else high = mid - 1;
    }
    cout << best << endl;
    for(int i = 1 ; i <= best ; i ++)
        cout << v[i][1].second << " " << v[i][2].second << " " << v[i][3].second << endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define mp make_pair
#define all(x) x.begin(), x.end()
#define Long long long
#define pii pair<int, int>
#define pli pair<Long, Long>
#define ld long double
#define si(x) scanf("%d", &x)
#define out(x) printf("%d\n", x);
/// Me 3nc4nta Soli
const Long inf = 140101008;
const int me = 100005;
const Long fixx = 2;
const Long mod = 1.e9 + 7;

int n, ptr;
map<int, int> m;
map<int, int> :: iterator it;
int a[me];
int main()
{
    ios_base:: sync_with_stdio(false);
    cin.tie(false);

    cin >> n;
    for(int i = 0 ; i < n ; i ++){
        int x;
        cin >> x;
        m[x] ++;
    }
    while(1){
        while((it = --m.end()) -> second == 0)
            m.erase(it);
        if(m.size() < 3)
            break;
        a[++ptr] = it -> first;
        it -> second --; it --;
        a[++ptr] = it -> first;
        it -> second --; it --;
        a[++ptr] = it -> first;
        it -> second --; it --;
    }
    cout << ptr / 3 << endl;
    for(int i = 1 ; i <= ptr ; i ++){
        cout << a[i] << " ";
        if(i % 3 == 0) cout << endl;
    }

    ///cout << "Elapsed time is: " << clock() / CLOCKS_PER_SEC << endl;

    return 0;
}


#include<stdio.h>
#include<algorithm>
#include<queue>
#include<string.h>
using namespace std;
int num[100005];
struct node
{
	int shu,inde;
	bool operator <(const node &u)const
	{
		return inde<u.inde;
	}
}book;
struct node2
{
	int x,y,z;
}ans[100005];
int cmp(node a ,node b)
{
	return a.shu>b.shu;
}
int main()
{
	int t;
	int n,i,j,re;
	priority_queue<node>q;
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&num[i]);
	sort(num,num+n);
	book.shu=0;
	for(j=0,i=0;i<n-1;i++)
		{
			book.shu++;
			book.inde=num[i]; 3
			if(num[i]!=num[i+1])
			{
				q.push(book);
				book.shu=0;
			}
		}
		if(num[n-1]==num[n-2])
		{
			book.shu++;
			q.push(book);
		}
		else
		{
			book.shu++;
			book.inde=num[n-1];
			q.push(book);
		}
	//	while(!q.empty())
	//	{
	//		book=q.top();
	//		q.pop();
	//		printf("%d %d\n",book.inde,book.shu);
	//	}
		j=0;
		node a,b,c;
		while(!q.empty())
		{
			a=q.top();
			q.pop();
			if(q.empty())
				break;
			b=q.top();
			q.pop();
			if(q.empty())
				break;
			c=q.top();
			q.pop();
			if(q.empty())
				break;
			ans[j].x=a.inde;
			ans[j].y=b.inde;
			ans[j].z=c.inde;
			j++;
			a.shu--;
			b.shu--;
			c.shu--;
			if(a.shu>0)
				q.push(a);
			if(b.shu>0)
				q.push(b);
			if(c.shu>0)
				q.push(c);
		}
		printf("%d\n",j);
		for(i=0;i<j;i++)
		printf("%d %d %d\n",ans[i].x,ans[i].y,ans[i].z);
		return 0;
}


#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
int num[100005];
struct node
{
	int shu,inde;
}book[100005];
int cmp(node a ,node b)
{
	return a.inde>b.inde;
}
struct node2
{
	int x,y,z;
}ans[100005];
int main()
{
	int t;
	int n,i,j,re,a,b,c;
	scanf("%d",&n);
		for(i=0;i<n;i++)
		scanf("%d",&num[i]);
		for(i=0;i<n+3;i++)
		{
			book[i].shu=0;
		}
		sort(num,num+n);
	//	for(i=0;i<n;i++)
	//	//printf("%d ",num[i]);
	//	printf("\n");
		for(j=0,i=0;i<n-1;i++)
		{
			book[j].shu++;
			book[j].inde=num[i];
			if(num[i]!=num[i+1])
			{
				j++;
			}
		}
		if(num[n-1]==num[n-2])
		{
			j++;
		}
		else
		{
			book[j].shu++;
			book[j++].inde=num[n-1];
		}
		//	printf("%d\n",j);
	//	for(i=0;i<j;i++)
	//	printf("%d ",book[i].inde);
	sort(book,book+j,cmp);
	int flog=0,sum=0;
		a=b=c=0;
		while(1)
		{
			while(book[a].shu==0)
			{
				a++;
				if(a>=j)
				{
					flog=1;
					break;
				}
			}
			b=a+1;
			while(book[b].shu==0)
			{
				b++;
				if(b>=j)
				{
					flog=1;
					break;
				}
			}
			c=b+1;
			while(book[c].shu==0)
			{
				c++;
				if(c>=j)
				{
					flog=1;
					break;
				}
			}
			if(flog)
			break;
			book[a].shu--;
			book[b].shu--;
			book[c].shu--;
			ans[sum].x=book[a].inde;
			ans[sum].y=book[b].inde;
			ans[sum].z=book[c].inde;
			sum++;
		}
		if(sum==0)
			printf("0\n");
		else
		{
			printf("%d\n",sum);
			for(i=0;i<sum;i++)
			printf("%d %d %d\n",ans[i].x,ans[i].y,ans[i].z);

		}
		return 0;

}


#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
int num[100005];
struct node
{
	int shu,inde;
}book[100005];
int cmp(node a ,node b)
{
	return a.inde>b.inde;
}
struct node2
{
	int x,y,z;
}ans[100005];
int main()
{
	int t;
	int n,i,j,re,a,b,c;
	scanf("%d",&n);
		for(i=0;i<n;i++)
		scanf("%d",&num[i]);
		for(i=0;i<n+3;i++)
		{
			book[i].shu=0;
		}
		sort(num,num+n);
	//	for(i=0;i<n;i++)
	//	//printf("%d ",num[i]);
	//	printf("\n");
		for(j=0,i=0;i<n-1;i++)
		{
			book[j].shu++;
			book[j].inde=num[i];
			if(num[i]!=num[i+1])
			{
				j++;
			}
		}
		if(num[n-1]==num[n-2])
		{
			book[j++].shu++;
		}
		else
		{
			book[j].shu++;
			book[j++].inde=num[n-1];
		}
	///		printf("%d\n",j);
	//	for(i=0;i<j;i++)
	//	printf("%d %d \n",book[i].inde,book[i].shu);
	sort(book,book+j,cmp);
	int flog=0,sum=0;
		a=b=c=0;
		while(1)
		{
			while(book[a].shu==0)
			{
				a++;
				if(a>=j)
				{
					flog=1;
					break;
				}
			}
			b=a+1;
			while(book[b].shu==0)
			{
				b++;
				if(b>=j)
				{
					flog=1;
					break;
				}
			}
			c=b+1;
			while(book[c].shu==0)
			{
				c++;
				if(c>=j)
				{
					flog=1;
					break;
				}
			}
			if(flog)
			break;
			book[a].shu--;
			book[b].shu--;
			book[c].shu--;
			ans[sum].x=book[a].inde;
			ans[sum].y=book[b].inde;
			ans[sum].z=book[c].inde;
			sum++;
		}
		if(sum==0)
			printf("0\n");
		else
		{
			printf("%d\n",sum);
			for(i=0;i<sum;i++)
			printf("%d %d %d\n",ans[i].x,ans[i].y,ans[i].z);

		}
		return 0;

}


#include<stdio.h>
#include<algorithm>
#include<queue>
#include<string.h>
using namespace std;
int num[100005];
struct node
{
	int shu,inde;
	bool operator <(const node &u)const
	{
		return shu<u.shu;
	}
}book;
struct node2
{
	int x,y,z;
}ans[100005];
int cmp(node a ,node b)
{
	return a.shu>b.shu;
}
int main()
{
	int t;
	int n,i,j,re;
	priority_queue<node>q;
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&num[i]);
	sort(num,num+n);
	book.shu=0;
	for(j=0,i=0;i<n-1;i++)
		{
			book.shu++;
			book.inde=num[i];
			if(num[i]!=num[i+1])
			{
				q.push(book);
				book.shu=0;
			}
		}
		if(num[n-1]==num[n-2])
		{
			book.shu++;
			q.push(book);
		}
		else
		{
			book.shu++;
			book.inde=num[n-1];
			q.push(book);
		}
	//	while(!q.empty())
	//	{
	//		book=q.top();
	//		q.pop();
	//		printf("%d %d\n",book.inde,book.shu);
	//	}
		j=0;
		node a,b,c;
		while(!q.empty())
		{
			a=q.top();
			q.pop();
			if(q.empty())
				break;
			b=q.top();
			q.pop();
			if(q.empty())
				break;
			c=q.top();
			q.pop();
			ans[j].x=a.inde;
			ans[j].y=b.inde;
			ans[j].z=c.inde;
			j++;
			a.shu--;
			b.shu--;
			c.shu--;
			if(a.shu>0)
				q.push(a);
			if(b.shu>0)
				q.push(b);
			if(c.shu>0)
				q.push(c);
		}
		printf("%d\n",j);
		int x1,x2,x3;
		for(i=0;i<j;i++)
		{
			if(ans[i].x>ans[i].y)
			{
				x1=ans[i].x;
				x2=ans[i].y;
			}
			else
			{
				x1=ans[i].y;
				x2=ans[i].x;
			}
			if(ans[i].z>x1)
			{
				printf("%d %d %d\n",ans[i].z,x1,x2);
			}
			else if(ans[i].z<x2)
			{
				printf("%d %d %d\n",x1,x2,ans[i].z);
			}
			else
			{
				printf("%d %d %d\n",x1,ans[i].z,x2);
			}
		}
		return 0;
}


#include<stdio.h>
#include<algorithm>
#include<queue>
#include<string.h>
using namespace std;
int num[100005];
struct node
{
	int shu,inde;
	bool operator <(const node &u)const
	{
		return inde<u.inde;
	}
}book;
struct node2
{
	int x,y,z;
}ans[100005];
int cmp(node a ,node b)
{
	return a.shu>b.shu;
}
int main()
{
	int t;
	int n,i,j,re;
	priority_queue<node>q;
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&num[i]);
	sort(num,num+n);
	book.shu=0;
	for(j=0,i=0;i<n-1;i++)
		{
			book.shu++;
			book.inde=num[i];
			if(num[i]!=num[i+1])
			{
				q.push(book);
				book.shu=0;
			}
		}
		if(num[n-1]==num[n-2])
		{
			book.shu++;
			q.push(book);
		}
		else
		{
			book.shu++;
			book.inde=num[n-1];
			q.push(book);
		}
	//	while(!q.empty())
	//	{
	//		book=q.top();
	//		q.pop();
	//		printf("%d %d\n",book.inde,book.shu);
	//	}
		j=0;
		node a,b,c;
		while(!q.empty())
		{
			a=q.top();
			q.pop();
			if(q.empty())
				break;
			b=q.top();
			q.pop();
			if(q.empty())
				break;
			c=q.top();
			q.pop();
			if(q.empty())
				break;
			ans[j].x=a.inde;
			ans[j].y=b.inde;
			ans[j].z=c.inde;
			j++;
			a.shu--;
			b.shu--;
			c.shu--;
			if(a.shu>0)
				q.push(a);
			if(b.shu>0)
				q.push(b);
			if(c.shu>0)
				q.push(c);
		}
		printf("%d\n",j);
		for(i=0;i<j;i++)
		printf("%d %d %d\n",ans[i].x,ans[i].y,ans[i].z);
		return 0;
}


#include<stdio.h>
#include<algorithm>
#include<queue>
#include<string.h>
using namespace std;
int num[100005];
struct node
{
	int shu,inde;
	bool operator <(const node &u)const
	{
		return inde<u.inde;
	}
}book;
struct node2
{
	int x,y,z;
}ans[100005];
int cmp(node a ,node b)
{
	return a.shu>b.shu;
}
int main()
{
	int t;
	int n,i,j,re;
	priority_queue<node>q;
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&num[i]);
	sort(num,num+n);
	book.shu=0;
	for(j=0,i=0;i<n-1;i++)
		{
			book.shu++;
			book.inde=num[i];
			if(num[i]!=num[i+1])
			{
				q.push(book);
				book.shu=0;
			}
		}
		if(num[n-1]==num[n-2])
		{
			book.shu++;
			q.push(book);
		}
		else
		{
			book.shu++;
			book.inde=num[n-1];
			q.push(book);
		}
	//	while(!q.empty())
	//	{
	//		book=q.top();
	//		q.pop();
	//		printf("%d %d\n",book.inde,book.shu);
	//	}
		j=0;
		node a,b,c;
		while(!q.empty())
		{
			a=q.top();
			q.pop();
			if(q.empty())
				break;
			b=q.top();
			q.pop();
			if(q.empty())
				break;
			c=q.top();
			q.pop();
			ans[j].x=a.inde;
			ans[j].y=b.inde;
			ans[j].z=c.inde;
			j++;
			a.shu--;
			b.shu--;
			c.shu--;
			if(a.shu>0)
				q.push(a);
			if(b.shu>0)
				q.push(b);
			if(c.shu>0)
				q.push(c);
		}
		printf("%d\n",j);
		for(i=0;i<j;i++)
		printf("%d %d %d\n",ans[i].x,ans[i].y,ans[i].z);
		return 0;
}


//in the name of allah.
//ilso

#include <bits/stdc++.h>

#define DEV(x) { cout << #x << " = " << (x) << endl; }
#define DEA(a,n) { for(int i=0 ; i<n ; i++) cout << a[i] << " " << endl; cout << endl; }
#define DEAP(a,n) { for(int i=0 ; i<n ; i++) cout << a[i].first << " , " << a[i].second << endl; }
#define F first
#define S second

using namespace std;

typedef long long ll;
typedef pair<int , int> ii;

struct tp{
    int a , b , c;
    tp();
    tp(int a , int b , int c):
        a(a) , b(b) , c(c) {}
};

map<int , int> mp;
vector< ii > v;
vector< tp > t;

tp sorted(int a1, int b1, int c1){
    int a=a1 , b=b1 , c=c1;
    for(int i=0 ; i<5 ; i++){
        if(a < b)
            swap(a ,b);
        if(b < c)
            swap(b , c);
    }
    return tp(c , b, a);
}

int main(){
    int n;
    cin >> n;
    for(int i=0 ; i<n ; i++){
        int a;
        cin >> a;
        mp[a] ++;
    }
    map<int , int>::iterator it;
    for(it=mp.begin() ; it!=mp.end() ; ++it){
        //if(it == mp.begin())
        //    continue;
        v.push_back(ii(it->S , it->F));
    }
    sort(v.begin() , v.end());
    int k=0;
    while(v.size() >= 3){
        int mi = min ( v[0].F , min(v[1].F , v[2].F) );
        k += mi;
        for(int i=0 ; i<mi ; i++)
            t.push_back( tp(sorted(v[0].S , v[1].S , v[2].S)) );
        for(int i=0 ; i<3 ; i++)
            v[i].F -= mi;
        int i=0;
        for(int j=0 ; j<3 ; j++)
            if(v[i].F == 0)
                v.erase(v.begin() + i);
            else
                i++;
    }
    cout << k << endl;
    for(int i=0 ; i<k ; i++)
        cout << t[i].c << " " << t[i].b << " " << t[i].a << endl;
    return 0;
}


//in the name of allah.
//ilso

#include <bits/stdc++.h>

#define DEV(x) { cout << #x << " = " << (x) << endl; }
#define DEA(a,n) { for(int i=0 ; i<n ; i++) cout << a[i] << " " << endl; cout << endl; }
#define DEAP(a,n) { for(int i=0 ; i<n ; i++) cout << a[i].first << " , " << a[i].second << endl; }
#define F first
#define S second

using namespace std;

typedef long long ll;
typedef pair<int , int> ii;

struct tp{
    int a , b , c;
    tp();
    tp(int a , int b , int c):
        a(a) , b(b) , c(c) {}
};

map<int , int> mp;
set< ii > v;
vector< pair< tp , int > > t;

tp sorted(int a1, int b1, int c1){
    int a=a1 , b=b1 , c=c1;
    for(int i=0 ; i<5 ; i++){
        if(a < b)
            swap(a ,b);
        if(b < c)
            swap(b , c);
    }
    return tp(c , b, a);
}

int main(){
    int n;
    cin >> n;
    for(int i=0 ; i<n ; i++){
        int a;
        cin >> a;
        mp[a] ++;
    }
    map<int , int>::iterator it;
    for(it=mp.begin() ; it!=mp.end() ; ++it)
        v.insert(ii(it->S , it->F));

    int k=0;
    while(v.size() >= 3){
        set< ii >::iterator it;
        ii p[3];
        for(int i=0 ; i<3 ; i++){
            it = v.begin(); for(int j=1 ; j<v.size() ; j++) ++it;
            p[i] = *it;
           // cout << i << endl;
            v.erase(it);
        }
        int mi = int(1e9);
        for(int i=0 ; i<3 ; i++)
            mi = min(mi , p[i].F);
        k += mi;
        t.push_back( make_pair( sorted( p[0].S , p[1].S , p[2].S ) , mi ) );
        for(int i=0 ; i<3 ; i++)
            p[i].F -= mi;
        for(int i=0 ; i<3 ; i++)
            if(p[i].F > 0) v.insert(p[i]);
    }
    cout << k << endl;
   // for(ll i=0 ; i<1e8 ; i++);
    for(int i=0 ; i<t.size() ; i++)
        for(int j=0 ; j<t[i].S ; j++){
          //  cout << j << " , " << t[i].S << endl;
            cout << t[i].F.c << " " << t[i].F.b << " " << t[i].F.a << endl;
        }
    return 0;
}


//in the name of allah.
//ilso

#include <bits/stdc++.h>

#define DEV(x) { cout << #x << " = " << (x) << endl; }
#define DEA(a,n) { for(int i=0 ; i<n ; i++) cout << a[i] << " " << endl; cout << endl; }
#define DEAP(a,n) { for(int i=0 ; i<n ; i++) cout << a[i].first << " , " << a[i].second << endl; }
#define F first
#define S second

using namespace std;

typedef long long ll;
typedef pair<int , int> ii;

struct tp{
    int a , b , c;
    tp();
    tp(int a , int b , int c):
        a(a) , b(b) , c(c) {}
};

map<int , int> mp;
vector< ii > v;
vector< tp > t;

tp sorted(int a1, int b1, int c1){
    int a=a1 , b=b1 , c=c1;
    for(int i=0 ; i<5 ; i++){
        if(a < b)
            swap(a ,b);
        if(b < c)
            swap(b , c);
    }
    return tp(a , b, c);
}

int main(){
    int n;
    cin >> n;
    for(int i=0 ; i<n ; i++){
        int a;
        cin >> a;
        mp[a] ++;
    }
    map<int , int>::iterator it;
    for(it=mp.begin() ; it!=mp.end() ; ++it){
        //if(it == mp.begin())
        //    continue;
        v.push_back(ii(it->S , it->F));
    }
    sort(v.begin() , v.end());
    int k=0;
    while(v.size() >= 3){
        int mi = min ( v[0].F , min(v[1].F , v[2].F) );
        k += mi;
        for(int i=0 ; i<mi ; i++)
            t.push_back( tp(sorted(v[0].S , v[1].S , v[2].S)) );
        for(int i=0 ; i<3 ; i++)
            v[i].F -= mi;
        int i=0;
        for(int j=0 ; j<3 ; j++)
            if(v[i].F == 0)
                v.erase(v.begin() + i);
            else
                i++;
    }
    cout << k << endl;
    for(int i=0 ; i<k ; i++)
        cout << t[i].c << " " << t[i].b << " " << t[i].a << endl;
    return 0;
}


//in the name of allah.
//ilso

#include <bits/stdc++.h>

#define DEV(x) { cout << #x << " = " << (x) << endl; }
#define DEA(a,n) { for(int i=0 ; i<n ; i++) cout << a[i] << " " << endl; cout << endl; }
#define DEAP(a,n) { for(int i=0 ; i<n ; i++) cout << a[i].first << " , " << a[i].second << endl; }
#define F first
#define S second

using namespace std;

typedef long long ll;
typedef pair<int , int> ii;

struct tp{
    int a , b , c;
    tp();
    tp(int a , int b , int c):
        a(a) , b(b) , c(c) {}
};

map<int , int> mp;
set< ii > v;
vector< tp > t;

tp sorted(int a1, int b1, int c1){
    int a=a1 , b=b1 , c=c1;
    for(int i=0 ; i<5 ; i++){
        if(a < b)
            swap(a ,b);
        if(b < c)
            swap(b , c);
    }
    return tp(c , b, a);
}

int main(){
    int n;
    cin >> n;
    for(int i=0 ; i<n ; i++){
        int a;
        cin >> a;
        mp[a] ++;
    }
    map<int , int>::iterator it;
    for(it=mp.begin() ; it!=mp.end() ; ++it)
        v.insert(ii(it->S , it->F));

    int k=0;
    while(v.size() >= 3){
        set< ii >::iterator it;
        ii p[3];
        for(int i=0 ; i<3 ; i++){
            it = v.begin(); for(int j=1 ; j<v.size() ; j++) ++it;
            p[i] = *it;
           // cout << i << endl;
            v.erase(it);
        }
        int mi = int(1e9);
        for(int i=0 ; i<3 ; i++)
            mi = min(mi , p[i].F);
        for(int i=0 ; i<mi ; i++){
            k ++;
            t.push_back( sorted( p[0].S , p[1].S , p[2].S ) );

        }
        for(int i=0 ; i<3 ; i++)
            p[i].F -= mi;
        for(int i=0 ; i<3 ; i++)
            if(p[i].F > 0) v.insert(p[i]);
    }
    cout << k << endl;
    for(int i=0 ; i<k ; i++)
        cout << t[i].c << " " << t[i].b << " " << t[i].a << endl;
    return 0;
}


//in the name of allah.
//ilso

#include <bits/stdc++.h>

#define DEV(x) { cout << #x << " = " << (x) << endl; }
#define DEA(a,n) { for(int i=0 ; i<n ; i++) cout << a[i] << " " << endl; cout << endl; }
#define DEAP(a,n) { for(int i=0 ; i<n ; i++) cout << a[i].first << " , " << a[i].second << endl; }
#define F first
#define S second

using namespace std;

typedef long long ll;
typedef pair<int , int> ii;

struct tp{
    int a , b , c;
    tp();
    tp(int a , int b , int c):
        a(a) , b(b) , c(c) {}
};

map<int , int> mp;
set< ii > v;
vector< tp > t;

tp sorted(int a1, int b1, int c1){
    int a=a1 , b=b1 , c=c1;
    for(int i=0 ; i<5 ; i++){
        if(a < b)
            swap(a ,b);
        if(b < c)
            swap(b , c);
    }
    return tp(c , b, a);
}

int main(){
    int n;
    cin >> n;
    for(int i=0 ; i<n ; i++){
        int a;
        cin >> a;
        mp[a] ++;
    }
    map<int , int>::iterator it;
    for(it=mp.begin() ; it!=mp.end() ; ++it)
        v.insert(ii(it->S , it->F));

    int k=0;
    while(v.size() >= 3){
        set< ii >::iterator it;
        ii p[3];
        for(int i=0 ; i<3 ; i++){
            it = v.end();
            --it;
            p[i] = *it;
           // cout << i << endl;
            v.erase(it);
        }
        int mi = int(1e9);
        for(int i=0 ; i<3 ; i++)
            mi = min(mi , p[i].F);
        k ++;

        t.push_back( sorted( p[0].S , p[1].S , p[2].S ) );
        for(int i=0 ; i<3 ; i++)
            p[i].F --;
        for(int i=0 ; i<3 ; i++)
            if(p[i].F > 0) v.insert(p[i]);
    }
    cout << k << endl;
    for(int i=0 ; i<t.size() ; i++)
        cout << t[i].c << " " << t[i].b << " " << t[i].a << endl;
    return 0;
}


//in the name of allah.
//ilso

#include <bits/stdc++.h>

#define DEV(x) { cout << #x << " = " << (x) << endl; }
#define DEA(a,n) { for(int i=0 ; i<n ; i++) cout << a[i] << " " << endl; cout << endl; }
#define DEAP(a,n) { for(int i=0 ; i<n ; i++) cout << a[i].first << " , " << a[i].second << endl; }
#define F first
#define S second

using namespace std;

typedef long long ll;
typedef pair<int , int> ii;

struct tp{
    int a , b , c;
    tp();
    tp(int a , int b , int c):
        a(a) , b(b) , c(c) {}
};

map<int , int> mp;
vector< ii > v;
vector< tp > t;

int main(){
    int n;
    cin >> n;
    for(int i=0 ; i<n ; i++){
        int a;
        cin >> a;
        mp[a] ++;
    }
    map<int , int>::iterator it;
    for(it=mp.begin() ; it!=mp.end() ; ++it){
        //if(it == mp.begin())
        //    continue;
        v.push_back(ii(it->first , it->second));
    }
    sort(v.begin() , v.end());
    int k=0;
    while(v.size() >= 3){
        int mi = min ( v[0].second , min(v[1].second , v[2].second) );
        k += mi;
        for(int i=0 ; i<mi ; i++)
            t.push_back( tp(v[0].F , v[1].F , v[2].F) );
        for(int i=0 ; i<3 ; i++)
            v[i].second -= mi;
        vector<ii> v2 =v;
        int i=0;
        for(int j=0 ; j<3 ; j++)
            if(v[i].second == 0)
                v.erase(v.begin() + i);
            else
                i++;
    }
    cout << k << endl;
    for(int i=0 ; i<k ; i++)
        cout << t[i].c << " " << t[i].b << " " << t[i].a << endl;
    return 0;
}


//in the name of allah.
//ilso

#include <bits/stdc++.h>

#define DEV(x) { cout << #x << " = " << (x) << endl; }
#define DEA(a,n) { for(int i=0 ; i<n ; i++) cout << a[i] << " " << endl; cout << endl; }
#define DEAP(a,n) { for(int i=0 ; i<n ; i++) cout << a[i].first << " , " << a[i].second << endl; }
#define F first
#define S second

using namespace std;

typedef long long ll;
typedef pair<int , int> ii;

struct tp{
    int a , b , c;
    tp();
    tp(int a , int b , int c):
        a(a) , b(b) , c(c) {}
};

map<int , int> mp;
set< ii > v;
vector< pair< tp , int > > t;

tp sorted(int a1, int b1, int c1){
    int a=a1 , b=b1 , c=c1;
    for(int i=0 ; i<5 ; i++){
        if(a < b)
            swap(a ,b);
        if(b < c)
            swap(b , c);
    }
    return tp(c , b, a);
}

int main(){
    int n;
    cin >> n;
    for(int i=0 ; i<n ; i++){
        int a;
        cin >> a;
        mp[a] ++;
    }
    map<int , int>::iterator it;
    for(it=mp.begin() ; it!=mp.end() ; ++it)
        v.insert(ii(it->S , it->F));

    int k=0;
    while(v.size() >= 3){
        set< ii >::iterator it;
        ii p[3];
        for(int i=0 ; i<3 ; i++){
            it = v.end();
            --it;
            p[i] = *it;
           // cout << i << endl;
            v.erase(it);
        }
        int mi = int(1e9);
        for(int i=0 ; i<3 ; i++)
            mi = min(mi , p[i].F);
        k += mi;
        t.push_back( make_pair( sorted( p[0].S , p[1].S , p[2].S ) , mi ) );
        for(int i=0 ; i<3 ; i++)
            p[i].F -= mi;
        for(int i=0 ; i<3 ; i++)
            if(p[i].F > 0) v.insert(p[i]);
    }
    cout << k << endl;
   // for(ll i=0 ; i<1e8 ; i++);
    for(int i=0 ; i<t.size() ; i++)
        for(int j=0 ; j<t[i].S ; j++){
          //  cout << j << " , " << t[i].S << endl;
            cout << t[i].F.c << " " << t[i].F.b << " " << t[i].F.a << endl;
        }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
struct snow{
    int num1, num2, num3;
};
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin>>n;
    map< int, int > mp;
    for(int i=0; i<n ;i++){
        int x;
        cin>>x;
        mp[x]++;
    }
    priority_queue< pair<int, int> > pq;
    vector<snow> res;
    for(map<int, int>::iterator it = mp.begin(); it != mp.end(); it++){
        pq.push( {it->second, it->first} );
    }

    while(pq.size()>=3){
        pair<int, int> p1 = pq.top();
        pq.pop();
        pair<int, int> p2 = pq.top();
        pq.pop();
        pair<int, int> p3 = pq.top();
        pq.pop();

        res.push_back({p1.second, p2.second, p3.second});
        p1.first--, p2.first--, p3.first--;
        if(p1.first) pq.push(p1);
        if(p2.first) pq.push(p2);
        if(p3.first) pq.push(p3);
    }
    cout<<res.size()<<endl;
    for(snow s:res){
        int srt[] = {s.num1, s.num2, s.num3};
        sort(srt, srt+3);
        for(int i=2; i>=0; i--)
            cout<<srt[i]<<" ";
        cout<<endl;
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
struct snow{
    int num1, num2, num3;
};
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin>>n;
    map< int, int > mp;
    for(int i=0; i<n ;i++){
        int x;
        cin>>x;
        mp[x]++;
    }
    vector< pair<int, int> > vp(mp.size());
    int i=0;
    for(map<int, int>::iterator it = mp.begin(); it != mp.end(); it++){
        vp[i++] = {it->second, it->first};
    }

    sort(vp.begin(), vp.end());
    vector<snow> res;
    for(int i=0; i+2<vp.size(); i++){
        while(vp[i].first){
            res.push_back({vp[i].second, vp[i+1].second, vp[i+2].second});
            vp[i].first--, vp[i+1].first--, vp[i+2].first--;
        }
    }
    cout<<res.size()<<endl;
    for(snow s:res){
        cout<<s.num3<<" "<<s.num2<<" "<<s.num1<<endl;
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
struct snow{
    int num1, num2, num3;
};
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin>>n;
    map< int, int > mp;
    for(int i=0; i<n ;i++){
        int x;
        cin>>x;
        mp[x]++;
    }
    vector< pair<int, int> > vp(mp.size());
    int i=0;
    for(map<int, int>::iterator it = mp.begin(); it != mp.end(); it++){
        vp[i++] = {it->second, it->first};
    }

    sort(vp.begin(), vp.end());
    vector<snow> res;
    for(int i=0; i+2<vp.size(); i++){
        while(vp[i].first){
            res.push_back({vp[i].second, vp[i+1].second, vp[i+2].second});
            vp[i].first--, vp[i+1].first--, vp[i+2].first--;
        }
    }
    cout<<res.size()<<endl;
    for(snow s:res){
        cout<<s.num1<<" "<<s.num2<<" "<<s.num3<<endl;
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
struct snow{
    int num1, num2, num3;
};
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin>>n;
    map< int, int > mp;
    for(int i=0; i<n ;i++){
        int x;
        cin>>x;
        mp[x]++;
    }
    vector< pair<int, int> > vp(mp.size());
    int i=0;
    for(map<int, int>::iterator it = mp.begin(); it != mp.end(); it++){
        vp[i++] = {it->second, it->first};
    }

    sort(vp.begin(), vp.end());
    vector<snow> res;
    for(int i=0; i+2<vp.size(); i++){
        while(vp[i].first){
            res.push_back({vp[i].second, vp[i+1].second, vp[i+2].second});
            vp[i].first--, vp[i+1].first--, vp[i+2].first--;
        }
    }
    cout<<res.size();
    for(snow s:res){
        cout<<s.num1<<" "<<s.num2<<" "<<s.num3<<endl;
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
struct snow{
    int num1, num2, num3;
};
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin>>n;
    map< int, int > mp;
    for(int i=0; i<n ;i++){
        int x;
        cin>>x;
        mp[x]++;
    }
    vector< pair<int, int> > vp(mp.size());
    int i=0;
    for(map<int, int>::iterator it = mp.begin(); it != mp.end(); it++){
        vp[i++] = {it->second, it->first};
    }

    sort(vp.rbegin(), vp.rend());
    vector<snow> res;

    int ind1=0, ind2=1, ind3=2;
    int curind=3;
    while(curind <= vp.size()){
        while(vp[ind1].first && vp[ind2].first && vp[ind3].first ){
            res.push_back({vp[ind1].second, vp[ind2].second, vp[ind3].second});
            vp[ind1].first--, vp[ind2].first--, vp[ind3].first--;
        }
        if(!vp[ind1].first)
            ind1 = curind++;
        else if(!vp[ind2].first)
            ind2 = curind++;
        else
            ind3 = curind++;
    }
    cout<<res.size()<<endl;
    for(snow s:res){
        int srt[] = {s.num1, s.num2, s.num3};
        sort(srt, srt+3);
        for(int i=2; i>=0; i--)
            cout<<srt[i]<<" ";
        cout<<endl;
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
struct snow{
    int num1, num2, num3;
};
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin>>n;
    map< int, int > mp;
    for(int i=0; i<n ;i++){
        int x;
        cin>>x;
        mp[x]++;
    }
    vector< pair<int, int> > vp(mp.size());
    int i=0;
    for(map<int, int>::iterator it = mp.begin(); it != mp.end(); it++){
        vp[i++] = {it->second, it->first};
    }

    sort(vp.begin(), vp.end());
    vector<snow> res;
    for(int i=0; i+2<vp.size(); i++){
        while(vp[i].first){
            res.push_back({vp[i].second, vp[i+1].second, vp[i+2].second});
            vp[i].first--, vp[i+1].first--, vp[i+2].first--;
        }
    }
    cout<<res.size()<<endl;
    for(snow s:res){
        int srt[] = {s.num1, s.num2, s.num3};
        sort(srt, srt+3);
        for(int i=2; i>=0; i--)
            cout<<srt[i]<<" ";
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int Max = 1e5+3;
set<int> st[Max];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector<int> arr(n);
    vector<int> comp(n);
    int temp;
    for(int i = 0; i < n; ++i) {
        cin >> temp;
        comp[i] = temp;
        arr[i] = temp;
    }
    sort(comp.begin(), comp.end());
    comp.erase(unique(comp.begin(), comp.end()), comp.end());
    for(int i = 0; i < n; ++i) {
        temp = lower_bound(comp.begin(), comp.end(), arr[i]) - comp.begin();
        st[temp].insert(i);
    }
/*    for(int i = 0; i < Max-1; ++i) {
        if(st[i].empty()) continue;
        cout << i << '\t';
        for(const int &elem : st[i]) cout << elem << ' ';cout << '\n';
    }*/
    priority_queue<pair<int, int> > q;//-size, ptr
    for(int i = 0; i < Max-1; ++i) {
        if(st[i].size()) {
            q.push({(int)st[i].size(), i});
        }
    }
    vector<pair<int, pair<int, int> > > snow;
    int ptr1, ptr2, ptr3, size1, size2, size3;
    while(q.size() > 2) {
        int i1, i2, i3;
        ptr1 = q.top().second;
        size1 = q.top().first;
        q.pop();
        i1 = *st[ptr1].begin();
        st[ptr1].erase(i1);

        ptr2 = q.top().second;
        size2 = q.top().first;
        q.pop();
        i2 = *st[ptr2].begin();
        st[ptr2].erase(i2);

        ptr3 = q.top().second;
        size3 = q.top().first;
        q.pop();
        i3 = *st[ptr3].begin();
        st[ptr3].erase(i3);

        if(!st[ptr1].empty()) {
            q.push({size1-1, ptr1});
        }
        if(!st[ptr2].empty()) {
            q.push({size2-1, ptr2});
        }
        if(!st[ptr3].empty()) {
            q.push({size3-1, ptr3});
        }

        if(arr[i1] < arr[i2]) swap(i1, i2);
        if(arr[i1] < arr[i3]) swap(i1, i3);
        if(arr[i2] < arr[i3]) swap(i2, i3);
        if(arr[i1] < arr[i2]) swap(i1, i2);
        if(arr[i1] < arr[i3]) swap(i1, i3);
        if(arr[i2] < arr[i3]) swap(i2, i3);
        if(arr[i1] < arr[i2]) swap(i1, i2);
        if(arr[i1] < arr[i3]) swap(i1, i3);
        if(arr[i2] < arr[i3]) swap(i2, i3);
        //cout << i1 << ' ' << i2 << ' ' << i3 << '\n';
        //snow.push_back({i1, {i2, i3}});
        snow.push_back({arr[i1], {arr[i2], arr[i3]}});
    }

    cout << snow.size() << '\n';
    for(auto &p : snow) cout << p.first << ' ' << p.second.first << ' ' << p.second.second << '\n';
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int Max = 1e5+3;
set<int> st[Max];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector<int> arr(n);
    vector<int> comp(n);
    int temp;
    for(int i = 0; i < n; ++i) {
        cin >> temp;
        comp[i] = temp;
        arr[i] = temp;
    }
    sort(comp.begin(), comp.end());
    comp.erase(unique(comp.begin(), comp.end()), comp.end());
    for(int i = 0; i < n; ++i) {
        temp = lower_bound(comp.begin(), comp.end(), arr[i]) - comp.begin();
        st[temp].insert(i);
    }
/*    for(int i = 0; i < Max-1; ++i) {
        if(st[i].empty()) continue;
        cout << i << '\t';
        for(const int &elem : st[i]) cout << elem << ' ';cout << '\n';
    }*/
    priority_queue<pair<int, int> > q;//-size, ptr
    for(int i = 0; i < Max-1; ++i) {
        if(st[i].size()) {
            q.push({-(int)st[i].size(), i});
        }
    }
    vector<pair<int, pair<int, int> > > snow;
    int ptr1, ptr2, ptr3, size1, size2, size3;
    while(q.size() > 2) {
        int i1, i2, i3;
        ptr1 = q.top().second;
        size1 = q.top().first;
        q.pop();
        i1 = *st[ptr1].begin();
        st[ptr1].erase(i1);

        ptr2 = q.top().second;
        size2 = q.top().first;
        q.pop();
        i2 = *st[ptr2].begin();
        st[ptr2].erase(i2);

        ptr3 = q.top().second;
        size3 = q.top().first;
        q.pop();
        i3 = *st[ptr3].begin();
        st[ptr3].erase(i3);

        if(!st[ptr1].empty()) {
            q.push({size1+1, ptr1});
        }
        if(!st[ptr2].empty()) {
            q.push({size2+1, ptr2});
        }
        if(!st[ptr3].empty()) {
            q.push({size3+1, ptr3});
        }

        if(arr[i1] < arr[i2]) swap(i1, i2);
        if(arr[i1] < arr[i3]) swap(i1, i3);
        if(arr[i2] < arr[i3]) swap(i2, i3);
        if(arr[i1] < arr[i2]) swap(i1, i2);
        if(arr[i1] < arr[i3]) swap(i1, i3);
        if(arr[i2] < arr[i3]) swap(i2, i3);
        if(arr[i1] < arr[i2]) swap(i1, i2);
        if(arr[i1] < arr[i3]) swap(i1, i3);
        if(arr[i2] < arr[i3]) swap(i2, i3);
        //cout << i1 << ' ' << i2 << ' ' << i3 << '\n';
        //snow.push_back({i1, {i2, i3}});
        snow.push_back({arr[i1], {arr[i2], arr[i3]}});
    }

    cout << snow.size() << '\n';
    for(auto &p : snow) cout << p.first << ' ' << p.second.first << ' ' << p.second.second << '\n';
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int Max = 1e5+3;
set<int> st[Max];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector<int> arr(n);
    vector<int> comp(n);
    int temp;
    for(int i = 0; i < n; ++i) {
        cin >> temp;
        comp[i] = temp;
        arr[i] = temp;
    }
    sort(comp.begin(), comp.end());
    comp.erase(unique(comp.begin(), comp.end()), comp.end());
    for(int i = 0; i < n; ++i) {
        temp = lower_bound(comp.begin(), comp.end(), arr[i]) - comp.begin();
        st[temp].insert(i);
    }
/*    for(int i = 0; i < Max-1; ++i) {
        if(st[i].empty()) continue;
        cout << i << '\t';
        for(const int &elem : st[i]) cout << elem << ' ';cout << '\n';
    }*/
    priority_queue<pair<int, int> > q;//-size, ptr
    for(int i = 0; i < Max-1; ++i) {
        if(st[i].size()) {
            q.push({(int)st[i].size(), i});
        }
    }
    vector<pair<int, pair<int, int> > > snow;
    int ptr1, ptr2, ptr3, size;
    while(q.size() > 2) {
        int i1, i2, i3;
        ptr1 = q.top().second;
        size = q.top().first;
        q.pop();
        i1 = *st[ptr1].begin();
        st[ptr1].erase(i1);

        ptr2 = q.top().second;
        size = q.top().first;
        q.pop();
        i2 = *st[ptr2].begin();
        st[ptr2].erase(i2);

        ptr3 = q.top().second;
        size = q.top().first;
        q.pop();
        i3 = *st[ptr3].begin();
        st[ptr3].erase(i3);

        if(!st[ptr1].empty()) {
            q.push({size-1, ptr1});
        }
        if(!st[ptr2].empty()) {
            q.push({size-1, ptr2});
        }
        if(!st[ptr3].empty()) {
            q.push({size-1, ptr3});
        }

        if(arr[i1] < arr[i2]) swap(i1, i2);
        if(arr[i1] < arr[i3]) swap(i1, i3);
        if(arr[i2] < arr[i3]) swap(i2, i3);
        if(arr[i1] < arr[i2]) swap(i1, i2);
        if(arr[i1] < arr[i3]) swap(i1, i3);
        if(arr[i2] < arr[i3]) swap(i2, i3);
        if(arr[i1] < arr[i2]) swap(i1, i2);
        if(arr[i1] < arr[i3]) swap(i1, i3);
        if(arr[i2] < arr[i3]) swap(i2, i3);
        //cout << i1 << ' ' << i2 << ' ' << i3 << '\n';
        //snow.push_back({i1, {i2, i3}});
        snow.push_back({arr[i1], {arr[i2], arr[i3]}});
    }

    cout << snow.size() << '\n';
    for(auto &p : snow) cout << p.first << ' ' << p.second.first << ' ' << p.second.second << '\n';
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int Max = 1e5+3;
set<int> st[Max];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector<pair<int, int> > arr(n);
    vector<int> comp(n);
    int temp;
    for(int i = 0; i < n; ++i) {
        cin >> temp;
        comp[i] = temp;
        arr[i] = {temp, i};
    }
    sort(comp.begin(), comp.end());
    for(int i = 0; i < n; ++i) {
        temp = lower_bound(comp.begin(), comp.end(), arr[i].first) - comp.begin();
        st[temp].insert(arr[i].second);
    }
    priority_queue<pair<int, int> > q;//-size, ptr
    for(int i = 0; i < Max-1; ++i) {
        if(st[i].size()) {
            q.push({-(int)st[i].size(), i});
        }
    }
    vector<pair<int, pair<int, int> > > snow;
    int ptr, size;
    while(q.size() > 2) {
        int i1, i2, i3;
        ptr = q.top().second;
        size = q.top().first;
        q.pop();
        i1 = *st[ptr].begin();
        st[ptr].erase(i1);
        if(!st[ptr].empty()) {
            q.push({size+1, ptr});
        }

        ptr = q.top().second;
        size = q.top().first;
        q.pop();
        i2 = *st[ptr].begin();
        st[ptr].erase(i2);
        if(!st[ptr].empty()) {
            q.push({size+1, ptr});
        }

        ptr = q.top().second;
        size = q.top().first;
        q.pop();
        i3 = *st[ptr].begin();
        st[ptr].erase(i3);
        if(!st[ptr].empty()) {
            q.push({size+1, ptr});
        }

        if(arr[i1].first < arr[i2].first) swap(i1, i2);
        if(arr[i1].first < arr[i3].first) swap(i1, i3);
        if(arr[i2].first < arr[i3].first) swap(i2, i3);

        snow.push_back({i1, {i2, i3}});
    }

    cout << snow.size() << '\n';
    for(auto &p : snow) cout << p.first+1 << ' ' << p.second.first+1 << ' ' << p.second.second+1 << '\n';
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    int temp;
    map<int, set<int> > table;
    for(int i = 0; i < n; ++i) {
        cin >> temp;
        table[temp].insert(i);
    }
    if(table.size() <= 2) {
        cout << "0\n";
        return 0;
    }
    vector<pair<int, pair<int, int> > > snow;
    while(table.size() > 2) {
        auto it = table.begin();
        int i1, i2, i3;
        i1 = *it->second.begin();
        it->second.erase(i1);
        if(it->second.size() == 0) {
            table.erase(it);
            it = table.begin();
        } else it++;

        i2 = *it->second.begin();
        it->second.erase(i2);
        if(it->second.size() == 0) {
            table.erase(it);
            it = table.begin();
        } else it++;

        i3 = *it->second.begin();
        it->second.erase(i3);
        if(it->second.size() == 0) {
            table.erase(it);
            it = table.begin();
        } else it++;

        snow.push_back({i3, {i2, i1}});
    }
    cout << snow.size() << '\n';
    for(auto &p : snow) cout << p.first+1 << ' ' << p.second.first+1 << ' ' << p.second.second+1 << '\n';
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    int temp;
    map<int, set<int> > table;
    for(int i = 0; i < n; ++i) {
        cin >> temp;
        table[temp].insert(i);
    }
    if(table.size() <= 2) {
        cout << "0\n";
        return 0;
    }
    vector<pair<int, pair<int, int> > > snow;
    while(table.size() > 2) {
        auto it = table.begin();
        int i1, i2, i3;
        i1 = *it->second.begin();
        it->second.erase(i1);
        if(it->second.size() == 0) {
            table.erase(it);
            it = table.begin();
        } else it++;

        i2 = *it->second.begin();
        it->second.erase(i2);
        if(it->second.size() == 0) {
            table.erase(it);
            it = table.begin();
        } else it++;

        i3 = *it->second.begin();
        it->second.erase(i3);
        if(it->second.size() == 0) {
            table.erase(it);
            it = table.begin();
        } else it++;

        snow.push_back({i1, {i2, i3}});
    }
    cout << snow.size() << '\n';
    for(auto &p : snow) cout << p.first+1 << ' ' << p.second.first+1 << ' ' << p.second.second+1 << '\n';
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int Max = 1e5+3;
set<int> st[Max];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector<int> arr(n);
    vector<int> comp(n);
    int temp;
    for(int i = 0; i < n; ++i) {
        cin >> temp;
        comp[i] = temp;
        arr[i] = temp;
    }
    sort(comp.begin(), comp.end());
    comp.erase(unique(comp.begin(), comp.end()), comp.end());
    for(int i = 0; i < n; ++i) {
        temp = lower_bound(comp.begin(), comp.end(), arr[i]) - comp.begin();
        st[temp].insert(i);
    }
/*    for(int i = 0; i < Max-1; ++i) {
        if(st[i].empty()) continue;
        cout << i << '\t';
        for(const int &elem : st[i]) cout << elem << ' ';cout << '\n';
    }*/
    priority_queue<pair<int, int> > q;//-size, ptr
    for(int i = 0; i < Max-1; ++i) {
        if(st[i].size()) {
            q.push({(int)st[i].size(), i});
        }
    }
    vector<pair<int, pair<int, int> > > snow;
    int ptr1, ptr2, ptr3, size;
    while(q.size() > 2) {
        int i1, i2, i3;
        ptr1 = q.top().second;
        size = q.top().first;
        q.pop();
        i1 = *st[ptr1].begin();
        st[ptr1].erase(i1);

        ptr2 = q.top().second;
        size = q.top().first;
        q.pop();
        i2 = *st[ptr2].begin();
        st[ptr2].erase(i2);

        ptr3 = q.top().second;
        size = q.top().first;
        q.pop();
        i3 = *st[ptr3].begin();
        st[ptr3].erase(i3);

        if(!st[ptr1].empty()) {
            q.push({size-1, ptr1});
        }
        if(!st[ptr2].empty()) {
            q.push({size-1, ptr2});
        }
        if(!st[ptr3].empty()) {
            q.push({size-1, ptr3});
        }

        if(arr[i1] < arr[i2]) swap(i1, i2);
        if(arr[i1] < arr[i3]) swap(i1, i3);
        if(arr[i2] < arr[i3]) swap(i2, i3);
        if(arr[i1] < arr[i2]) swap(i1, i2);
        if(arr[i1] < arr[i3]) swap(i1, i3);
        if(arr[i2] < arr[i3]) swap(i2, i3);
        if(arr[i1] < arr[i2]) swap(i1, i2);
        if(arr[i1] < arr[i3]) swap(i1, i3);
        if(arr[i2] < arr[i3]) swap(i2, i3);
        //cout << i1 << ' ' << i2 << ' ' << i3 << '\n';
        snow.push_back({i1, {i2, i3}});
        //snow.push_back({arr[i1].first, {arr[i2].first, arr[i3].first}});
    }

    cout << snow.size() << '\n';
    for(auto &p : snow) cout << p.first+1 << ' ' << p.second.first+1 << ' ' << p.second.second+1 << '\n';
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int Max = 1e5+3;
set<int> st[Max];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector<pair<int, int> > arr(n);
    vector<int> comp(n);
    int temp;
    for(int i = 0; i < n; ++i) {
        cin >> temp;
        comp[i] = temp;
        arr[i] = {temp, i};
    }
    sort(comp.begin(), comp.end());
    for(int i = 0; i < n; ++i) {
        temp = lower_bound(comp.begin(), comp.end(), arr[i].first) - comp.begin();
        st[temp].insert(arr[i].second);
    }
    priority_queue<pair<int, int> > q;//-size, ptr
    for(int i = 0; i < Max-1; ++i) {
        if(st[i].size()) {
            q.push({(int)st[i].size(), i});
        }
    }
    vector<pair<int, pair<int, int> > > snow;
    int ptr, size;
    while(q.size() > 2) {
        int i1, i2, i3;
        ptr = q.top().second;
        size = q.top().first;
        q.pop();
        i1 = *st[ptr].begin();
        st[ptr].erase(i1);
        if(!st[ptr].empty()) {
            q.push({size-1, ptr});
        }

        ptr = q.top().second;
        size = q.top().first;
        q.pop();
        i2 = *st[ptr].begin();
        st[ptr].erase(i2);
        if(!st[ptr].empty()) {
            q.push({size-1, ptr});
        }

        ptr = q.top().second;
        size = q.top().first;
        q.pop();
        i3 = *st[ptr].begin();
        st[ptr].erase(i3);
        if(!st[ptr].empty()) {
            q.push({size-1, ptr});
        }

        if(arr[i1].first < arr[i2].first) swap(i1, i2);
        if(arr[i1].first < arr[i3].first) swap(i1, i3);
        if(arr[i2].first < arr[i3].first) swap(i2, i3);
        if(arr[i1].first < arr[i2].first) swap(i1, i2);
        if(arr[i1].first < arr[i3].first) swap(i1, i3);
        if(arr[i2].first < arr[i3].first) swap(i2, i3);
        if(arr[i1].first < arr[i2].first) swap(i1, i2);
        if(arr[i1].first < arr[i3].first) swap(i1, i3);
        if(arr[i2].first < arr[i3].first) swap(i2, i3);

        snow.push_back({i1, {i2, i3}});
    }

    cout << snow.size() << '\n';
    for(auto &p : snow) cout << p.first+1 << ' ' << p.second.first+1 << ' ' << p.second.second+1 << '\n';
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int Max = 1e5+3;
set<int> st[Max];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector<pair<int, int> > arr(n);
    vector<int> comp(n);
    int temp;
    for(int i = 0; i < n; ++i) {
        cin >> temp;
        comp[i] = temp;
        arr[i] = {temp, i};
    }
    sort(comp.begin(), comp.end());
    for(int i = 0; i < n; ++i) {
        temp = lower_bound(comp.begin(), comp.end(), arr[i].first) - comp.begin();
        st[temp].insert(arr[i].second);
    }
    priority_queue<pair<int, int> > q;//-size, ptr
    for(int i = 0; i < Max-1; ++i) {
        if(st[i].size()) {
            q.push({-(int)st[i].size(), i});
        }
    }
    vector<pair<int, pair<int, int> > > snow;
    int ptr, size;
    while(q.size() > 2) {
        int i1, i2, i3;
        ptr = q.top().second;
        size = q.top().first;
        q.pop();
        i1 = *st[ptr].begin();
        st[ptr].erase(i1);
        if(!st[ptr].empty()) {
            q.push({size+1, ptr});
        }

        ptr = q.top().second;
        size = q.top().first;
        q.pop();
        i2 = *st[ptr].begin();
        st[ptr].erase(i2);
        if(!st[ptr].empty()) {
            q.push({size+1, ptr});
        }

        ptr = q.top().second;
        size = q.top().first;
        q.pop();
        i3 = *st[ptr].begin();
        st[ptr].erase(i3);
        if(!st[ptr].empty()) {
            q.push({size+1, ptr});
        }

        if(arr[i1].first < arr[i2].first) swap(i1, i2);
        if(arr[i1].first < arr[i3].first) swap(i1, i3);
        if(arr[i2].first < arr[i3].first) swap(i2, i3);
        if(arr[i1].first < arr[i2].first) swap(i1, i2);
        if(arr[i1].first < arr[i3].first) swap(i1, i3);
        if(arr[i2].first < arr[i3].first) swap(i2, i3);
        if(arr[i1].first < arr[i2].first) swap(i1, i2);
        if(arr[i1].first < arr[i3].first) swap(i1, i3);
        if(arr[i2].first < arr[i3].first) swap(i2, i3);

        snow.push_back({i1, {i2, i3}});
    }

    cout << snow.size() << '\n';
    for(auto &p : snow) cout << p.first+1 << ' ' << p.second.first+1 << ' ' << p.second.second+1 << '\n';
    return 0;
}


#include <queue>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;
typedef long long ll;
const int N=1e5+10;
inline int read() {
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return f*x;
}

int n;
int r[N],cnt[N],w[N];
struct cmp{
	bool operator () (const int &x,const int &y) {
		return cnt[x]>cnt[y];
	}
};
struct ANS{
	int x,y,z;
	ANS(){}
	ANS(int x_,int y_,int z_):x(x_),y(y_),z(z_){}
}st[N];
int ans=0;
priority_queue< int,vector<int>,cmp >Q;
int main() {
	n=read();
	for(int i=1;i<=n;i++) r[i]=read();
	sort(r+1,r+1+n);
	int tot=0;
	for(int i=1;i<=n;i++) {
		if(r[i]==r[i-1]) cnt[tot]++;
		else cnt[++tot]=1,w[tot]=r[i],Q.push(tot);
	}
	while(Q.size()) {
		int x=Q.top();Q.pop();
		if(Q.empty()) break;
		int y=Q.top();Q.pop();
		if(Q.empty()) break;
		int z=Q.top();Q.pop();
		cnt[x]-=cnt[z];cnt[y]-=cnt[z];
		for(int i=1;i<=cnt[z];i++)
			st[++ans]=ANS(w[x],w[y],w[z]);
		if(cnt[y]) Q.push(y);
		if(cnt[x]) Q.push(x);
	}
	printf("%d\n",ans);
	for(int i=1;i<=ans;i++)
		printf("%d %d %d\n",st[i].x,st[i].y,st[i].z);
	return 0;
}


#include <queue>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;
typedef long long ll;
const int N=1e5+10;
inline int read() {
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return f*x;
}
#define MP make_pair
#define pii pair<int,int>
int n;
int r[N],cnt[N],w[N];
struct ANS{
	int x,y,z;
	ANS(){}
	int a[4];
	ANS(int x_,int y_,int z_) {
		a[0]=x_;a[1]=y_;a[2]=z_;
		sort(a,a+3);
		x=a[2],y=a[1],z=a[0];
	}
}st[N];
int ans=0;
priority_queue< pair<int,int> >Q;
int main() {
	n=read();
	for(int i=1;i<=n;i++) r[i]=read();
	sort(r+1,r+1+n);
	int tot=0;
	for(int i=1;i<=n;i++) {
		if(r[i]==r[i-1]) cnt[tot]++;
		else cnt[++tot]=1,w[tot]=r[i];
	}
	for(int i=1;i<=tot;i++)
		Q.push(MP(cnt[i],i));
	while(Q.size()) {
		pii x=Q.top();Q.pop();
		if(Q.empty()) break;
		pii y=Q.top();Q.pop();
		if(Q.empty()) break;
		pii z=Q.top();Q.pop();
		x.first-=z.first;
		y.first-=z.first;
		for(int i=1;i<=z.first;i++)
			st[++ans]=ANS(w[x.second],w[y.second],w[z.second]);
		if(x.first) Q.push(x);
		if(y.first) Q.push(y);
	}
	printf("%d\n",ans);
	for(int i=1;i<=ans;i++)
		printf("%d %d %d\n",st[i].x,st[i].y,st[i].z);
	return 0;
}


#include <queue>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;
typedef long long ll;
const int N=1e5+10;
inline int read() {
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return f*x;
}

int n;
int r[N],cnt[N],w[N];
struct cmp{
	bool operator () (const int &x,const int &y) {
		return cnt[x]>cnt[y];
	}
};
struct ANS{
	int x,y,z;
	ANS(){}
	int a[4];
	ANS(int x_,int y_,int z_) {
		a[0]=x_;a[1]=y_;a[2]=z_;
		sort(a,a+3);
		x=a[2],y=a[1],z=a[0];
	}
}st[N];
int ans=0;
priority_queue< int,vector<int>,cmp >Q;
int main() {
	n=read();
	for(int i=1;i<=n;i++) r[i]=read();
	sort(r+1,r+1+n);
	int tot=0;
	for(int i=1;i<=n;i++) {
		if(r[i]==r[i-1]) cnt[tot]++;
		else cnt[++tot]=1,w[tot]=r[i],Q.push(tot);
	}
	while(Q.size()) {
		int x=Q.top();Q.pop();
		if(Q.empty()) break;
		int y=Q.top();Q.pop();
		if(Q.empty()) break;
		int z=Q.top();Q.pop();
		cnt[x]-=cnt[z];cnt[y]-=cnt[z];
		for(int i=1;i<=cnt[z];i++)
			st[++ans]=ANS(w[x],w[y],w[z]);
		if(cnt[y]) Q.push(y);
		if(cnt[x]) Q.push(x);
	}
	printf("%d\n",ans);
	for(int i=1;i<=ans;i++)
		printf("%d %d %d\n",st[i].x,st[i].y,st[i].z);
	return 0;
}


#include <queue>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;
typedef long long ll;
const int N=1e5+10;
inline int read() {
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return f*x;
}
#define MP make_pair
#define pii pair<int,int>
int n;
int r[N],cnt[N],w[N];
struct ANS{
	int x,y,z;
	ANS(){}
	int a[4];
	ANS(int x_,int y_,int z_) {
		a[0]=x_;a[1]=y_;a[2]=z_;
		sort(a,a+3);
		x=a[2],y=a[1],z=a[0];
	}
}st[N];
int ans=0;
priority_queue< pair<int,int> >Q;
int main() {
	n=read();
	for(int i=1;i<=n;i++) r[i]=read();
	sort(r+1,r+1+n);
	int tot=0;
	for(int i=1;i<=n;i++) {
		if(r[i]==r[i-1]) cnt[tot]++;
		else cnt[++tot]=1,w[tot]=r[i];
	}
	for(int i=1;i<=tot;i++)
		Q.push(MP(cnt[i],i));
	while(Q.size()) {
		pii x=Q.top();Q.pop();
		if(Q.size()==1) break;
		pii y=Q.top();Q.pop();
		// if(Q.empty()) break;
		pii z=Q.top();Q.pop();
		x.first-=z.first;
		y.first-=z.first;
		for(int i=1;i<=z.first;i++)
			st[++ans]=ANS(w[x.second],w[y.second],w[z.second]);
		if(x.first) Q.push(x);
		if(y.first) Q.push(y);
	}
	printf("%d\n",ans);
	for(int i=1;i<=ans;i++)
		printf("%d %d %d\n",st[i].x,st[i].y,st[i].z);
	return 0;
}


#include <queue>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;
typedef long long ll;
const int N=1e5+10;
inline int read() {
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return f*x;
}

int n;
int r[N],cnt[N],w[N];
struct cmp{
	bool operator () (const int &x,const int &y) {
		return cnt[x]>cnt[y];
	}
};
struct ANS{
	int x,y,z;
	ANS(){}
	ANS(int x_,int y_,int z_):x(x_),y(y_),z(z_){}
}st[N];
int ans=0;
priority_queue< int,vector<int>,cmp >Q;
int main() {
	n=read();
	for(int i=1;i<=n;i++) r[i]=read();
	sort(r+1,r+1+n);
	int tot=0;
	for(int i=1;i<=n;i++) {
		if(r[i]==r[i-1]) cnt[tot]++;
		else cnt[++tot]=1,w[tot]=r[i],Q.push(tot);
	}
	while(Q.size()) {
		int x=Q.top();Q.pop();
		if(Q.empty()) break;
		int y=Q.top();Q.pop();
		if(Q.empty()) break;
		int z=Q.top();Q.pop();
		cnt[x]-=cnt[z];cnt[y]-=cnt[z];
		for(int i=1;i<=cnt[z];i++)
			st[++ans]=ANS(w[x],w[y],w[z]);
		if(cnt[y]) Q.push(y);
		if(cnt[x]) Q.push(x);
	}
	printf("%d\n",ans);
	for(int i=1;i<=ans;i++)
		printf("%d %d %d\n",st[i].x,st[i].y,st[i].z);
	return 0;
}t


#include <queue>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;
typedef long long ll;
const int N=1e5+10;
inline int read() {
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return f*x;
}
#define MP make_pair
#define pii pair<int,int>
int n;
int r[N],cnt[N],w[N];
struct ANS{
	int x,y,z;
	ANS(){}
	int a[4];
	ANS(int x_,int y_,int z_) {
		a[0]=x_;a[1]=y_;a[2]=z_;
		sort(a,a+3);
		x=a[2],y=a[1],z=a[0];
	}
}st[N];
int ans=0;
priority_queue< pair<int,int> >Q;
int main() {
	n=read();
	for(int i=1;i<=n;i++) r[i]=read();
	sort(r+1,r+1+n);
	int tot=0;
	for(int i=1;i<=n;i++) {
		if(r[i]==r[i-1]) cnt[tot]++;
		else cnt[++tot]=1,w[tot]=r[i];
	}
	for(int i=1;i<=tot;i++)
		Q.push(MP(cnt[i],i));
	while(Q.size()) {
		pii x=Q.top();Q.pop();
		if(Q.empty()) break;
		pii y=Q.top();Q.pop();
		if(Q.empty()) break;
		pii z=Q.top();Q.pop();
		x.first-=z.first;
		y.first-=z.first;
		for(int i=1;i<=z.first;i++)
			st[++ans]=ANS(w[x.second],w[y.second],w[z.second]);
		if(x.first) Q.push(y);
		if(y.first) Q.push(x);
	}
	printf("%d\n",ans);
	for(int i=1;i<=ans;i++)
		printf("%d %d %d\n",st[i].x,st[i].y,st[i].z);
	return 0;
}


#include <queue>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;
typedef long long ll;
const int N=1e5+10;
inline int read() {
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return f*x;
}
#define MP make_pair
#define pii pair<int,int>
int n;
int r[N],cnt[N],w[N];
struct ANS{
	int x,y,z;
	ANS(){}
	int a[4];
	ANS(int x_,int y_,int z_) {
		a[0]=x_;a[1]=y_;a[2]=z_;
		sort(a,a+3);
		x=a[2],y=a[1],z=a[0];
	}
}st[N];
int ans=0;
priority_queue< pair<int,int> >Q;
int main() {
	n=read();
	for(int i=1;i<=n;i++) r[i]=read();
	sort(r+1,r+1+n);
	int tot=0;
	for(int i=1;i<=n;i++) {
		if(r[i]==r[i-1]) cnt[tot]++;
		else cnt[++tot]=1,w[tot]=r[i];
	}
	for(int i=1;i<=tot;i++)
		Q.push(MP(cnt[i],i));
	while(Q.size()) {
		pii x=Q.top();Q.pop();
		if(Q.empty()) break;
		pii y=Q.top();Q.pop();
		if(Q.empty()) break;
		pii z=Q.top();Q.pop();
		x.first--;
		y.first--;
		z.first--;
		st[++ans]=ANS(w[x.second],w[y.second],w[z.second]);
		if(x.first) Q.push(x);
		if(y.first) Q.push(y);
		if(z.first) Q.push(z);
	}
	printf("%d\n",ans);
	for(int i=1;i<=ans;i++)
		printf("%d %d %d\n",st[i].x,st[i].y,st[i].z);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef __int64 ll;
const double eps = 1e-6;
const ll INF = 1e9;
const int N = 1e5 + 10;
int n, m, k, t;
int a[N], arr[N];
char s[N];
bool vis[N], walked[N];
string str;

struct node
{
	int id, v;
}p[N];

bool cmp(node x, node y)
{
	if(x.v != y.v) return x.v > y.v;
	else return x.id < y.id;
}

bool judge(int x)
{
	if(x * 3 > n) return false;
	bool f = true;
	memset(vis, false, sizeof(vis));
	int pre = a[0];
	int tt = 0;
	arr[tt++] = a[0];
	int num = 1;
	for(int i = 0; i < n; i++)
	{
		if(pre == a[i])
		{
			num++;
			if(num > x) continue;
			arr[tt++] = a[i];
		}
		else
		{
			pre = a[i];
			num = 1;
			arr[tt++] = a[i];
		}
	}
	sort(arr, arr + tt);
	if(x * 3 > tt) return false;
	for(int i = 0; i < tt; i++)
	{
		if(vis[i]) continue;
		if(i + 2 * x >= n) break;
		if(arr[i] != arr[i + x] && arr[i + x] != arr[i + 2 * x])
		{
			vis[i] = true;
			vis[i + x] = true;
			vis[i + 2 * x] = true;
		}
		else
		{
			f = false; break;
		}
	}
	return f;
}

int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int i, j;
	scanf("%d", &n);
	for(i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
	}
	sort(a, a + n);
	int ans = 0;
	int l = 0, r = n;
	while(l <= r)
	{
		int mid = (l + r) / 2;
		if(judge(mid))
			l = mid + 1;
		else
			r = mid - 1;
	}
	ans = r;
	if(ans <= 0)
	{
		puts("0"); return 0;
	}
	printf("%d\n", ans);
	memset(vis, false, sizeof(vis));
	int pre = a[0];
	int tt = 0;
	arr[tt++] = a[0];
	int num = 1;
	for(int i = 0; i < n; i++)
	{
		if(pre == a[i])
		{
			num++;
			if(num > ans) continue;
			arr[tt++] = a[i];
		}
		else
		{
			pre = a[i];
			num = 1;
			arr[tt++] = a[i];
		}
	}
	sort(arr, arr + tt);
	for(int i = 0; i < tt; i++)
	{
		if(vis[i]) continue;
		if(i + 2 * ans >= n) break;
		printf("%d %d %d\n", a[i + 2 * ans], a[i + ans], a[i]);
		vis[i] = true;
		vis[i + ans] = true;
		vis[i + 2 * ans] = true;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef __int64 ll;
const double eps = 1e-6;
const ll INF = 1e9;
const int N = 1e5 + 10;
int n, m, k, t;
int a[N], b[N];
char s[N];
bool vis[N];
string str;
priority_queue<pair<int, int> >q;
pair<int, int>mp[5];

int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int i, j;
	scanf("%d", &n);
	for(i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
	}
	sort(a, a + n);
	for(i = 0; i < n; i = j)
    {
        for(j = i + 1; j < n && a[j] == a[i]; j++);
        q.push(make_pair(j - i, a[i]));
    }
    t = 0;
    int ans[N];
    while(!q.empty())
    {
        for(i = 0; i < 3 && !q.empty(); i++)
        {
            mp[i] = q.top();
			q.pop();
            ans[t++] = mp[i].second;
        }
        if(i==3)
        {
        	for(i = 0; i < 3; i++)
        	{
        		if(--mp[i].first) q.push(mp[i]);
        	}
        }
    }
    printf("%d\n", t / 3);
    for(i = 0; (i + 3) <= t; i += 3)
    {
        int aa = max(ans[i], max(ans[i + 1], ans[i + 2]));
		int cc = min(ans[i], min(ans[i + 1], ans[i + 2]));
        printf("%d %d %d\n", aa, ans[i] + ans[i + 1] + ans[i + 2] - aa - cc, cc);
    }
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef __int64 ll;
const double eps = 1e-6;
const ll INF = 1e9;
const int N = 1e5 + 10;
int n, m, k, t;
int a[N], arr[N];
char s[N];
bool vis[N], walked[N];
string str;

struct node
{
	int id, v;
}p[N];

bool cmp(node x, node y)
{
	if(x.v != y.v) return x.v > y.v;
	else return x.id < y.id;
}

bool judge(int x)
{
	if(x * 3 > n) return false;
	bool f = true;
	memset(vis, false, sizeof(vis));
	int pre = a[0];
	int tt = 0;
	arr[tt++] = a[0];
	int num = 1;
	for(int i = 0; i < n; i++)
	{
		if(pre == a[i])
		{
			num++;
			if(num > x) continue;
			arr[tt++] = a[i];
		}
		else
		{
			pre = a[i];
			num = 1;
			arr[tt++] = a[i];
		}
	}
	sort(arr, arr + tt);
	for(int i = 0; i < tt; i++)
	{
		if(vis[i]) continue;
		if(i + 2 * x >= n) break;
		if(arr[i] != arr[i + x] && arr[i + x] != arr[i + 2 * x])
		{
			vis[i] = true;
			vis[i + x] = true;
			vis[i + 2 * x] = true;
		}
		else
		{
			f = false; break;
		}
	}
	return f;
}

int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int i, j;
	scanf("%d", &n);
	for(i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
	}
	sort(a, a + n);
	int ans = 0;
	int l = 0, r = n;
	while(l <= r)
	{
		int mid = (l + r) / 2;
		if(judge(mid))
			l = mid + 1;
		else
			r = mid - 1;
	}
	ans = r;
	if(ans <= 0)
	{
		puts("0"); return 0;
	}
	printf("%d\n", ans);
	memset(vis, false, sizeof(vis));
	int pre = a[0];
	int tt = 0;
	arr[tt++] = a[0];
	int num = 1;
	for(int i = 0; i < n; i++)
	{
		if(pre == a[i])
		{
			num++;
			if(num > ans) continue;
			arr[tt++] = a[i];
		}
		else
		{
			pre = a[i];
			num = 1;
			arr[tt++] = a[i];
		}
	}
	sort(arr, arr + tt);
	for(int i = 0; i < tt; i++)
	{
		if(vis[i]) continue;
		if(i + 2 * ans >= n) break;
		printf("%d %d %d\n", a[i + 2 * ans], a[i + ans], a[i]);
		vis[i] = true;
		vis[i + ans] = true;
		vis[i + 2 * ans] = true;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef __int64 ll;
const double eps = 1e-6;
const ll INF = 1e9;
const int N = 1e5 + 10;
int n, m, k, t;
int a[N];
char s[N];
bool vis[N], walked[N];
string str;

struct node
{
	int id, v;
}p[N];

bool cmp(node x, node y)
{
	if(x.v != y.v) return x.v > y.v;
	else return x.id < y.id;
}

int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int i, j;
	scanf("%d", &n);
	for(i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
	}
	sort(a, a + n);
	int pre = a[0];
	p[0].id = a[0];
	p[0].v = 1;
	t = 0;
	for(int i = 1; i < n; i++)
	{
		if(a[i] == pre)
		{
			p[t].v++;
		}
		else
		{
			pre = a[i];
			p[++t].id = a[i];
			p[t].v = 1;
		}
	}
	sort(p, p + t + 1, cmp);
	int ans[N];
	int sum = 0, id = 0;
	memset(vis, false, sizeof(vis));
	int b[5];
	int tt = 0;
	m = 0;
	for(i = 0; i <= t; i++)
	{
		if(p[i].v == 0) continue;
		m = 0;
		p[i].v--;
		b[m++] = p[i].id;
		bool f = false;
		for(j = i + 1; j < n; j++)
		{
			if(p[j].v == 0) continue;
			else
			{
				b[m++] = p[j].id;
				p[j].v--;
				break;
			}
		}
		for(k = j + 1; k < n; k++)
		{
			if(p[k].v == 0) continue;
			else
			{
				b[m++] = p[k].id;
				p[k].v--;
				break;
			}
		}
		i = -1;
		if(m == 3)
		{
			sort(b, b + 3);
			ans[tt++] = b[2];
			ans[tt++] = b[1];
			ans[tt++] = b[0];
			sum++;
		}
		else break;
	}
	printf("%d\n", sum);
	for(int i = 0; i < tt; i+=3)
	{
		printf("%d %d %d\n", ans[i], ans[i + 1], ans[i + 2]);
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef __int64 ll;
const double eps = 1e-6;
const ll INF = 1e9;
const int N = 1e5 + 10;
int n, m, k, t;
int a[N], arr[N];
char s[N];
bool vis[N], walked[N];
string str;

struct node
{
	int id, v;
}p[N];

bool cmp(node x, node y)
{
	if(x.v != y.v) return x.v > y.v;
	else return x.id < y.id;
}

bool judge(int x)
{
	if(x * 3 > n) return false;
	bool f = true;
	memset(vis, false, sizeof(vis));
	memset(arr, 0, sizeof(arr));
	int pre = a[0];
	int tt = 0;
	arr[tt++] = a[0];
	int num = 1;
	for(int i = 1; i < n; i++)
	{
		if(pre == a[i])
		{
			num++;
			if(num > x) continue;
			arr[tt++] = a[i];
		}
		else
		{
			pre = a[i];
			num = 1;
			arr[tt++] = a[i];
		}
	}
	sort(arr, arr + tt);
	if(x * 3 > tt) return false;
	for(int i = 0; i < tt; i++)
	{
		if(vis[i]) continue;
		if(i + 2 * x >= n) break;
		if(arr[i] != arr[i + x] && arr[i + x] != arr[i + 2 * x])
		{
			vis[i] = true;
			vis[i + x] = true;
			vis[i + 2 * x] = true;
		}
		else
		{
			f = false; break;
		}
	}
	return f;
}

int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int i, j;
	scanf("%d", &n);
	for(i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
	}
	sort(a, a + n);
	int ans = 0;
	int l = 0, r = n;
	while(l <= r)
	{
		int mid = (l + r) / 2;
		if(judge(mid))
			l = mid + 1;
		else
			r = mid - 1;
	}
	ans = r;
	if(ans <= 0)
	{
		puts("0"); return 0;
	}
	printf("%d\n", ans);
	memset(vis, false, sizeof(vis));
	memset(arr, 0, sizeof(arr));
	int pre = a[0];
	int tt = 0;
	arr[tt++] = a[0];
	int num = 1;
	for(int i = 1; i < n; i++)
	{
		if(pre == a[i])
		{
			num++;
			if(num > ans) continue;
			arr[tt++] = a[i];
		}
		else
		{
			pre = a[i];
			num = 1;
			arr[tt++] = a[i];
		}
	}
	sort(arr, arr + tt);
	for(int i = 0; i < tt; i++)
	{
		if(vis[i]) continue;
		if(i + 2 * ans >= n) break;
		printf("%d %d %d\n", arr[i + 2 * ans], arr[i + ans], arr[i]);
		vis[i] = true;
		vis[i + ans] = true;
		vis[i + 2 * ans] = true;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef __int64 ll;
const double eps = 1e-6;
const ll INF = 1e9;
const int N = 1e5 + 10;
int n, m, k, t;
int a[N], arr[N];
char s[N];
bool vis[N];
string str;

struct node
{
	int id, v;
}p[N];

bool cmp(node x, node y)
{
	if(x.v != y.v) return x.v > y.v;
	else return x.id < y.id;
}

bool judge(int x)
{
	if(x * 3 > n) return false;
	bool f = true;
	memset(vis, false, sizeof(vis));
	memset(arr, 0, sizeof(arr));
	int pre = a[0];
	int tt = 0;
	arr[tt++] = a[0];
	int num = 1;
	for(int i = 1; i < n; i++)
	{
		if(pre == a[i])
		{
			num++;
			if(num > x) continue;
			arr[tt++] = a[i];
		}
		else
		{
			pre = a[i];
			num = 1;
			arr[tt++] = a[i];
		}
	}
	sort(arr, arr + tt);
	if(x * 3 > tt) return false;
	for(int i = 0; i < tt; i++)
	{
		if(vis[i]) continue;
		if(i + 2 * x >= n) break;
		if(arr[i] != arr[i + x] && arr[i + x] != arr[i + 2 * x])
		{
			vis[i] = true;
			vis[i + x] = true;
			vis[i + 2 * x] = true;
		}
		else
		{
			f = false; break;
		}
	}
	return f;
}

int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int i, j;
	scanf("%d", &n);
	for(i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
	}
	sort(a, a + n);
	int ans = 0;
	int l = 1, r = n;
	while(l <= r)
	{
		int mid = (l + r) / 2;
		if(judge(mid))
			l = mid + 1;
		else
			r = mid - 1;
	}
	ans = r;
	if(ans <= 0)
	{
		puts("0"); return 0;
	}
	printf("%d\n", ans);
	memset(vis, false, sizeof(vis));
	memset(arr, 0, sizeof(arr));
	int pre = a[0];
	int tt = 0;
	arr[tt++] = a[0];
	int num = 1;
	for(int i = 1; i < n; i++)
	{
		if(pre == a[i])
		{
			num++;
			if(num > ans) continue;
			arr[tt++] = a[i];
		}
		else
		{
			pre = a[i];
			num = 1;
			arr[tt++] = a[i];
		}
	}
	sort(arr, arr + tt);
	for(int i = 0; i < tt; i++)
	{
		if(vis[i]) continue;
		if(i + 2 * ans >= n) break;
		printf("%d %d %d\n", arr[i + 2 * ans], arr[i + ans], arr[i]);
		vis[i] = true;
		vis[i + ans] = true;
		vis[i + 2 * ans] = true;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef __int64 ll;
const double eps = 1e-6;
const ll INF = 1e9;
const int N = 1e5 + 10;
int n, m, k, t;
int a[N];
char s[N];
bool vis[N], walked[N];
string str;

struct node
{
	int id, v;
}p[N];

bool cmp(node x, node y)
{
	if(x.v != y.v) return x.v > y.v;
	else return x.id < y.id;
}

bool judge(int x)
{
	if(x * 3 > n) return false;
	bool f = true;
	memset(vis, false, sizeof(vis));
	for(int i = 0; i < n; i++)
	{
		if(vis[i]) continue;
		if(i + 2 * x >= n) break;
		if(a[i] != a[i + x] && a[i + x] != a[i + 2 * x])
		{
			vis[i] = true;
			vis[i + x] = true;
			vis[i + 2 * x] = true;
		}
		else
		{
			f = false; break;
		}
	}
	return f;
}

int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int i, j;
	scanf("%d", &n);
	for(i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
	}
	sort(a, a + n);
	int ans = 0;
	int l = 0, r = n;
	while(l <= r)
	{
		int mid = (l + r) / 2;
		if(judge(mid))
			l = mid + 1;
		else
			r = mid - 1;
	}
	ans = r;
	if(ans <= 0)
	{
		puts("0"); return 0;
	}
	printf("%d\n", ans);
	memset(vis, false, sizeof(vis));
	for(int i = 0; i < n; i++)
	{
		if(vis[i]) continue;
		if(i + 2 * ans >= n) break;
		printf("%d %d %d\n", a[i + 2 * ans], a[i + ans], a[i]);
		vis[i] = true;
		vis[i + ans] = true;
		vis[i + 2 * ans] = true;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef __int64 ll;
const double eps = 1e-6;
const ll INF = 1e9;
const int N = 1e5 + 10;
int n, m, k, t;
int a[N];
char s[N];
bool vis[N], walked[N];
string str;

int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int i, j;
	scanf("%d", &n);
	for(i = 0; i < n; i++) scanf("%d", &a[i]);
	sort(a, a + n);
	int ans[N];
	int sum = 0, id = 0;
	memset(vis, false, sizeof(vis));
	int aa, bb, cc;
	t = 0;
	for(i = 0; i < n; i++)
	{
		if(vis[i]) continue;
		vis[i] = true;
		aa =0, bb = 0, cc = 0;
		aa = a[i];
		bool f = false;
		for(j = i + 1; j < n; j++)
		{
			if(vis[j]) continue;
			if(a[j] != aa)
			{
				bb = a[j];
				vis[j] = true;
				break;
			}
			else if(!f)
			{
				f = true; id = j;
			}
		}
		for(k = j + 1; k < n; k++)
		{
			if(vis[k]) continue;
			if(a[k] != bb)
			{
				cc = a[k];
				vis[k] = true;
				break;
			}
			else if(!f)
			{
				f = true; id = k;
			}
		}
		if(!f) i = k;
		else i = id - 1;
		if(aa != 0 && bb != 0 && cc != 0)
		{
			ans[t++] = cc;
			ans[t++] = bb;
			ans[t++] = aa;
			sum++;
		}
	}
	printf("%d\n", sum);
	for(int i = 0; i < t; i+=3)
	{
		printf("%d %d %d\n", ans[i], ans[i + 1], ans[i + 2]);
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<cstdlib>
#include<cctype>
#include<cmath>

#define ll long long
#define I inline
#define N 100001

using namespace std;

struct Ball{
    int id;
    int number;
    bool operator < (const Ball &b) const{
        if(number == b.number){
            return id < b.id;
        }
        return number < b.number;
    }
}ball[N];

int n;
int a[N] , b[N];
int ans_x[N] , ans_y[N] , ans_z[N];

priority_queue<Ball > Q;

int main(){
    cin >> n;
    for(int i = 1; i <= n; i ++){
        cin >> a[i];
        b[i] = a[i];
    }
    sort(b + 1 , b + 1 + n);
    sort(a + 1 , a + 1 + n);
    int len = unique(b + 1 , b + 1 + n) - b - 1;
    for(int i = 1; i <= n;){
        int j = i;
        while(j + 1 <= n && a[j + 1] == a[i]){
            j ++;
        }
        int finish = j - i + 1;
        int num = lower_bound(b + 1 , b + 1 + len , a[i]) - b;
        Q.push((Ball){num , finish});
        i = j + 1;
    }
    int ans = 0;
    while(Q.size() >= 3){
        Ball x = Q.top();
        Q.pop();
        Ball y = Q.top();
        Q.pop();
        Ball z = Q.top();
        Q.pop();
        x.number --;
        y.number --;
        z.number --;
        ans ++;
        ans_x[ans] = x.id;
        ans_y[ans] = y.id;
        ans_z[ans] = z.id;
        if(x.number > 0){
            Q.push((Ball){x.id , x.number});
        }
        if(y.number > 0){
            Q.push((Ball){x.id , x.number});
        }
        if(z.number > 0){
            Q.push((Ball){x.id , x.number});
        }
    }
    cout << ans << "\n";
    for(int i = 1; i <= ans; i ++){
        printf("%d %d %d\n" , ans_x[i] , ans_y[i] , ans_z[i]);
    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long  long
#define ld long double
#define mod 1000000007
#define max_char 128
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define lbd lower_bound
#define ubd upper_bound
#define PI 3.141592653589793238
#define pf push_front
#define all(x) x.begin(),x.end()
#define input(arr,n) for(ll c1=0;c1<n;c1++)cin>>arr[c1];
#define rep(i,a,n) for( ll i=a ; i<n ; i++)
#define mems(x, y) memset(x, y, sizeof(x))
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
//cout<<"Case #"<<v1+1<<": ";

ll power(ll base,ll pow, ll mo)
{
   ll res=1;
   while(pow)
   {
        if (pow%2!=0)  res=(res*base)%mo;
        base=(base*base)%mo;
        pow/=2;
   }
   return res;
}

int binarySearch(int arr[], int l, int r, int x)
{
    while (l <= r) {
        int m = l + (r - l) / 2;

        // Check if x is present at mid
        if (arr[m] == x)
            return m;

        // If x greater, ignore left half
        if (arr[m] < x)
            l = m + 1;

        // If x is smaller, ignore right half
        else
            r = m - 1;
    }

    // if we reach here, then element was
    // not present
    return -1;
}

int main()
{
    fastio
	ll t,i,j,x;
	cin>>t;
	while(t--)
	{
	    int n,k;
	    cin>>n;
	    vector<int>a(n);

	    for(i=0;i<n;i++)
	    cin>>a[i];

	    vector<pair<ll,ll>>v;
	    for(i=0;i<n;i++)
	    {
	        v.pb(mp(a[i],i));
	    }
	    sort(all(v));
	    int f=1;

	    int end=n-1;
	    int pos;
	    int vv=0;
	    for(i=0;i<n;i++)
	    {
	        pos=v[i].ss;
	        //cout<<pos<<" ";
	        if(vv==0&&pos==end)
	        {
	            --end;
	            vv=1;
	        }
	        else if(pos==end && end-v[i].ss!=1)
	        {
	            f=0;
	            break;
	        }
	        else if(pos!=0 && vv==0 && a[pos]-a[pos-1]!=1)
	        {
	            f=0;
	            //cout<<i<<" ";
	            break;
	        }

	        else{
	            vv=0;
	        }
	    }

	    if(f)
	    cout<<"Yes";
	    else cout<<"No";
	    cout<<"\n";
	}
	return 0;
}


#include <bits/stdc++.h>
#define ll long  long
#define ld long double
#define mod 1000000007
#define max_char 128
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define lbd lower_bound
#define ubd upper_bound
#define PI 3.141592653589793238
#define pf push_front
#define all(x) x.begin(),x.end()
#define input(arr,n) for(ll c1=0;c1<n;c1++)cin>>arr[c1];
#define rep(i,a,n) for( ll i=a ; i<n ; i++)
#define mems(x, y) memset(x, y, sizeof(x))
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
//cout<<"Case #"<<v1+1<<": ";

ll power(ll base,ll pow, ll mo)
{
   ll res=1;
   while(pow)
   {
        if (pow%2!=0)  res=(res*base)%mo;
        base=(base*base)%mo;
        pow/=2;
   }
   return res;
}

int binarySearch(int arr[], int l, int r, int x)
{
    while (l <= r) {
        int m = l + (r - l) / 2;

        // Check if x is present at mid
        if (arr[m] == x)
            return m;

        // If x greater, ignore left half
        if (arr[m] < x)
            l = m + 1;

        // If x is smaller, ignore right half
        else
            r = m - 1;
    }

    // if we reach here, then element was
    // not present
    return -1;
}

int main()
{
    fastio
	ll t,i,j,x;
	cin>>t;
	while(t--)
	{
	    int n,k;
	    cin>>n;
	    vector<int>a(n);

	    for(i=0;i<n;i++)
	    cin>>a[i];

	    vector<pair<ll,ll>>v;
	    for(i=0;i<n;i++)
	    {
	        v.pb(mp(a[i],i));
	    }
	    sort(all(v));
	    int f=1;

	    int end=n-1;
	    int pos;
	    int vv=0;
	    for(i=0;i<n;i++)
	    {
	        pos=v[i].ss;
	        //cout<<pos<<" ";
	        if(vv==0&&pos==end)
	        {
	            --end;
	            vv=1;
	        }
	        else if(pos==end && end-v[i-1].ss!=1)
	        {
	            //cout<<"A";
	            f=0;
	            break;
	        }
	        else if(pos!=0 && vv==0 && a[pos]-a[pos-1]!=1)
	        {
	            f=0;
	            //cout<<i<<" ";
	            break;
	        }

	        else{
	            vv=0;
	        }
	    }

	    if(f)
	    cout<<"Yes";
	    else cout<<"No";
	    cout<<"\n";
	}
	return 0;
}


#include <bits/stdc++.h>
#define ll long  long
#define ld long double
#define mod 1000000007
#define max_char 128
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define lbd lower_bound
#define ubd upper_bound
#define PI 3.141592653589793238
#define pf push_front
#define all(x) x.begin(),x.end()
#define input(arr,n) for(ll c1=0;c1<n;c1++)cin>>arr[c1];
#define rep(i,a,n) for( ll i=a ; i<n ; i++)
#define mems(x, y) memset(x, y, sizeof(x))
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
//cout<<"Case #"<<v1+1<<": ";

ll power(ll base,ll pow, ll mo)
{
   ll res=1;
   while(pow)
   {
        if (pow%2!=0)  res=(res*base)%mo;
        base=(base*base)%mo;
        pow/=2;
   }
   return res;
}

int binarySearch(int arr[], int l, int r, int x)
{
    while (l <= r) {
        int m = l + (r - l) / 2;

        // Check if x is present at mid
        if (arr[m] == x)
            return m;

        // If x greater, ignore left half
        if (arr[m] < x)
            l = m + 1;

        // If x is smaller, ignore right half
        else
            r = m - 1;
    }

    // if we reach here, then element was
    // not present
    return -1;
}

int main()
{
    fastio
	ll t,i,j,x;
	cin>>t;
	while(t--)
	{
	    int n,k;
	    cin>>n;
	    vector<int>a(n);

	    for(i=0;i<n;i++)
	    cin>>a[i];

	    vector<pair<ll,ll>>v;
	    for(i=0;i<n;i++)
	    {
	        v.pb(mp(a[i],i));
	    }
	    sort(all(v));
	    int f=1;

	    int end=n-1;
	    int pos;
	    int vv=0;
	    for(i=0;i<n;i++)
	    {
	        pos=v[i].ss;
	        //cout<<pos<<" ";
	        if(vv==0&&pos==end)
	        {
	            --end;
	            vv=1;
	        }
	        else if(pos==end && end-v[i-1].ss==-1)
	        {
	            //cout<<"A";
	            f=0;
	            break;
	        }
	        else if(pos!=0 && vv==0 && a[pos]-a[pos-1]!=1)
	        {
	            f=0;
	            //cout<<i<<" ";
	            break;
	        }

	        else{
	            vv=0;
	        }
	    }

	    if(f)
	    cout<<"Yes";
	    else cout<<"No";
	    cout<<"\n";
	}
	return 0;
}


#include <bits/stdc++.h>
#define ll long  long
#define ld long double
#define mod 1000000007
#define max_char 128
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define lbd lower_bound
#define ubd upper_bound
#define PI 3.141592653589793238
#define pf push_front
#define all(x) x.begin(),x.end()
#define input(arr,n) for(ll c1=0;c1<n;c1++)cin>>arr[c1];
#define rep(i,a,n) for( ll i=a ; i<n ; i++)
#define mems(x, y) memset(x, y, sizeof(x))
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
//cout<<"Case #"<<v1+1<<": ";

ll power(ll base,ll pow, ll mo)
{
   ll res=1;
   while(pow)
   {
        if (pow%2!=0)  res=(res*base)%mo;
        base=(base*base)%mo;
        pow/=2;
   }
   return res;
}

int binarySearch(int arr[], int l, int r, int x)
{
    while (l <= r) {
        int m = l + (r - l) / 2;

        // Check if x is present at mid
        if (arr[m] == x)
            return m;

        // If x greater, ignore left half
        if (arr[m] < x)
            l = m + 1;

        // If x is smaller, ignore right half
        else
            r = m - 1;
    }

    // if we reach here, then element was
    // not present
    return -1;
}

int main()
{
    fastio
	ll t,i,j,x;
	cin>>t;
	while(t--)
	{
	    int n,k;
	    cin>>n;
	    vector<int>a(n);

	    for(i=0;i<n;i++)
	    cin>>a[i];

	    vector<pair<ll,ll>>v;
	    for(i=0;i<n;i++)
	    {
	        v.pb(mp(a[i],i));
	    }
	    sort(all(v));
	    int f=1;

	    int end=n-1;
	    int pos;
	    int vv=0;
	    for(i=0;i<n;i++)
	    {
	        pos=v[i].ss;
	        if(vv==0 && pos==end)
	        {
	            --end;
	            vv=1;
	        }
	        else if(vv&&pos==end)
	        {
	            if(end-v[i-1].ss!=1)
	            {
	                f=0;
	                break;
	            }
	        }
	        else if(pos!=0 && vv==0 && a[pos]-a[pos-1]!=1)
	        {
	            f=0;
	            //cout<<i<<" ";
	            break;
	        }
	        else{
	            vv=0;
	        }
	    }
	    if(f)
	    cout<<"Yes";
	    else cout<<"No";
	    cout<<"\n";
	}
	return 0;
}


#include <bits/stdc++.h>
#define ll long  long
#define ld long double
#define mod 1000000007
#define max_char 128
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define lbd lower_bound
#define ubd upper_bound
#define PI 3.141592653589793238
#define pf push_front
#define all(x) x.begin(),x.end()
#define input(arr,n) for(ll c1=0;c1<n;c1++)cin>>arr[c1];
#define rep(i,a,n) for( ll i=a ; i<n ; i++)
#define mems(x, y) memset(x, y, sizeof(x))
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
//cout<<"Case #"<<v1+1<<": ";

ll power(ll base,ll pow, ll mo)
{
   ll res=1;
   while(pow)
   {
        if (pow%2!=0)  res=(res*base)%mo;
        base=(base*base)%mo;
        pow/=2;
   }
   return res;
}

int binarySearch(int arr[], int l, int r, int x)
{
    while (l <= r) {
        int m = l + (r - l) / 2;

        // Check if x is present at mid
        if (arr[m] == x)
            return m;

        // If x greater, ignore left half
        if (arr[m] < x)
            l = m + 1;

        // If x is smaller, ignore right half
        else
            r = m - 1;
    }

    // if we reach here, then element was
    // not present
    return -1;
}

int main()
{
    fastio
	ll t,i,j,x;
	cin>>t;
	while(t--)
	{
	    int n,k;
	    cin>>n;
	    vector<int>a(n);

	    for(i=0;i<n;i++)
	    cin>>a[i];

	    vector<pair<ll,ll>>v;
	    for(i=0;i<n;i++)
	    {
	        v.pb(mp(a[i],i));
	    }
	    sort(all(v));
	    int f=1;

	    int end=n-1;
	    int pos;
	    int vv=0;
	    for(i=0;i<n;i++)
	    {
	        pos=v[i].ss;
	        //cout<<pos<<" ";
	        if(vv==0&&pos==end)
	        {
	            --end;
	            vv=1;
	        }
	        else if(pos==end && end-v[i-1].ss=-1)
	        {
	            //cout<<"A";
	            f=0;
	            break;
	        }
	        else if(pos!=0 && vv==0 && a[pos]-a[pos-1]!=1)
	        {
	            f=0;
	            //cout<<i<<" ";
	            break;
	        }

	        else{
	            vv=0;
	        }
	    }

	    if(f)
	    cout<<"Yes";
	    else cout<<"No";
	    cout<<"\n";
	}
	return 0;
}


#include <bits/stdc++.h>
#define ll long  long
#define ld long double
#define mod 1000000007
#define max_char 128
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define lbd lower_bound
#define ubd upper_bound
#define PI 3.141592653589793238
#define pf push_front
#define all(x) x.begin(),x.end()
#define input(arr,n) for(ll c1=0;c1<n;c1++)cin>>arr[c1];
#define rep(i,a,n) for( ll i=a ; i<n ; i++)
#define mems(x, y) memset(x, y, sizeof(x))
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
//cout<<"Case #"<<v1+1<<": ";

ll power(ll base,ll pow, ll mo)
{
   ll res=1;
   while(pow)
   {
        if (pow%2!=0)  res=(res*base)%mo;
        base=(base*base)%mo;
        pow/=2;
   }
   return res;
}

int main()
{
    fastio
	ll t,i,j,x;
	cin>>t;
	while(t--)
	{
	    int n,k;
	    cin>>n;
	    vector<int>a(n);

	    for(i=0;i<n;i++)
	    cin>>a[i];
	    int f=1;
	    for(i=1;i<n;i++)
	    {
	        if(a[i]-a[i-1]>1)
	        {
	            f=0;
	            break;
	        }
	    }
	    if(f)
	    cout<<"Yes";
	    else cout<<"No";
	    cout<<"\n";
	}
	return 0;
}


#include<bits/stdc++.h>
#include<algorithm>
using namespace std;

#define ll long long
#define ff first
#define ss second

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	ll t; cin >> t;
	while (t--) {
		ll n; cin >> n;
		ll cnt[n] = {0};
		pair<ll, ll> a[n];
		bool vis[n] = {0};
		for (int i = 0; i < n; ++i)
		{
			cin >> a[i].ff;
			cnt[i] = 1;
			a[i].ss = i;
		}
		sort(a, a + n);
		ll mx = 1;
		bool f = 1;
		for (int i = 0; i < n; i++) {
			if (!vis[a[i].ss]) {
				if (cnt[a[i].ss] != mx) {f = 0; break;}

				if (a[i].ss + 1 < n) {cnt[a[i].ss + 1] += cnt[a[i].ss]; mx = 1; if (!vis[a[i].ss + 1])mx = max(mx, cnt[a[i].ss + 1]);}
				else {mx = 1;}
				cnt[a[i].ss] = 0;
				vis[a[i].ss] = 1;
			}
			else {f = 0; break;}
		}
		if (f)cout << "YES\n";
		else cout << "NO\n";

	}

	return 0;
}