#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e6 + 5;
vector<int> G[MAX_N];
char tp[MAX_N];
bool val[MAX_N], ans[MAX_N];
void dfs1(int now, int par) {
  int nOo = 0;
  for (int nxt : G[now]) {
    if (nxt == par) continue;
    dfs1(nxt, now);
    nOo += val[nxt];
  }
  if (tp[now] == 'I')
    return;
  else if (tp[now] == 'X') {
    if (nOo == 1)
      val[now] = true;
    else
      val[now] = false;
  } else if (tp[now] == 'O') {
    if (nOo >= 1)
      val[now] = true;
    else
      val[now] = false;
  } else if (tp[now] == 'A') {
    if (nOo == 2)
      val[now] = true;
    else
      val[now] = false;
  } else {
    if (nOo == 1)
      val[now] = false;
    else
      val[now] = true;
  }
  return;
}
void dfs2(int now, int par, bool canchange) {
  if (tp[now] == 'I') {
    ans[now] = canchange ^ 1;
    return;
  }
  int nOo = 0;
  for (int nxt : G[now]) {
    if (nxt == par) continue;
    nOo += val[nxt];
  }
  for (int nxt : G[now]) {
    if (nxt == par) continue;
    if (canchange) {
      dfs2(nxt, now, true);
    } else {
      if (tp[now] == 'X') {
        dfs2(nxt, now, false);
      } else if (tp[now] == 'O') {
        if (nOo == 2)
          dfs2(nxt, now, true);
        else if (nOo == 0)
          dfs2(nxt, now, false);
        else {
          if (val[nxt])
            dfs2(nxt, now, false);
          else
            dfs2(nxt, now, true);
        }
      } else if (tp[now] == 'A') {
        if (nOo == 0)
          dfs2(nxt, now, true);
        else if (nOo == 2)
          dfs2(nxt, now, false);
        else {
          if (val[nxt])
            dfs2(nxt, now, true);
          else
            dfs2(nxt, now, false);
        }
      } else {
        dfs2(nxt, now, false);
      }
    }
  }
  return;
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    string t;
    int a, b;
    cin >> t;
    tp[i] = t[0];
    if (t[0] == 'I') {
      cin >> a;
      val[i] = a;
    } else if (t[0] == 'N') {
      cin >> a;
      G[i].push_back(a);
      G[a].push_back(i);
    } else {
      cin >> a >> b;
      G[i].push_back(a);
      G[i].push_back(b);
      G[a].push_back(i);
      G[b].push_back(i);
    }
  }
  dfs1(1, -1);
  dfs2(1, -1, false);
  for (int i = 1; i <= n; i++) {
    if (tp[i] == 'I') cout << (val[1] ^ (ans[i]));
  }
  cout << endl;
  return 0;
}

### Prompt

Generate a Cpp solution to the following problem:

Natasha travels around Mars in the Mars rover. But suddenly it broke down, namely — the logical scheme inside it. The scheme is an undirected tree (connected acyclic graph) with a root in the vertex 1, in which every leaf (excluding root) is an input, and all other vertices are logical elements, including the root, which is output. One bit is fed to each input. One bit is returned at the output.

There are four types of logical elements: [AND](https://en.wikipedia.org/wiki/Logical_conjunction) (2 inputs), [OR](https://en.wikipedia.org/wiki/Logical_disjunction) (2 inputs), [XOR](https://en.wikipedia.org/wiki/Exclusive_or) (2 inputs), [NOT](https://en.wikipedia.org/wiki/Negation) (1 input). Logical elements take values from their direct descendants (inputs) and return the result of the function they perform. Natasha knows the logical scheme of the Mars rover, as well as the fact that only one input is broken. In order to fix the Mars rover, she needs to change the value on this input.

For each input, determine what the output will be if Natasha changes this input.

Input

The first line contains a single integer n (2 ≤ n ≤ 10^6) — the number of vertices in the graph (both inputs and elements).

The i-th of the next n lines contains a description of i-th vertex: the first word "AND", "OR", "XOR", "NOT" or "IN" (means the input of the scheme) is the vertex type. If this vertex is "IN", then the value of this input follows (0 or 1), otherwise follow the indices of input vertices of this element: "AND", "OR", "XOR" have 2 inputs, whereas "NOT" has 1 input. The vertices are numbered from one.

It is guaranteed that input data contains a correct logical scheme with an output produced by the vertex 1.

Output

Print a string of characters '0' and '1' (without quotes) — answers to the problem for each input in the ascending order of their vertex indices.

Example

Input

10
AND 9 4
IN 1
IN 1
XOR 6 5
AND 3 7
IN 0
NOT 10
IN 1
IN 1
AND 2 8


Output

10110

Note

The original scheme from the example (before the input is changed):

<image>

Green indicates bits '1', yellow indicates bits '0'.

If Natasha changes the input bit 2 to 0, then the output will be 1.

If Natasha changes the input bit 3 to 0, then the output will be 0.

If Natasha changes the input bit 6 to 1, then the output will be 1.

If Natasha changes the input bit 8 to 0, then the output will be 1.

If Natasha changes the input bit 9 to 0, then the output will be 0.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e6 + 5;
vector<int> G[MAX_N];
char tp[MAX_N];
bool val[MAX_N], ans[MAX_N];
void dfs1(int now, int par) {
  int nOo = 0;
  for (int nxt : G[now]) {
    if (nxt == par) continue;
    dfs1(nxt, now);
    nOo += val[nxt];
  }
  if (tp[now] == 'I')
    return;
  else if (tp[now] == 'X') {
    if (nOo == 1)
      val[now] = true;
    else
      val[now] = false;
  } else if (tp[now] == 'O') {
    if (nOo >= 1)
      val[now] = true;
    else
      val[now] = false;
  } else if (tp[now] == 'A') {
    if (nOo == 2)
      val[now] = true;
    else
      val[now] = false;
  } else {
    if (nOo == 1)
      val[now] = false;
    else
      val[now] = true;
  }
  return;
}
void dfs2(int now, int par, bool canchange) {
  if (tp[now] == 'I') {
    ans[now] = canchange ^ 1;
    return;
  }
  int nOo = 0;
  for (int nxt : G[now]) {
    if (nxt == par) continue;
    nOo += val[nxt];
  }
  for (int nxt : G[now]) {
    if (nxt == par) continue;
    if (canchange) {
      dfs2(nxt, now, true);
    } else {
      if (tp[now] == 'X') {
        dfs2(nxt, now, false);
      } else if (tp[now] == 'O') {
        if (nOo == 2)
          dfs2(nxt, now, true);
        else if (nOo == 0)
          dfs2(nxt, now, false);
        else {
          if (val[nxt])
            dfs2(nxt, now, false);
          else
            dfs2(nxt, now, true);
        }
      } else if (tp[now] == 'A') {
        if (nOo == 0)
          dfs2(nxt, now, true);
        else if (nOo == 2)
          dfs2(nxt, now, false);
        else {
          if (val[nxt])
            dfs2(nxt, now, true);
          else
            dfs2(nxt, now, false);
        }
      } else {
        dfs2(nxt, now, false);
      }
    }
  }
  return;
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    string t;
    int a, b;
    cin >> t;
    tp[i] = t[0];
    if (t[0] == 'I') {
      cin >> a;
      val[i] = a;
    } else if (t[0] == 'N') {
      cin >> a;
      G[i].push_back(a);
      G[a].push_back(i);
    } else {
      cin >> a >> b;
      G[i].push_back(a);
      G[i].push_back(b);
      G[a].push_back(i);
      G[b].push_back(i);
    }
  }
  dfs1(1, -1);
  dfs2(1, -1, false);
  for (int i = 1; i <= n; i++) {
    if (tp[i] == 'I') cout << (val[1] ^ (ans[i]));
  }
  cout << endl;
  return 0;
}

```