CF739D Recover a functional graph
Description
Functional graph is a directed graph in which all vertices have outdegree equal to $ 1 $ . Loops are allowed.
Some vertices of a functional graph lay on a cycle. From the others we can come to a cycle by making a finite number of steps along the edges (we consider only finite functional graphs in this problem).
Let's compute two values for each vertex. $ precycle_{i} $ is the amount of edges we should pass to get to a vertex which is a part of some cycle (zero, if $ i $ itself lies on a cycle), $ cycle_{i} $ is the length of the cycle we get to.
You are given the information about these values for some functional graph. For each vertex you know the values $ precycle_{i} $ and $ cycle_{i} $ , however, instead of some values there can be the question mark. It means that these values are unknown.
Build any functional graph that suits the description or determine that there is no such graph.
Input Format
The first line contains single integer $ n $ ( $ 1
Output Format
In case there is no solution, print -1.
Otherwise, print $ n $ integers. $ i $ -th of them is the number of vertex to which the edge form the $ i $ -th vertex go.
The vertices should be in the same order as they go in input data.
If there are multiple solutions, print any of them.