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 Maxn = 310;
const int inf = 1 << 23;
int _min(int x, int y) { return x < y ? x : y; }
int _max(int x, int y) { return x > y ? x : y; }
void read(int &x) {
  char ch = getchar();
  for (; ch < '0' || ch > '9'; ch = getchar())
    if (ch == '?') {
      x = -1;
      return;
    }
  for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
}
int n;
int prec[Maxn], cyc[Maxn];
int cs[Maxn], t[Maxn];
int num[Maxn][Maxn], u[Maxn][Maxn], maxx[Maxn];
vector<int> vec[Maxn];
struct node {
  int y, next, c, opp;
} a[Maxn * Maxn << 2];
int first[Maxn << 1], len, cnt;
void ins(int x, int y, int c) {
  len++;
  int k1 = len;
  a[len].y = y;
  a[len].c = c;
  a[len].next = first[x];
  first[x] = len;
  len++;
  int k2 = len;
  a[len].y = x;
  a[len].c = 0;
  a[len].next = first[y];
  first[y] = len;
  a[k1].opp = k2;
  a[k2].opp = k1;
}
int st, ed, h[Maxn << 1];
bool bfs() {
  queue<int> q;
  memset(h, -1, sizeof(h));
  h[st] = 0;
  q.push(st);
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (int k = first[x]; k; k = a[k].next) {
      int y = a[k].y;
      if (h[y] == -1 && a[k].c > 0) {
        h[y] = h[x] + 1;
        q.push(y);
      }
    }
  }
  return h[ed] > 0;
}
int dfs(int x, int flow) {
  if (x == ed) return flow;
  int delta = 0;
  for (int k = first[x]; k; k = a[k].next) {
    int y = a[k].y;
    if (h[y] == h[x] + 1 && a[k].c > 0 && flow - delta > 0) {
      int minf = dfs(y, _min(a[k].c, flow - delta));
      delta += minf;
      a[k].c -= minf;
      a[a[k].opp].c += minf;
    }
  }
  if (delta == 0) h[x] = -1;
  return delta;
}
int ans[Maxn];
void construct() {
  int i, j, k;
  for (i = 1; i <= n; i++) {
    if (prec[i] != -1 && cyc[i] != -1) {
      if (prec[i] == 0) vec[cyc[i]].push_back(i);
      u[cyc[i]][prec[i]] = i;
    }
  }
  for (i = 1; i <= n; i++) {
    if (vec[i].size() > 0) {
      for (j = 0; j < vec[i].size(); j += i) {
        for (k = 0; k < i; k++) ans[vec[i][j + k]] = vec[i][j + ((k + 1) % i)];
      }
    }
  }
  for (i = 1; i <= n; i++) {
    if (prec[i] == -1 && cyc[i] != -1) {
      ans[i] = u[cyc[i]][0];
    } else if (prec[i] != -1 && cyc[i] == -1) {
      if (prec[i] == 0)
        ans[i] = i;
      else
        for (j = 1; j <= n; j++)
          if (u[j][prec[i] - 1]) {
            ans[i] = u[j][prec[i] - 1];
            break;
          }
    } else if (prec[i] == -1 && cyc[i] == -1)
      ans[i] = i;
    else {
      if (prec[i] > 0) ans[i] = u[cyc[i]][prec[i] - 1];
    }
  }
  for (i = 1; i <= n; i++) printf("%d ", ans[i]);
}
int main() {
  int i, j, k;
  scanf("%d", &n);
  int po = 1;
  for (i = 1; i <= n; i++) {
    read(prec[i]);
    read(cyc[i]);
    if (prec[i] == 0 && cyc[i] != -1) cs[cyc[i]]++;
    if (cyc[i] != -1) t[cyc[i]]++;
    if (prec[i] != -1 && cyc[i] != -1) {
      u[cyc[i]][prec[i]] = i;
      maxx[cyc[i]] = _max(maxx[cyc[i]], prec[i]);
    }
    if (prec[i] > prec[po] || (prec[i] == prec[po] && cyc[i] != -1)) po = i;
  }
  if (cyc[po] != -1) {
    int xq = 0;
    int st = 0;
    ed = 2 * n + 1;
    cnt = 0;
    memset(num, 0, sizeof(num));
    for (i = 1; i <= n && xq <= n; i++) {
      if (t[i] > 0) {
        if (cs[i] == 0)
          ins((num[i][0] = ++cnt) + n, ed, i), xq += i;
        else if (cs[i] % i != 0)
          ins((num[i][0] = ++cnt) + n, ed, i - (cs[i] % i)),
              xq += i - (cs[i] % i);
      }
    }
    for (i = 1; i <= n && xq <= n; i++) {
      if (t[i] > 0) {
        for (j = 1; j <= maxx[i] && xq <= n; j++) {
          if (!u[i][j]) {
            num[i][j] = ++cnt;
            xq++;
            ins(num[i][j] + n, ed, 1);
          }
        }
      }
    }
    if (xq > n) {
      printf("-1\n");
      return 0;
    }
    for (i = 1; i <= n; i++) {
      ins(st, i, 1);
      if (prec[i] == -1 && cyc[i] == -1) {
        for (j = 1; j <= cnt; j++) ins(i, j + n, 1);
      } else if (prec[i] == -1 && cyc[i] != -1) {
        for (j = 0; j <= maxx[cyc[i]]; j++)
          if (num[cyc[i]][j]) ins(i, num[cyc[i]][j] + n, 1);
      } else if (prec[i] != -1 && cyc[i] == -1) {
        for (j = 1; j <= n; j++)
          if (num[j][prec[i]]) ins(i, num[j][prec[i]] + n, 1);
      }
    }
    int delta = 0;
    while (bfs()) delta += dfs(st, inf);
    if (delta == xq) {
      for (i = 1; i <= n; i++) {
        for (j = 0; j <= maxx[i]; j++) {
          if (!num[i][j]) continue;
          int x = num[i][j] + n;
          for (k = first[x]; k; k = a[k].next) {
            if (a[k].y <= n && a[k].c > 0) prec[a[k].y] = j, cyc[a[k].y] = i;
          }
        }
      }
      construct();
    } else
      printf("-1\n");
  } else {
    bool bk = false;
    for (int qq = 1; qq <= n && !bk; qq++) {
      int xq = 0;
      int st = 0;
      ed = 2 * n + 1;
      cnt = 0;
      len = 0;
      memset(first, 0, sizeof(first));
      memset(num, 0, sizeof(num));
      for (i = 1; i <= n && xq <= n; i++) {
        if (t[i] > 0 || i == qq) {
          if (cs[i] == 0)
            ins((num[i][0] = ++cnt) + n, ed, i), xq += i;
          else if (cs[i] % i != 0)
            ins((num[i][0] = ++cnt) + n, ed, i - (cs[i] % i)),
                xq += i - (cs[i] % i);
        }
      }
      for (i = 1; i <= n && xq <= n; i++) {
        if (t[i] > 0 || i == qq) {
          int r = maxx[i];
          if (i == qq) r = prec[po];
          for (j = 1; j <= r && xq <= n; j++) {
            if (!u[i][j]) {
              num[i][j] = ++cnt;
              xq++;
              ins(num[i][j] + n, ed, 1);
            }
          }
        }
      }
      if (xq > n) continue;
      for (i = 1; i <= n; i++) {
        ins(st, i, 1);
        if (prec[i] == -1 && cyc[i] == -1) {
          for (j = 1; j <= cnt; j++) ins(i, j + n, 1);
        } else if (prec[i] == -1 && cyc[i] != -1) {
          int r = maxx[cyc[i]];
          if (cyc[i] == qq) r = prec[po];
          for (j = 0; j <= r; j++)
            if (num[cyc[i]][j]) ins(i, num[cyc[i]][j] + n, 1);
        } else if (prec[i] != -1 && cyc[i] == -1) {
          for (j = 1; j <= n; j++)
            if (num[j][prec[i]]) ins(i, num[j][prec[i]] + n, 1);
        }
      }
      int delta = 0;
      while (bfs()) delta += dfs(st, inf);
      if (delta == xq) {
        for (i = 1; i <= n; i++) {
          int r = maxx[i];
          if (i == qq) r = prec[po];
          for (j = 0; j <= r; j++) {
            if (!num[i][j]) continue;
            int x = num[i][j] + n;
            for (k = first[x]; k; k = a[k].next) {
              if (a[k].y <= n && a[k].c > 0) prec[a[k].y] = j, cyc[a[k].y] = i;
            }
          }
        }
        maxx[qq] = prec[po];
        construct();
        bk = true;
      }
    }
    if (!bk) printf("-1");
  }
  return 0;
}