You are given an integer n. Consider an equilateral triangle of side length n, broken up into n² unit equilateral triangles.
The triangle has n 1-indexed rows where the i-th row has 2i - 1 unit equilateral triangles. The triangles in the i-th row are also 1-indexed with coordinates from (i, 1) to (i, 2i - 1).
Two triangles are neighbors if they share a side. For example:
- Triangles
(1,1)and(2,2)are neighbors - Triangles
(3,2)and(3,3)are neighbors - Triangles
(2,2)and(3,3)are not neighbors because they do not share any side
Initially, all unit triangles are white. You want to choose k triangles and color them red. We will then run the following algorithm:
- Choose a white triangle that has at least two red neighbors
- If there is no such triangle, stop the algorithm
- Color that triangle red
- Go to step 1
Choose the minimum k possible and set k triangles red before running this algorithm such that after the algorithm stops, all unit triangles are colored red.
Return a 2D list of the coordinates of the triangles that you will color red initially. The answer has to be of the smallest size possible. If there are multiple valid solutions, return any.
Input & Output
Constraints
- 1 ≤ n ≤ 1000
- Triangle has n² unit triangles total
- Row i has 2i - 1 triangles