> For the complete documentation index, see [llms.txt](https://mayanktyagi3111.gitbook.io/interview-prep/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mayanktyagi3111.gitbook.io/interview-prep/dynamic-programming/ways-to-color-a-3xn-board.md).

# Ways to color a 3xN Board

Given a **3 x A** board, find the number of ways to color it using at most **4** colors such that no **2** adjacent boxes have same color.

Diagonal neighbors are not treated as adjacent boxes.

Return the ways modulo **109 + 7** as the answer grows quickly.

**Input Format:**

```
The first and the only argument contains an integer, A.
```

**Output Format:**

```
Return an integer representing the number of ways to color the board.
```

**Constraints:**

```
1 <= A < 100000
```

**Examples:**

```
Input 1:
    A = 1

Output 1:
    36

Input 2:
    A = 2

Output 2:
    588
```

```java
public class Solution {
    public int solve(int A) {
        long color3 = 24;
        long color2 = 12;

        for (int i = 2; i <= A; i++) {
            long temp = color3;
            color3 = (11 * color3 + 10 * color2) % 1000000007;
            color2 = (5 * temp + 7 * color2) % 1000000007;
        }
        long ans = (color2 + color3) % 1000000007;

        return (int) ans;
    }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mayanktyagi3111.gitbook.io/interview-prep/dynamic-programming/ways-to-color-a-3xn-board.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
