Mars rover

题意翻译

给定一棵有根树,令根节点为1,有$n$个节点。 每个节点有五种形式:AND表示对两个子节点进行与运算,OR表示对两个子节点进行或运算,XOR表示对两个子节点进行异或运算,NOT表示对子节点(只有一个)进行非运算。特殊地,IN表示这个节点是叶子节点,它的初值($0/1$)由读入决定。 现在,你要依次对每个叶子节点进行改变,改变其$0/1$状态,并按叶节点编号顺序,分别输出改变叶节点的状态后,根节点的值是$0$还是$1$。

题目描述

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.

输入输出格式

输入格式


The first line contains a single integer $ n $ ( $ 2 \le n \le 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 $ .

输出格式


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.

输入输出样例

输入样例 #1

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

输出样例 #1

10110

说明

The original scheme from the example (before the input is changed): ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1010D/12e9ee861137e7cc1d9adb641b01a0e9e6b988c2.png) 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 $ .