#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <map>
#include <iomanip>
typedef long long ll;
typedef long double ld;
using namespace std;
#define ff first
#define ss second
#define gigachad 1e9+7.0

int main() {
    ll n;
    cin>>n;
    ll k = log2(n+1)-1;

    map<ll,ll>mp, cnt;
    vector<ll>v(n), ch;
    set<ll>s;
    for(int i=0;i<n;i++){
        ll a;
        cin>>a;
        v[i]=a;
        mp[a]++;
        s.insert(a);
    }
    for(auto i : s)
        ch.push_back(i);
    if(mp.size() != pow(2,k)){
        cout<<-1;
        return 0;
    }
    for(auto i:mp)
        cnt[i.second]++;
    ll col=pow(2,k-1);
    cout<<k<<'\n';
    for(auto i :cnt)
        cout<<i.first<<" "<<i.second<<'\n';
    for(auto i:cnt){
        cout<<i.second<<" "<<col<<'\n';
        if(i.second == col && i.first != k + 1)
            col/=2;
        else if(i.first != k + 1 && i.second != col){
            cout<<-1;
            return 0;
        }
        else if(i.first == k + 1)
            break;
    }
    vector<pair<ll,ll>>a(n), b(n);
    for(int i=0;i<n;i++){
        a[i] = {mp[v[i]], v[i]};
    }
    sort(a.rbegin(),a.rend());
    for(int i=0;i<n;i++)
        b[i]={a[i].second,a[i].first};
    vector<ll>ans(pow(2,k), 0);
    sort(v.begin(),v.end());
    ans[0]=v[0];
    for(int i=1;i<n;i++){
        if(mp[ch[i]] == 1 && ans[i] == 0)
            ans[i]=ch[i];
        else if(i/2+1>=mp[1] - 1 && ans[i] == 0){
            ans[i]=ch[i];
        }
        else if(i/2+1<mp[1]- 1 && ans[mp[1] * 2 - 2 - mp[ch[i]]/2+1] == 0){
            ans[mp[1] * 2 - 2 - mp[ch[i]]/2+1]=ch[i];
        }
        else if(mp[ch[i]] == 1 && ans[i] != 0){
            for(int j=0;j<n;j++){
                if(ans[i]==0){
                    ans[i]=ch[i];
                    break;
                }
            }
        }
    }
    for(auto i:ans)
        cout<<i<<" ";
    return 0;
}
