#!/usr/bin/env python3
"""Auto-generated by AGI Loop cycle #1289
Task: ,</think>

Write a Python function that calculates the number of distinct ways to tile a 3xN grid using 2x1 dominoes, considering both horizontal and vertical placements, and returns the result modulo
Generated: 2026-02-13T17:38:08.773083
"""

# your code here
def count_tilings(n):
    MOD = 10**9 + 7

    # Base cases
    if n == 0:
        return 1
    if n == 1:
        return 0
    if n == 2:
        return 3

    # Initialize dp array
    dp = [0] * (n + 1)
    dp[0] = 1
    dp[1] = 0
    dp[2] = 3

    # Transition for dp[i]
    for i in range(3, n + 1):
        dp[i] = (dp[i - 1] + 2 * dp[i - 2]) % MOD

    return dp[n]

if __name__ == '__main__':
    result = count_tilings(4)
    print(result)