Problem:
Score : 400 points

Problem Statement

Snuke has an empty sequence a.

He will perform N operations on this sequence.

In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1).

You are given a sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it.

Constraints

All values in input are integers.

1 \leq N \leq 100

1 \leq b_i \leq N

Input

Input is given from Standard Input in the following format:

N
b_1 \dots b_N

Output

If there is no sequence of N operations after which a would be equal to b, print -1.
If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted.

Sample Input 1

3
1 2 1

Sample Output 1

1
1
2

In this sequence of operations, the sequence a changes as follows:

After the first operation: (1)

After the second operation: (1,1)

After the third operation: (1,2,1)

Sample Input 2

2
2 2

Sample Output 2

-1

2 cannot be inserted at the beginning of the sequence, so this is impossible.

Sample Input 3

9
1 1 1 2 2 1 2 3 2

Sample Output 3

1
2
2
3
1
2
2
1
1

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

//#include "pch.h" 
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <stdio.h>
#include <vector>
#include <time.h>
#include <iomanip>
#include <thread>
#include <atomic>
#include <mutex>
#include <future>
#define double long double
#define int long long
#define low lower_bound
#define upp upper_bound
#define mod 1000000007 //10^9+7
#define inf 10000000000000000 //10^16
#define rep(i,n) for(int i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define vsort(vec) sort(all(vec))
#define vrever(vec) reverse(all(vec));
#define vunsort(vec) vsort(vec); vrever(vec);
#define bisea binary_search
using namespace std;
int n;
signed main() {
	cin >> n;
	vector<pair<int, int>>ans, cnt;
	int sum = n * (n + 1) / 2;
	int k=n;
	if (n % 2) k--;
	rep(i, k) {
		rep(j, k) {
			if (i != j) {
				if (i + j +2*(n%2)!= sum / (k / 2) - n / 2) {
					pair<int, int>a;
					a.first = i + 1;
					a.second = j + 1;
					ans.push_back(a);
					
				}
			}
		}
	}
	if (n % 2 == 1) {
		rep(i, ans.size()) {
			ans[i].first++;
			ans[i].second++;
		}
		rep(i, n - 1) {
			pair<int, int>a;
			a.first = 1;
			a.second = i + 2;
			ans.push_back(a);
		}
	}
	cnt = ans;
	rep(i, cnt.size()) {
		rep(j, cnt.size()) {
			if (i != j) {
				if (ans[i].first == ans[j].second&&ans[i].second == ans[j].first) {
					ans[i].first = 0;
					ans[i].second = 0;
				}
			}
		}
	}
	int cn = 0;
	rep(i, ans.size()) {
		if (ans[i].first) cn++;
	}
	cout << cn << endl;
	rep(i, ans.size()) {
		if (ans[i].first) {
			cout << ans[i].first << " " << ans[i].second << endl;
		}
	}
}