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;
int read_it() {
  string s;
  cin >> s;
  if (s == "?") {
    return -1;
  } else {
    return atoi(s.c_str());
  }
}
int pop(vector<int>& v) {
  int x = v.back();
  v.pop_back();
  return x;
}
int n;
int source, dest, fre, required, nodes;
int C[2 * 310][2 * 310], F[2 * 310][2 * 310], from[2 * 310];
vector<int> G[2 * 310];
bool viz[2 * 310];
vector<int> no_cycle[310], all_fre;
int pr[310];
class Cycle {
  int dim, max_level;
  vector<int> level[310], fre;
  bool empty() { return max_level == -1; }

 public:
  Cycle() : max_level(-1) {}
  Cycle(int dim) : dim(dim), max_level(-1) {}
  void add(int lvl, int i) {
    level[lvl].push_back(i);
    max_level = max(max_level, lvl);
  }
  void add_fre(int i) {
    fre.push_back(i);
    max_level = max(max_level, 0);
  }
  void pop(int lvl) {
    level[lvl].pop_back();
    int new_max_level = -1;
    for (int i = 0; i <= max_level; ++i) {
      if (!level[i].empty()) new_max_level = i;
    }
    if (!fre.empty()) {
      new_max_level = max(new_max_level, 0);
    }
    max_level = new_max_level;
  }
  int level_needs(int i) {
    if (empty()) return 0;
    if (i == 0) {
      if (level[0].empty()) return dim;
      int val = dim - (level[0].size() % dim);
      return val == dim ? 0 : val;
    } else {
      if (i > max_level) return 0;
      return (level[i].empty() ? 1 : 0);
    }
  }
  int needs() {
    if (empty()) return 0;
    int needs = 0;
    for (int i = 0; i <= max_level; ++i) {
      needs += level_needs(i);
    }
    needs -= fre.size();
    needs = max(needs, 0);
    return needs;
  }
  void wire() {
    if (empty()) return;
    for (int i = 0; i <= max_level; ++i) {
      while (level_needs(i)) {
        add(i, ::pop(fre));
      }
    }
    while (!fre.empty()) {
      add(1, ::pop(fre));
    }
    for (int i = 0; i < level[0].size(); i += dim) {
      for (int j = 0; j < dim; ++j) {
        int jj = (j + 1 == dim ? 0 : j + 1);
        pr[level[0][i + j]] = level[0][i + jj];
      }
    }
    for (int i = 1; i <= max_level; ++i) {
      for (auto el : level[i]) {
        pr[el] = level[i - 1][0];
      }
    }
  }
} cycle[310];
void add_edge(int x, int y, int c) {
  G[x].push_back(y);
  G[y].push_back(x);
  C[x][y] += c;
}
void build_graph() {
  source = (2 * n) + 1;
  dest = source + 1;
  fre = dest + 1;
  nodes = fre;
  for (int i = 1; i <= nodes; ++i) {
    G[i].clear();
    for (int j = 1; j <= nodes; ++j) {
      C[i][j] = F[i][j] = 0;
    }
  }
  for (int f = 0; f < n; ++f) {
    add_edge(source, f + 1, no_cycle[f].size());
  }
  for (int f = 0; f < n; ++f) {
    for (int c = 1; c <= n; ++c) {
      if (cycle[c].level_needs(f)) {
        add_edge(f + 1, c + n, cycle[c].level_needs(f));
      }
    }
  }
  add_edge(source, fre, all_fre.size());
  for (int c = 1; c <= n; ++c) {
    add_edge(fre, c + n, all_fre.size());
  }
  required = 0;
  for (int c = 1; c <= n; ++c) {
    add_edge(c + n, dest, cycle[c].needs());
    required += cycle[c].needs();
  }
}
void dfs(int x) {
  viz[x] = true;
  for (auto y : G[x]) {
    if (!viz[y] && F[x][y] != C[x][y]) {
      from[y] = x;
      dfs(y);
    }
  }
}
bool find_path() {
  for (int i = 1; i <= nodes; ++i) {
    from[i] = viz[i] = 0;
  }
  dfs(source);
  return viz[dest];
}
int max_flow() {
  int flow = 0;
  while (find_path()) {
    int minf = 1e9;
    for (int i = dest; i != source; i = from[i]) {
      minf = min(minf, C[from[i]][i] - F[from[i]][i]);
    }
    flow += minf;
    for (int i = dest; i != source; i = from[i]) {
      F[from[i]][i] += minf;
      F[i][from[i]] -= minf;
    }
  }
  return flow;
}
int main() {
  cin >> n;
  int no_cycle_max = -1;
  for (int i = 1; i <= n; ++i) {
    cycle[i] = Cycle(i);
  }
  for (int i = 1; i <= n; ++i) {
    int x, y;
    x = read_it();
    y = read_it();
    if (x != -1 && y != -1) {
      cycle[y].add(x, i);
    } else if (y != -1) {
      cycle[y].add_fre(i);
    } else if (x != -1) {
      no_cycle[x].push_back(i);
      no_cycle_max = max(no_cycle_max, x);
    } else {
      all_fre.push_back(i);
    }
  }
  int repr_max = (no_cycle_max != -1 ? pop(no_cycle[no_cycle_max]) : -1);
  int keeper_of_max = 1;
  bool found = false;
  for (int i = 1; i <= n; ++i) {
    if (repr_max != -1) cycle[i].add(no_cycle_max, repr_max);
    build_graph();
    int f = max_flow();
    if (f == required) {
      found = true;
      keeper_of_max = i;
      break;
    }
    if (repr_max != -1) cycle[i].pop(no_cycle_max);
  }
  if (!found) {
    cout << "-1\n";
    return 0;
  }
  for (int f = 0; f < n; ++f) {
    for (int c = 1; c <= n; ++c) {
      while (F[f + 1][c + n]) {
        cycle[c].add(f, pop(no_cycle[f]));
        --F[f + 1][c + n];
      }
    }
    while (!no_cycle[f].empty()) {
      if (f != 0)
        cycle[keeper_of_max].add(f, pop(no_cycle[f]));
      else
        cycle[1].add(f, pop(no_cycle[f]));
    }
  }
  for (int c = 1; c <= n; ++c) {
    while (F[fre][c + n]) {
      cycle[c].add_fre(pop(all_fre));
      --F[fre][c + n];
    }
  }
  while (!all_fre.empty()) {
    cycle[1].add_fre(pop(all_fre));
  }
  for (int i = 1; i <= n; ++i) {
    cycle[i].wire();
  }
  for (int i = 1; i <= n; ++i) {
    cout << pr[i] << " ";
  }
}