given 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 (2
 inputs), OR (2
 inputs), XOR (2
 inputs), NOT (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≤106
) — 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
InputCopy
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
OutputCopy
10110


and the following code:

#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define filein freopen("input.in", "r", stdin);
#define fileout freopen("output.txt", "w", stdout);
#define ld long double
#define ll long long
#define ull unsigned long long
#define PI 3.14159265358979323846
#pragma GCC target("popcnt")
using namespace std;

const int N = 1e6+10;

struct node
{
    char i, type;
    bool state;
    bool done = false;
    node* ch[2];
};

bool getstate(node &x)
{
    if (x.done) return x.state;
    x.done = true;
    if (x.type == 0) return x.state = getstate(*x.ch[0]) && getstate(*x.ch[1]);
    if (x.type == 1) return x.state = getstate(*x.ch[0]) || getstate(*x.ch[1]);
    if (x.type == 2) return x.state = getstate(*x.ch[0]) ^ getstate(*x.ch[1]);
    return x.state = !getstate(*x.ch[0]);
}

string types[5] = {"AND", "OR", "XOR", "NOT", "IN"};
bool ans[N];

void dfs(node x)
{
    if (x.type == 4) ans[x.i-1] = true;
    else if (x.type == 0)
    {
        if (getstate(x)) dfs(*x.ch[0]), dfs(*x.ch[1]);
        else if (getstate(*x.ch[0])) dfs(*x.ch[1]);
        else if (getstate(*x.ch[1])) dfs(*x.ch[0]);
    }
    else if (x.type == 1)
    {
        if (!getstate(x)) dfs(*x.ch[0]), dfs(*x.ch[1]);
        else if (!getstate(*x.ch[0])) dfs(*x.ch[1]);
        else if (!getstate(*x.ch[1])) dfs(*x.ch[0]);
    }
    else if (x.type == 2) dfs(*x.ch[0]), dfs(*x.ch[1]);
    else dfs(*x.ch[0]);
}

int main()
{fastio
    int n, x, y;
    string s;
    cin >> n;
    bool output[n] = {};
    node *arr = new node[n+1];
    for (int i = 1; i <= n; i++)
    {
        cin >> s >> x;
        arr[i].type = find(types, types+5, s)-types;
        arr[i].i = i;
        if (s == "IN") arr[i].state = x, arr[i].done = true, output[i-1] = true;
        else
        {
            arr[i].ch[0] = arr+x;
            if (s != "NOT") cin >> y, arr[i].ch[1] = arr+y;
        }
    }
    dfs(arr[1]);
    for (int i = 0; i < n; i++) if (output[i]) cout << (ans[i]^getstate(arr[1]));
}

the code passes 17 test cases but fails on the 18th, what's the logical issue in the code?