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;
inline int gi() {
  char c = getchar();
  while (c != '?' && (c < '0' || c > '9')) c = getchar();
  if (c == '?') return -1;
  int sum = 0;
  while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar();
  return sum;
}
const int maxn = 305, maxs = maxn * maxn, Inf = 1 << 30;
int n, d[maxn], l[maxn], _d[maxn], _l[maxn], vis[maxn], cnt[maxn], mx[maxn], md,
    ex[maxn][maxn], to[maxn], ps;
int len, x[maxs], y[maxs];
struct edge {
  int to, next, cap;
} e[500005];
int s, t, h[maxs], cur[maxs], tot, vs[maxs], dis[maxs];
vector<int> vec[maxn];
inline void clear() {
  tot = 1;
  memset(h + 1, 0, sizeof(int) * t);
}
inline void add(int u, int v, int w) {
  e[++tot] = (edge){v, h[u], w};
  h[u] = tot;
  e[++tot] = (edge){u, h[v], 0};
  h[v] = tot;
}
bool bfs() {
  memset(vs + 1, 0, sizeof(int) * t);
  dis[s] = 0;
  vs[s] = 1;
  static int l, r, u, q[maxs];
  l = 0;
  q[r = 1] = s;
  while (l < r) {
    u = q[++l];
    for (int i = h[u], v; v = e[i].to, i; i = e[i].next)
      if (!vs[v] && e[i].cap) {
        vs[v] = 1;
        dis[v] = dis[u] + 1;
        q[++r] = v;
      }
  }
  return vs[t];
}
int dfs(int u, int a) {
  if (u == t || !a) return a;
  int f, flow = 0;
  for (int &i = cur[u], v; v = e[i].to, i; i = e[i].next)
    if (dis[v] == dis[u] + 1 && (f = dfs(v, min(e[i].cap, a)))) {
      e[i].cap -= f;
      e[i ^ 1].cap += f;
      flow += f;
      a -= f;
      if (!a) break;
    }
  return flow;
}
int max_flow() {
  int res = 0;
  while (bfs()) {
    memcpy(cur + 1, h + 1, sizeof(int) * t);
    res += dfs(s, Inf);
  }
  return res;
}
void build() {
  for (int i = 1; i <= n; ++i) vec[l[i]].push_back(i);
  for (int i = 1; i <= n; ++i)
    if (!vec[i].empty()) {
      sort(vec[i].begin(), vec[i].end(),
           [](const int &a, const int &b) { return d[a] < d[b]; });
      int lst, j = 0, siz = vec[i].size();
      for (int k = 0; j < siz && !d[vec[i][j]]; j = k + 1) {
        while (k < siz - 1 && k - j + 1 < i && !d[vec[i][k + 1]]) ++k;
        for (int l = j; l < k; ++l) to[vec[i][l]] = vec[i][l + 1];
        to[vec[i][k]] = vec[i][j];
      }
      lst = vec[i][j - 1];
      for (; j < siz; ++j) {
        to[vec[i][j]] = lst;
        if (j < siz - 1 && d[vec[i][j]] != d[vec[i][j + 1]]) lst = vec[i][j];
      }
    }
  for (int i = 1; i <= n; ++i) printf("%d ", to[i]);
}
int main() {
  n = gi();
  for (int i = 1; i <= n; ++i) {
    d[i] = gi();
    l[i] = gi();
    if (~l[i]) {
      vis[l[i]] = 1;
      if (d[i] == 0) ++cnt[l[i]];
      if (~d[i]) ex[l[i]][d[i]] = 1;
      mx[l[i]] = max(mx[l[i]], d[i]);
    } else
      md = max(md, d[i]), ps = i;
  }
  memcpy(_d + 1, d + 1, sizeof(int) * n);
  memcpy(_l + 1, l + 1, sizeof(int) * n);
  for (int p = 1; p <= n; ++p) {
    int _vis = vis[p], _cnt = cnt[p], _ex = ex[p][md], _mx = mx[p];
    if (md) {
      vis[p] = 1;
      if (md == 0) ++cnt[md];
      if (~md) ex[p][md] = 1;
      mx[p] = max(mx[p], md);
    }
    len = 0;
    for (int i = 1; i <= n; ++i)
      if (vis[i]) {
        int rqr = !cnt[i] ? i : (cnt[i] + i - 1) / i * i;
        for (int j = cnt[i] + 1; j <= rqr; ++j) x[++len] = 0, y[len] = i;
        for (int j = 1; j <= mx[i]; ++j)
          if (!ex[i][j]) x[++len] = j, y[len] = i;
      }
    s = n + len + 1;
    t = s + 1;
    clear();
    bool fl = 0;
    for (int i = 1; i <= n; ++i) {
      if (~l[i] && ~d[i]) continue;
      if (md && d[i] == md && !fl) {
        fl = 1;
        continue;
      }
      add(s, i, 1);
      for (int j = 1; j <= len; ++j)
        if ((d[i] == -1 || d[i] == x[j]) && (l[i] == -1 || l[i] == y[j]))
          add(i, j + n, 1);
    }
    for (int i = 1; i <= len; ++i) add(i + n, t, 1);
    if (max_flow() == len) {
      for (int u = 1; u <= n; ++u)
        for (int i = h[u], v; v = e[i].to, i; i = e[i].next)
          if (!e[i].cap && n + 1 <= v && v <= n + len) {
            d[u] = x[v - n];
            l[u] = y[v - n];
            break;
          }
      bool fl = 0;
      for (int i = 1; i <= n; ++i) {
        if (~l[i] && ~d[i]) continue;
        if (md && d[i] == md && !fl) {
          fl = 1;
          l[i] = p;
          continue;
        } else {
          if (!~l[i] && !~d[i])
            l[i] = 1, d[i] = 0;
          else if (~l[i])
            d[i] = 1;
          else if (!d[i])
            l[i] = 1;
          else
            l[i] = p;
        }
      }
      build();
      return 0;
    }
    vis[p] = _vis;
    cnt[p] = _cnt;
    mx[p] = _mx;
    ex[p][md] = _ex;
    memcpy(d + 1, _d + 1, sizeof(int) * n);
    memcpy(l + 1, _l + 1, sizeof(int) * n);
  }
  puts("-1");
  return 0;
}