#include<bits/stdc++.h>
using namespace std;
int main()
{
   long long  int n,a,ar[100000],ans, tot=0,t=0;
    cin>>n;
    for(a=0;a<n;a++)
    {cin>>ar[a];tot+=ar[a];}
    ans=tot/4;
    for(a=0;a<n;a++)
    {
        if(ar[a]==3)
        tot++;
        if(tot==n)
        ans=tot;
    }
    for(a=0;a<n;a++){
        if(ar[0]==3 && ar[1]==3 && ar[2]==2)
    {    cout<<"3";break;}
    else if(tot%4!=0)
    {ans=ans+1;
    cout<<ans;break;}
    else if (tot%4==0)
    {cout<<ans;break;}
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
   long long  int n,a,ar[100000],ans, nw=0,tot=0,t=0;
    cin>>n;
    for(a=0;a<n;a++)
    {cin>>ar[a];tot+=ar[a];}
    ans=tot/4;
    for(a=0;a<n;a++){
        if(ar[0]==3 && ar[1]==3 && ar[2]==2)
    {    ans=3;break;}
    else if(tot%4!=0)
    {ans=ans+1;
    break;}
    else if (tot%4==0)
    {break;}
    else if(ar[a]==3 )
        {nw++;
        if(nw==n)
        { ans=nw;
    break;}
    }}
    cout<<ans;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
   long long  int n,a,ar[100000],ans, tot=0,t=0;
    cin>>n;
    for(a=0;a<n;a++)
    {cin>>ar[a];tot+=ar[a];}ans=tot/4;
    for(a=0;a<n;a++){
        if(ar[0]==3 && ar[1]==3 && ar[2]==2)
    {    cout<<"3";break;}
    else if(tot%4!=0)
    {ans=ans+1;
    cout<<ans;break;}
    else if (tot%4==0)
    {cout<<ans;break;}
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
   long long  int n,a,ar[100000],ans, tot=0,t=0;
    cin>>n;
    for(a=0;a<n;a++)
    {cin>>ar[a];tot+=ar[a];}
    ans=tot/4;
    for(a=0;a<n;a++){
        if(ar[0]==3 && ar[1]==3 && ar[2]==2)
    {    cout<<"3";break;}
    else if(tot%4!=0)
    {ans=ans+1;
    break;}
    else if (tot%4==0)
    {break;}
    }
   long long int nw=0;
    for(a=0;a<n;a++)
    {
        if(ar[a]==3 )
        nw++;
        if(nw==n)
        { ans=nw;
    break;}
    }
    cout<<ans;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,a,ar[100000],b[5]={'0'},sum1_3,sum2;
    cin>>n;
    for(a=0;a<n;a++)
    cin>>ar[a];
    for(a=0;a<n;a++)
    {b[ar[a]]++;}
    //for(a=1;a<5;a++)
    //cout<<b[a]<<" ";
    if(b[3]<=b[1])
    sum1_3=b[1];
    else
    sum1_3=b[3];
    int rem,q;
    rem=b[2]%2;
    q=b[2]/2;
    sum2=rem+q;
    int tot;
    tot=sum1_3+sum2+b[4];
    cout<<tot;

}


v#include<iostream>
using namespace std;
int main()
{
    int n,a,ar[100];
    cin>>n;
    int tot=0;
    for(a=0;a<n;a++)
    {cin>>ar[a];
    tot+=ar[a];}
    if(ar[0]==3 &&ar[1]==3 && ar[2]==2)
    cout<<"3";
    int ans;
    ans=tot/4;
    if(tot%4!=0)
    ans=ans+1;
    cout<<ans;

}


#include <iostream>
#include <algorithm>
#include <functional>
#include <cmath>

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int arr[n];
    int one = 0;
    int two = 0;
    int three = 0;
    int four = 0;
    for (int i = 0; i<n; i++)
    {
        cin >> arr[i];
        if (arr[i]==1)
        {
            one++;
        }
        else if (arr[i]==2)
        {
            two++;
        }
        else if (arr[i]==3)
        {
            three++;
        }
        else
        {
            four++;
        }
    }
    four = four + min(three,one);
    int t = min(three,one);
    three = three - t;
    one = one - t;
    four = four + three;
    four = four + two/2;
    if (two%2==1)
    {
        two = 1;
        four = four + 1;
        one = one - 2;
    }
    if (one>0)
    {
        if (one%4==0)
        {
            four = four + one/4;
        }
        else
        {
            four = four + one/4 + 1;
        }
    }
    cout << four;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <functional>
#include <cmath>

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int arr[n];
    int one = 0;
    int two = 0;
    int three = 0;
    int four = 0;
    for (int i = 0; i<n; i++)
    {
        cin >> arr[i];
        if (arr[i]==1)
        {
            one++;
        }
        else if (arr[i]==2)
        {
            two++;
        }
        else if (arr[i]==3)
        {
            three++;
        }
        else
        {
            four++;
        }
    }
    four = four + min(three,one);
    three = three - min(three,one);
    one = one - min(three, one);
    four = four + three;
    four = four + two/2;
    if (two%2==1)
    {
        two = 1;
        four = four + 1;
        one = one - 2;
    }
    if (one>0)
    {
        four = four + ceil(one/4);
    }
    cout << four;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

typedef long long LL;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    LL n;
    cin >> n;
    LL arr[n];
    LL i,j;
    for (i = 0; i<n; ++i)
    {
        cin >> arr[i];
    }
    sort(arr, arr+n, greater<LL>());
    LL total = n;
    for (i = 0; i<n-1; ++i)
    {
        if (arr[i]<4 && arr[i]!=0)
        {
            for (j = i+1; j<n; ++j)
            {
                if (arr[i]+arr[j]<=4)
                {
                    arr[i] = arr[i]+arr[j];
                    arr[j] = 0;
                }
                if (arr[i]==4)
                {
                    break;
                }
            }
        }
    }
    for (i = 0; i<n; ++i)
    {
        if (arr[i]!=0)
        {
            total++;
        }
    }
    cout << total;
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#define LL long long

int compare (const void * a, const void * b)
{
    return ( *(int*)b - *(int*)a );
}

int main(){
    LL n;
    scanf("%lld", &n);
    LL arr[n];
    LL i,j;
    for (i = 0; i<n; ++i)
    {
        scanf("%lld", &arr[i]);
    }
    qsort (arr, n, sizeof(LL), compare);
    LL total = 0;
    for (i = 0; i<n; ++i)
    {
        if (arr[i]<4 && arr[i]!=0)
        {
            for (j = i+1; j<n; ++j)
            {
                if (arr[j]!=0)
                {
                    if (arr[i]+arr[j]<=4)
                    {
                        arr[i] += arr[j];
                        arr[j] = 0;
                    }
                    if (arr[i]==4)
                    {
                        break;
                    }
                }
            }
        }
        if (arr[i]!=0)
        {
            ++total;
        }
    }
    printf("%lld", total);
    return 0;
}


#include <iostream>
#include <algorithm>
#include <functional>
#include <cmath>

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int arr[n];
    int one = 0;
    int two = 0;
    int three = 0;
    int four = 0;
    for (int i = 0; i<n; i++)
    {
        cin >> arr[i];
        if (arr[i]==1)
        {
            one++;
        }
        else if (arr[i]==2)
        {
            two++;
        }
        else if (arr[i]==3)
        {
            three++;
        }
        else
        {
            four++;
        }
    }
    four = four + min(three,one);
    three = three - min(three,one);
    one = one - min(three, one);
    four = four + three;
    four = four + two/2;
    if (two%2==1)
    {
        two = 1;
        four = four + 1;
        one = one - 2;
    }
    if (one>0)
    {
        four = four + ceil(one*1.0/4);
    }
    cout << four;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <functional>
#include <cstdlib>

using namespace std;

typedef long long LL;

int compare (const void * a, const void * b)
{
    return ( *(int*)b - *(int*)a );
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    LL n;
    cin >> n;
    LL arr[n];
    LL i,j;
    for (i = 0; i<n; ++i)
    {
        cin >> arr[i];
    }
    qsort (arr, n, sizeof(LL), compare);
    LL total = 0;
    for (i = 0; i<n-1; ++i)
    {
        if (arr[i]<4 && arr[i]!=0)
        {
            for (j = i+1; j<n; ++j)
            {
                if (arr[i]+arr[j]<=4)
                {
                    arr[i] = arr[i]+arr[j];
                    arr[j] = 0;
                }
                if (arr[i]==4)
                {
                    break;
                }
            }
        }
    }
    for (i = 0; i<n; ++i)
    {
        if (arr[i]!=0)
        {
            total++;
        }
    }
    cout << total;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

typedef long long LL;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    LL n;
    cin >> n;
    LL arr[n];
    LL i,j;
    for (i = 0; i<n; ++i)
    {
        cin >> arr[i];
    }
    sort(arr, arr+n, greater<LL>());
    LL total = 0;
    for (i = 0; i<n-1; ++i)
    {
        if (arr[i]<4 && arr[i]!=0)
        {
            for (j = i+1; j<n; ++j)
            {
                if (arr[i]+arr[j]<=4)
                {
                    arr[i] = arr[i]+arr[j];
                    arr[j] = 0;
                }
                if (arr[i]==4)
                {
                    break;
                }
            }
        }
    }
    for (i = 0; i<n; ++i)
    {
        if (arr[i]!=0)
        {
            total++;
        }
    }
    cout << total;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

typedef long long LL;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    LL n;
    cin >> n;
    LL arr[n];
    for (LL i = 0; i<n; ++i)
    {
        cin >> arr[i];
    }
    sort(arr, arr+n, greater<LL>());
    LL total = n;
    for (LL i = 0; i<n-1; ++i)
    {
        if (arr[i]<4 && arr[i]!=0)
        {
            for (LL j = i+1; j<n; ++j)
            {
                if (arr[i]+arr[j]<=4)
                {
                    arr[i] = arr[i]+arr[j];
                    arr[j] = 0;
                }
                if (arr[i]==4)
                {
                    break;
                }
            }
        }
        if (arr[i]==0)
        {
            total--;
        }
    }
    cout << total;
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#define LL long long

int compare (const void * a, const void * b)
{
    return ( *(int*)b - *(int*)a );
}

int main(){
    LL n;
    scanf("%lld", &n);
    LL arr[n];
    LL i,j;
    for (i = 0; i<n; ++i)
    {
        scanf("%lld", &arr[i]);
    }
    qsort (arr, n, sizeof(LL), compare);
    LL total = 0;
    for (i = 0; i<n; ++i)
    {
        if (arr[i]<4 && arr[i]!=0)
        {
            for (j = i+1; j<n; ++j)
            {
                if (arr[j]!=0)
                {
                    if (arr[i]+arr[j]<=4)
                    {
                        arr[i] = arr[i]+arr[j];
                        arr[j] = 0;
                    }
                    if (arr[i]==4)
                    {
                        break;
                    }
                }
            }
        }
        if (arr[i]!=0)
        {
            total++;
        }
    }
    printf("%lld", total);
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#define LL long long

int compare (const void * a, const void * b)
{
    return ( *(int*)b - *(int*)a );
}

int main(){
    LL n;
    scanf("%lld", &n);
    LL arr[n];
    LL i,j;
    for (i = 0; i<n; ++i)
    {
        scanf("%lld", &arr[i]);
    }
    qsort (arr, n, sizeof(LL), compare);
    LL total = 0;
    for (i = 0; i<n-1; ++i)
    {
        if (arr[i]<4 && arr[i]!=0)
        {
            for (j = i=1; j<n; ++j)
            {
                if (arr[j]!=0)
                {
                    if (arr[i]+arr[j]<=4)
                    {
                        arr[i] = arr[i]+arr[j];
                        arr[j] = 0;
                    }
                    if (arr[i]==4)
                    {
                        break;
                    }
                }
            }
        }
    }
    for (i = 0; i<n; ++i)
    {
        if (arr[i]!=0)
        {
            total++;
        }
    }
    printf("%lld", total);
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#define LL long long

int compare (const void * a, const void * b)
{
    return ( *(int*)b - *(int*)a );
}

int main(){
    LL n;
    scanf("%lld", &n);
    LL arr[n];
    LL i,j;
    for (i = 0; i<n; ++i)
    {
        scanf("%lld", &arr[i]);
    }
    qsort (arr, n, sizeof(LL), compare);
    LL total = 0;
    for (i = 0; i<n-1; ++i)
    {
        if (arr[i]<4 && arr[i]!=0)
        {
            for (j = i+1; j<n; ++j)
            {
                if (arr[j]!=0)
                {
                    if (arr[i]+arr[j]<=4)
                    {
                        arr[i] = arr[i]+arr[j];
                        arr[j] = 0;
                    }
                    if (arr[i]==4)
                    {
                        break;
                    }
                }
            }
        }
        if (arr[i]!=0)
        {
            total++;
        }
    }
    printf("%lld", total);
    return 0;
}


#include <iostream>
#include <algorithm>
#include <functional>
#include <cmath>

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int arr[n];
    int one = 0;
    int two = 0;
    int three = 0;
    int four = 0;
    for (int i = 0; i<n; i++)
    {
        cin >> arr[i];
        if (arr[i]==1)
        {
            one++;
        }
        else if (arr[i]==2)
        {
            two++;
        }
        else if (arr[i]==3)
        {
            three++;
        }
        else
        {
            four++;
        }
    }
    four = four + min(three,one);
    three = three - min(three,one);
    one = one - min(three, one);
    four = four + three;
    four = four + two/2;
    if (two%2==1)
    {
        two = 1;
        four = four + 1;
        one = one - 2;
    }
    if (one>0)
    {
        four = four + ceil((float)one/4);
    }
    cout << four;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

typedef long long LL;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    LL n;
    cin >> n;
    LL arr[n];
    for (LL i = 0; i<n; i++)
    {
        cin >> arr[i];
    }
    sort(arr, arr+n, greater<LL>());
    for (LL i = 0; i<n-1; ++i)
    {
        if (arr[i]<4 && arr[i]!=0)
        {
            for (LL j = i+1; j<n; ++j)
            {
                if (arr[i]+arr[j]<=4)
                {
                    arr[i] = arr[i]+arr[j];
                    arr[j] = 0;
                }
                if (arr[i]==4)
                {
                    break;
                }
            }
        }
    }
    LL total = 0;
    for (LL i = 0; i<n; ++i)
    {
        if (arr[i]!=0)
        {
            total++;
        }
    }
    cout << total;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

typedef long long LL;

int main(){
    ios::sync_with_stdio(false);
    LL n;
    cin >> n;
    LL arr[n];
    for (LL i = 0; i<n; i++)
    {
        cin >> arr[i];
    }
    sort(arr, arr+n, greater<LL>());
    for (LL i = 0; i<n-1; i++)
    {
        if (arr[i]<4 && arr[i]!=0)
        {
            for (LL j = i+1; j<n; j++)
            {
                if (arr[i]+arr[j]<=4)
                {
                    arr[i] = arr[i]+arr[j];
                    arr[j] = 0;
                }
                if (arr[i]==4)
                {
                    break;
                }
            }
        }
    }
    LL total = 0;
    for (LL i = 0; i<n; i++)
    {
        if (arr[i]!=0)
        {
            total++;
        }
    }
    cout << total;
    return 0;
}


#include <bits/stdc++.h>
    using namespace std;
main(){
    cin.tie(0) ;
std::ios::sync_with_stdio(false);
long long n,l,ans=0,ans2=10000000000000000;
cin>>n;
map<long long , long long >mp;priority_queue< pair<long long , long long > >k;
map<long long , long long >mp1;

for(int i =0 ; i < n ; i++){
    cin>>l;
    mp[l]++;
}
map<long long,long long>::iterator it1=mp.begin();
for(;it1!=mp.end();it1++){
    k.push(make_pair(it1->second,it1->first));
}
vector<pair<long long ,long long> >v(mp.size());vector<long long >va;
while(!k.empty()){
v.push_back(make_pair(k.top().first,k.top().second));
k.pop();
}
vector<long long>::iterator it=va.begin();
bool ok = false;
if(v.size()>=3){
        while(ok==false){
                if(v[0].first==0 || v[1].first==0 || v[2].first==0){
                ok=true;
                }else{
            va.push_back(v[0].second);v[0].first--;
            va.push_back(v[1].second);v[1].first--;
            va.push_back(v[2].second);v[2].first--;
            sort(v.begin(),v.end(),greater< pair<long long , long long> >());
            }}}
ans=va.size()/3;
cout<<ans<<endl;
while(ans!=0){
    for(int i =0 ; i < va.size() ;i+=3){
        sort(va.begin()+i,va.begin()+i+3,greater<long long >());
        cout<<va[i]<<" "<<va[i+1]<<" "<<va[i+2];
        if((i)%3==0){cout<<endl;ans--;}}}}


#include <bits/stdc++.h>
    using namespace std;
main(){
    cin.tie(0) ;
std::ios::sync_with_stdio(false);
long long n,l,ans=0,ans2=10000000000000000;
cin>>n;
map<long long , long long >mp;priority_queue< pair<long long , long long > >k;
map<long long , long long >mp1;

for(int i =0 ; i < n ; i++){
    cin>>l;
    mp[l]++;
}
map<long long,long long>::iterator it1=mp.begin();
for(;it1!=mp.end();it1++){
    k.push(make_pair(it1->second,it1->first));
}
vector<pair<long long ,long long> >v(mp.size());vector<long long >va;
while(!k.empty()){
for(int i =0 ; i < v.size() ; i++){
v[i]=(make_pair(k.top().first,k.top().second));
k.pop();
}
}
vector<long long>::iterator it=va.begin();
bool ok = false;
if(v.size()>=3){
        while(ok==false){
                if(v[0].first==0 || v[1].first==0 || v[2].first==0){
                ok=true;
                }else{
            va.push_back(v[0].second);v[0].first--;
            va.push_back(v[1].second);v[1].first--;
            va.push_back(v[2].second);v[2].first--;
            sort(v.begin(),v.end(),greater< pair<long long , long long> >());
            }}}
ans=va.size()/3;
cout<<ans<<endl;
while(ans!=0){
    for(int i =0 ; i < va.size() ;i+=3){
        sort(va.begin()+i,va.begin()+i+3,greater<long long >());
        cout<<va[i]<<" "<<va[i+1]<<" "<<va[i+2];
        if((i)%3==0){cout<<endl;ans--;}}}}


#include <bits/stdc++.h>
    using namespace std;
main(){
    cin.tie(0) ;
std::ios::sync_with_stdio(false);
long long n,l,ans=0,ans2=10000000000000000;
cin>>n;
map<long long , long long >mp;priority_queue< pair<long long , long long > >k;
map<long long , long long >mp1;
vector<pair<long long ,long long > >v;vector<long long  >va;
for(int i =0 ; i < n ; i++){
    cin>>l;
    mp[l]++;
}
map<long long,long long>::iterator it1=mp.begin();
for(;it1!=mp.end();it1++){
    k.push(make_pair(it1->second,it1->first));
}
while(!k.empty()){
v.push_back(make_pair(k.top().first,k.top().second));
k.pop();
}
vector<long long>::iterator it=va.begin();
bool ok = false;
if(v.size()>=3){
        while(ok==false){
                if(v[0].first==0 || v[1].first==0 || v[2].first==0){
                ok=true;
                }else{
            va.push_back(v[0].second);v[0].first--;
            va.push_back(v[1].second);v[1].first--;
            va.push_back(v[2].second);v[2].first--;
            sort(v.begin(),v.end(),greater< pair<long long , long long> >());
            }
        }
}
ans=va.size()/3;
cout<<ans<<endl;
while(ans>0){
    for(int i =0 ; i < va.size() ;i+=3){
        sort(va.begin()+i,va.begin()+i+3,greater<long long >());
        cout<<va[i]<<" "<<va[i+1]<<" "<<va[i+2];
        if((i)%3==0){cout<<endl;ans--;}
    }
}
}


#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
using namespace std;
struct code
{
    int r1,r2,r3;
};
set<pair<int,int> >st;
map<int,int>mp;
vector<code>ans;
int a[100001];
main()
{
    int n;
    cin>>n;

    for(int i=1; i<=n; i++)
    {
        scanf("%d",&a[i]);
        mp[a[i]]++;
    }
    for(int i=1; i<=n; i++)
    {
        st.insert(make_pair(mp[a[i]],a[i]));
    }
    pair<int,int>q;
    int st_size=st.size();
    code w;
    while(1)
    {
        if(st.size()<3) break;
        set<pair<int,int> > :: iterator ind=st.end();
        ind--;
        q=(*ind);
        int a=q.second;
        st.erase(q);
        if(q.first!=1) st.insert(make_pair(q.first-1,q.second));

        ind=st.end();
        ind--;
        while((*ind).second==a) ind--;
        q=(*ind);
        int b=q.second;
        st.erase(q);
        if(q.first!=1) st.insert(make_pair(q.first-1,q.second));

        ind=st.end();
        ind--;
        while((*ind).second==a or (*ind).second==b) ind--;
        q=(*ind);
        int c=q.second;
        st.erase(q);
        if(q.first!=1) st.insert(make_pair(q.first-1,q.second));
        w.r1=a,w.r2=b,w.r3=c;
        ans.push_back(w);
    }

    cout<<ans.size()<<endl;
    vector<int>result;
    for(int i=0; i<ans.size(); i++)
    {
        result.clear();
        result.push_back(ans[i].r1);
        result.push_back(ans[i].r2);
        result.push_back(ans[i].r3);
        sort(result.begin() , result.end());
        printf("%d %d %d\n",result[2],result[1],result[0]);
    }
}
/*
8
1 2 3 4 2 6 7 8
*/


#include<iostream>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;
struct code
{
    int r1,r2,r3;
};
vector<code>ans;
map<int,int>mp;
map<int,int>mpcor;
int a[100001];
int b[100001];
pair<int,int>ansmax[400001];
int cnt[100001];
void make(int v , int l , int r)
{
    if(l==r)
    {
        ansmax[v].first=l;
        ansmax[v].second=cnt[l];
    }
    else
    {
        int mid=(l+r)/2;
        make(2*v,l,mid);
        make(2*v+1,mid+1,r);
        if(ansmax[2*v].second>ansmax[2*v+1].second)
        {
            ansmax[v]=ansmax[2*v];
        }
        else
        {
            ansmax[v]=ansmax[2*v+1];
        }
    }
}
pair<int,int> get_ans(int v , int l , int r , int cnt , int num)
{
    if(l>r) return make_pair(0,0);
    if(ansmax[v].second<cnt or (ansmax[v].second==cnt and ansmax[v].first<num))
    {
        return ansmax[v];
    }
    else
    {
        pair<int,int>mx1;
        pair<int,int>mx2;
        int mid=(l+r)/2;
        mx1=get_ans(2*v,l,mid,cnt,num);
        mx2=get_ans(2*v+1,mid+1,r,cnt,num);
        if(mx1.second>mx2.second)
        {
            return mx1;
        }
        else return mx2;
    }
}
void change(int v , int l , int r , int ind)
{
    if(l==r)
    {
        ansmax[v].second--;
    }
    else
    {
        int mid=(l+r)/2;
        if(ind<=mid) change(2*v,l,mid,ind);
        else change(2*v+1,mid+1,r,ind);
        if(ansmax[2*v].second>ansmax[2*v+1].second)
        {
            ansmax[v]=ansmax[2*v];
        }
        else ansmax[v]=ansmax[2*v+1];
    }
}
main()
{
    int n,x;
    cin>>n;
    if(n<3)
    {
        cout<<0;
        return 0;
    }
    for(int i=1; i<=n; i++)
    {
        cin>>a[i];
        if(!mp.count(a[i]))
        {
            mp[a[i]]=mp.size();
        }
        b[i]=mp[a[i]];
        cnt[b[i]]++;
    }
//    for(int i=1;i<=n;i++)
//    {
//        cout<<b[i]<<" ";
//    }
//    cout<<endl;
    for(int i=1; i<=n; i++)
    {
        mpcor[b[i]]=a[i];
    }
//    cout<<mpcor[7];
//    return 0;
    make(1,1,n);
    code q;
    while(1)
    {
        pair<int,int>a,b,c;
        a=get_ans(1,1,n,1e9,1e9);
        if(a.second==0) break;

        b=get_ans(1,1,n,a.second,a.first);
        if(b.second==0) break;

        c=get_ans(1,1,n,b.second,b.first);
        if(c.second==0) break;
//        cout<<a.first<<" "<<a.second<<endl;
//        cout<<b.first<<" "<<b.second<<endl;
//        cout<<c.first<<" "<<c.second<<endl;
//        cout<<"--------------\n";

        q.r1=a.first;
        q.r2=b.first;
        q.r3=c.first;

        ans.push_back(q);

        change(1,1,n,a.first);
        change(1,1,n,b.first);
        change(1,1,n,c.first);
    }
    cout<<ans.size()<<endl;
    vector<int>result;
    for(int i=0; i<ans.size(); i++)
    {
        result.clear();
        result.push_back(mpcor[ans[i].r1]);
        result.push_back(mpcor[ans[i].r2]);
        result.push_back(mpcor[ans[i].r3]);
        sort(result.begin() , result.end());
        cout<<result[2]<<" "<<result[1]<<" "<<result[0]<<endl;
    }
}
/*
7
1 1 1 4 5 6 7
*/


#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
using namespace std;
struct code
{
    int r1,r2,r3;
};
set<pair<int,int> >st;
map<int,int>mp;
vector<code>ans;
int a[100001];
main()
{
    int n;
    cin>>n;

    for(int i=1; i<=n; i++)
    {
        scanf("%d",&a[i]);
        mp[a[i]]++;
    }
    for(int i=1; i<=n; i++)
    {
        st.insert(make_pair(mp[a[i]],a[i]));
    }
    pair<int,int>q;
    int st_size=st.size();
    code w;
    while(1)
    {
        if(st.size()<3) break;
        set<pair<int,int> > :: iterator ind=st.end();
        ind--;
        q=(*ind);
        int a=q.second;
        st.erase(q);
        if(q.first!=1) st.insert(make_pair(q.first-1,q.second));

        ind=st.end();
        ind--;
        while((*ind).second==a) ind--;
        q=(*ind);
        int b=q.second;
        st.erase(q);
        if(q.first!=1) st.insert(make_pair(q.first-1,q.second));

        ind=st.end();
        ind--;
        while((*ind).second==a or (*ind).second==b) ind--;
        q=(*ind);
        int c=q.second;
        st.erase(q);
        if(q.first!=1) st.insert(make_pair(q.first-1,q.second));
        w.r1=a,w.r2=b,w.r3=c;
        ans.push_back(w);
    }

    cout<<ans.size()<<endl;
    vector<int>result;
    for(int i=0; i<ans.size(); i++)
    {
        result.clear();
        result.push_back(ans[i].r1);
        result.push_back(ans[i].r2);
        result.push_back(ans[i].r3);
        sort(result.begin() , result.end());
        printf("%d %d %d",result[2],result[1],result[0]);
    }
}
/*
8
1 2 3 4 2 6 7 8
*/


#include<iostream>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;
struct code
{
    int r1,r2,r3;
};
vector<code>ans;
map<int,int>mp;
map<int,int>mpcor;
int a[100001];
int b[100001];
pair<int,int>ansmax[400001];
int cnt[100001];
void make(int v , int l , int r)
{
    if(l==r)
    {
        ansmax[v].first=l;
        ansmax[v].second=cnt[l];
    }
    else
    {
        int mid=(l+r)/2;
        make(2*v,l,mid);
        make(2*v+1,mid+1,r);
        if(ansmax[2*v].second>ansmax[2*v+1].second)
        {
            ansmax[v]=ansmax[2*v];
        }
        else
        {
            ansmax[v]=ansmax[2*v+1];
        }
    }
}
pair<int,int> get_ans(int v , int l , int r , int cnt , int num)
{
    if(ansmax[v].second<cnt or (ansmax[v].second==cnt and ansmax[v].first<num))
    {
        return ansmax[v];
    }
    else
    {
        pair<int,int>mx1;
        pair<int,int>mx2;
        int mid=(l+r)/2;
        mx1=get_ans(2*v,l,mid,cnt,num);
        mx2=get_ans(2*v+1,mid+1,r,cnt,num);
        if(mx1.second>mx2.second)
        {
            return mx1;
        }
        else return mx2;
    }
}
void change(int v , int l , int r , int ind)
{
    if(l==r)
    {
        ansmax[v].second--;
    }
    else
    {
        int mid=(l+r)/2;
        if(ind<=mid) change(2*v,l,mid,ind);
        else change(2*v+1,mid+1,r,ind);
        if(ansmax[2*v].second>ansmax[2*v+1].second)
        {
            ansmax[v]=ansmax[2*v];
        }
        else ansmax[v]=ansmax[2*v+1];
    }
}
main()
{
    int n,x;
    cin>>n;
    if(n<3)
    {
        cout<<0;
        return 0;
    }
    for(int i=1; i<=n; i++)
    {
        cin>>a[i];
        if(!mp.count(a[i]))
        {
            mp[a[i]]=mp.size();
        }
        b[i]=mp[a[i]];
        cnt[b[i]]++;
    }
//    for(int i=1;i<=n;i++)
//    {
//        cout<<b[i]<<" ";
//    }
//    cout<<endl;
    for(int i=1;i<=n;i++)
    {
        mpcor[b[i]]=a[i];
    }
//    cout<<mpcor[7];
//    return 0;
    make(1,1,n);
    code q;
    while(1)
    {
        pair<int,int>a,b,c;
        a=get_ans(1,1,n,1e9,1e9);
        if(a.second==0) break;
        b=get_ans(1,1,n,a.second,a.first);
        if(b.second==0) break;
        c=get_ans(1,1,n,b.second,b.first);
        if(c.second==0) break;
//        cout<<a.first<<" "<<a.second<<endl;
//        cout<<b.first<<" "<<b.second<<endl;
//        cout<<c.first<<" "<<c.second<<endl;
//        cout<<"--------------\n";

        q.r1=a.first;
        q.r2=b.first;
        q.r3=c.first;

        ans.push_back(q);

        change(1,1,n,a.first);
        change(1,1,n,b.first);
        change(1,1,n,c.first);
    }
    cout<<ans.size()<<endl;
    vector<int>result;
    for(int i=0;i<ans.size();i++)
    {
        result.clear();
        result.push_back(mpcor[ans[i].r1]);
        result.push_back(mpcor[ans[i].r2]);
        result.push_back(mpcor[ans[i].r3]);
        sort(result.begin() , result.end());
        cout<<result[2]<<" "<<result[1]<<" "<<result[0]<<endl;
    }
}
/*
7
1 1 1 4 5 6 7
*/


#include<iostream>
#include<vector>
#include<set>
#include<map>
using namespace std;
struct code
{
    int r1,r2,r3;
};
set<pair<int,int> >st;
map<int,int>mp;
vector<code>ans;
int a[100001];
main()
{
    int n;
    cin>>n;

    for(int i=1; i<=n; i++)
    {
        cin>>a[i];
        mp[a[i]]++;
    }
    for(int i=1; i<=n; i++)
    {
        st.insert(make_pair(mp[a[i]],a[i]));
    }
    pair<int,int>q;
    int st_size=st.size();
    code w;
    while(1)
    {
        if(st.size()<3) break;
        set<pair<int,int> > :: iterator ind=st.end();
        ind--;
        q=(*ind);
//        cout<<q.second<<" "<<q.first<<" "<<st.size()<<endl;
        int a=q.second;
        st.erase(q);
        if(q.first!=1) st.insert(make_pair(q.first-1,q.second));

        ind=st.end();
        ind--;
        while((*ind).second==a) ind--;
        q=(*ind);
        int b=q.second;
        st.erase(q);
        if(q.first!=1) st.insert(make_pair(q.first-1,q.second));

        ind=st.end();
        ind--;
        while((*ind).second==a or (*ind).second==b) ind--;
        q=(*ind);
//        cout<<q.second<<" "<<q.first<<" "<<st.size()<<endl;
        int c=q.second;
        st.erase(q);
        if(q.first!=1) st.insert(make_pair(q.first-1,q.second));
        w.r1=a,w.r2=b,w.r3=c;
//        cout<<a<<"           "<<b<<"            "<<c<<endl;
        ans.push_back(w);
    }

    cout<<ans.size()<<endl;
    vector<int>result;
    for(int i=0; i<ans.size(); i++)
    {
        result.clear();
        result.push_back(ans[i].r1);
        result.push_back(ans[i].r2);
        result.push_back(ans[i].r3);
        sort(result.begin() , result.end());
        cout<<result[2]<<" "<<result[1]<<" "<<result[0]<<endl;
    }
}
/*
8
1 2 3 4 2 6 7 8
*/


#include<iostream>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;
struct code
{
    int r1,r2,r3;
};
vector<code>ans;
map<int,int>mp;
map<int,int>mpcor;
int a[100001];
int b[100001];
pair<int,int>ansmax[400001];
int cnt[100001];
void make(int v , int l , int r)
{
    if(l==r)
    {
        ansmax[v].first=l;
        ansmax[v].second=cnt[l];
    }
    else
    {
        int mid=(l+r)/2;
        make(2*v,l,mid);
        make(2*v+1,mid+1,r);
        if(ansmax[2*v].second>ansmax[2*v+1].second)
        {
            ansmax[v]=ansmax[2*v];
        }
        else
        {
            ansmax[v]=ansmax[2*v+1];
        }
    }
}
pair<int,int> get_ans(int v , int l , int r , int cnt , int num)
{
    if(l>r) make_pair(0,0);
    if(ansmax[v].second<cnt or (ansmax[v].second==cnt and ansmax[v].first<num))
    {
        return ansmax[v];
    }
    else
    {
        pair<int,int>mx1;
        pair<int,int>mx2;
        int mid=(l+r)/2;
        mx1=get_ans(2*v,l,mid,cnt,num);
        mx2=get_ans(2*v+1,mid+1,r,cnt,num);
        if(mx1.second>mx2.second)
        {
            return mx1;
        }
        else return mx2;
    }
}
void change(int v , int l , int r , int ind)
{
    if(l==r)
    {
        ansmax[v].second--;
    }
    else
    {
        int mid=(l+r)/2;
        if(ind<=mid) change(2*v,l,mid,ind);
        else change(2*v+1,mid+1,r,ind);
        if(ansmax[2*v].second>ansmax[2*v+1].second)
        {
            ansmax[v]=ansmax[2*v];
        }
        else ansmax[v]=ansmax[2*v+1];
    }
}
main()
{
    int n,x;
    cin>>n;
    if(n<3)
    {
        cout<<0;
        return 0;
    }
    for(int i=1; i<=n; i++)
    {
        cin>>a[i];
        if(!mp.count(a[i]))
        {
            mp[a[i]]=mp.size();
        }
        b[i]=mp[a[i]];
        cnt[b[i]]++;
    }
//    for(int i=1;i<=n;i++)
//    {
//        cout<<b[i]<<" ";
//    }
//    cout<<endl;
    for(int i=1; i<=n; i++)
    {
        mpcor[b[i]]=a[i];
    }
//    cout<<mpcor[7];
//    return 0;
    make(1,1,n);
    code q;
    while(1)
    {
        pair<int,int>a,b,c;
        a=get_ans(1,1,n,1e9,1e9);
        if(a.second==0) break;

        b=get_ans(1,1,n,a.second,a.first);
        if(b.second==0) break;

        c=get_ans(1,1,n,b.second,b.first);
        if(c.second==0) break;
//        cout<<a.first<<" "<<a.second<<endl;
//        cout<<b.first<<" "<<b.second<<endl;
//        cout<<c.first<<" "<<c.second<<endl;
//        cout<<"--------------\n";

        q.r1=a.first;
        q.r2=b.first;
        q.r3=c.first;

        ans.push_back(q);

        change(1,1,n,a.first);
        change(1,1,n,b.first);
        change(1,1,n,c.first);
    }
    cout<<ans.size()<<endl;
    vector<int>result;
    for(int i=0; i<ans.size(); i++)
    {
        result.clear();
        result.push_back(mpcor[ans[i].r1]);
        result.push_back(mpcor[ans[i].r2]);
        result.push_back(mpcor[ans[i].r3]);
        sort(result.begin() , result.end());
        cout<<result[2]<<" "<<result[1]<<" "<<result[0]<<endl;
    }
}
/*
7
1 1 1 4 5 6 7
*/


#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
using namespace std;
struct code
{
    int r1,r2,r3;
};
set<pair<int,int> >st;
map<int,int>mp;
vector<code>ans;
int a[100001];
main()
{
    int n;
    cin>>n;

    for(int i=1; i<=n; i++)
    {
        scanf("%d",&a[i]);
        mp[a[i]]++;
    }
    for(int i=1; i<=n; i++)
    {
        st.insert(make_pair(mp[a[i]],a[i]));
    }
    pair<int,int>q;
    int st_size=st.size();
    code w;
    while(1)
    {
        if(st.size()<3) break;
        set<pair<int,int> > :: iterator ind=st.end();
        ind--;
        q=(*ind);
        int a=q.second;
        st.erase(q);
        if(q.first!=1) st.insert(make_pair(q.first-1,q.second));

        ind=st.end();
        ind--;
        while((*ind).second==a) ind--;
        q=(*ind);
        int b=q.second;
        st.erase(q);
        if(q.first!=1) st.insert(make_pair(q.first-1,q.second));

        ind=st.end();
        ind--;
        while((*ind).second==a or (*ind).second==b) ind--;
        q=(*ind);
        int c=q.second;
        st.erase(q);
        if(q.first!=1) st.insert(make_pair(q.first-1,q.second));
        w.r1=a,w.r2=b,w.r3=c;
        ans.push_back(w);
    }

    cout<<ans.size()<<endl;
    vector<int>result;
    for(int i=0; i<ans.size(); i++)
    {
        result.clear();
        result.push_back(ans[i].r1);
        result.push_back(ans[i].r2);
        result.push_back(ans[i].r3);
        sort(result.begin() , result.end());
        printf("%d %d %d",result[2],result[1],result[0])
        cout<<result[2]<<" "<<result[1]<<" "<<result[0]<<endl;
    }
}
/*
8
1 2 3 4 2 6 7 8
*/


#include<iostream>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;
struct code
{
    int num1,cnt;
};
vector<int>ans[3];
map<int,int>mp;
code b[100001];
bool comp(code a , code b)
{
    return a.cnt>b.cnt or (a.cnt==b.cnt and a.num1>b.num1);
}
main()
{
    int n,x;
    cin>>n;

    for(int i=1; i<=n; i++)
    {
        cin>>x;
        mp[x]++;
    }
    int ind=0;
    for(map<int,int> :: iterator i=mp.begin();i!=mp.end();i++)
    {
        ++ind;
        b[ind].num1=(*i).first;
        b[ind].cnt=(*i).second;
    }

//    for(int i=1;i<=ind;i++)
//    {
//        cout<<b[i]<<" ";
//    }
//    cout<<endl;
    sort(b+1 , b+ind+1 , comp);
    if(ind<3)
    {
        cout<<0;
        return 0;
    }

    int ind1=1,ind2=2,ind3=3;
    while(1)
    {
//        cout<<ind1<<" "<<ind2<< " "<<ind3<<endl;
        ans[0].push_back(b[ind1].num1);
        ans[1].push_back(b[ind2].num1);
        ans[2].push_back(b[ind3].num1);
        b[ind1].cnt--;
        b[ind2].cnt--;
        b[ind3].cnt--;
        while(ind1<=ind and b[ind1].cnt==0) ind1++;
        while(ind2<=ind and (b[ind2].cnt==0 or ind1>=ind2)) ind2++;
        while(ind3<=ind and (b[ind3].cnt==0 or ind2>=ind3)) ind3++;
        if(ind3>ind) break;
    }

    sort(b+1 , b+n+1 , comp);
//
    cout<<ans[0].size()<<endl;
    vector<int>result;
    for(int i=0; i<ans[0].size(); i++)
    {
        result.clear();
        result.push_back(ans[0][i]);
        result.push_back(ans[1][i]);
        result.push_back(ans[2][i]);
        sort(result.begin() , result.end());
        cout<<result[2]<<" "<<result[1]<<" "<<result[0]<<endl;
    }
}
/*
7
1 1 1 4 1 6 7
*/


#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
using namespace std;
struct code
{
    int r1,r2,r3;
};
set<pair<int,int> >st;
map<int,int>mp;
vector<code>ans;
int a[100001];
main()
{
    int n;
    cin>>n;

    for(int i=1; i<=n; i++)
    {
        cin>>a[i];
        mp[a[i]]++;
    }
    for(int i=1; i<=n; i++)
    {
        st.insert(make_pair(mp[a[i]],a[i]));
    }
    pair<int,int>q;
    int st_size=st.size();
    code w;
    while(1)
    {
        if(st.size()<3) break;
        set<pair<int,int> > :: iterator ind=st.end();
        ind--;
        q=(*ind);
//        cout<<q.second<<" "<<q.first<<" "<<st.size()<<endl;
        int a=q.second;
        st.erase(q);
        if(q.first!=1) st.insert(make_pair(q.first-1,q.second));

        ind=st.end();
        ind--;
        while((*ind).second==a) ind--;
        q=(*ind);
        int b=q.second;
        st.erase(q);
        if(q.first!=1) st.insert(make_pair(q.first-1,q.second));

        ind=st.end();
        ind--;
        while((*ind).second==a or (*ind).second==b) ind--;
        q=(*ind);
//        cout<<q.second<<" "<<q.first<<" "<<st.size()<<endl;
        int c=q.second;
        st.erase(q);
        if(q.first!=1) st.insert(make_pair(q.first-1,q.second));
        w.r1=a,w.r2=b,w.r3=c;
//        cout<<a<<"           "<<b<<"            "<<c<<endl;
        ans.push_back(w);
    }

    cout<<ans.size()<<endl;
    vector<int>result;
    for(int i=0; i<ans.size(); i++)
    {
        result.clear();
        result.push_back(ans[i].r1);
        result.push_back(ans[i].r2);
        result.push_back(ans[i].r3);
        sort(result.begin() , result.end());
        cout<<result[2]<<" "<<result[1]<<" "<<result[0]<<endl;
    }
}
/*
8
1 2 3 4 2 6 7 8
*/


#include <bits/stdc++.h>
#include <fstream>

using namespace std;

struct f
{
    int x,y;
    f(){}
    f(int x,int y)
    :x(x),y(y){}
};
struct f1
{
    int x,y,z;
    f1(){}
    f1(int x,int y,int z)
    :x(x),y(y),z(z){}
};

long long fl,i,j,n,m,k,ans,ans1,ans2,x,y,f2,kol,mi=-1e9,ma=-1e9;
int L[300010],R[300010];
int a[300010];
string s,s1;
vector <f> v;
vector <f1> v1;
map <int,int> mp;

bool cmp(f l,f r)
{
    if(l.y==r.y) return l.x>r.x;
    else return l.y>r.y;
}

int main()
{
    ios_base::sync_with_stdio(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    cin>>n;
    for(i=1;i<=n;i++)
    {
        int x;
        cin>>x;
        mp[x]++;
    }
    map <int,int> ::iterator it;
    for(it=mp.begin();it!=mp.end();it++)
    {
        int x=it->first;
        int y=it->second;
        v.push_back(f(x,y));
    }
    sort(v.begin(),v.end(),cmp);
    int x=0;
    int y=1;
    int z=2;
    if(v.size()<3)
    {
        cout<<0;
        return 0;
    }
    //for(i=0;i<v.size();i++)
    //    cout<<v[i].x<<' '<<v[i].y<<endl;
    while(1)
    {
        //cout<<x<<' '<<y<<' '<<z<<endl;
        int mi=min(min(v[x].y,v[y].y),v[z].y);
        v[x].y-=mi;
        v[y].y-=mi;
        v[z].y-=mi;
        for(i=1;i<=mi;i++)v1.push_back(f1(max(max(v[x].x,v[y].x),v[z].x),v[x].x+v[y].x+v[z].x-min(min(v[x].x,v[y].x),v[z].x)-max(max(v[x].x,v[y].x),v[z].x),min(min(v[x].x,v[y].x),v[z].x)));
        if((x==v.size()-1 || y==v.size()-1 || z==v.size()-1)&& (x==0 || y==0 || z==0))break;
        if(v[x].y<=0)x=max(max(y,z),x)+1;
        if(v[y].y<=0)y=max(max(y,z),x)+1;
        if(v[z].y<=0)z=max(max(y,z),x)+1;
        if(x>v.size()-1 || y>v.size()-1 || z>v.size()-1)break;
    }
    cout<<v1.size()<<endl;
    for(i=0;i<v1.size();i++)
        cout<<v1[i].x<<' '<<v1[i].y<<' '<<v1[i].z<<endl;
}

/* Sat Feb 10 2018 11:25:21 GMT+0300 (MSK) */


#include <bits/stdc++.h>

using namespace std;
priority_queue<pair <int,int> > q;
int a[100005], koms[3];
int main()
{
    int n;
    cin >> n;
    for (int i=1;i<=n;i++)
    {
        cin >> a[i];
    }
    sort(a+1,a+n+1);
    for (int i=1;i<=n;i++)
    {
        int j=i;
        while (j<=n && a[j]==a[i])j++;
        q.push(make_pair(j-i,a[i]));
    }
    vector <pair <int,pair<int,int> > > ans;
    while (q.size()>2)
    {
        pair <int,int> kom1=q.top();
        q.pop();
         pair <int,int> kom2=q.top();
        q.pop();
         pair <int,int> kom3=q.top();
        q.pop();
        koms[0]=kom1.second;
        koms[1]=kom2.second;
        koms[2]=kom3.second;
        sort (koms,koms+3);
        ans.push_back(make_pair(koms[2],make_pair(koms[1],koms[0])));
        kom1.first--;kom2.first--;kom3.first--;
        if (kom1.first>0) q.push(kom1);
        if (kom2.first>0) q.push(kom2);
        if (kom3.first>0) q.push(kom3);
    }
    cout << ans.size() << endl;
    for (int i=0;i<ans.size();i++)
    {
        cout << ans[i].first << " " << ans[i].second.first << " " << ans[i].second.second << endl;
    }
}

/* Sat Feb 10 2018 11:03:21 GMT+0300 (MSK) */


#include <stdio.h>
#include <bits/stdc++.h>

using namespace std;

#define str string
#define ll long long
#define vec vector
#define pb push_back
#define v1 vec<int>
#define v2 vec<v1>

const int inf=1e9;

int n;

map<int,int>cnt;

void input(){
    scanf("%d",&n);
    int a;
    for(int i=0;i<n;i++){
        scanf("%d",&a);
        cnt[a]++;
    }
    return;
}

map<int,int>::iterator it;

void find_ans(){
    int max_val;
    int new_n=n;
    bool fl=0;
    while(1){
        max_val=new_n/3;
        fl=0;
        for(it=cnt.begin();it!=cnt.end();it++){
            int num=it->first;
            int val=it->second;
            if(val-max_val>0){
                fl=1;
                new_n-=val-max_val;
                cnt[num]=max_val;
            }
        }
        if(fl==0){
            break;
        }
    }
    printf("%d\n",new_n/3);
    v2 ans(new_n/3,v1(3,0));
    it=cnt.begin();
    for(int i=0;i<3;i++){
        for(int j=0;j<new_n/3;j++){
            if(it->second==0){
                it++;
            }
            ans[j][i]=it->first;
            it->second--;
        }
    }
    for(int i=0;i<new_n/3;i++){
        for(int j=2;j>=0;j--){
            printf("%d ",ans[i][j]);
        }
        printf("\n");
    }
    return;
}

int main(){
    input();
    find_ans();
    return 0;
}

/* Sat Feb 10 2018 11:01:51 GMT+0300 (MSK) */


#include <bits/stdc++.h>
#include <fstream>

using namespace std;

struct f
{
    int x,y;
    f(){}
    f(int x,int y)
    :x(x),y(y){}
};
struct f1
{
    int x,y,z;
    f1(){}
    f1(int x,int y,int z)
    :x(x),y(y),z(z){}
};

long long fl,i,j,n,m,k,ans,ans1,ans2,x,y,f2,kol,mi=-1e9,ma=-1e9;
int L[300010],R[300010];
int a[300010];
string s,s1;
vector <f> v;
vector <f1> v1;
map <int,int> mp;

bool cmp(f l,f r)
{
    return (l.x+l.y)>(r.x+r.y);
}

int main()
{
    ios_base::sync_with_stdio(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    cin>>n;
    for(i=1;i<=n;i++)
    {
        int x;
        cin>>x;
        mp[x]++;
    }
    map <int,int> ::iterator it;
    for(it=mp.begin();it!=mp.end();it++)
    {
        int x=it->first;
        int y=it->second;
        v.push_back(f(x,y));
    }
    sort(v.begin(),v.end(),cmp);
    int x=0;
    int y=1;
    int z=2;
    if(v.size()<3)
    {
        cout<<0;
        return 0;
    }
    //for(i=0;i<v.size();i++)
    //    cout<<v[i].x<<' '<<v[i].y<<endl;
    while(1)
    {
        //cout<<x<<' '<<y<<' '<<z<<endl;
        int mi=min(min(v[x].y,v[y].y),v[z].y);
        v[x].y-=mi;
        v[y].y-=mi;
        v[z].y-=mi;
        for(i=1;i<=mi;i++)v1.push_back(f1(v[x].x,v[y].x,v[z].x));
        if((x==v.size()-1 || y==v.size()-1 || z==v.size()-1)&& (x==0 || y==0 || z==0))break;
        if(v[x].y<=0)x=max(max(y,z),x)+1;
        if(v[y].y<=0)y=max(max(y,z),x)+1;
        if(v[z].y<=0)z=max(max(y,z),x)+1;
        if(x>v.size() || y>v.size() || z>v.size())break;
    }
    cout<<v1.size()<<endl;
    for(i=0;i<v1.size();i++)
        cout<<v1[i].x<<' '<<v1[i].y<<' '<<v1[i].z<<endl;
}

/* Sat Feb 10 2018 11:00:34 GMT+0300 (MSK) */


//#include "stdafx.h"
#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <string>
#include <vector>
#include <cmath>
#include <math.h>
#include <map>
#include <algorithm>
#include <set>
#include<complex>
#include <stdio.h>
#include<stdint.h>
#include<iterator>
#include <cstdlib>
#include <fstream>
#define ll long long

#define forin for(fint i = 0; i < n; i++)
#define forkm for(fint k = 0; k < m; k++)
#define forjp for(fint j =0; j < p; j++)
#define all(x) x.begin(), x.end()
#define INF 99999999999
#define fint int_fast32_t
#define mp(x,y) make_pair(x,y)
#define cmp complex<double>

using namespace std;

const double PI = 3.1415926535897932384626433832795;

ll all;

vector<ll> arr1;

void rec(ll a)
{
	if (a > 1000000000) return;
	arr1.push_back(a);
	rec(a * 10 + 4);
	rec(a * 10 + 7);
}

int main() {

	int n; cin >> n;
	set<pair<ll,ll> > st;
	map<ll, ll> mp;
	vector<ll> arr;
	for (int i = 0; i < n; i++)
	{
		int a; cin >> a;
		mp[a]++;
		if (mp[a]==1)
		{
			st.insert(mp(a, 1));
		}
		else
		{
			st.erase(mp(a, mp[a] - 1));
			st.insert(mp(a, mp[a]));
		}
		arr.push_back(a);

	}
	//sort(arr.begin(), arr.end());
	vector<vector<ll> > result;
	while (st.size()>2)
	{
		int count = 0;
		vector<ll> tmp;
		vector<pair<ll, ll> > todel, toins;
		for (set<pair<ll,ll> >::reverse_iterator it = st.rbegin(); it != st.rend(); it++)
		{
			if (count == 3) break;
			tmp.push_back((*it).first);
			mp[(*it).first]--;
			if (mp[(*it).first] == 0)
			{
				todel.push_back(*it);
			}
			else
			{
				toins.push_back(mp((*it).first, (*it).second - 1));
				todel.push_back(*it);
			}
			count++;
		}
		for (int i = 0; i < todel.size(); i++)
		{
			st.erase(todel[i]);
		}
		for (int i = 0; i < toins.size(); i++)
		{
			st.insert(toins[i]);
		}
		sort(tmp.begin(), tmp.end());
		result.push_back(tmp);
	}
	cout << result.size() << endl;
	for (int i = 0; i < result.size(); i++)
	{
		for (int j = result[i].size()-1; j >=0 ; j--)
		{
			cout << result[i][j] << " ";
		}
		cout << endl;
	}
	return 0;
}

/* Sun Oct 08 2017 15:21:44 GMT+0300 (MSK) */

/* Sun Oct 08 2017 15:48:49 GMT+0300 (MSK) */

/* Thu Oct 12 2017 14:25:07 GMT+0300 (MSK) */


#include <bits/stdc++.h>

using namespace std;

int const N  = 1e5 + 7;

int  n, ans, sn[N], nac, l, r, kl, kr, kol;

int pr1 = 0; int pr2 = 0; int pk1 = 0; int pk2 = 0;

struct abc{
    int f;
    int s;
    int tr;
} otv[N];

vector <int> komu, mark;
int main() {

    /*freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);*/

    ios_base :: sync_with_stdio(0);

    cin >> n;

    for (int  i = 1; i <= n; i++) {
        cin >> sn[i];
    }

    sort (sn + 1, sn + n + 1);

    for (int i = 1; i <= n; i++) {
        if (sn[i] == sn[i-1]) {
            mark[komu.size() - 1] ++;
            continue;
        }

        komu.push_back(sn[i]); mark.push_back(1);
    }

     l = komu[0];  r = komu [1];
     kl = mark[0];  kr = mark[1]; mark[0] = 0; mark[1] = 0;

    reverse(komu.begin(), komu.end());
    reverse(mark.begin(), mark.end());

    for (int i = 0 ; i < komu.size(); i++) {

        while (1) {
        kol = 0;
        kol = min(mark[i], kl);
        kol = min(kr, kol);
        for (int j = 1; j <= kol; j++) {
            ans++;
            otv[ans].f = komu[i]; otv[ans].s = r; otv[ans].tr = l;
            kl --; kr --; mark[i] --;
        }

        if (kl == 0) {
            for (int j = komu.size() - 1; j >= i; j--) {
                if (mark[j] != 0) {
                    pr1 = komu[j];
                    pk1 = mark[j];
                    mark[j] = 0;
                    break;
                }
            }
            l = pr1; kl = pk1;
        }

        if (kr == 0) {
            for (int j = komu.size() - 1; j >= i; j--) {
                if (mark[j] != 0) {
                    pr2 = komu[j];
                    pk2 = mark[j];
                    mark[j] = 0;
                    break;
                }
            }
            r = pr2; kr = pk2;
        }
        if (kr == 0 || kl == 0 || mark[i] == 0) break;
        }
    }

    cout << ans << endl;

    for (int i = 1; i <= ans; i++) {
        cout << otv[i].f << ' ' << otv[i].s << ' ' << otv[i].tr << endl;
    }

    return 0;
}

/* Sat Feb 10 2018 12:22:15 GMT+0300 (MSK) */


#include <stdio.h>
#include<bits/stdc++.h>

using namespace std;

long long n,m,x2,y2,i,j,ma,mi=1e18,x,y,z,ans,k,t,f,l,r,bl=200,a[200000],b[500000],d[500005],d2[500005],d3[500005],p;
string s,s1;
char c;
vector<int>v[100005];
map<int,int>mp;
map<int,int>::iterator it;
//vector<long long>v1,v2,v3;

int main()
{
//freopen("war.in","r",stdin);
//freopen("war.out","w",stdout);
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
cin>>n;
for(i=1;i<=n;i++)
{
    scanf("%I64d",&a[i]);
    mp[a[i]]++;
}
m=n;
while(true)
{
    f=0;
    t=m/3;
    //cout<<t<<endl;
    for(it=mp.begin();it!=mp.end();it++)
    {
        int x=it->first;
        int y=it->second;

        if(y>t)
        {
            f=1;
            m-=(y-t);
             y=t;
             mp[x]=y;
        }
    }
    if(f==0)break;
}
n=m;
cout<<m/3<<endl;
for(it=mp.begin();it!=mp.end();it++)
    {
        int x=it->first;
        int y=it->second;
        for(j=0;j<m/3;j++)
        {
            if(v[j].size()<3){v[j].push_back(x);y--;}
            if(y==0)break;
        }
    }
    for(i=0;i<m/3;i++)
    {
        printf("%d %d %d\n",v[i][2],v[i][1],v[i][0]);
    }

}

/* Sat Feb 10 2018 12:14:13 GMT+0300 (MSK) */


#include <bits/stdc++.h>

using namespace std;
priority_queue<pair <int,int> > q;
int a[100005], koms[3];
int main()
{
    int n;
    cin >> n;
    for (int i=1;i<=n;i++)
    {
        cin >> a[i];
    }
    sort(a+1,a+n+1);
    for (int i=1;i<=n;)
    {
        int j=i;
        while (j<=n && a[j]==a[i])j++;
        q.push(make_pair(j-i,a[i]));
        i=j;
    }
    vector <pair <int,pair<int,int> > > ans;
    while (q.size()>2)
    {
        pair <int,int> kom1=q.top();
        q.pop();
         pair <int,int> kom2=q.top();
        q.pop();
         pair <int,int> kom3=q.top();
        q.pop();
        koms[0]=kom1.second;
        koms[1]=kom2.second;
        koms[2]=kom3.second;
        sort (koms,koms+3);
        ans.push_back(make_pair(koms[2],make_pair(koms[1],koms[0])));
        kom1.first--;kom2.first--;kom3.first--;
        if (kom1.first>0) q.push(kom1);
        if (kom2.first>0) q.push(kom2);
        if (kom3.first>0) q.push(kom3);
    }
    cout << ans.size() << endl;
    for (int i=0;i<ans.size();i++)
    {
        cout << ans[i].first << " " << ans[i].second.first << " " << ans[i].second.second << endl;
    }
}

/* Sat Feb 10 2018 11:06:43 GMT+0300 (MSK) */


#include <bits/stdc++.h>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back

using namespace std;

typedef double dd;
typedef long long ll;

priority_queue <pair <int, int> > p;
vector<int> ans[111111];
int a[111111];
map <int, int> b;
int main()
{
    //freopen("input.txt", "r", stdin);    freopen("output.txt", "w", stdout);
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i];
        b[a[i]]++;
    }
    for(auto x : b)
    {
        pair <int, int> y = mp(x.ss, x.ff);
        p.push(y);
    }
    int ii = 0;
    while(p.size() > 2)
    {
        pair <int, int> x, y, z;
        x = p.top();
        p.pop();
        y = p.top();
        p.pop();
        z = p.top();
        p.pop();
        ans[ii].pb(x.ss);
        ans[ii].pb(y.ss);
        ans[ii].pb(z.ss);
        ii++;
        x.ff--;
        if(x.ff)
            p.push(x);
        y.ff--;
        if(y.ff)
            p.push(y);
        z.ff--;
        if(z.ff)
            p.push(y);
    }
    cout << ii << endl;
    for(int i = 0; i < ii; i++)
    {
        sort(ans[i].begin(), ans[i].end());
        cout << ans[i][2] << " " << ans[i][1] << " " << ans[i][0] << endl;
    }
    return 0;
}

/* Sat Feb 10 2018 12:27:36 GMT+0300 (MSK) */


#include <stdio.h>
#include<bits/stdc++.h>

using namespace std;

long long n,m,x2,y2,i,j,ma,mi=1e18,x,y,z,ans,k,t,f,l,r,bl=200,a[200000],b[500000],d[500005],d2[500005],d3[500005],p;
string s,s1;
char c;
vector<int>v[100005];
map<int,int>mp;
map<int,int>::iterator it;
//vector<long long>v1,v2,v3;

int main()
{
//freopen("war.in","r",stdin);
//freopen("war.out","w",stdout);
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
cin>>n;
for(i=1;i<=n;i++)
{
    scanf("%I64d",&a[i]);
    mp[a[i]]++;
}
m=n;
while(true)
{
    f=0;
    t=m/3;
    //cout<<t<<endl;
    for(it=mp.begin();it!=mp.end();it++)
    {
        int x=it->first;
        int y=it->second;

        if(y>t)
        {
            f=1;
            m-=(y-t);
             y=t;
             mp[x]=y;
        }
    }
    if(f==0)break;
}
n=m;
cout<<m/3<<endl;

it=mp.begin();
for(int i=0;i<3;i++){
    for(int j=0;j<m/3;j++){
        if(it->second==0){
            it++;
        }
        v[j].push_back(it->first);
        it->second--;
    }
}

/*for(it=mp.begin();it!=mp.end();it++)
    {
        int x=it->first;
        int y=it->second;
        for(j=0;j<m/3;j++)
        {
            if(y==0)break;
            if(v[j].size()<3){v[j].push_back(x);y--;}
            if(y==0)break;
        }
    }*/
    for(i=0;i<m/3;i++)
    {
        printf("%d %d %d\n",v[i][2],v[i][1],v[i][0]);
    }

}

/* Sat Feb 10 2018 12:20:56 GMT+0300 (MSK) */


#include <bits/stdc++.h>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back

using namespace std;

typedef double dd;
typedef long long ll;

map <int, int> b;
vector <pair <int, int> > a;
vector <int> ans[111111];

int main()
{
    //freopen("input.txt", "r", stdin);    freopen("output.txt", "w", stdout);
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        int x;
        cin >> x;
        b[x]++;
    }
    for(auto x : b)
    {
        a.pb(mp(x.second, x.first));
    }
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    int pn = 0;
    for(int i = 0; i < a.size(); i++)
    {
        int kl = a[i].ff;
        for(int j = pn; kl > 0; kl--, j++)
        {
            ans[j].pb(a[i].ss);
            if(ans[j].size() == 3)
                pn = j + 1;
        }
    }
    cout << pn << endl;
    for(int i = 0; i < pn; i++)
    {
        sort(ans[i].begin(), ans[i].end());
        cout << ans[i][2] << " " << ans[i][1] << " " << ans[i][0] << endl;
    }
    return 0;
}

/* Sat Feb 10 2018 10:01:23 GMT+0300 (MSK) */


#include <bits/stdc++.h>

#define F first
#define S second
#define ll long long
#define p_b push_back
#define m_p make_pair
#define pii pair <int, int>

using namespace std;

const int  N = 3e5 + 5, INF = 1e9 + 7;

ll n, i, j;
ll m, k, s, ans;
ll a[N], b[N];
vector <int> v1, v2, v3;
string st;
struct S {
    int x, y, z;
    S(){}
    S(int x, int y, int z)
    :x(x), y(y), z(z){}
};
vector <S> v;
multiset <int> ss;
multiset <int> :: iterator it;

int main()
{
    //freopen("dwarfs.in", "r", stdin);
    //freopen("dwarfs.out", "w", stdout);

    ios_base::sync_with_stdio(0);

    cin >> n;
    for (i = 1; i <= n; i++)
    {
        ll t;
        cin >> t;
        ss.insert(-t);
    }
    while (ss.size() >= 3)
    {
        int a = *(ss.begin());
        ss.erase(ss.find(a));

        it = ss.upper_bound(a);
        if (it == ss.end()) break;
        int b = *(it);
        ss.erase(it);

        it = ss.upper_bound(b);
        if (it == ss.end()) break;
        int c = *(it);
        ss.erase(it);

        v.p_b(S(-a, -b, -c));
    }
    cout << v.size() << endl;
    for (i = 0; i < v.size(); i++)
    {
        cout << v[i].x << ' ' << v[i].y << ' ' << v[i].z << endl;
    }
}

/* Sat Feb 10 2018 11:48:55 GMT+0300 (MSK) */


#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second

using namespace std;

struct str
{
    int x;
    int y;
    int z;
};

const int N=1e5+10;

int r[N];

int main()
{

    ios_base::sync_with_stdio(0);

    //freopen("output.txt", "w", stdout);

    int n;
    cin>>n;

    for (int i=1; i<=n; i++){
        cin>>r[i];
    }

    sort(r+1, r+n+1);
    reverse(r+1, r+n+1);

    vector<pair<int, int> > v;
    int lst=0;
    for (int i=1; i<=n; i++){
        if (r[i]!=lst){
            v.push_back(make_pair(1, r[i])); lst=r[i];
        }
        else {
            v[v.size()-1].F++;
        }
    }

    if ((int)v.size()<=2){
        cout<<"0\n"; return 0;
    }

    vector<str> ans;
    priority_queue<pair<int, int>, vector<pair<int, int> >, less<pair<int, int> > > q;
    for (auto x: v){
        q.push(x);
    }

    while (1){

        pair<int, int> p1, p2, p3;
        p1=q.top(); q.pop();
        p2=q.top(); q.pop();
        p3=q.top(); q.pop();
        if (p1.F==0 || p2.F==0 || p3.F==0){
            break;
        }

        str g;
        g.x=p1.S; g.y=p2.S; g.z=p3.S;
        p1.F--; p2.F--; p3.F--;

        q.push(p1); q.push(p2); q.push(p3);

        if (g.x<g.y){
            swap(g.x, g.y);
        }
        if (g.x<g.z){
            swap(g.x, g.z);
        }
        if (g.y<g.z){
            swap(g.y, g.z);
        }

        ans.push_back(g);

    }

    cout<<ans.size()<<"\n";
    for (auto x: ans){
        cout<<x.x<<" "<<x.y<<" "<<x.z<<"\n";
    }

    return 0;
}


//#include "stdafx.h"
#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <string>
#include <vector>
#include <cmath>
#include <math.h>
#include <map>
#include <algorithm>
#include <set>
#include<complex>
#include <stdio.h>
#include<stdint.h>
#include<iterator>
#include <cstdlib>
#include <fstream>
#define ll long long

#define forin for(fint i = 0; i < n; i++)
#define forkm for(fint k = 0; k < m; k++)
#define forjp for(fint j =0; j < p; j++)
#define all(x) x.begin(), x.end()
#define INF 99999999999
#define fint int_fast32_t
#define mp(x,y) make_pair(x,y)
#define cmp complex<double>

using namespace std;

const double PI = 3.1415926535897932384626433832795;

ll all;

vector<ll> arr1;

void rec(ll a)
{
	if (a > 1000000000) return;
	arr1.push_back(a);
	rec(a * 10 + 4);
	rec(a * 10 + 7);
}

int main() {

	int n; cin >> n;
	set<ll> st;
	map<ll, ll> mp;
	vector<ll> arr;
	for (int i = 0; i < n; i++)
	{
		int a; cin >> a;
		st.insert(a);
		arr.push_back(a);
		mp[a]++;
	}
	sort(arr.begin(), arr.end());
	vector<vector<ll> > result;
	while (st.size()>2)
	{
		int count = 0;
		vector<ll> tmp;
		vector<ll> todel;
		for (set<ll>::iterator it = st.begin(); it != st.end(); it++)
		{
			if (count == 3) break;
			tmp.push_back(*it);
			mp[*it]--;
			if (mp[*it] == 0) todel.push_back(*it);
			count++;
		}
		result.push_back(tmp);
		for (int i = 0; i < todel.size(); i++)
		{
			st.erase(todel[i]);
		}
	}
	cout << result.size() << endl;
	for (int i = 0; i < result.size(); i++)
	{
		for (int j = result[i].size()-1; j >=0 ; j--)
		{
			cout << result[i][j] << " ";
		}
		cout << endl;
	}
	return 0;
}

/* Sun Oct 08 2017 15:21:44 GMT+0300 (MSK) */

/* Sun Oct 08 2017 15:48:49 GMT+0300 (MSK) */

/* Thu Oct 12 2017 13:47:37 GMT+0300 (MSK) */


#include <bits/stdc++.h>
#include <fstream>

using namespace std;

struct f
{
    int x,y;
    f(){}
    f(int x,int y)
    :x(x),y(y){}
};
struct f1
{
    int x,y,z;
    f1(){}
    f1(int x,int y,int z)
    :x(x),y(y),z(z){}
};

long long fl,i,j,n,m,k,ans,ans1,ans2,x,y,f2,kol,mi=-1e9,ma=-1e9;
int L[300010],R[300010];
int a[300010];
string s,s1;
vector <f> v;
vector <f1> v1;
map <int,int> mp;

bool cmp(f l,f r)
{
    if(l.x==r.x) return l.y>r.y;
    else return l.x>r.x;
}

int main()
{
    ios_base::sync_with_stdio(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    cin>>n;
    for(i=1;i<=n;i++)
    {
        int x;
        cin>>x;
        mp[x]++;
    }
    map <int,int> ::iterator it;
    for(it=mp.begin();it!=mp.end();it++)
    {
        int x=it->first;
        int y=it->second;
        v.push_back(f(x,y));
    }
    sort(v.begin(),v.end(),cmp);
    int x=0;
    int y=1;
    int z=2;
    if(v.size()<3)
    {
        cout<<0;
        return 0;
    }
    //for(i=0;i<v.size();i++)
    //    cout<<v[i].x<<' '<<v[i].y<<endl;
    while(1)
    {
        //cout<<x<<' '<<y<<' '<<z<<endl;
        int mi=min(min(v[x].y,v[y].y),v[z].y);
        v[x].y-=mi;
        v[y].y-=mi;
        v[z].y-=mi;
        for(i=1;i<=mi;i++)v1.push_back(f1(max(max(v[x].x,v[y].x),v[z].x),v[x].x+v[y].x+v[z].x-min(min(v[x].x,v[y].x),v[z].x)-max(max(v[x].x,v[y].x),v[z].x),min(min(v[x].x,v[y].x),v[z].x)));
        if((x==v.size()-1 || y==v.size()-1 || z==v.size()-1)&& (x==0 || y==0 || z==0))break;
        if(v[x].y<=0)x=max(max(y,z),x)+1;
        if(v[y].y<=0)y=max(max(y,z),x)+1;
        if(v[z].y<=0)z=max(max(y,z),x)+1;
        if(x>v.size() || y>v.size() || z>v.size())break;
    }
    cout<<v1.size()<<endl;
    for(i=0;i<v1.size();i++)
        cout<<v1[i].x<<' '<<v1[i].y<<' '<<v1[i].z<<endl;
}

/* Sat Feb 10 2018 11:13:15 GMT+0300 (MSK) */


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 7;

int n;
int r[N];
int sel[N];

bool valid(int x)
{
	int p = 0;
	for (int i=0; i<n && p<3*x; i++)
		if (p < x || r[i] > sel[p - x])
			sel[p++] = r[i];
	return p == 3 * x;
}

void solution() {

    cin >> n;
	for (int i=0; i<n; i++)
		cin >> r[i];
	sort(r, r+n);
	int l = 0, r = n / 3 + 1;
	while (r - l > 1)
	{
		int mid = (l + r) / 2;
		if (valid(mid))
			l = mid;
		else
			r = mid;
	}
	cout << l << "\n";
	valid(l);
	for (int i=0; i<l; i++)
		cout << sel[i + 2 * l] << " " << sel[i + l] << " " << sel[i] << "\n";

}

int main()
{
	ios::sync_with_stdio(0);
    solution();
	return 0;
}
/* Sat Feb 10 2018 13:44:39 GMT+0300 (MSK) */


//#include "stdafx.h"
#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <string>
#include <vector>
#include <cmath>
#include <math.h>
#include <map>
#include <algorithm>
#include <set>
#include<complex>
#include <stdio.h>
#include<stdint.h>
#include<iterator>
#include <cstdlib>
#include <fstream>
#define ll long long

#define forin for(fint i = 0; i < n; i++)
#define forkm for(fint k = 0; k < m; k++)
#define forjp for(fint j =0; j < p; j++)
#define all(x) x.begin(), x.end()
#define INF 99999999999
#define fint int_fast32_t
#define mp(x,y) make_pair(x,y)
#define cmp complex<double>

using namespace std;

const double PI = 3.1415926535897932384626433832795;

ll all;

vector<ll> arr1;

void rec(ll a)
{
	if (a > 1000000000) return;
	arr1.push_back(a);
	rec(a * 10 + 4);
	rec(a * 10 + 7);
}

int main() {

	int n; cin >> n;
	set<pair<ll,ll> > st;
	map<ll, ll> mp;
	vector<ll> arr;
	for (int i = 0; i < n; i++)
	{
		int a; cin >> a;
		mp[a]++;
		if (mp[a]==1)
		{
			st.insert(mp(1, a));
		}
		else
		{
			st.erase(mp(mp[a] - 1,a));
			st.insert(mp(mp[a],a));
		}
		arr.push_back(a);

	}
	//sort(arr.begin(), arr.end());
	vector<vector<ll> > result;
	while (st.size()>2)
	{
		int count = 0;
		vector<ll> tmp;
		vector<pair<ll, ll> > todel, toins;
		for (set<pair<ll,ll> >::reverse_iterator it = st.rbegin(); it != st.rend(); it++)
		{
			if (count == 3) break;
			tmp.push_back((*it).second);
			mp[(*it).second]--;
			if (mp[(*it).second] == 0)
			{
				todel.push_back(*it);
			}
			else
			{
				toins.push_back(mp((*it).first -1 , (*it).second));
				todel.push_back(*it);
			}
			count++;
		}
		for (int i = 0; i < todel.size(); i++)
		{
			st.erase(todel[i]);
		}
		for (int i = 0; i < toins.size(); i++)
		{
			st.insert(toins[i]);
		}
		sort(tmp.begin(), tmp.end());
		result.push_back(tmp);
	}
	cout << result.size() << endl;
	for (int i = 0; i < result.size(); i++)
	{
		for (int j = result[i].size()-1; j >=0 ; j--)
		{
			cout << result[i][j] << " ";
		}
		cout << endl;
	}
	return 0;
}

/* Sun Oct 08 2017 15:21:44 GMT+0300 (MSK) */

/* Sun Oct 08 2017 15:48:49 GMT+0300 (MSK) */


#include <bits/stdc++.h>
#include <fstream>

using namespace std;

struct f
{
    int x,y;
    f(){}
    f(int x,int y)
    :x(x),y(y){}
};
struct f1
{
    int x,y,z;
    f1(){}
    f1(int x,int y,int z)
    :x(x),y(y),z(z){}
};

long long fl,i,j,n,m,k,ans,ans1,ans2,x,y,f2,kol,mi=-1e9,ma=-1e9;
int L[300010],R[300010];
int a[300010];
string s,s1;
vector <f> v;
vector <f1> v1;
map <int,int> mp;

bool cmp(f l,f r)
{
    if(l.x==r.x) return l.y>r.y;
    else return l.x>r.x;
}

int main()
{
    ios_base::sync_with_stdio(0);
   // freopen("input.txt","r",stdin);
   // freopen("output.txt","w",stdout);
    cin>>n;
    for(i=1;i<=n;i++)
    {
        int x;
        cin>>x;
        mp[x]++;
    }
    map <int,int> ::iterator it;
    for(it=mp.begin();it!=mp.end();it++)
    {
        int x=it->first;
        int y=it->second;
        v.push_back(f(x,y));
    }
    sort(v.begin(),v.end(),cmp);
    int x=0;
    int y=1;
    int z=2;
    if(v.size()<3)
    {
        cout<<0;
        return 0;
    }
    //for(i=0;i<v.size();i++)
    //    cout<<v[i].x<<' '<<v[i].y<<endl;
    while(1)
    {
        //cout<<x<<' '<<y<<' '<<z<<endl;
        //cout<<x<<' '<<y<<' '<<z<<endl;
        int mi=min(min(v[x].y,v[y].y),v[z].y);
        v[x].y-=mi;
        v[y].y-=mi;
        v[z].y-=mi;
        for(i=1;i<=mi;i++)v1.push_back(f1(max(max(v[x].x,v[y].x),v[z].x),v[x].x+v[y].x+v[z].x-min(min(v[x].x,v[y].x),v[z].x)-max(max(v[x].x,v[y].x),v[z].x),min(min(v[x].x,v[y].x),v[z].x)));
        if((x==v.size()-1 || y==v.size()-1 || z==v.size()-1)&& (x==0 || y==0 || z==0))break;
        if(v[x].y<=0)x=max(max(y,z),x)+1;
        if(v[y].y<=0)y=max(max(y,z),x)+1;
        if(v[z].y<=0)z=max(max(y,z),x)+1;
        if(x>v.size()-1 || y>v.size()-1 || z>v.size()-1)break;
    }
    cout<<v1.size()<<endl;
    for(i=0;i<v1.size();i++)
        cout<<v1[i].x<<' '<<v1[i].y<<' '<<v1[i].z<<endl;
}

/* Sat Feb 10 2018 11:17:00 GMT+0300 (MSK) */


#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <queue>
#include <cmath>
#include <set>
#include <map>

using namespace std;
vector <int> v[100010];
int a[100010];
map<int,int> mp;
set<pair<int,int> > ::iterator it;
set<pair<int,int> > ::iterator it1,it2,it3;
int main()
{
 //freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
 int n;
 cin>>n;
 set<pair<int,int> > st;
 for (int i=0;i<n;i++)
  {cin>>a[i];mp[a[i]]++;}
 for (int i=0;i<n;i++)
  if (mp[a[i]]>0) {st.insert(make_pair(mp[a[i]],a[i]));mp[a[i]]=0;}
 int l=-1;
 while(st.size()>=3)
 {
  it=st.end();it--;
  int k=1e9;
  k=min(k,(*it).first);
  //cout<<(*it).first<<endl;
  int kol1=(*it).second;
  it1=it;
  it--;
   k=min(k,(*it).first);//cout<<(*it).first<<endl;
   it2=it;
  int kol2=(*it).second;//cout<<(*it).first<<endl;
  it--;
  it3=it;
   k=min(k,(*it).first);
  int kol3=(*it).second;
  int kk=k;
  //while(k>0)
  //{
   l++;
   v[l].push_back(kol1);
    v[l].push_back(kol2);
     v[l].push_back(kol3);
   k--;
  //}
  k=kk;
  if ((*it1).first>1 )st.insert(make_pair((*it1).first-1,(*it1).second));
  if ((*it2).first>1 )st.insert(make_pair((*it2).first-1,(*it2).second));
  if ((*it3).first>1 )st.insert(make_pair((*it3).first-1,(*it3).second));
  //cout<<(*it1).first-k<<' '<<k<<endl;
  //cout<<(*it2).first-k<<endl;
  //cout<<(*it3).first-k<<endl;
  st.erase(st.find(*it1));
  st.erase(st.find(*it2));
  st.erase(st.find(*it3));
 }
 cout<<l+1<<endl;
 for (int i=0;i<=l;i++)
  {sort(v[i].begin(),v[i].end());reverse(v[i].begin(),v[i].end());cout<<v[i][0]<<' '<<v[i][1]<<' '<<v[i][2]<<endl;}
}

/* Sat Feb 10 2018 12:29:52 GMT+0300 (MSK) */


#include <bits/stdc++.h>
#include <fstream>

using namespace std;

struct f
{
    int x,y;
    f(){}
    f(int x,int y)
    :x(x),y(y){}
};
struct f1
{
    int x,y,z;
    f1(){}
    f1(int x,int y,int z)
    :x(x),y(y),z(z){}
};

long long fl,i,j,n,m,k,ans,ans1,ans2,x,y,f2,kol,mi=-1e9,ma=-1e9;
int L[300010],R[300010];
int a[300010];
string s,s1;
vector <f> v;
vector <f1> v1;
map <int,int> mp;

bool cmp(f l,f r)
{
    return (l.x+l.y)>(r.x+r.y);
}

int main()
{
    ios_base::sync_with_stdio(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    cin>>n;
    for(i=1;i<=n;i++)
    {
        int x;
        cin>>x;
        mp[x]++;
    }
    map <int,int> ::iterator it;
    for(it=mp.begin();it!=mp.end();it++)
    {
        int x=it->first;
        int y=it->second;
        v.push_back(f(x,y));
    }
    sort(v.begin(),v.end(),cmp);
    int x=0;
    int y=1;
    int z=2;
    if(v.size()<3)
    {
        cout<<0;
        return 0;
    }
    //for(i=0;i<v.size();i++)
    //    cout<<v[i].x<<' '<<v[i].y<<endl;
    while(1)
    {
        //cout<<x<<' '<<y<<' '<<z<<endl;
        int mi=min(min(v[x].y,v[y].y),v[z].y);
        v[x].y-=mi;
        v[y].y-=mi;
        v[z].y-=mi;
        for(i=1;i<=mi;i++)v1.push_back(f1(max(max(v[x].x,v[y].x),v[z].x),v[x].x+v[y].x+v[z].x-min(min(v[x].x,v[y].x),v[z].x)-max(max(v[x].x,v[y].x),v[z].x),min(min(v[x].x,v[y].x),v[z].x)));
        if((x==v.size()-1 || y==v.size()-1 || z==v.size()-1)&& (x==0 || y==0 || z==0))break;
        if(v[x].y<=0)x=max(max(y,z),x)+1;
        if(v[y].y<=0)y=max(max(y,z),x)+1;
        if(v[z].y<=0)z=max(max(y,z),x)+1;
        if(x>v.size() || y>v.size() || z>v.size())break;
    }
    cout<<v1.size()<<endl;
    for(i=0;i<v1.size();i++)
        cout<<v1[i].x<<' '<<v1[i].y<<' '<<v1[i].z<<endl;
}

/* Sat Feb 10 2018 11:08:55 GMT+0300 (MSK) */


#include <bits/stdc++.h>

using namespace std;
priority_queue<pair <int,int> > q;
int a[100005], koms[3];
int main()
{
    int n;
    cin >> n;
    for (int i=1;i<=n;i++)
    {
        cin >> a[i];
    }
    sort(a+1,a+n+1);
    for (int i=1;i<=n;i++)
    {
        int j=i;
        while (j<=n && a[j]==a[i])j++;
        q.push(make_pair(j-i,a[i]));
        i=j;
    }
    vector <pair <int,pair<int,int> > > ans;
    while (q.size()>2)
    {
        pair <int,int> kom1=q.top();
        q.pop();
         pair <int,int> kom2=q.top();
        q.pop();
         pair <int,int> kom3=q.top();
        q.pop();
        koms[0]=kom1.second;
        koms[1]=kom2.second;
        koms[2]=kom3.second;
        sort (koms,koms+3);
        ans.push_back(make_pair(koms[2],make_pair(koms[1],koms[0])));
        kom1.first--;kom2.first--;kom3.first--;
        if (kom1.first>0) q.push(kom1);
        if (kom2.first>0) q.push(kom2);
        if (kom3.first>0) q.push(kom3);
    }
    cout << ans.size() << endl;
    for (int i=0;i<ans.size();i++)
    {
        cout << ans[i].first << " " << ans[i].second.first << " " << ans[i].second.second << endl;
    }
}

/* Sat Feb 10 2018 11:05:01 GMT+0300 (MSK) */


#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second

using namespace std;

struct str
{
    int x;
    int y;
    int z;
};

const int N=1e5+10;

int r[N];

int main()
{

    ios_base::sync_with_stdio(0);

    int n;
    cin>>n;

    for (int i=1; i<=n; i++){
        cin>>r[i];
    }

    sort(r+1, r+n+1);

    vector<pair<int, int> > v;
    int lst=0;
    for (int i=1; i<=n; i++){
        if (r[i]!=lst){
            v.push_back(make_pair(r[i], 1)); lst=r[i];
        }
        else {
            v[v.size()-1].S++;
        }
    }

    int p1=0, p2=1, p3=2, s=v.size(); vector<str> ans;
    while (p1<s && p2<s && p3<s){

        if (v[p1].S==0){
            while (p1<s && v[p1].S==0){
                p1++;
            }
            if (p1>=s){
                break;
            }
            p2=p1+1;
            while (p2<s && v[p2].S==0){
                p2++;
            }
            if (p2>=s){
                break;
            }
            p3=p2+1;
            while (p3<s && v[p3].S==0){
                p3++;
            }
            if (p3>=s){
                break;
            }
        }
        else if (v[p2].S==0){
            while (p2<s && v[p2].S==0){
                p2++;
            }
            if (p2>=s){
                break;
            }
            p3=p2+1;
            while (p3<s && v[p3].S==0){
                p3++;
            }
            if (p3>=s){
                break;
            }
        }
        else if (v[p3].S==0){
            while (p3<s && v[p3].S==0){
                p3++;
            }
            if (p3>=s){
                break;
            }
        }

        str g;
        g.x=v[p1].F; g.y=v[p2].F; g.z=v[p3].F;
        ans.push_back(g);

        v[p1].S--; v[p2].S--; v[p3].S--;

    }

    cout<<ans.size()<<"\n";
    for (auto x: ans){
        cout<<x.z<<" "<<x.y<<" "<<x.x<<"\n";
    }

    return 0;
}

/* Sat Feb 10 2018 09:57:41 GMT+0300 (MSK) */


#include <bits/stdc++.h>

using namespace std;

int const N  = 1e5 + 7;

int  n, ans, sn[N], nac;

struct abc{
    int f;
    int s;
    int tr;
} otv[N];

vector <int> komu, mark;
int main() {

    /*freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);*/

    ios_base :: sync_with_stdio(0);

    cin >> n;

    for (int  i = 1; i <= n; i++) {
        cin >> sn[i];
    }

    sort (sn + 1, sn + n + 1);

    for (int i = 1; i <= n; i++) {
        if (sn[i] == sn[i-1]) {
            mark[komu.size() - 1] ++;
            continue;
        }

        komu.push_back(sn[i]); mark.push_back(1);
    }

    int l = komu[0]; int r = komu [1];
    int kl = mark[0]; int kr = mark[1];

    for (int i = 2 ;i < komu.size(); i++) {
        int kol;
        kol = min(mark[i], kl);
        kol = min(kr, kol);
        for (int j = 1; j <= kol; j++) {
            ans++;
            otv[ans].f = komu[i]; otv[ans].s = r; otv[ans].tr = l;
            kl --; kr --; mark[i] --;
        }

        int pr1; int pr2; int pk1; int pk2;

        if (kl == 0) {
            for (int j = i; j < komu.size(); j++) {
                if (mark[j] != 0) {
                    pr1 = komu[j];
                    pk1 = mark[j];
                    mark[j] = 0;
                    break;
                }
            }
            l = pr1; kl = pk1;
        }

        if (kr == 0) {
            for (int j = i; j < komu.size(); j++) {
                if (mark[j] != 0) {
                    pr2 = komu[j];
                    pk2 = mark[j];
                    mark[j] = 0;
                    break;
                }
            }
            r = pr2; kr = pk2;
        }

    }

    cout << ans << endl;

    for (int i = 1; i <= ans; i++) {
        cout << otv[i].f << ' ' << otv[i].s << ' ' << otv[i].tr << endl;
    }

    return 0;
}

/* Sat Feb 10 2018 11:51:46 GMT+0300 (MSK) */


#include <bits/stdc++.h>

using namespace std;

int const N  = 1e5 + 7;

int  n, ans, sn[N], nac;

struct abc{
    int f;
    int s;
    int tr;
} otv[N];

vector <int> komu, mark;
int main() {

    /*freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);*/

    ios_base :: sync_with_stdio(0);

    cin >> n;

    for (int  i = 1; i <= n; i++) {
        cin >> sn[i];
    }

    sort (sn + 1, sn + n + 1);

    for (int i = 1; i <= n; i++) {
        if (sn[i] == sn[i-1]) {
            mark[komu.size() - 1] ++;
            continue;
        }

        komu.push_back(sn[i]); mark.push_back(1);
    }

    int l = komu[0]; int r = komu [1];
    int kl = mark[0]; int kr = mark[1];

    for (int i = 2 ;i < komu.size(); i++) {
        int kol;
        kol = min(mark[i], kl);
        kol = min(kr, kol);
        for (int j = 1; j <= kol; j++) {
            ans++;
            otv[ans].f = l; otv[ans].s = r; otv[ans].tr = komu[i];
            kl --; kr --; mark[i] --;
        }

        int pr1; int pr2; int pk1; int pk2;

        if (kl == 0) {
            for (int j = i; j < komu.size(); j++) {
                if (mark[j] != 0) {
                    pr1 = komu[j];
                    pk1 = mark[j];
                    mark[j] = 0;
                    break;
                }
            }
            l = pr1; kl = pk1;
        }

        if (kr == 0) {
            for (int j = i; j < komu.size(); j++) {
                if (mark[j] != 0) {
                    pr2 = komu[j];
                    pk2 = mark[j];
                    mark[j] = 0;
                    break;
                }
            }
            r = pr2; kr = pk2;
        }

    }

    cout << ans << endl;

    for (int i = 1; i <= ans; i++) {
        cout << otv[i].f << ' ' << otv[i].s << ' ' << otv[i].tr << endl;
    }

    return 0;
}

/* Sat Feb 10 2018 11:50:06 GMT+0300 (MSK) */


#include <bits/stdc++.h>
#include <fstream>

using namespace std;

struct f
{
    int x,y;
    f(){}
    f(int x,int y)
    :x(x),y(y){}
};

long long l,r,i,j,n,m,k,ans1,ans2,x,y,f2,kol,mi=-1e9,ma=-1e9;
int a[100010][3];
string s,s1;
map <int,int> mp;
priority_queue <pair<int,int> > q;
map<int, int> p;

int main()
{
    ios_base::sync_with_stdio(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
	cin>>n;
	for(int i=0;i<n;i++) {
		int x;
        cin>>x;
        mp[x]++;
	}
	map<int, int>::iterator it;
	for(it=mp.begin(); it!=mp.end();it++)
		q.push(make_pair(it->second, it->first));
	while (q.size() >= 3) {
		pair <int,int> x=q.top(); q.pop();
		pair <int,int> y=q.top(); q.pop();
		pair <int,int> z=q.top(); q.pop();
		a[k][0] = x.second;
		a[k][1] = y.second;
		a[k][2] = z.second;
		sort(a[k], a[k]+3);
		k++;
		if (--x.first > 0) q.push(x);
		if (--y.first > 0) q.push(y);
		if (--z.first > 0) q.push(z);
	}
	cout<<k<<endl;
	for(int i=0;i<k;i++)
		cout<<a[i][2]<<' '<<a[i][1]<<' '<<a[i][0]<<endl;
}

/* Sat Feb 10 2018 11:59:49 GMT+0300 (MSK) */


#include <bits/stdc++.h>

#define F first
#define S second
#define ll long long
#define p_b push_back
#define m_p make_pair
#define pii pair <int, int>

using namespace std;

const int  N = 3e5 + 5, INF = 1e9 + 7;

ll n, i, j;
ll m, k, s, ans;
ll a[N], b[N];
vector <int> v1, v2, v3;
string st;
struct S {
    int x, y, z;
    S(){}
    S(int x, int y, int z)
    :x(x), y(y), z(z){}
};
vector <S> v;
set <int> ss;
set <int> :: iterator it;

int main()
{
    //freopen("dwarfs.in", "r", stdin);
    //freopen("dwarfs.out", "w", stdout);

    ios_base::sync_with_stdio(0);

    cin >> n;
    for (i = 1; i <= n; i++)
    {
        ll t;
        cin >> t;
        ss.insert(-t);
    }
    while (ss.size() >= 3)
    {
        int a = *(ss.begin());
        ss.erase(ss.find(a));

        it = ss.upper_bound(a);
        if (it == ss.end()) break;
        int b = *(it);
        ss.erase(it);

        it = ss.upper_bound(b);
        if (it == ss.end()) break;
        int c = *(it);
        ss.erase(it);

        v.p_b(S(-a, -b, -c));
    }
    cout << v.size() << endl;
    for (i = 0; i < v.size(); i++)
    {
        cout << v[i].x << ' ' << v[i].y << ' ' << v[i].z << endl;
    }
}

/* Sat Feb 10 2018 11:43:12 GMT+0300 (MSK) */


#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second

using namespace std;

struct str
{
    int x;
    int y;
    int z;
};

const int N=1e5+10;

int r[N];

int main()
{

    ios_base::sync_with_stdio(0);

    int n;
    cin>>n;

    for (int i=1; i<=n; i++){
        cin>>r[i];
    }

    sort(r+1, r+n+1);
    reverse(r+1, r+n+1);

    vector<pair<int, int> > v;
    int lst=0;
    for (int i=1; i<=n; i++){
        if (r[i]!=lst){
            v.push_back(make_pair(r[i], 1)); lst=r[i];
        }
        else {
            v[v.size()-1].S++;
        }
    }

    int p1=0, p2=1, p3=2, s=v.size(); vector<str> ans;
    while (p1<s && p2<s && p3<s){

        if (v[p1].S==0){
            while (p1<s && v[p1].S==0){
                p1++;
            }
            if (p1>=s){
                break;
            }
            p2=p1+1;
            while (p2<s && v[p2].S==0){
                p2++;
            }
            if (p2>=s){
                break;
            }
            p3=p2+1;
            while (p3<s && v[p3].S==0){
                p3++;
            }
            if (p3>=s){
                break;
            }
        }
        else if (v[p2].S==0){
            while (p2<s && v[p2].S==0){
                p2++;
            }
            if (p2>=s){
                break;
            }
            p3=p2+1;
            while (p3<s && v[p3].S==0){
                p3++;
            }
            if (p3>=s){
                break;
            }
        }
        else if (v[p3].S==0){
            while (p3<s && v[p3].S==0){
                p3++;
            }
            if (p3>=s){
                break;
            }
        }

        str g;
        g.x=v[p1].F; g.y=v[p2].F; g.z=v[p3].F;
        ans.push_back(g);

        v[p1].S--; v[p2].S--; v[p3].S--;

    }

    cout<<ans.size()<<"\n";
    for (auto x: ans){
        cout<<x.x<<" "<<x.y<<" "<<x.z<<"\n";
    }

    return 0;
}

/* Sat Feb 10 2018 10:03:04 GMT+0300 (MSK) */


/*
    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 arr[ M ] , n , ans[ M ] , res ;
bool check ( int x ){
    res = 0 ; int ase = 0;
    fr( i , 1 , n , 1 ){
        if( arr[ i ] == arr[ i - 1 ] ) ase++ ;
        else ase = 1 ;
        if( ase <= x ) ans[ ++res ] = arr[ i ] ;
    }
    return res / 3 >= x ;
}
int main(){
    int tc = 1 ;
    while( tc-- ){
         n = Int ;
        fr( i , 1 , n , 1 ) arr[ i ] = Int ;
        sort( arr + 1  , arr + 1 + n ) ;
        int l = 1 , h = n ;
        while( l <= h ){
            int m = l + ( h - l ) / 2 ;
            if( check( m ) ) l = m + 1 ;
            else h = m - 1 ;
        }
        pf("%d\n",res / 3 ) ;
        fr( i , 1 , res / 3 , 1 ){
            pf("%d %d %d\n", ans[ i + ( res / 3 ) * 2 ] , ans[ i + ( res / 3 ) ] , ans[ i ] ) ;
        }
    }
 done ;
}


/*
    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 arr[ M ] , n , ans[ M ] , res ;
bool check ( int x ){
    res = 0 ; int ase = 0;
    fr( i , 1 , n , 1 ){
        if( arr[ i ] == arr[ i - 1 ] ) ase++ ;
        else ase = 1 ;
        if( ase <= x ) ans[ ++res ] = arr[ i ] ;
    }
    return res / 3 >= x ;
}
int main(){
    int tc = 1 ;
    while( tc-- ){
         n = Int ;
        fr( i , 1 , n , 1 ) arr[ i ] = Int ;
        sort( arr + 1  , arr + 1 + n ) ;
        int l = 1 , h = n ;
        while( l <= h ){
            int m = l + ( h - l ) / 2 ;
            if( check( m ) ) l = m + 1 ;
            else h = m - 1 ;
        }
        check( l - 1 ) ;
    //    cout<<res<<endl;
        pf("%d\n",res / 3 ) ;
        fr( i , 1 , res / 3 , 1 ){
            pf("%d %d %d\n", ans[ i + ( res / 3 ) * 2 ] , ans[ i + ( res / 3 ) ] , ans[ i ] ) ;
        }
    }
 done ;
}


/*
    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 arr[ M ] , n , ans[ M ] , res ;
bool check ( int x ){
    res = 0 ; int ase = 0;
    fr( i , 1 , n , 1 ){
        if( arr[ i ] == arr[ i - 1 ] ) ase++ ;
        else ase = 1 ;
        if( ase <= x ) ans[ ++res ] = arr[ i ] ;
    }
    return res / 3 == x ;
}
int main(){
    int tc = 1 ;
    while( tc-- ){
         n = Int ;
        fr( i , 1 , n , 1 ) arr[ i ] = Int ;
        sort( arr + 1  , arr + 1 + n ) ;
        int l = 1 , h = n ;
        while( l <= h ){
            int m = l + ( h - l ) / 2 ;
            if( check( m ) ) l = m + 1 ;
            else h = m - 1 ;
        }
        check( l - 1 ) ;
    //    cout<<res<<endl;
        pf("%d\n",res / 3 ) ;
        fr( i , 1 , res / 3 , 1 ){
            pf("%d %d %d\n", ans[ i + ( res / 3 ) * 2 ] , ans[ i + ( res / 3 ) ] , ans[ i ] ) ;
        }
    }
 done ;
}


/*
    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 ;
        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() ){
          //   cout<<u<<"  "<<*id1<<" "<<*id2<<endl;
                v1.pb( u ) ; v1.pb( *id1 ) ; v1.pb( *id2 ) ;
                ans++ ;
                ms.erase( id2 ) ;
                ms.erase( id1 ) ;
            }
            ms.erase( ms.begin() ) ;
        }
        pf("%d\n",ans) ;
        fr( i , 1 , 3 * ans , 3 ){
            pf("%d %d %d\n",v1[ i + 1 ] , v1[ i ] , v1[ i - 1 ] ) ;
        }
    }
 done ;
}


/*
    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 ;
        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() ){
          //   cout<<u<<"  "<<*id1<<" "<<*id2<<endl;
                v1.pb( u ) ; v1.pb( *id1 ) ; v1.pb( *id2 ) ;
                ans++ ;
                ms.erase( id2 ) ;
                ms.erase( id1 ) ;
            }
            ms.erase( ms.begin() ) ;
        }
        pf("%d\n",ans) ;
        fr( i , 1 , 3 * ans , 3 ){
            pf("%d %d %d\n",v1[ i - 1 ] , v1[ i ] , v1[ i + 1 ] ) ;
        }
    }
 done ;
}