import java.util.*;


public class Solution {
    /**
     *
     * @param root TreeNode类 the root of binary tree
     * @return int整型二维数组
     */
    public  static ArrayList<Integer> list;
    public void  pre(TreeNode root){
        if (root != null){
            list.add(root.val);
            pre(root.left);
            pre(root.right);
        }
    }
    public void  mid(TreeNode root){
        if (root != null){

            mid(root.left);
            list.add(root.val);
            mid(root.right);
        }
    }
    public void  last(TreeNode root){
        if (root != null){

            last(root.left);

            last(root.right);
            list.add(root.val);
        }
    }
    public int[][] threeOrders (TreeNode root) {
        list = new ArrayList<>();
        TreeNode node = root;
        pre(node);
        node = root;
        mid(node);
        node = root;
        last(node);

        int[][] resultArray = new int[3][list.size()/3];
        int count = 0;
        for (int i = 0 ; i < 3;i ++){
            for (int j = 0 ; j < list.size() / 3 ; j++){
                resultArray[i][j] = list.get(count);
                count++;
            }
        }
        return resultArray;

        // write code here
    }
}