There is a legend about a magical park with N × N trees. The trees are positioned in a square grid with Nrows (numbered from 1 to N from north to south) and N columns (numbered from 1 to N from west to east).The height (in metres) of each tree is an integer between 1 and N × N, inclusive. Magically, the height ofall trees is unique.Bunga is standing on the northmost point of the park and wants to count the number of visible trees for eachcolumn. Similarly, Lestari is standing on the westmost point of the park and wants to count the number ofvisible trees for each row. A tree X is visible if all other trees in front of the tree X are shorter than the treeX.For example, let N = 3 and the height (in metres) of the trees are as follows.6 1 87 5 32 9 4• On the first column, Bunga can see two trees, as the tree on the third row is obstructed by the othertrees.• On the second column, Bunga can see all three trees.• On the third column, Bunga can see only the tree on the first row, as the other trees are obstructed bythe tree on the first row.• On the first row, Lestari can see two trees, as the tree on the second column is obstructed by the treeon the first column.• On the second row, Lestari can see only the tree on the first column, as the other trees are obstructedby the tree on the first column.• On the third row, Lestari can see two trees, as the tree on the third column is obstructed by the tree onthe second column.Your task is to determine the numbers reported by Bunga and Lestari.InputInput begins with a line containing an integer: N (1 ≤ N ≤ 10) representing the number of trees on eachrow and column. The next N lines each contains N integers representing the height (in metres) of the trees.The jth integer on the ith line is the height of the tree on the ith row and jth column between 1 to N × N,inclusive. It is guaranteed that all trees have different heights.
OutputOutput begins with a line containing N integers representing the number of trees visible by Bunga. Thejth integer is the number of visible trees on the jth column. The next N lines each contains an integerrepresenting the number of trees visible by Lestari. The integer on the ith line is the number of visible treeson the ith row.
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here