Problem: 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. precyclei 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), cyclei 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 precyclei and cyclei, 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 — precyclei (0 ≤ precyclei ≤ n - 1) and cyclei (1 ≤ cyclei ≤ 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

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int N = 330, M = 100233;
int head[N * 2], dis[N * 2], q[N * 2];
int id[N][N], mx[N], cur[N];
int num[N], ANS[N];
struct lzh {
  int x, y;
} a[N], B[N * 2];
struct LZH {
  int x, y, q;
} Ans[N];
struct edge {
  int to, next, f;
} e[M];
int S, T, n, m, maxx, tot, at;
int read() {
  int x = 0;
  char ch = getchar();
  for (; ch < '0' || ch > '9'; ch = getchar())
    if (ch == '?') return -1;
  for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 - 48 + ch;
  return x;
}
bool cmp(LZH a, LZH b) { return a.y == b.y ? a.x < b.x : a.y < b.y; }
void add(int x, int y, int v) {
  e[++tot] = (edge){y, head[x], v};
  head[x] = tot;
  e[++tot] = (edge){x, head[y], 0};
  head[y] = tot;
}
bool bfs() {
  for (int i = (1); i <= (T); i++) dis[i] = -1;
  int h = 0, t = 1;
  q[1] = S;
  dis[S] = 0;
  while (h != t) {
    int x = q[++h];
    for (int i = head[x]; i; i = e[i].next)
      if (dis[e[i].to] == -1 && e[i].f) {
        dis[e[i].to] = dis[x] + 1;
        if (e[i].to == T) return 1;
        q[++t] = e[i].to;
      }
  }
  return 0;
}
int dfs(int x, int flow) {
  if (x == T) return flow;
  int k, rest = flow;
  for (int i = cur[x]; i && flow; i = e[i].next)
    if (dis[e[i].to] == dis[x] + 1 && e[i].f) {
      cur[x] = i;
      k = dfs(e[i].to, min(e[i].f, rest));
      e[i].f -= k;
      e[i ^ 1].f += k;
      rest -= k;
    }
  if (rest) dis[x] = -1;
  return flow - rest;
}
bool work() {
  S = n;
  tot = 1;
  int ans = 0, sum = 0;
  memset(head, 0, sizeof(head));
  memset(id, 0, sizeof(id));
  memset(mx, -1, sizeof(mx));
  memset(num, 0, sizeof(num));
  for (int i = (1); i <= (n); i++)
    if (a[i].y != -1) {
      if (a[i].x == 0) num[a[i].y]++;
      if (a[i].y) mx[a[i].y] = max(mx[a[i].y], 0);
      mx[a[i].y] = max(mx[a[i].y], a[i].x);
    }
  for (int i = (1); i <= (n); i++)
    for (int j = (0); j <= (mx[i]); j++) {
      id[i][j] = ++S;
      B[S].x = j;
      B[S].y = i;
    }
  S++;
  T = S + 1;
  for (int i = (1); i <= (n); i++)
    if (a[i].x == 0 && a[i].y != -1)
      add(S, i, 0);
    else
      add(S, i, 1);
  for (int i = (1); i <= (n); i++)
    if (mx[i] > -1) {
      int k = i;
      for (; k < num[i]; k += i)
        ;
      add(id[i][0], T, k - num[i]);
      sum += k - num[i] + mx[i];
      for (int j = (1); j <= (mx[i]); j++) add(id[i][j], T, 1);
    }
  if (sum > n) return 0;
  for (int i = (1); i <= (n); i++)
    if (a[i].x != -1 && a[i].y != -1) {
      if (!a[i].x)
        add(i, id[a[i].y][a[i].x], 0);
      else
        add(i, id[a[i].y][a[i].x], 1);
    } else if (a[i].x == -1 && a[i].y == -1) {
      for (int j = (n + 1); j <= (S - 1); j++) add(i, j, 1);
    } else if (a[i].x != -1) {
      for (int j = (1); j <= (n); j++)
        if (id[j][a[i].x]) add(i, id[j][a[i].x], 1);
    } else {
      for (int j = (0); j <= (n); j++)
        if (id[a[i].y][j]) add(i, id[a[i].y][j], 1);
    }
  while (bfs()) {
    for (int i = (1); i <= (T); i++) cur[i] = head[i];
    ans += dfs(S, 1e9);
  }
  if (ans != sum) return 0;
  for (int i = (1); i <= (n); i++) {
    int k;
    Ans[i].q = i;
    if (!e[i * 2].f) {
      for (k = head[i]; k; k = e[k].next)
        if (e[k].to != S && !e[k].f) {
          Ans[i].x = B[e[k].to].x;
          Ans[i].y = B[e[k].to].y;
          break;
        }
    } else {
      for (k = head[i]; k; k = e[k].next)
        if (e[k].to != S && B[e[k].to].x) {
          Ans[i].x = B[e[k].to].x;
          Ans[i].y = B[e[k].to].y;
          break;
        }
      if (!k) {
        if (a[i].x <= 0 && a[i].y == -1) {
          Ans[i].x = 0;
          Ans[i].y = 1;
          continue;
        }
        if (a[i].x == -1 && a[i].y != -1) {
          Ans[i].x = 1;
          Ans[i].y = a[i].y;
          continue;
        }
        return 0;
      }
    }
  }
  sort(Ans + 1, Ans + n + 1, cmp);
  for (int i = (1); i <= (n); i++)
    if (Ans[i].x == 0) {
      for (int j = (1); j <= (Ans[i].y - 1); j++)
        ANS[Ans[i + j].q] = Ans[i + j - 1].q;
      ANS[Ans[i].q] = Ans[i + Ans[i].y - 1].q;
      i += Ans[i].y - 1;
    } else {
      int j = i;
      while (Ans[j].x == Ans[j + 1].x && Ans[j].y == Ans[j + 1].y) j++;
      for (int k = (i); k <= (j); k++) ANS[Ans[k].q] = Ans[i - 1].q;
      i = j;
    }
  for (int i = (1); i <= (n); i++) printf("%d ", ANS[i]);
  return 1;
}
int main() {
  n = read();
  maxx = 0;
  for (int i = (1); i <= (n); i++) {
    a[i].x = read();
    a[i].y = read();
    if (a[i].x > maxx && a[i].y == -1) maxx = a[i].x, at = i;
  }
  if (work()) return 0;
  if (!at) return puts("-1"), 0;
  for (int i = (1); i <= (n); i++) {
    a[at].y = i;
    if (work()) return 0;
    a[at].y = -1;
  }
  puts("-1");
}