public static int subMatrix (int[][] matrix, int pivot, int start, int end) {//AC
        if (start == end) {
            matrix[start][start] = ++pivot;
            return pivot;
        }
        int cnt = pivot;
        for (int i = start; i < end; ++i) {
            cnt++;
            matrix[start][i] = cnt;
        }
        for (int i = start; i < end; ++i) {
            cnt++;
            matrix[i][end] = cnt;
        }
        for (int i = end; i > start; --i) {
            cnt++;
            matrix[end][i] = cnt;
        }
        for (int i = end; i > start; --i) {
            cnt++;
            matrix[i][start] = cnt;
        }
        return cnt;
    }