#include <iostream>
#include <vector>

struct ArrNode {
  int data;
  int left;
  int right;

  ArrNode() : data(0), left(-1), right(-1) {}
  ArrNode(int data, int left, int right) : data(data), left(left), right(right) {}
};

class AVL { 
public:
    
    struct Node {
        int value;
        Node* left;
        Node* right;
        int height;
        Node() : left(nullptr), right(nullptr) {}
        Node(int value) : value(value), left(nullptr), right(nullptr), height(1) {}
    };
    
    int GetHeight(Node* node) {
        if (node == nullptr) return 0;  
        return node->height;  
    }

    void UpdateHeight(Node* node) {
        if (node->left == 0 && node->right == 0) {
            node->height = 0;
        }
        else {
            node->height = 1 + std::max(GetHeight(node->left), GetHeight(node->right));
        }
    }

    Node* Insert(Node* node, ArrNode value) {
        if (node->value == 0 || node == nullptr) {
            return new Node(value.data);
        }
        if (value.data < node->value) {
            node->left = Insert(node->left, value);
        }
        else if (value.data > node->value) {
            node->right = Insert(node->right, value);
        }
        else {
            return node;
        }

        node->height = 1 + std::max(GetHeight(node->left), GetHeight(node->right));
        return node;
    }

    Node* LeftRotation(Node* x) {  
      Node *y = x->right;  
      Node *T2 = y->left;  
   
    y->left = x;  
    x->right = T2;  
  
    x->height = std::max(GetHeight(x->left), GetHeight(x->right)) + 1;  
    y->height = std::max(GetHeight(y->left), GetHeight(y->right)) + 1;  
   
    return y; 
}

Node* RightRotation(Node* y) { 
  Node *x = y->left;  
    Node *T2 = x->right;  
  
    x->right = y;  
    y->left = T2;  
   
    y->height = std::max(GetHeight(y->left), GetHeight(y->right)) + 1;  
    x->height = std::max(GetHeight(x->left), GetHeight(x->right)) + 1;  
  
    return x;
  }

    bool Search(Node* node, int value) {
        if (node->value == 0) {
            return false;
        }
        if (value == node->value) {
            return true;
        }
        if (value < node->value) {
            return Search(node->left, value);
        }
        else {
            return Search(node->right, value);
        }
    }

    void Insert(ArrNode value) {
      root = Insert(root, value);
    }
    
    bool Search(int value) {
        return Search(root, value);
    }

    void Balance() {
      if (GetHeight(root->right->left) > GetHeight(root->right->right)) {
        root->right = RightRotation(root->right);
      }
      root = LeftRotation(root);
    }



   void PrintCurrentLevel(Node* root, int level, int& counter_childs, int& index, ArrNode arr[]) {
    if (root == nullptr) return;
    if (level == 1) {
      arr[index].data = root->value;
      if (root->left != nullptr) {
        arr[index].left = ++counter_childs;
      } else {
        arr[index].left = 0;
      }
      if (root->right != nullptr) {
        arr[index].right = ++counter_childs;
      } else {
        arr[index].right = 0;
      }
      ++index;
    }
    else if (level > 1) {
        PrintCurrentLevel(root->left, level - 1, counter_childs, index, arr);
        PrintCurrentLevel(root->right, level - 1, counter_childs, index, arr);
    }
}

void PrintLevelOrder(ArrNode arr[]) {
  int h = GetHeight(root);
  int counter_childs = 1;
  int index = 0;
  for (int i = 1; i <= h; i++) {
    PrintCurrentLevel(root, i, counter_childs, index, arr);
  }
}


private:
    Node* root;
};

int main() {
    int size;
    std::cin >> size;
    ArrNode arr[size];
    AVL avl;

    for (int i = 0; i < size; ++i) {
        int value, left_child, right_child;
        std::cin >> value >> left_child >> right_child;
        arr[i].data = value;
        arr[i].left = left_child;
        arr[i].right = right_child;
    }

    for (int i = 0; i < size; ++i) {
      avl.Insert(arr[i]);
    }
    // avl.Balance(); 

    // avl.PrintLevelOrder(arr);
    // for (int i = 0; i < size; ++i) {
    // std::cout << arr[i].data << ' ';
    // std::cout << arr[i].left << ' ';
    // std::cout << arr[i].right << '\n';
    // }
}


❯ ./main2
7
-2 7 2
8 4 3
9 0 0
3 5 6
0 0 0
6 0 0
-7 0 0
[1]    32306 segmentation fault  ./main2


почему?
НЕ НАДО ДЕЛАТЬ БАЛАНСИРОВКИ!!!!