# Problem Description
This is a matrix transformation problem where we need to rearrange rows of an N×3 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×3 matrix (first example)
   - 4×3 matrix (second example)
   - 6×3 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 3 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 (3 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, 5, 6],
          [7, 8, 9],
          [10, 11, 12]],
          [[1, 2, 3],
           [7, 8, 9],
           [4, 5, 6],
           [10, 11, 12]]
        ),
        ([[1, 2, 3],
          [4, 5, 6],
          [7, 8, 9],
          [10, 11, 12],
          [13, 14, 15],
          [16, 17, 18]],
          [[1, 2, 3],
           [7, 8, 9],
           [13, 14, 15],
           [4, 5, 6],
           [10, 11, 12],
           [16, 17, 18]]
        ),
        ([[10, 11, 12],
          [7, 8, 9],
          [4, 5, 6],
          [1, 2, 3]],
          [[10, 11, 12],
           [4, 5, 6],
           [7, 8, 9],
           [1, 2, 3]]),
        ([[1, 1, 1],
          [2, 2, 2],
          [3, 3, 3],
          [4, 4, 4],
          [5, 5, 5],
          [6, 6, 6],
          [7, 7, 7],
          [8, 8, 8],
          [9, 9, 9],
          [10, 10, 10],
          [11, 11, 11],
          [12, 12, 12]],
          [[1, 1, 1],
           [3, 3, 3],
           [5, 5, 5],
           [7, 7, 7],
           [9, 9, 9],
           [11, 11, 11],
           [2, 2, 2],
           [4, 4, 4],
           [6, 6, 6],
           [8, 8, 8],
           [10, 10, 10],
           [12, 12, 12]]
        ),
        ([[2, 4, 6],
          [1, 3, 5]],
         [[2, 4, 6],
          [1, 3, 5]])
    ]

    for i, (input_matrix, expected_output) in enumerate(test_cases):
        try:
            output = np.array(solution(np.array(input_matrix)))
        except Exception as e:
            error_message = (
                f"An exception occurred while running test case {i+1}:\n"
                f"`input_matrix`:\n{np.array(input_matrix)}\n\n"
                f"Exception: '{str(e)}'"
            )
            assert False, error_message
            
        if not np.array_equal(output, np.array(expected_output)):
            error_message = (
                f"The following Test Case {i+1} failed:\n"
                f"`input_matrix`:\n{np.array(input_matrix)}\n\n"
                f"Actual Output:\n{output}\n"
                f"Expected Output:\n{np.array(expected_output)}"
            )
            assert False, error_message

test()