# your code goes here
class Node:
def __init__(self):
self.left = None
self.right = None
self.num = -1
class Solution:
def insert(self, string, i, node, num):
if i == len(string):
node.num = num
return
if string[i] == "0":
if not node.left:
node.left = Node()
self.insert(string, i+1, node.left, num)
else:
if not node.right:
node.right = Node()
self.insert(string, i+1, node.right, num)
def search_max(self, string, i, node):
if i == len(string):
return node.num
if string[i] == "0":
if node.right:
return self.search_max(string, i+1, node.right)
else:
return self.search_max(string, i+1, node.left)
else:
if node.left:
return self.search_max(string, i+1, node.left)
else:
return self.search_max(string, i+1, node.right)
def convert_bin(self, num, b):
ans = ""
for _ in range(b):
ans += str(num%2)
num //= 2
return ans[::-1]
def QueryAnswer(self, arr):
pass
#Plz help implement this query function
IyB5b3VyIGNvZGUgZ29lcyBoZXJlCmNsYXNzIE5vZGU6CiAgICBkZWYgX19pbml0X18oc2VsZik6CiAgICAgICAgc2VsZi5sZWZ0ID0gTm9uZQogICAgICAgIHNlbGYucmlnaHQgPSBOb25lCiAgICAgICAgc2VsZi5udW0gPSAtMQoKY2xhc3MgU29sdXRpb246CgogICAgZGVmIGluc2VydChzZWxmLCBzdHJpbmcsIGksIG5vZGUsIG51bSk6CiAgICAgICAgaWYgaSA9PSBsZW4oc3RyaW5nKToKICAgICAgICAgICAgbm9kZS5udW0gPSBudW0KICAgICAgICAgICAgcmV0dXJuCiAgICAgICAgaWYgc3RyaW5nW2ldID09ICIwIjoKICAgICAgICAgICAgaWYgbm90IG5vZGUubGVmdDoKICAgICAgICAgICAgICAgIG5vZGUubGVmdCA9IE5vZGUoKQogICAgICAgICAgICBzZWxmLmluc2VydChzdHJpbmcsIGkrMSwgbm9kZS5sZWZ0LCBudW0pCiAgICAgICAgZWxzZToKICAgICAgICAgICAgaWYgbm90IG5vZGUucmlnaHQ6CiAgICAgICAgICAgICAgICBub2RlLnJpZ2h0ID0gTm9kZSgpCiAgICAgICAgICAgIHNlbGYuaW5zZXJ0KHN0cmluZywgaSsxLCBub2RlLnJpZ2h0LCBudW0pCgogICAgZGVmIHNlYXJjaF9tYXgoc2VsZiwgc3RyaW5nLCBpLCBub2RlKToKICAgICAgICBpZiBpID09IGxlbihzdHJpbmcpOgogICAgICAgICAgICByZXR1cm4gbm9kZS5udW0KICAgICAgICBpZiBzdHJpbmdbaV0gPT0gIjAiOgogICAgICAgICAgICBpZiBub2RlLnJpZ2h0OgogICAgICAgICAgICAgICAgcmV0dXJuIHNlbGYuc2VhcmNoX21heChzdHJpbmcsIGkrMSwgbm9kZS5yaWdodCkKICAgICAgICAgICAgZWxzZToKICAgICAgICAgICAgICAgIHJldHVybiBzZWxmLnNlYXJjaF9tYXgoc3RyaW5nLCBpKzEsIG5vZGUubGVmdCkKICAgICAgICBlbHNlOgogICAgICAgICAgICBpZiBub2RlLmxlZnQ6CiAgICAgICAgICAgICAgICByZXR1cm4gc2VsZi5zZWFyY2hfbWF4KHN0cmluZywgaSsxLCBub2RlLmxlZnQpCiAgICAgICAgICAgIGVsc2U6CiAgICAgICAgICAgICAgICByZXR1cm4gc2VsZi5zZWFyY2hfbWF4KHN0cmluZywgaSsxLCBub2RlLnJpZ2h0KQogICAgICAgIAoKCgogICAgZGVmIGNvbnZlcnRfYmluKHNlbGYsIG51bSwgYik6CiAgICAgICAgYW5zID0gIiIKICAgICAgICBmb3IgXyBpbiByYW5nZShiKToKICAgICAgICAgICAgYW5zICs9IHN0cihudW0lMikKICAgICAgICAgICAgbnVtIC8vPSAyCiAgICAgICAgcmV0dXJuIGFuc1s6Oi0xXQogICAgICAgICAgICAKICAgIGRlZiBRdWVyeUFuc3dlcihzZWxmLCBhcnIpOgogICAgCXBhc3MKICAgICNQbHogaGVscCBpbXBsZW1lbnQgdGhpcyBxdWVyeSBmdW5jdGlvbiA=