# Problem Description
This is a matrix transformation problem where we need to rearrange rows of an N×4 matrix according to specific rules. The input matrix has an even number of rows (N is even), and we need to reorder these rows based on their position (odd/even-numbered rows) while maintaining certain patterns.

# Visual Facts
1. Each example shows a transformation of a matrix with 3 columns
2. Matrix dimensions shown in examples:
   - 2×4 matrix (first example)
   - 4×4 matrix (second example)
   - 6×4 matrix (third example)
3. All matrices contain sequential numbers starting from 0
4. The color coding shows three columns:
   - Left column (pink/salmon)
   - Middle column (green)
   - Right column (purple)
5. Each row has exactly 4 elements
6. The number of rows is always even
7. The original sequential ordering is preserved within each row

# Visual Patterns
1. **Row Reordering Pattern**:
   - For N=2: No change in row order
   - For N=4: Odd-numbered rows (1st, 3rd) are grouped at the top, followed by even-numbered rows (2nd, 4th)
   - For N=6: Odd-numbered rows (1st, 3rd, 5th) are grouped at the top, followed by even-numbered rows (2nd, 4th, 6th)

2. **General Transformation Rules**:
   - If matrix has only 2 rows (N=2), no transformation is needed
   - For matrices with N>2 rows:
     * All odd-numbered rows (1-based index) move to the first half of the matrix
     * All even-numbered rows move to the second half of the matrix
     * The relative order within odd and even groups is preserved

3. **Preservation Rules**:
   - Elements within each row stay in their original order
   - Column structure (4 columns) remains unchanged
   - The total number of rows remains unchanged
   - The grouping creates two sections: odd-indexed rows section and even-indexed rows section

4. **Mathematical Pattern**:
   - For a matrix with N rows, the transformation creates:
     * First N/2 rows: Contains odd-indexed rows from original matrix
     * Last N/2 rows: Contains even-indexed rows from original matrix

# Solution
from typing import List
import numpy as np

def solution(input_matrix: List[List[int]]) -> List[List[int]]:
    """
    Transform the given N*3 matrix as illustrated in the figure.
    
    Args:
        input_matrix: A 2D list where input_matrix[i][j] contains an integer. 
                      (i is in range [0, N-1], N % 2 == 0; j is in range [0, 2])
    
    Returns:
        A 2D list containing the transformed N*3 matrix.
    """
    input_matrix = np.array(input_matrix)
    n = input_matrix.shape[0]
    even_rows = input_matrix[0:n:2, :]
    odd_rows = input_matrix[1:n:2, :]
    result_matrix = np.vstack((even_rows, odd_rows))
    return result_matrix.tolist()


# Test Script
import numpy as np

def test():
    test_cases = [
        ([[1, 2, 3, 4], 
          [6, 7, 8, 9]],
         [[1, 2, 3, 4], 
          [6, 7, 8, 9]]),

        ([[1, 2, 3, 4], 
          [6, 7, 8, 9], 
          [11, 12, 13, 14], 
          [16, 17, 18, 19]],
         [[1, 2, 3, 4], 
          [11, 12, 13, 14], 
          [6, 7, 8, 9], 
          [16, 17, 18, 19]]
        ),

        ([[1, 2, 3, 4], 
          [6, 7, 8, 9], 
          [11, 12, 13, 14], 
          [16, 17, 18, 19], 
          [21, 22, 23, 24], 
          [26, 27, 28, 29]],
         [[1, 2, 3, 4], 
          [11, 12, 13, 14],
          [21, 22, 23, 24],
          [6, 7, 8, 9],
          [16, 17, 18, 19],
          [26, 27, 28, 29]]
        ),

        ([[1, 2, 3, 4], 
          [6, 7, 8, 9], 
          [11, 12, 13, 14], 
          [16, 17, 18, 19], 
          [21, 22, 23, 24]],
         [[1, 2, 3, 4], 
          [11, 12, 13, 14], 
          [21, 22, 23, 24], 
          [6, 7, 8, 9], 
          [16, 17, 18, 19]]
         ),

        ([[2, 4, 6, 8],
          [1, 3, 5, 7]],
         [[2, 4, 6, 8],
          [1, 3, 5, 7]])
    ]
    for input_matrix, expected_output in test_cases:
        try:
            output = solution(np.array(input_matrix))
            output = np.array(output)
            expected_output = np.array(expected_output)
            
            if not np.array_equal(output, expected_output):
                error_message = (
                    f"The following Test Case failed:\n"
                    f"`input_matrix`:\n{np.array(input_matrix)}\n\n"
                    f"Actual Output:\n{output}\n\n"
                    f"Expected Output:\n{expected_output}"
                )
                assert False, error_message
                
        except Exception as e:
            error_message = (
                f"An exception occurred while running the test case:\n"
                f"`input_matrix`:\n{np.array(input_matrix)}\n\n"
                f"Exception: '{str(e)}'"
            )
            assert False, error_message

test()