You are given an array of n elements. Your task is to construct a segment tree recursively and calculate the value of each node in the tree. The value of each node represents the sum of the respective subarray it represents.
The first line of the input contains an integer n (1 ≤ n ≤ 100 000), representing the number of elements in the array.
The second line contains n space-separated integers (), representing the elements of the array.
Print the segment tree with all the values of the nodes. Each level of the segment tree should be printed on a separate line separated by a space.