# 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: Even-numbered (1-indexed) rows (2nd, 4th) are grouped at the top, followed by odd-numbered rows (1st, 3rd)
   - For N=6: Even-numbered (1-indexed) rows (2nd, 4th, 6th) are grouped at the top, followed by odd-numbered rows (1st, 3rd, 5th)

2. **General Transformation Rules**:
   - If matrix has only 2 rows (N=2), no transformation is needed
   - For matrices with N>2 rows:
     * All even-numbered (1-indexed) rows move to the first half of the matrix
     * All odd-numbered (1-indexed) 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 even-indexed rows (1-indexed) from original matrix
     * Last N/2 rows: Contains odd-indexed rows (1-indexed) 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]
    odd_rows = input_matrix[1:n:2, :]
    even_rows = input_matrix[0:n:2, :]
    result_matrix = np.vstack((odd_rows, even_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]],
         [[4, 5, 6],
          [10, 11, 12],
          [1, 2, 3],
          [7, 8, 9]]
         ),

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

        ([[10, 11, 12],
          [7, 8, 9],
          [4, 5, 6],
          [1, 2, 3]],
         [[7, 8, 9],
          [1, 2, 3],
          [10, 11, 12],
          [4, 5, 6]]),

        ([[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]],
         [[2, 2, 2],
          [4, 4, 4],
          [6, 6, 6],
          [8, 8, 8],
          [10, 10, 10],
          [12, 12, 12],
          [1, 1, 1],
          [3, 3, 3],
          [5, 5, 5],
          [7, 7, 7],
          [9, 9, 9],
          [11, 11, 11]]
         ),
        ([[2, 4, 6],
          [1, 3, 5]],
         [[1, 3, 5],
          [2, 4, 6]])
    ]
    for test_case in test_cases:
        input_matrix, expected_output = test_case
        try:
            output = solution(input_matrix)
        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
            
        if not np.array_equal(np.array(output), np.array(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{np.array(output)}\n"
                f"Expected Output:\n{np.array(expected_output)}"
            )
            assert False, error_message

test()