<|instruction|>
Solve the below problem. The solution should start with an abridged problem statement. Then key observations. Then full solution based on the observations. Then C++ and Python implementations with comments.

361. National Flag
Time limit per test: 0.25 second(s)
Memory limit: 65536 kilobytes
input: standard
output: standard



Series of bloody civil wars in Berland finished! After the long-awaited reunion it was decided to create new Berland flag. Berland Heraldic Council proposed following requirements:

1. Berland flag must be a rectangle of Nx M cells. Each cell must be painted with blue or red;

2. any 3x 2 or 2x 3 rectangle of the flag must have exactly two blue cells;

3. blue paint is very expensive, so the number of blue cells should as low as possible.

Write a program that creates Berland flag.

Input
Input file contains two integer numbers N and M (3 ≤ N, M ≤ 200) separated by a space.

Output
Print to the output file N lines with M characters on each line: j-th character on the i-th line must be 0 (zero) if the cell (i, j) painted with read, and "#" if it is blue. If there are several solutions output any of them. Print "No solution" (without quotes) if there is no solution.

Example(s)
sample input
sample output
3 3
#00 
00# 
0#0

<|response|>
1. Abridged Problem Statement  
Given integers N, M (3 ≤ N, M ≤ 200), color each cell of an N×M grid either red (‘0’) or blue (‘#’) so that every 3×2 or 2×3 sub‐rectangle contains exactly two blue cells. Among all valid colorings, use as few blue cells as possible. Print any one such coloring, or “No solution” if none exists.

2. Key Observations  
- If you number the rows and columns from 0, then in any 3×2 or 2×3 block the six cells have exactly two occurrences of each residue class mod 3 of (row+column).  
- Therefore, a pattern that paints exactly those cells blue for which (i + j + offset) mod 3 = 0 automatically satisfies the local constraint (every 3×2 or 2×3 contains exactly two blues).  
- There are three choices of offset (0,1,2). Each yields about ⌈N·M/3⌉ blue cells, but due to edges one offset may have slightly fewer blues than the others. We can try all three and pick the best.

3. Full Solution Approach  
a. Read N, M.  
b. For each offset in {0,1,2}:  
   i.   Count how many cells (i,j) in the N×M grid satisfy (i + j + offset) % 3 == 0.  
c. Pick the offset that gives the smallest count of blue cells.  
d. Construct the grid: for each cell (i,j), if (i + j + best_offset) % 3 == 0 print ‘#’, else print ‘0’.  
e. Output the grid.  

Time Complexity: O(3·N·M) = O(N·M), easily fits N,M ≤ 200.

4. C++ Implementation with Detailed Comments  
```cpp
#include <bits/stdc++.h>
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N, M;
    cin >> N >> M;
    // Will store which offset yields the fewest blues
    int best_offset = 0;
    int min_blue = INT_MAX;

    // Try all three possible offsets
    for(int offset = 0; offset < 3; offset++){
        int count_blue = 0;
        // Count cells that would be painted blue with this offset
        for(int i = 0; i < N; i++){
            for(int j = 0; j < M; j++){
                if ((i + j + offset) % 3 == 0) {
                    count_blue++;
                }
            }
        }
        // Keep the offset that minimizes blue count
        if (count_blue < min_blue) {
            min_blue = count_blue;
            best_offset = offset;
        }
    }

    // Build and print the grid using best_offset
    // '0' for red, '#' for blue
    for(int i = 0; i < N; i++){
        for(int j = 0; j < M; j++){
            if ((i + j + best_offset) % 3 == 0)
                cout << '#';
            else
                cout << '0';
        }
        cout << "\n";
    }

    return 0;
}
```

5. Python Implementation with Detailed Comments  
```python
import sys
def main():
    input = sys.stdin.readline
    N, M = map(int, input().split())

    best_offset = 0
    min_blue = N * M + 1  # larger than any possible count

    # Determine which offset yields the fewest blue cells
    for offset in range(3):
        count_blue = 0
        for i in range(N):
            for j in range(M):
                if (i + j + offset) % 3 == 0:
                    count_blue += 1
        if count_blue < min_blue:
            min_blue = count_blue
            best_offset = offset

    # Construct and print the flag
    # Blue ('#') where (i+j+best_offset)%3==0, else Red ('0')
    for i in range(N):
        row = []
        for j in range(M):
            if (i + j + best_offset) % 3 == 0:
                row.append('#')
            else:
                row.append('0')
        print(''.join(row))

if __name__ == "__main__":
    main()
```