Time limit
2s
Memory limit
128 MB
You want to draw a binary tree on a two-dimensional grid. Each vertex is placed on a grid point, and the root of the whole drawing is placed at the top-left corner of the used grid.
A drawing must satisfy the following conditions.
The area of a drawing is the product of the width and height of the grid needed to contain the whole drawing. Given the binary tree, compute the minimum possible area among all drawings that satisfy these conditions.
The first line contains the number of vertices n. (1 <= n <= 100)
The second line contains n integers separated by spaces. Assume that the preorder traversal of the binary tree is 1, 2, ..., n; the given sequence is the inorder traversal of that tree. The input is always a valid tree satisfying this condition.
Print the minimum possible area of a drawing that satisfies the conditions.