Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ACM-ICPC mode for virtual contests.
If you've seen these problems, a virtual contest is not for you - solve these problems in the archive.
If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive.
Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.

No tag edit access

D. Recover a functional graph

time limit per test

2 secondsmemory limit per test

256 megabytesinput

standard inputoutput

standard outputFunctional 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

The first line contains single integer *n* (1 ≤ *n* ≤ 300) — the number of vertices in the graph.

Each of the next *n* lines contain two integers — *precycle*_{i} (0 ≤ *precycle*_{i} ≤ *n* - 1) and *cycle*_{i} (1 ≤ *cycle*_{i} ≤ *n*). There could be question marks instead of some of these values.

Output

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.

Examples

Input

3

0 3

0 3

? ?

Output

2 3 1

Input

5

3 2

? ?

? ?

? ?

? ?

Output

5 3 2 2 4

Input

8

? 3

? ?

0 2

0 2

0 3

0 3

0 3

3 3

Output

5 1 4 3 6 7 5 2

Input

1

? ?

Output

1

Input

6

0 3

0 3

0 3

0 3

0 3

0 3

Output

2 3 1 5 6 4

Input

2

1 1

1 1

Output

-1

Codeforces (c) Copyright 2010-2018 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: May/21/2018 11:55:30 (d2).

Desktop version, switch to mobile version.

User lists

Name |
---|