import java.util.Arrays;

public class SingleThread {

    private int[][] array;

    public SingleThread(int[][] array){
        this.array = array;
    }

    public int[][] OperationMatrixSingleThread(){
        int[][] result = operationMatrix(array);
        return result;
    }

    private int[][] operationMatrix(int[][] array) {
        if (array.length <= 1) {
            return array;
        }

        int mid = array.length / 2;
        int[][] left = Arrays.copyOfRange(array, 0, mid);
        int[][] right = Arrays.copyOfRange(array, mid, array.length);

        left = operationMatrix(left);
        right = operationMatrix(right);

        return merge(left, right);
    }

    private int[][] merge(int[][] left, int[][] right) {
        int[][] result = new int[left.length + right.length][];
        int i = 0, j = 0, k = 0;

        while (i < left.length && j < right.length) {
            if (findMaxElementRow(left[i]) >= findMaxElementRow(right[j])) {
                result[k++] = left[i++];
            } else {
                result[k++] = right[j++];
            }
        }

        while (i < left.length) {
            result[k++] = left[i++];
        }
        while (j < right.length) {
            result[k++] = right[j++];
        }

        return result;
    }
    private static int findMaxElementRow(int[] row){
        int maxCurrentValue = Integer.MIN_VALUE;
        for(int i = 0; i < row.length; i++){
            maxCurrentValue = (row[i] >= maxCurrentValue ? row[i] : maxCurrentValue);
        }
        return maxCurrentValue;
    }
}