We need to maximize the number of duels: pairs of knights of different colors that attack each other. Each cell gets either white or black. Knights attack each other if they are of opposite colors and within knight move. So each unordered pair of cells that are a knight's move apart can contribute at most 1 duel if the two knights are opposite colors. If they are same color, they contribute 0. So the total number of duels is the number of edges (pairs of cells that are knight moves apart) connecting cells of opposite colors.
Thus we have a graph where vertices are board cells, edges between cells that are a knight move apart. We need to 2-color the vertices (white/black) to maximize the number of edges that are bichromatic. This is essentially the complement of the problem of minimizing monochromatic edges. Since total edges is fixed (depending on board size n), maximizing bichromatic edges is equivalent to minimizing monochromatic edges. If we 2-color the graph, the number of bichromatic edges = total edges - (edges within color 0 + edges within color 1). So to maximize bichromatic, we want to minimize sum of intra-color edges.
This is like a Max Cut problem on a bipartite graph? Actually the knight move graph: is it bipartite? The chessboard with knight moves: Knight moves always change color of square? On a chessboard, standard coloring (alternating black and white squares) yields that a knight move goes from a black square to a white square? Let's check: Knight moves are (2,1) - sum of coordinates changes by 3, so parity flips: (x+y) mod 2 changes? (x+y) to (x+2+y+1)= (x+y+3) mod 2 = (x+y+1) mod 2? Actually mod 2, adding 3 is equivalent to adding 1, so parity flips. So knight moves from a square of one color to opposite color in the standard chessboard coloring. So the graph is bipartite. For a bipartite graph, we can achieve all edges being bichromatic if we color vertices according to the bipartition. That would yield maximum bichromatic edges = total edges, i.e., all edges connect opposite colors. But wait, can we assign white and black to the two partitions arbitrarily? If we assign one partition all white and the other all black, then every edge connects a white and a black, so all edges are duels. That would be maximum possible: total edges. So why does the example output not achieve all edges? For n=3, board 3x3, what is the knight move graph? Let's list edges. Coordinates 1-indexed as in problem. Knights can move only if within board. For n=3, the cells: (1,1) can attack (3,2) and (2,3)? Actually (1,1) -> (2+? Let's compute: (1+2,1+1) = (3,2) valid; (1+1,1+2) = (2,3) valid; (1-2,1-1) etc out; (1-1,1-2) out. So edges: (1,1) with (3,2) and (2,3). Similarly (1,2) can attack (3,1),(3,3)? (1+2,2+1)=(3,3); (1+1,2+2)=(2,4) out; (1-2,2-1)=(-1,1) out; (1-1,2-2)=(0,0) out; also (1+2,2-1)=(3,1); (1-2,2+1) out; (1+1,2-2)=(2,0) out; (1-1,2+2)=(0,4) out. So (1,2) connects to (3,1) and (3,3). (1,3) connects to (2,1) and (3,2). (2,1) connects to (1,3) and (3,3) also? (2,1): (2+2,1+1)=(4,2) out; (2+1,1+2)=(3,3); (2-2,1-1)=(0,0) out; (2-1,1-2)=(1,-1) out; also (2+2,1-1)=(4,0) out; (2-2,1+1)=(0,2) out; (2+1,1-2)=(3,-1) out; (2-1,1+2)=(1,3) valid. So (2,1) to (1,3) and (3,3). (2,2): no knight moves? (2,2): (2+2,2+1)=(4,3) out; (2+1,2+2)=(3,4) out; (2-2,2-1)=(0,1) out; (2-1,2-2)=(1,0) out; also (2+2,2-1)=(4,1) out; (2-2,2+1)=(0,3) out; (2+1,2-2)=(3,0) out; (2-1,2+2)=(1,4) out. So (2,2) isolated. (2,3) connects to (1,1) and (3,1) and (??) Actually (2,3): (2+2,3+1)=(4,4) out; (2+1,3+2)=(3,5) out; (2-2,3-1)=(0,2) out; (2-1,3-2)=(1,1); (2+2,3-1)=(4,2) out; (2-2,3+1)=(0,4) out; (2+1,3-2)=(3,1); (2-1,3+2)=(1,5) out. So (2,3) to (1,1) and (3,1). (3,1) to (1,2),(2,3) and (??) also (1,2) we saw; (2,3) we saw; also (3,1) to (1,2) and (2,3). Also (3,1) to (??) (3+2,1+1)=(5,2) out; (3+1,1+2)=(4,3) out; etc. So edges: (3,1) to (1,2) and (2,3). (3,2) to (1,1),(1,3) and (??) (3,2): (3-2,2-1)=(1,1); (3-1,2-2)=(2,0) out; (3-2,2+1)=(1,3); (3-1,2+2)=(2,4) out; also (3+2,2+1) out etc. So (3,2) to (1,1) and (1,3). (3,3) to (1,2),(2,1). So total edges: each unordered pair counted once. Let's count: (1,1) edges: to (3,2),(2,3) ->2. (1,2): to (3,1),(3,3) ->2. (1,3): to (2,1),(3,2) ->2. (2,1): to (1,3),(3,3) ->2 but note (1,3) already counted from (1,3) to (2,1) so it's fine. (2,2):0. (2,3): to (1,1),(3,1) ->2. (3,1): to (1,2),(2,3) ->2. (3,2): to (1,1),(1,3) ->2. (3,3): to (1,2),(2,1) ->2. So total undirected edges = (2*8? Actually 8 vertices have degree 2, sum degrees=16, edges=8). So total edges =8.
Now the bipartition of the graph: standard chessboard coloring (parity of i+j). Let's compute parity: (1,1) sum=2 even? Actually (i+j)%2: (1+1)=2 even; (1,2)=3 odd; (1,3)=4 even; (2,1)=3 odd; (2,2)=4 even; (2,3)=5 odd; (3,1)=4 even; (3,2)=5 odd; (3,3)=6 even. So one partition: even sum (white squares in chessboard) includes (1,1),(1,3),(2,2),(3,1),(3,3). Odd includes (1,2),(2,1),(2,3),(3,2). But note that (2,2) is isolated. In a bipartite graph, edges only go between even and odd partitions. Let's verify: (1,1) even to (3,2) odd? (3,2) odd yes. (1,1) to (2,3) odd? (2,3) odd yes. (1,2) odd to (3,1) even, (3,3) even. (1,3) even to (2,1) odd, (3,2) odd. (2,1) odd to (1,3) even, (3,3) even. (2,3) odd to (1,1) even, (3,1) even. (3,1) even to (1,2) odd, (2,3) odd. (3,2) odd to (1,1) even, (1,3) even. (3,3) even to (1,2) odd, (2,1) odd. So indeed edges only cross partitions. So graph is bipartite. If we assign all even squares white, all odd squares black (or vice versa), then every edge connects white and black, so number of duels = total edges =8. But the example output shows a configuration with 8 duels as they claim. Wait example output:
WBW
BBB
WBW
Let's parse: row1: W B W -> (1,1)=W, (1,2)=B, (1,3)=W. row2: B B B -> (2,1)=B, (2,2)=B, (2,3)=B. row3: W B W -> (3,1)=W, (3,2)=B, (3,3)=W.
So even parity cells: (1,1) even=W, (1,3) even=W, (2,2) even=B, (3,1) even=W, (3,3) even=W. Odd cells: (1,2)=B, (2,1)=B, (2,3)=B, (3,2)=B. So all even cells except (2,2) are W, odd cells are B. (2,2) is B (even cell assigned B). In this assignment, edges from (2,2) to none, so no problem. But what about edges between even and odd: all even cells are W except (2,2) even B, odd cells are B. So edges between even W and odd B yield duels; edges between even B and odd B yield same color, so no duel. Since the only even cell with B is (2,2) which is isolated, no edges are lost. So effectively all edges are between W (even) and B (odd), so all 8 duels. So they achieved maximum 8. So indeed it's possible to get all edges as duels for n=3.
But wait, why does the problem statement mention maximum possible? Because for some board sizes, is the knight graph bipartite? Always bipartite as argued. So in theory, we can color according to parity to make every knight move between opposite colors, yielding duels for every possible knight move. That would be maximum possible because you cannot have more duels than total edges. So why would maximum not be total edges for all n? Let's check: But knights are placed on all cells, edges are defined between cells that are a knight's move apart. Since the graph is bipartite, if we assign one color to all vertices of one part and the opposite color to the other part, then every edge connects opposite colors, so all edges become duels. So maximum number of duels is total edges, which is achievable by this bipartite coloring. So answer should be simple: color cell (i,j) white if (i+j) even, black if odd, or vice versa. That yields maximum duels.
But is there any catch? Could there be a scenario where this simple parity coloring does not maximize duels? Let's think: The maximum duels is at most total edges. And total edges is fixed. Since we can achieve all edges as duels using parity coloring, that is optimal. So answer is trivial: print a chessboard pattern of W and B based on (i+j) parity.
But why does the example output not show a full chessboard pattern? For n=3, chessboard pattern would be:
W B W
B W B
W B W
But the example output is:
W B W
B B B
W B W
That's not the pure chessboard pattern: (2,2) is B instead of W. But (2,2) is isolated, so it doesn't matter. So they provided a variant. So indeed any pattern that respects the bipartition on non-isolated vertices (i.e., assign all vertices in one part one color, the other part the opposite color) yields maximum duels. However, isolated vertices (like (2,2) when n=3) have no edges, they can be assigned arbitrarily without affecting duels.
Thus the problem reduces to: output any coloring that for each pair of cells that are a knight's move apart, they have opposite colors. That is equivalent to a proper 2-coloring of the knight move graph. Since the graph is bipartite (we should verify for all n? Yes, because (i+j) parity flips on knight moves). So we can simply output pattern based on parity. That gives all edges bichromatic.
But wait: is it always possible to color the entire graph properly? Since it's bipartite, yes. But there is a nuance: the graph may not be connected, but each component is bipartite. However, there might be odd cycles? Let's check if there exists any cycle of odd length in knight move graph. On a standard chessboard, knights move always change color parity, so any cycle must have even length. Indeed the graph is bipartite. So proper 2-coloring exists. So we can achieve total duels = total edges.
Thus answer is straightforward. But why does problem ask to maximize? Possibly because some participants might not realize it's bipartite or think about constraints? But indeed it's simple.
But wait: The problem says "You are given a chess board with n rows and n columns." It didn't say that n is odd or even, but parity works for any n. So I'm convinced answer is to color by parity.
Let's double-check with n=4. The knight graph on 4x4: Some cells have edges. If we color by parity, will every edge connect opposite colors? Yes, because (dx,dy) sum of coordinates changes by odd (3), so parity flips. So edges are between opposite parity. So all edges become duels. So maximum duels = total edges. Could there be any limitation that we must use both colors? The problem statement says "put a white or a black knight into each cell". It doesn't require both colors to be used, but using only one color would yield 0 duels, so not optimal. So using both colors is implied but not forced. So parity coloring uses both colors if board has both parities. For n>=1, there are both parities unless n=1? But n>=3, so both exist.
Thus answer: output 'W' if (i+j) % 2 == 0, else 'B', or vice versa. But careful: The example output for (2,2) gave B while parity would be even => W. So any assignment that differs only on isolated vertices is fine.
But are there any vertices that are isolated? For n>=3, is there any cell with no knight moves? Possibly central cells for small n? For n=3, (2,2) isolated. For n=4, check (2,2) can attack? (2,2) -> (4,3),(4,1),(3,4),(1,4),(0,...). Actually on 4x4: (2,2) can go to (4,3) and (4,1) and (3,4) and (1,4) and (0,...) negative invalid. So (2,2) has moves: (2+2,2+1)=(4,3) valid; (2+2,2-1)=(4,1) valid; (2-2,2+1)=(0,3) invalid; (2-2,2-1)=(0,1) invalid; (2+1,2+2)=(3,4) valid; (2+1,2-2)=(3,0) invalid; (2-1,2+2)=(1,4) valid; (2-1,2-2)=(1,0) invalid. So (2,2) has 4 moves. So not isolated. For n>=4, all cells have at least one move? Possibly corners may have moves? For n=3, corners have 2 moves each, edges have 2, center isolated. For n=4, center area may have moves. For n=5, all cells likely have moves. But still parity coloring works.
Thus the solution is trivial. But why would the problem be rated? Possibly it's an easy problem from some contest, but it's indeed straightforward.
But before finalizing, let's consider if there is any twist: The duel is defined as a pair of knights of different colors such that these knights attack each other. That means if a white knight attacks a black knight, that's one duel. If both attack each other (they always do, attack is symmetric), then it's still one pair. So it's unordered.
Now, if we color by parity, then for every edge we have opposite colors, so each edge counts as one duel. So total duels = number of edges. Is there any way to have more duels than number of edges? Could a pair of knights be counted multiple times? No, duel is a pair of knights. So each pair can at most contribute one duel if they are of opposite colors and attack each other. So maximum is number of edges. So parity coloring achieves maximum.
Therefore the answer is to produce a bipartite coloring. The simplest is to use (i+j)%2.
But the problem might have trick: The board is n x n, and we have to put a knight in each cell. Knights attack each other if they are a knight's move apart. But note: A knight attacks any piece in reachable cells, regardless of intervening pieces. So the graph edges are independent. So fine.
Thus solution: For i from 1 to n: for j from 1 to n: if ((i+j) % 2 == 0) print 'W' else 'B'. Or the opposite. It yields maximum duels.
But wait: Example output is different: They put 'B' at (2,2). That's fine as isolated. But our pattern would put 'W' at (2,2). Both are acceptable.
But is there any possibility that the knight move graph is not bipartite? Let's double-check: A knight move changes the sum of coordinates by ±1 or ±3? Actually move (2,1) changes sum by 3, which is odd. Move (1,2) also changes sum by 3, odd. So parity flips. So indeed any move changes parity. So graph is bipartite with partition based on parity. So coloring by parity yields a proper 2-coloring.
Thus answer is trivial.
Given that n up to 100, we can just output the chessboard pattern.
But why does problem statement include that example output? Possibly to show that other colorings are also acceptable.
Thus final answer: print board where cell (i,j) is 'W' if (i+j) even else 'B'. Or swap.
But wait, I recall a known Codeforces problem: "1195A - Drinks Choosing" no; actually "1195B" something? Hmm. But I think this is from a contest maybe where the intended solution is to realize that maximum duels equals total number of knight moves, achieved by coloring like a chessboard. So it's indeed simple.
But let's double-check with n=3, total edges =8, our pattern yields 8 duels? Let's compute using parity: (1,1) W; (1,2) B; (1,3) W; (2,1) B; (2,2) W; (2,3) B; (3,1) W; (3,2) B; (3,3) W. Check edges: (1,1) W - (3,2) B => duel; (1,1) W - (2,3) B => duel; (1,2) B - (3,1) W => duel; (1,2) B - (3,3) W => duel; (1,3) W - (2,1) B => duel; (1,3) W - (3,2) B => duel; (2,1) B - (3,3) W => duel; (2,3) B - (3,1) W => duel; (2,2) isolated. So 8 duels. Yes.
Thus answer.
But wait: The example output has (2,2)=B, but still 8 duels. So any pattern that respects parity on vertices with degree>0 yields all edges bichromatic. However, vertices with degree 0 can be anything.
But is it possible that there is an edge connecting two vertices of same parity if board not infinite? No, because parity flips always.
Thus solution.
But maybe there is a catch: The duel count counts each pair of knights of different colors that attack each other. If a white knight attacks a black knight, that's a duel; also the black knight attacks the white knight, but it's the same pair, so counted once. So it's edges.
Thus the answer.
Implementation: read n, loop i=0..n-1, j=0..n-1, print 'W' if (i+j)%2==0 else 'B'. Or the opposite, but to match example maybe they prefer 'W' on corners? Example output corners are W. So I'll do parity even -> W, odd -> B. That matches corners: (1,1) even => W, (1,2) odd => B, etc. For n=3, (2,2) even => W, but example had B; but it's fine because it's isolated. However, for n=3, (2,2) is isolated, so both are valid. The problem states "If there are multiple optimal answers, print any of them." So it's okay.
But wait: What about n=100? All cells have degree? For even n maybe all cells have some moves? Actually in large boards all cells have at least one knight move? Let's check corners: (1,1) can attack (2,3) and (3,2) if n>=3. So corners have moves. Edge cells near corners also have moves. So for n>=4, likely all cells have at least one move. For n=3, only (2,2) is isolated. For n=4, maybe all have moves? Check (1,1): (2,3) and (3,2) valid. (1,2): (2,4),(3,1),(3,3) maybe? (1,2) -> (3,3),(3,1) valid; (2,4) valid? (1+1,2+2)=(2,4) valid; so yes. (1,3): (2,1),(2,5) invalid, (3,2),(3,4) valid? (1+2,3+1)=(3,4) valid; (1+2,3-1)=(3,2) valid; (1-2,3+1) invalid; (1-2,3-1) invalid; (1+1,3+2)=(2,5) invalid; (1+1,3-2)=(2,1) valid; (1-1,3+2)=(0,5) invalid; (1-1,3-2)=(0,1) invalid; so yes. (1,4): (2,2),(3,3) valid? (1+2,4-1)=(3,3) valid; (1+1,4-2)=(2,2) valid; etc. So all cells have moves? Check (2,2) we saw has moves. So for n=4, all cells have at least one move. For n=5, all cells have moves. So only for n=3 we have isolated cell. Possibly n=1,2 but n>=3 so only n=3 has isolated center. Actually n=3, center isolated. For n=1 and 2 not allowed. So for n>=4, there are no isolated cells, so every cell is part of at least one edge. Then to have all edges bichromatic, we must assign colors strictly according to parity (or opposite) for all cells; any deviation would cause at least one edge to be monochromatic (since the graph is connected? Let's check connectivity: For n>=5, the knight graph is connected? I think for chessboard with knight moves, the graph is connected for boards sufficiently large, but for n=4, maybe not fully connected? Actually let's examine connectivity on 4x4. Might be that some cells cannot reach others? Possibly the knight graph on 4x4 is not connected? Let's test: (1,1) can go to (2,3) and (3,2). From (2,3) can go to (4,4), (4,2), (1,1), (1,5 invalid), (3,1), (3,5 invalid), (0,2 invalid), (0,4 invalid). So (4,4) reachable. So likely all cells are connected? But I recall that on a 4x4 board, knights can tour? Actually knight's tour on 4x4 doesn't exist because it's not possible to visit all squares, but graph connectivity might still be connected? Let's check if (2,2) can reach (1,1)? (2,2) -> (4,3),(4,1),(3,4),(1,4). From (1,4) -> (2,2) (since (1+1,4-2)=(2,2)), so (2,2) connects to (1,4). (1,4) connects to (2,2) and (3,3) (since (1+2,4-1)=(3,3)). So (2,2) connects to (3,3). (3,3) connects to (1,2),(1,4),(2,1),(4,1),(4,5 invalid),(5,2 invalid),(5,4 invalid),(2,5 invalid). So indeed connectivity likely exists across board. I think the knight graph on any board of size at least 4x5 or something is connected; but 4x4 might be connected? Let's test if there is any component separate: (1,1) connects to (2,3),(3,2). (3,2) connects to (1,1),(1,3),(4,4),(4,0 invalid, etc). (1,3) connects to (2,1),(3,2). (2,1) connects to (1,3),(3,3),(4,2? Actually (2+2,1+1)=(4,2) valid, (2+2,1-1)=(4,0) invalid, (2+1,1+2)=(3,3) valid, (2+1,1-2)=(3,-1) invalid, (2-2,1+1)=(0,2) invalid, (2-2,1-1)=(0,0) invalid, (2-1,1+2)=(1,3) valid, (2-1,1-2)=(1,-1) invalid. So (2,1) connects to (4,2) as well. So (4,2) is reachable. (4,2) connects to (2,1),(2,3),(3,4) maybe? (4-2,2-1)=(2,1) valid, (4-2,2+1)=(2,3) valid, (4-1,2-2)=(3,0) invalid, (4-1,2+2)=(3,4) valid. So connectivity to (3,4). (3,4) connects to (1,3),(1,5 invalid),(2,2),(4,2),(5,3 invalid),(5,5 invalid),(2,6 invalid),(4,6 invalid). So everything seems connected. So for n>=4, graph is connected. Then any proper 2-coloring must assign opposite colors to the two partitions. If we deviate, we get at least one edge monochromatic, reducing duels. So the only optimal colorings are exactly those where each parity gets a consistent color (all even white, all odd black, or all even black, all odd white). However, for n=3, there is isolated vertex (2,2) which can be either without affecting edges. So algorithm as described (parity coloring) yields an optimal answer.
Thus solution is trivial.
But I'm suspicious: Could there be any hidden nuance? Perhaps the definition of duel: "A duel of knights is a pair of knights of different colors such that these knights attack each other." It says "such that these knights attack each other". If a white knight attacks a black knight, that is a duel. But if the black knight also attacks the white knight, it's the same pair. So it's fine.
Alternatively, maybe they consider directed? But typical interpretation is unordered pair.
Thus I think answer is simple.
But why would this problem be included if it's that trivial? Possibly it's from an educational contest. I'll check problem source: It might be from Codeforces Round #119? Actually I recall problem "Knight Tournament" or "Knight Placement"? Not sure.
Anyway, I'll produce solution.
Implementation: Read integer n, then for i in range(n): for j in range(n): if (i+j)%2==0: print('W', end='') else: print('B', end=''); after each row print newline.
But the example output: They have 'W' at (1,1), (1,3), (3,1), (3,3) and 'B' at others including (2,2). With parity, (2,2) would be 'W'. So if we want to exactly match example, we could invert parity on isolated cells? But not necessary.
Thus final answer.
But wait: Let's test n=4 with parity: output chessboard pattern. Count duels? All edges are between opposite colors, so number of duels = total edges. That should be maximum.
Now, confirm that no better than total edges is possible. So answer.
Thus solution is O(n^2).
Now, the problem may be expecting a pattern like "WBWB..." and "BWBW..." alternating rows. That's same.
Thus final.
But there is another nuance: The board is n x n, and n can be up to 100, which is small. So any O(n^2) works.
Thus answer: print a chessboard coloring.
Now, let's produce final solution. ```python
import sys
def main():
data = sys.stdin.read().strip().split()
if not data:
return
n = int(data[0])
out_lines = []
for i in range(n):
row = []
for j in range(n):
if (i + j) % 2 == 0:
row.append('W')
else:
row.append('B')
out_lines.append(''.join(row))
sys.stdout.write('\n'.join(out_lines))
if name == 'main':
main()