main.py 511 B

12345678910111213141516171819
  1. def recurse(tree, id, min, max):
  2. if id >= len(tree):
  3. return True
  4. if tree[id] <= min or max <= tree[id]:
  5. return False
  6. return recurse(tree, id*2, min, tree[id]) and recurse(tree, id*2+1, tree[id], max)
  7. if __name__ == '__main__':
  8. line = input().strip().split(',')
  9. tree = [0]
  10. for l in line:
  11. if l == 'None':
  12. continue
  13. tree.append(int(l))
  14. if recurse(tree, 1, (1 << 32) * -1, 1 << 32 - 1):
  15. print('True')
  16. else:
  17. print('False')