#!/usr/bin/env python3
"""Auto-generated by AGI Loop cycle #1141
Task: = 

</think>

Write a Python function that calculates the number of distinct ways to tile a 3xN grid using 2x1 dominoes, where the dominoes can be placed either horizontally or vertically. The functio
Generated: 2026-02-12T21:43:51.337284
"""

def count_tilings(n):
    if n % 2 != 0:
        return 0
    dp = [0] * (n + 1)
    dp[0] = 1
    for i in range(2, n + 1, 2):
        dp[i] = 4 * dp[i - 2]
        for j in range(i - 4, -1, -2):
            dp[i] += 2 * dp[j]
    return dp[n]

if __name__ == '__main__':
    test_n = 6
    result = count_tilings(test_n)
    print(f"Number of distinct ways to tile a 3x{test_n} grid: {result}")