After becoming famous, the CodeBots decided to move into a new building together. Each of the rooms has a different cost, and some of them are free, but there's a rumour that all the free rooms are haunted! Since the CodeBots are quite superstitious, they refuse to stay in any of the free rooms, or any of the rooms below any of the free rooms.

Given matrix, a rectangular matrix of integers, where each value represents the cost of the room, your task is to return the total sum of all rooms that are suitable for the CodeBots (ie: add up all the values that don't appear below a 0).

Example

Input/Output

풀이

int solution(int[][] matrix) {
    // 결과 값
    int result = 0;
    boolean [] ban = new boolean [matrix[0].length];

    for (int i = 0; i < matrix.length; i ++) {
        for (int j = 0; j < matrix[i].length; j ++) {
            // 유령이 없던 열
            if (ban[j] == false) {
                // 코스트가 0 초과의 경우 결과값 누적
                if (matrix[i][j] > 0) result += matrix[i][j];
                // 0 이면 해당 열 체크
                else ban[j] = true;
            }
        }
    }
    
    return result;
}