We need to solve: place two bishops on an n x n board such that no cell is attacked by both bishops (i.e., their diagonals do not intersect at any cell other than possibly they themselves? Actually "there is no cell that is attacked by both of them" means for any cell (i,j), it cannot be that both bishops attack it. This includes the cells where bishops are placed? The bishops themselves are considered attacked by themselves (since the cell where the bishop is considered attacked). So they cannot attack the same cell, which would happen if they share a diagonal or if they are on intersecting diagonals. But if two bishops are on different colored squares? Actually bishops attack along diagonals: main (top-left to bottom-right) and anti (top-right to bottom-left). Two bishops will attack a cell if it lies on at least one of their diagonals. For a cell to be attacked by both, it must lie on a diagonal of both bishops. This can happen if the bishops are placed such that some cell belongs to both a main diagonal from one bishop and an anti diagonal from the other, etc. Actually careful: A bishop attacks all cells that are on the same main diagonal (i-j constant) and same anti-diagonal (i+j constant). So a cell is attacked by a bishop if its (i-j) equals bishop's (i-j) OR its (i+j) equals bishop's (i+j). Wait, both conditions? Actually a bishop moves along both diagonals: it moves on squares that share either the same main diagonal (i-j constant) or the same anti-diagonal (i+j constant). But the move is along both diagonals; a bishop can move any number of squares along either diagonal. So a square is attacked if it lies on either of the two diagonals that the bishop sits on. So yes, the set of squares attacked by a bishop is the union of all squares with the same (i-j) and all squares with the same (i+j). Note that the bishop's own square is in both sets, but it's fine.
Now two bishops attack a cell if that cell is in the attack set of bishop1 AND in the attack set of bishop2. For that to happen, the cell must satisfy either: it shares main diagonal with bishop1 and either main or anti with bishop2? Actually intersection condition: (cell satisfies (i-j = d1) or (i+j = s1)) AND (i-j = d2) or (i+j = s2)). So the cell could be in any of the four combinations:
- i-j = d1 and i-j = d2 => d1 = d2 (same main diagonal)
- i-j = d1 and i+j = s2
- i+j = s1 and i-j = d2
- i+j = s1 and i+j = s2 => s1 = s2 (same anti diagonal)
Thus, if d1 == d2, then all cells on that main diagonal are attacked by both (since both bishops share that main diagonal? Actually if both bishops are on same main diagonal, then each bishop attacks all cells on that main diagonal (because each attacks squares with same i-j). So any cell on that main diagonal is attacked by both. Similarly if they share same anti diagonal, any cell on that anti diagonal is attacked by both.
If they don't share main or anti diagonal but there could be cells where one diagonal from first intersects one diagonal from second. For example, condition i-j = d1 and i+j = s2 gives a unique cell (if exists) solving i = (s2 + d1)/2, j = (s2 - d1)/2. Similarly the other intersection gives a unique cell. So there could be at most two cells (maybe the same) where a main diagonal of one intersects an anti diagonal of the other.
The requirement is that no cell is attacked by both. That means we must avoid any intersection cell. This means:
- The bishops must not share the same main diagonal (d1 != d2)
- They must not share the same anti diagonal (s1 != s2)
- Additionally, there must be no cell that is the intersection of d1 with s2, and similarly d2 with s1 (these could be distinct cells). Those intersections exist only if the resulting coordinates are integers (i and j within 1..n). So we must ensure that the intersection cells either don't exist (out of board) or if they exist, we must ensure they are not attacked by both? But if they exist, they would be attacked by both because they satisfy i-j = d1 and i+j = s2, so attacked by bishop1 via main diagonal and bishop2 via anti diagonal. Actually careful: For cell to be attacked by bishop1, it's enough that it lies on either main or anti diagonal. So if a cell satisfies i-j = d1, it is attacked by bishop1 (since it's on its main diagonal). If it satisfies i+j = s2, it is attacked by bishop2 (since it's on its anti diagonal). So yes, that cell would be attacked by both. So it's forbidden. Similarly the other intersection.
Thus, the bishops must be placed such that:
- d1 != d2
- s1 != s2
- The intersection of d1 and s2 does not correspond to a valid board cell (or if it does, we cannot place? Actually we must avoid any cell being attacked by both, so if that intersection cell exists on board, it's forbidden. So we need to ensure that either (s2 + d1) is odd? Since i = (s2 + d1)/2 must be integer and within range, j = (s2 - d1)/2 integer. Because i and j must be integers, given d1, s2 integers. The parity condition: (s2 + d1) must be even for integer i. Actually i = (s2 + d1)/2; j = (s2 - d1)/2. Since s2 = i2 + j2, d1 = i1 - j1. Both s2 and d1 are integers. Their sum parity: s2 + d1 = (i2 + j2) + (i1 - j1) = i1 + i2 + j2 - j1. This could be even or odd. For i and j to be integer, the sum must be even. So if parity differs, no integer cell. Similarly for other intersection: i = (s1 + d2)/2, j = (s1 - d2)/2.
Thus we can avoid intersection cells by ensuring that these equations give non-integer solutions (odd sum) or if integer, they fall outside board. But we can consider only integer solutions within board. It's easier to enforce that bishops are placed on squares of opposite colors? Let's examine. In chessboard coloring: black squares have i+j even, white i+j odd. Bishops move on same color only? Actually bishops stay on squares of the same color because moving along diagonals preserves parity of i+j. Indeed, i+j changes by ±2 when moving one step diagonally. So bishops attack only squares of same color. So if two bishops are on opposite colors, they attack disjoint sets of squares (since their attack sets are on different colors). Then no cell is attacked by both because any cell is of one color, and only bishops on that color can attack it. However, could a bishop attack a square of opposite color? No, because i+j parity changes along diagonal? Actually moving diagonally, i and j both increase or both decrease by 1, so i+j changes by ±2; parity remains the same. Similarly for anti-diagonal: i increases, j decreases, sum i+j stays constant. So indeed bishops only move on squares with the same i+j parity as their starting square. So they only attack squares of the same color. Therefore if bishops are on opposite colors, their attack sets are completely disjoint. That automatically satisfies the condition that no cell is attacked by both. So one obvious valid placement: bishops on opposite colors.
But can bishops be on same color and still satisfy the condition? Possibly if they are placed such that their diagonals do not intersect? Let's think: If they are on same color, they share the same parity of i+j. Their main diagonals d = i-j can be different, anti diagonals s = i+j can be different. But as argued, there could be intersection cells: For example, take bishops at (1,1) and (2,2). Both are same color (i+j even: 2 and 4). d1=0, s1=2; d2=0, s2=4. They share main diagonal d=0, so they attack same main diagonal cells -> many cells attacked by both. Not allowed. If we avoid d1=d2 and s1=s2, but still there could be intersection of d1 and s2 and d2 and s1. Let's test if it's possible to have bishops on same color but avoid any cell being attacked by both. For example, n=2. Board: (1,1) and (1,2) etc. Bishops on same color? Only squares: (1,1) color even? i+j=2 even; (1,2) sum=3 odd; (2,1) sum=3 odd; (2,2) sum=4 even. So same color possibilities: both on even squares: (1,1) and (2,2) -> share main diagonal (since 1-1=0, 2-2=0). So not allowed. (1,1) and (2,2) share main; (1,1) and (2,? Actually only two even squares: (1,1) and (2,2). They share main. So cannot place two bishops on same color without conflict? Possibly on larger board. Consider bishops at (1,3) and (3,1). Both i+j=4 even. d1= -2, s1=4; d2=2, s2=4. They share same anti-diagonal s=4 -> they attack all squares on that anti-diagonal, so many cells attacked by both. Not allowed. Try (1,3) and (2,4). Both even? (1,3) sum=4; (2,4) sum=6. d1 = -2, s1=4; d2 = -2, s2=6. Share main diagonal d=-2 -> conflict. Try (2,1) and (1,4)? (2,1) sum=3 odd; (1,4) sum=5 odd, both odd. d2=1, s2=5; d1=1, s1=3? Actually (2,1): i-j=1, i+j=3; (1,4): i-j=-3, i+j=5. They have different d and s. Intersection cells: d1=1 with s2=5 => i = (5+1)/2=3, j=(5-1)/2=2 => (3,2) valid? n=4? 3,2 is within board. That cell would be attacked by both? Check: (3,2) i-j=1 -> matches d1, so attacked by bishop1; i+j=5 -> matches s2, attacked by bishop2. So conflict. Intersection d2=-3 with s1=3 => i=(3 + (-3))/2=0, j=(3 - (-3))/2=3 => (0,3) out of board. So one conflict exists. So not allowed. It appears that placing bishops on same color almost always leads to some conflict. Let's think theoretically: For bishops on same color, i1+j1 and i2+j2 are both even or both odd, so s1 and s2 have same parity. d1 = i1 - j1, d2 = i2 - j2. For the intersection cell from d1 and s2: i = (s2 + d1)/2. Since s2 and d1 have same parity? s2 has parity = (i2+j2) mod2, d1 = (i1 - j1) mod2 = (i1 + j1) mod2 because (i-j mod2) = (i+j) mod2 (since subtraction mod2 same as addition). Indeed, because modulo 2, -j ≡ j (since -1 ≡ 1 mod2). So d1 mod2 = (i1 + j1) mod2. So if both bishops are on same color, then s1 mod2 = s2 mod2 = color parity, and d1 mod2 = s1 mod2, d2 mod2 = s2 mod2. So d1 mod2 = s2 mod2. Therefore s2 + d1 is even. So (s2+d1)/2 is integer. Similarly s1 + d2 even. So the intersection cells are integer coordinates. Are they always on board? Not necessarily, but often they can be off board. Could it be that both intersection cells are off board, thus no cell attacked by both? Possibly if the bishops are placed such that the intersection points land outside the n x n grid. For example, n large enough but maybe near corners? Let's analyze: For bishops on same color, we get two potential intersection cells: P = intersection of main diagonal of bishop1 (d1) and anti-diagonal of bishop2 (s2), and Q = intersection of anti-diagonal of bishop1 (s1) and main diagonal of bishop2 (d2). P is defined by i = (s2 + d1)/2, j = (s2 - d1)/2. Since s2 = i2+j2, d1 = i1 - j1, we can compute: i = (i2+j2 + i1 - j1)/2 = (i1 + i2 + j2 - j1)/2. j = (i2+j2 - i1 + j1)/2 = (j1 + j2 + i2 - i1)/2. For P to be within [1,n], these need to satisfy constraints. Similarly Q.
Is it possible to have both P and Q outside the board? Possibly if bishops are placed near edges so that intersection points fall outside. But we must ensure that no cell is attacked by both. However, what about the bishops themselves? They are attacked by themselves, but do we count the bishops' own squares? The condition says "there is no cell that is attacked by both of them." A bishop's own square is attacked by itself, but does it count as attacked by both? Only if both bishops attack that square. If bishops are on different squares, a bishop's square is attacked by the other bishop if it lies on a diagonal of the other bishop. That can happen. For example, bishop1 at (i1,j1) is attacked by bishop2 if (i1,j1) lies on bishop2's main or anti diagonal. That would mean the cell (i1,j1) is attacked by both (by bishop1 itself and bishop2). So we need to avoid that as well. So bishops cannot be placed such that one lies on any diagonal of the other. That includes sharing same main or anti diagonal, or being on the intersecting diagonal? Actually if bishop2 lies on bishop1's main diagonal or anti diagonal, then bishop1 is attacked by both. So we need to avoid any such situation.
Thus the condition that no cell is attacked by both is equivalent to: The sets of cells attacked by each bishop are disjoint. Because any cell that is attacked by both would be a problem. It's possible that some cells are attacked by only one. So we need attack sets to be disjoint.
Given that bishops only attack squares of their own color, if bishops are on opposite colors, their attack sets are disjoint (since colors are disjoint). That's a sufficient condition. Is it necessary? Could bishops be on same color but have disjoint attack sets? Attack sets of bishops on same color are subsets of squares of that color. They could be disjoint if the bishops' diagonals do not intersect at any square of that color? But note, a bishop attacks all squares on its two diagonals. For two bishops on same color, each bishop attacks all squares on its main diagonal (color same as bishop) and all squares on its anti diagonal (color same). Since both bishops are on same color, their main diagonals are sets of squares of that color. Intersection of their attack sets includes at least the intersection of main diagonals (if they share a main diagonal) or intersection of main of one and anti of other (which we computed) etc. Could those intersections be empty? Possibly if the diagonals do not intersect within the board. But recall, for a given bishop, its main diagonal is a line of squares of the same color (since i-j constant, i+j parity changes? Wait, i-j constant: moving along main diagonal, i and j both increase by 1, so i+j changes by 2, so parity stays constant. So all squares on a main diagonal have same parity as the bishop's color? Because starting from bishop square with parity p, moving +1,+1 gives i+j increased by 2 => parity unchanged; similarly -1,-1 decreases by 2, parity unchanged. So all squares on a main diagonal have same parity. Similarly, anti diagonal: i+j constant, so parity is fixed. So indeed, all squares attacked by a bishop are of the same color as the bishop. So both bishops' attack sets are subsets of the same color squares.
Now consider two bishops on same color. Their main diagonals are lines of that color. Two distinct main diagonals (d1 != d2) are disjoint? Two different main diagonals: they might intersect? In a square grid, lines defined by i-j = constant are parallel, they never intersect. So main diagonals of different d are disjoint. Similarly, two different anti diagonals (s constant) are parallel and disjoint. However, a main diagonal and an anti diagonal intersect at exactly one point (if that point is integer and within board). So attack set of bishop1 includes its main diagonal M1 and anti diagonal A1. Attack set of bishop2 includes M2 and A2. Intersections to consider: M1 ∩ M2 = ∅ if d1≠d2. A1 ∩ A2 = ∅ if s1≠s2. M1 ∩ A2 = possibly one point (if within board). A1 ∩ M2 = possibly one point. Also M1 ∩ A1 = the bishop's own square (since the bishop sits at intersection of its own M1 and A1). But that's not an intersection between two bishops' sets. So for the attack sets to be disjoint, we need: M1 ∩ A2 = ∅ and A1 ∩ M2 = ∅. Also we need that the bishops themselves are not in each other's attack sets: bishop1 (which is in M1∩A1) should not be in attack set of bishop2, i.e., bishop1 ∉ M2 ∪ A2. Similarly bishop2 ∉ M1 ∪ A1. Those are essentially the same as the above intersections because bishop1 is on M1 and A1, so if bishop1 ∈ M2 ∪ A2, then either M1 ∩ M2 (if bishop1 lies on M2) or A1 ∩ M2? Actually bishop1 ∈ M2 would mean that d1 = d2 (since bishop1's main diagonal equals bishop2's main), or bishop1 ∈ A2 would mean s1 = s2. So those are covered by d1≠d2 and s1≠s2. So we need d1≠d2 and s1≠s2 and also that the two cross-intersections yield no board cells.
Now, can the cross-intersections be empty? For them to be empty, the unique intersection point must lie outside the board. That is possible. For example, consider n=3. Bishops on same color? Let's try positions (1,2) and (2,3)? (1,2) sum=3 odd, (2,3) sum=5 odd. d1 = -1, s1=3; d2 = -1, s2=5 => d1 = d2 => conflict because share main diagonal? Actually -1 = -1, so d1 = d2. That's not allowed. So choose different d and s. Try (1,2) and (3,2). (1,2) sum=3 odd; (3,2) sum=5 odd. d1 = -1, s1=3; d2 = 1, s2=5. d1≠d2, s1≠s2. Compute P: intersection of M1 (d1=-1) and A2 (s2=5): i = (5 + (-1))/2 = 2, j = (5 - (-1))/2 = 3 => (2,3). That is within board (n=3). So cell (2,3) is attacked by both. Not allowed. Q: intersection of A1 (s1=3) and M2 (d2=1): i = (3+1)/2=2, j=(3-1)/2=1 => (2,1). Also within board. So conflict.
Try (1,1) and (2,3)? (1,1) sum=2 even, (2,3) sum=5 odd -> different color. So same color only. For same color, parity equal. Let's search systematically: We need d1≠d2, s1≠s2, and both cross-intersection points outside board. Is that possible? Consider n large. Suppose we put bishops near corners such that the intersection falls outside. For a given bishop1 at (i1,j1), bishop2 at (i2,j2) with same parity. The intersection point P: (i = (i2+j2 + i1 - j1)/2, j = (i2+j2 - i1 + j1)/2). For P to be outside board, either i<1 or i>n or j<1 or j>n. Similarly for Q: (i = (i1+j1 + i2 - j2)/2, j = (i1+j1 - i2 + j2)/2). These are symmetric.
Let's denote sum1 = s1, diff1 = d1; sum2 = s2, diff2 = d2.
P = ((s2+d1)/2, (s2-d1)/2). This is essentially the coordinates of the intersection of the lines: i-j = d1 and i+j = s2. That's exactly the point that is symmetric? In the coordinate system rotated 45 degrees, this is the point.
Observation: Since both bishops are on same color, s1 and s2 have same parity, and d1 parity matches that, so (s2±d1) are even, so P has integer coordinates. Similarly Q.
Now, note that i1 = (s1+d1)/2, j1 = (s1-d1)/2; i2 = (s2+d2)/2, j2 = (s2-d2)/2.
Given i1,j1,i2,j2 in [1,n], can both P and Q be outside? Possibly, but we also need bishops not to attack each other: i.e., bishop1 not on M2∪A2 => d2 != d1 and s2 != s1, which we already require.
I suspect that for same color bishops, unless the intersection points are outside, they will cause conflict. But can we have both intersection points outside? Let's try n=2: only two squares per color, so if two bishops on same color they'd be (1,1) and (2,2) or (1,2) and (2,1)?? (1,2) and (2,1) are odd? (1,2): sum=3 odd; (2,1): sum=3 odd; these share anti-diagonal? s=3 same, conflict. So not allowed. n=3: squares of same color: even sum: (1,1)2, (1,3)4, (2,2)4, (3,1)4, (3,3)6? Actually n=3, even sums: 2,4,6. Coordinates: sum2: (1,1). sum4: (1,3), (2,2), (3,1). sum6: (3,3). So 5 even squares. We need to choose two such that d1≠d2, s1≠s2, and cross intersections outside. Let's brute think: choose (1,1) d=0 s=2; and (3,3) d=0 s=6 -> d same => conflict. (1,1) and (1,3): d1=0, s1=2; d2=-2, s2=4. P: (s2+d1)/2 = (4+0)/2=2, (4-0)/2=2 => (2,2) inside. Q: (s1+d2)/2 = (2 + (-2))/2=0, (2 - (-2))/2=2 => (0,2) out. But one conflict (2,2) is attacked by both? Check: (2,2) is on main diagonal of (1,1)? i-j=0, yes; on anti diagonal of (1,3)? i+j=4, yes. So conflict. So not allowed.
(1,1) and (2,2): d1=0,s1=2; d2=0,s2=4 -> d same conflict.
(1,1) and (3,1): d1=0,s1=2; d2=2,s2=4. P: (4+0)/2=2, (4-0)/2=2 => (2,2) inside -> conflict.
(1,3) and (2,2): d1=-2,s1=4; d2=0,s2=4 -> s same conflict.
(1,3) and (3,1): d1=-2,s1=4; d2=2,s2=4 -> s same conflict.
(1,3) and (3,3): d1=-2,s1=4; d2=0,s2=6. P: (6 + (-2))/2=2, (6 - (-2))/2=4 => (2,4) out of board (j=4>3). Q: (4+0)/2=2, (4-0)/2=2 => (2,2) inside -> conflict.
(2,2) and (3,1): d1=0,s1=4; d2=2,s2=4 -> s same conflict.
(2,2) and (3,3): d1=0,s1=4; d2=0,s2=6 -> d conflict.
(3,1) and (3,3): d1=2,s1=4; d2=0,s2=6. P: (6+2)/2=4, (6-2)/2=2 => (4,2) out; Q: (4+0)/2=2, (4-0)/2=2 => (2,2) inside -> conflict.
So indeed for n=3, any two same-colored bishops cause conflict (either share d/s or intersection inside). Maybe it's always impossible for same color? Let's reason mathematically.
We have two bishops on same color, so s1 ≡ s2 (mod 2). As argued, P = ((s2+d1)/2, (s2-d1)/2). This point's coordinates are integer. Also note that i1 = (s1+d1)/2, j1 = (s1-d1)/2. So consider the midpoint? Actually the coordinates of P can be expressed in terms of the bishops. Alternatively, note that P and Q are the reflections? There's known property: In a chessboard, the two diagonals from bishops intersect at points that are symmetric. Could it be that P and Q are actually the two squares that are the "midpoints" of the segment joining the bishops in rotated coordinates? Perhaps one of them always lies on the board when both bishops are on same color? Let's check.
We need to prove that for any two distinct squares on same color, either d1 = d2, or s1 = s2, or both cross-intersections are inside the board? But maybe one is always inside. Let's test some larger board: n=4. Even squares: many. Pick (1,1) and (4,4)? d1=0,s1=2; d2=0,s2=8 -> d same conflict.
Pick (1,1) and (2,3): (1,1) even, (2,3) odd? (2,3) sum=5 odd, different color. So same color only. (1,3) sum=4 even; (3,1) sum=4 even: they share s conflict. (1,3) and (4,2): (1,3) s=4, d=-2; (4,2) s=6, d=2. P: (6+(-2))/2=2, (6-(-2))/2=4 -> (2,4) within 4x4? Yes (2,4) is inside. Q: (4+2)/2=3, (4-2)/2=1 -> (3,1) inside. Conflict.
Try (1,1) and (3,2): (1,1) even s2,d0; (3,2) sum=5 odd, different color. So same color only. (2,1) sum=3 odd; (1,4) sum=5 odd: (2,1) d=1,s=3; (1,4) d=-3,s=5. P: (5+1)/2=3, (5-1)/2=2 -> (3,2) inside? n=4, yes (3,2) inside. Q: (3+(-3))/2=0, (3-(-3))/2=3 -> (0,3) out. Conflict due to P.
Try (2,1) and (4,3): (2,1) s=3,d=1; (4,3) s=7,d=1? Actually (4,3): i-j=1, s=7. d1 = d2 =1 -> conflict.
Try (2,1) and (4,1)? (4,1) s=5,d=3; different color? (2,1) s=3 odd; (4,1) s=5 odd, same color. d1=1, s1=3; d2=3, s2=5. P: (5+1)/2=3, (5-1)/2=2 -> (3,2) inside. Q: (3+3)/2=3, (3-3)/2=0 -> (3,0) out. Conflict.
Try (1,2) odd and (3,4) odd: (1,2) s=3,d=-1; (3,4) s=7,d=-1? d same? (3,4) i-j=-1, so d same conflict.
Try (1,2) and (4,3): (1,2) s=3,d=-1; (4,3) s=7,d=1. P: (7+(-1))/2=3, (7-(-1))/2=4 -> (3,4) inside. Q: (3+1)/2=2, (3-1)/2=1 -> (2,1) inside. Conflict.
It seems that if bishops are on same color, then at least one of the intersection points (P or Q) is within the board. Let's attempt to prove.
We have two bishops on same color: s1 and s2 have same parity, and d1, d2 have same parity as s's. The coordinates of P: i = (s2+d1)/2, j = (s2-d1)/2. Q: i' = (s1+d2)/2, j' = (s1-d2)/2.
We need to see if it's possible that both i and i' are out of [1,n] or j/j' out. But note that i and j satisfy i+j = s2, i-j = d1. Since s2 is between 2 and 2n (since i,j∈[1,n], s=i+j ∈ [2,2n]) and d1 ∈ [-(n-1), n-1]. So P lies on the board if i∈[1,n] and j∈[1,n] i.e., 1 ≤ (s2+d1)/2 ≤ n and 1 ≤ (s2-d1)/2 ≤ n. Similarly for Q.
Now, consider the sum i + i'? Or note that the midpoints? Perhaps we can use the fact that (i1,j1) and (i2,j2) are both on the board. Maybe we can show that either P or Q is the "intersection" of the lines through the bishops that falls inside. There's known property: On a chessboard, for any two squares of the same color, the intersection of the main diagonal of one and the anti-diagonal of the other is always a square of the opposite color? Actually the parity of P? Since s2 is same parity as d1, i and j are integers. The color of P: i+j = s2, which is the same as bishop2's sum, so P has same color as bishop2 (which is same as bishop1 because same color). So P is also same color. Q similarly same color.
Now, can both P and Q be outside? Possibly if the board is small? But let's try a constructed example: Suppose bishop1 at (1,2) (odd), bishop2 at (2,1) (odd) - they share same anti-diagonal? (1,2) s=3, (2,1) s=3 -> conflict. Not allowed.
What about (1,4) and (4,1) in n=4: both odd? (1,4) s=5, (4,1) s=5 -> share anti-diagonal conflict.
What about (1,4) and (3,2) in n=4: (1,4) s=5,d=-3; (3,2) s=5,d=1 -> s same conflict.
So seems sharing either d or s is common.
Maybe it's always that for same color squares, either d1 = d2 or s1 = s2 or both cross-intersections are inside. But we can try to find a counterexample by brute reasoning: need d1≠d2, s1≠s2, and both P and Q outside. Let's attempt to formalize conditions for P outside.
P outside means either (s2+d1)/2 < 1 or > n, or (s2-d1)/2 < 1 or > n.
Since s2 = i2+j2, d1 = i1 - j1. We have ranges: s2 ∈ [2, 2n], d1 ∈ [-(n-1), n-1].
Let's denote u = (s2+d1)/2, v = (s2-d1)/2. Then u+v = s2, u-v = d1. Conditions: u∈[1,n], v∈[1,n].
P outside if either u<1, u>n, v<1, v>n.
Similarly Q: u' = (s1+d2)/2, v' = (s1-d2)/2.
Now, note that u = (s2+d1)/2 = (i2+j2 + i1 - j1)/2 = (i1 + i2 + j2 - j1)/2. v = (i2+j2 - i1 + j1)/2.
Given that (i1,j1) and (i2,j2) are inside, can both u and v be outside? Possibly if i1 and i2 are at extremes.
Let's attempt to construct a scenario: For P to be outside, maybe u>n and v<1, or u<1 and v>n? But u+v = s2 which is between 2 and 2n. If u>n and v<1, then u+v > n+0 = n, but v<1 implies v≤0, so u+v ≤ u+0 = u, but u > n so u+v > n? Actually u+v could be > n. But s2 = u+v must be ≤ 2n. So it's possible: e.g., u = n+1, v = 0 → s2 = n+1 which is within [2,2n] if n≥2. But v=0 is outside (v<1). So P would be outside. Similarly, u=0, v=n+1 gives s2=n+1, u=0 outside. So it's possible for P to be outside if s2 and d1 are such that the coordinates are extreme.
Similarly Q can be outside. Could both be outside? Possibly.
Let's try to find specific n and positions. We'll attempt to solve equations for both P and Q to be outside. Let’s set n=5. We'll pick bishop1 at (1,2) (odd), bishop2 at (5,4) (odd)? (1,2): s1=3, d1=-1. (5,4): s2=9, d2=1. Check: d1≠d2 (-1 vs 1), s1≠s2 (3 vs9). Compute P: u = (9 + (-1))/2 = 4, v = (9 - (-1))/2 = 5 -> (4,5) within 5x5? j=5, i=4 -> inside. So conflict.
Try bishop1 at (1,2) and bishop2 at (5,2)? (5,2): s=7, d=3. P: u=(7-1)/2=3, v=(7+1)/2=4? Wait compute: (s2+d1) = 7 + (-1) =6/2=3, v = (7 - (-1))=8/2=4 -> (3,4) inside. Q: u'=(3+3)/2=3, v'=(3-3)/2=0 -> (3,0) out. But P inside => conflict.
Try bishop1 at (1,3) odd? (1,3): s=4 even, so even color. We need both same color, so pick both even. Let's try even squares: bishop1 (1,1) s=2,d=0; bishop2 (5,5) s=10,d=0 -> d conflict. So choose d different. (1,1) and (5,3): (5,3) s=8,d=2. P: u=(8+0)/2=4, v=(8-0)/2=4 -> (4,4) inside. Q: (2+2)/2=2, (2-2)/2=0 -> (2,0) out. Conflict.
(1,1) and (5,1): (5,1) s=6,d=4. P: u=(6+0)/2=3, v=(6-0)/2=3 -> (3,3) inside. Q: (2+4)/2=3, (2-4)/2=-1 -> (3,-1) out. Conflict.
(1,1) and (4,5) n=5: (4,5) s=9 odd -> different color.
So seems one of P or Q often inside. Let's attempt a systematic search for n=2000 but we want to know if it's possible to have both outside. Maybe there's a known result: Two bishops on same color always attack a common square (if they are not on same diagonal). I recall that on a chessboard, two bishops of the same color always attack each other or share a common square? Actually in chess, two bishops of the same color can be placed such that they don't attack each other directly if they are not on same diagonal. For example, bishops on a1 and c3? a1 (1,1) and c3 (3,3) share main diagonal -> attack each other. Bishops on a3 (1,3) and c1 (3,1) share anti diagonal -> attack each other. Bishops on a1 and b3? a1 (1,1) and b3 (2,3) have different d and s? (1,1) d=0,s=2; (2,3) d=-1,s=5. They don't share main or anti diagonals. Do they attack a common square? The square (1,1) is attacked by both? No, (1,1) attacked by bishop1, bishop2 does not attack (1,1) because (1,1) i-j=0, not -1; i+j=2, not 5. (2,3) attacked by bishop2, bishop1 does not attack (2,3). But is there any square attacked by both? Let's compute P: M1 ∩ A2: i-j=0, i+j=5 -> (2.5,2.5) not integer? Actually (5+0)/2=2.5 not integer -> so no intersection because parity? Wait bishop1 is (1,1) even, bishop2 (2,3) odd? (2,3) sum=5 odd, different color. So they are opposite colors. So that's allowed and indeed no common attack. But if same color, parity matches so intersections are integer. So the parity condition forces the intersection to be integer. So for same color, the cross-intersections are always integer points. But are they always within board? Not necessarily, but we need to see if they can both be outside.
I want to check n=2: only squares of same color: (1,1) and (2,2) share main diagonal -> conflict. (1,2) and (2,1) share anti diagonal -> conflict. So no.
n=3: we attempted many combos, all had at least one intersection inside or shared diagonal.
n=4: let's brute think: all even squares coordinates: (i+j even). List them:
(1,1) d0 s2
(1,3) d-2 s4
(2,2) d0 s4
(2,4) d-2 s6? (2,4) i+j=6, d=-2
(3,1) d2 s4
(3,3) d0 s6
(4,2) d2 s6
(4,4) d0 s8
Also (1,? ) (2,? ) etc.
We need two bishops with distinct d and s. Try (1,1) s2,d0 and (2,4) s6,d-2. P: (s2' from second? Actually bishop1 d1=0, bishop2 s2=6 => P: (6+0)/2=3, (6-0)/2=3 => (3,3) inside (since n=4, (3,3) valid). So conflict. Q: (2+(-2))/2=0, (2-(-2))/2=2 -> (0,2) out. So conflict.
(1,1) and (3,1) s4,d2: P: (4+0)/2=2, (4-0)/2=2 => (2,2) inside. Q: (2+2)/2=2, (2-2)/2=0 -> (2,0) out. Conflict.
(1,1) and (4,2) s6,d2: P: (6+0)/2=3, (6-0)/2=3 => (3,3) inside. Q: (2+2)/2=2, (2-2)/2=0 -> (2,0) out.
(1,3) s4,d-2 and (2,2) s4,d0 => s same conflict.
(1,3) and (3,3) s6,d0: P: (6+(-2))/2=2, (6-(-2))/2=4 -> (2,4) inside? n=4, (2,4) valid. Q: (4+0)/2=2, (4-0)/2=2 -> (2,2) inside. Conflict.
(1,3) and (4,2) s6,d2: P: (6+(-2))/2=2, (6-(-2))/2=4 -> (2,4) inside. Q: (4+2)/2=3, (4-2)/2=1 -> (3,1) inside. Conflict.
(2,2) and (3,1) both s4? (2,2) s4, (3,1) s4 -> s same conflict.
(2,2) and (4,4) s8,d0: d0 same conflict.
(2,4) s6,d-2 and (3,1) s4,d2: P: (4+(-2))/2=1, (4-(-2))/2=3 -> (1,3) inside. Q: (6+2)/2=4, (6-2)/2=2 -> (4,2) inside. Conflict.
(2,4) and (4,2) s6,d-2 vs s6,d2 -> s same conflict.
(3,1) s4,d2 and (4,4) s8,d0: P: (8+2)/2=5, (8-2)/2=3 -> (5,3) out (i=5>4). Q: (4+0)/2=2, (4-0)/2=2 -> (2,2) inside. Conflict.
(3,1) and (3,3) s6,d0: P: (6+2)/2=4, (6-2)/2=2 -> (4,2) inside. Q: (4+0)/2=2, (4-0)/2=2 -> (2,2) inside. Conflict.
(3,3) s6,d0 and (4,2) s6,d2 -> s same conflict.
Seems no pair of same-colored bishops with distinct d and s yields both cross-intersections outside. At least one of them always inside. Perhaps it's a theorem: On a chessboard, any two squares of the same color have a common square attacked by bishops placed on them, unless they are on the same diagonal (i.e., share d or s)? Actually if they share d or s, they already have common attacked squares (the whole diagonal). If they don't share, then the intersection of one's main diagonal and the other's anti diagonal is always a square on the board. Let's try to prove: For any two squares (i1,j1) and (i2,j2) of the same color (i.e., i1+j1 and i2+j2 have same parity), the point ( (i2+j2 + i1 - j1)/2 , (i2+j2 - i1 + j1)/2 ) must satisfy 1 ≤ i ≤ n, 1 ≤ j ≤ n. Is that always true? Let's test some examples where we thought it might be outside but wasn't. In many cases we saw at least one inside. But could there be a case where both are outside? Let's attempt to find a counterexample by reasoning: Without loss, assume i1+j1 ≤ i2+j2 (since s1 ≤ s2). Also consider d1 and d2.
We have i = (s2 + d1)/2. Since d1 = i1 - j1, and i1 = (s1 + d1)/2, j1 = (s1 - d1)/2. Actually we can express d1 in terms of i1,j1. Similarly.
Maybe we can bound i: i = (s2 + d1)/2 = (i2+j2 + i1 - j1)/2.
Given that i1 ≥ 1, j1 ≥ 1, i2 ≥ 1, j2 ≥ 1. Could i be less than 1? i = (i2 + j2 + i1 - j1)/2 < 1 => i2 + j2 + i1 - j1 < 2. Since each at least 1, the smallest sum is i2=1,j2=1,i1=1,j1=n? Actually j1 can be as large as n. i2+j2 minimal 2. So i2+j2 + i1 - j1 could be as low as 2 + 1 - n = 3 - n. For n>=3, 3-n could be ≤0, so i could be less than 1. For example, i1=1, j1=n, i2=1, j2=1 gives i = (2 + 1 - n)/2 = (3 - n)/2. For n=4, (3-4)/2 = -0.5 -> not integer because parity? Need same parity: i1+j1 = 1+n, i2+j2 = 2, parity differ if n is odd/even? For same color, i1+j1 and i2+j2 have same parity. Let's check: i1=1, j1=4 => s1=5 odd; i2=1, j2=1 => s2=2 even -> not same color. So for same color, s1 and s2 have same parity. So we need to enforce that. So with n=4, same color: even sums: s even. So s1 and s2 both even. For i1=1, j1=4 => s1=5 odd, not allowed. So to have i1=1, j1 large, s1 = 1 + j1 must be even => j1 odd. For n=4, max j1=4 even? 1+4=5 odd, not same parity with s2=2. Could try i1=1, j1=3 => s1=4 even; i2=1, j2=1 => s2=2 even. Good. Then i = (s2 + d1)/2 = (2 + (1-3)= -? d1 = i1 - j1 = -2) => (2 + (-2))/2 = 0, v = (2 - (-2))/2 = 2 -> (0,2) out. So P is (0,2) which is outside. So for this pair, P is outside. Now check Q: Q = ((s1 + d2)/2, (s1 - d2)/2) = ( (4 + (1-1)=0? d2=0 ) => (4+0)/2=2, (4-0)/2=2 -> (2,2) inside. So Q inside. So one is inside. Could we have both outside? We need Q also outside. For Q to be outside, we need ((s1 + d2)/2) <1 or >n, or ((s1 - d2)/2) <1 or >n. For the same pair, Q was inside.
Let's try to make both outside. We need to choose i1,j1,i2,j2 such that:
- s1 and s2 same parity.
- d1 ≠ d2, s1 ≠ s2.
- For P: either u = (s2+d1)/2 ∉ [1,n] or v = (s2-d1)/2 ∉ [1,n] (preferably both outside? Actually just at least one coordinate out, but to be outside the board, we need either u<1 or u>n or v<1 or v>n. However it's possible that one coordinate in range but the other out; then point is outside. So we just need that point not inside board. Similarly for Q.
We need both P and Q not to be inside. Could it be that for same color, at least one of P or Q is always inside? Let's try to prove.
Observing earlier examples, Q inside occurred when s1+d2 gave something. Let's derive relationship between P and the bishops' positions. Notice that the point P is actually the "reflection" of bishop1 across the center of bishop2? Not exactly.
Alternative perspective: Consider the board coordinates in the transformed space: let u = i, v = j. The condition for a square to be attacked by a bishop is that either its (i-j) equals that bishop's (i-j) or its (i+j) equals that bishop's (i+j). So the attack set is the union of two orthogonal lines in the (i-j, i+j) coordinate system. In that system, a bishop corresponds to a point (d, s) where d = i-j, s = i+j, with parity constraint that s and d have same parity (since i = (s+d)/2, j = (s-d)/2 must be integers). The board is the set of (d,s) such that s from 2 to 2n, d from -(n-1) to (n-1), with s and d having same parity.
Now a bishop at (d1,s1) attacks all points (d, s) such that either d = d1 or s = s1 (within board). Two bishops attack a common square if there exists (d,s) within board such that (d = d1 or s = s1) AND (d = d2 or s = s2). That yields four possibilities: d = d1 = d2 (requires d1=d2), s = s1 = s2 (requires s1=s2), (d=d1 and s=s2), (d=d2 and s=s1). So the existence of a common attacked square is equivalent to either d1 = d2, or s1 = s2, or the point (d1, s2) is a valid board cell (i.e., corresponds to integer i,j within range), or (d2, s1) is a valid board cell. Note that (d1, s2) corresponds to i = (s2+d1)/2, j = (s2-d1)/2, which is valid if parity matches (s2 and d1 same parity) and coordinates within range. Since both bishops are same color, s1 ≡ d1 (mod 2) and s2 ≡ d2 (mod 2). And s1 ≡ s2 (mod 2) (same color), so s2 ≡ d1 (mod 2) because d1 ≡ s1 ≡ s2. So parity condition holds automatically. So (d1,s2) always corresponds to integer coordinates. Similarly (d2,s1). So the only condition for common attack is whether these coordinates lie within the board. So the condition for no common attacked square is: d1 ≠ d2, s1 ≠ s2, and both (d1, s2) and (d2, s1) are outside the board (i.e., either i or j out of range). Because if either is inside, then that square is attacked by both.
Thus, the problem reduces to: choose two cells (d1,s1) and (d2,s2) within the board (with parity condition) such that d1≠d2, s1≠s2, and both (d1,s2) and (d2,s1) are not within the board. Also note that the bishops themselves must not be in each other's attack sets, but that is equivalent to d1≠d2 and s1≠s2 and also (d1,s2) and (d2,s1) not being exactly the bishop positions? Actually bishop1 is (d1,s1). Could bishop2 be equal to (d1,s2)? That would mean bishop2 lies on the intersection of d1 and s2, but then bishop2 is on bishop1's main diagonal? Actually bishop2 being (d1,s2) would mean its d = d1, so it shares main diagonal with bishop1 => not allowed because then bishop1 would be attacked by bishop2? Actually if bishop2 is at (d1,s2), then bishop1 is at (d1,s1). Then bishop1 and bishop2 share main diagonal d1, so they attack each other along that diagonal (unless they are the only cell? Actually they are on same main diagonal but distinct, so they attack each other). So such placement is invalid anyway because d1=d2? Actually if bishop2 is at (d1,s2) then d2 = d1, so d1=d2, which we already exclude. So it's covered.
Thus, the condition is as above.
So we need to decide if there exists a pair of same-colored squares such that both (d1,s2) and (d2,s1) are outside the board. If such pairs exist, then we could place bishops on same color without conflict. But if not, then the only valid placements are bishops on opposite colors. We need to maximize sum of attacked values (each bishop attacks its own diagonals; each cell attacked by a bishop gives its value, but if a cell is attacked by both, it's not allowed; but we only get money for each cell that is attacked by at least one bishop? Wait the problem statement: "Consider a cell with number x written on it, if this cell is attacked by one of the bishops Gargari will get x dollars for it." Actually: "if this cell is attacked by one of the bishops Gargari will get x dollars for it." That suggests that if a cell is attacked by both bishops, does he get x dollars only once? Or does he get x for each bishop? The phrase: "Consider a cell with number x written on it, if this cell is attacked by one of the bishops Gargari will get x dollars for it." It seems ambiguous. However typical interpretation: For each cell, if it is attacked by at least one bishop, he gets its value. But the condition says there is no cell that is attacked by both. So the attack sets are disjoint. Therefore total money = sum of values on cells attacked by bishop1 plus sum on cells attacked by bishop2, and these sets are disjoint. So effectively he gets the sum over the union of cells attacked by the bishops, but since they are disjoint, it's just the sum of values on all cells attacked by either bishop, with no double counting.
But careful: Could a cell be attacked by both if we place them such that no cell is attacked by both? The condition forbids that. So we must choose placements such that the attack sets are disjoint. So total money = sum of values on all cells that lie on either bishop's main diagonal or anti diagonal, but we must avoid double counting and also the condition ensures no overlap, so we can sum the values on the two bishops' diagonals (union) directly.
So the problem: Choose two squares (x1,y1) and (x2,y2) such that the union of cells on their two diagonals (main and anti) for each bishop are disjoint, maximize total sum.
Given that bishops on opposite colors automatically have disjoint attack sets (since they attack only cells of that color), and bishops on same color seem to always have at least one common cell (I suspect it's impossible to have disjoint attack sets for same color bishops unless n is very small? Let's try to formally prove or disprove existence of same-color non-attacking bishop pair.
We can think in (d,s) coordinate system. The board is set of integer pairs (d,s) with s from 2 to 2n, d from -(n-1) to (n-1), and s ≡ d (mod 2). The attack set of bishop at (d1,s1) is { (d,s) : d = d1, 2 ≤ s ≤ 2n, s ≡ d1 mod 2 } ∪ { (d,s) : s = s1, -(n-1) ≤ d ≤ n-1, d ≡ s1 mod 2 }. These are two lines.
For two bishops on same parity (i.e., both have same parity of s and d, but also s1 ≡ d1, s2 ≡ d2), we require that these two sets are disjoint. Intersection can occur at points where (d1,s2) (the intersection of line d=d1 and s=s2) and (d2,s1). For disjointness, both these points must be outside the board. Also lines d=d1 and d=d2 are disjoint if d1≠d2 (they're parallel distinct lines). Lines s=s1 and s=s2 are disjoint if s1≠s2. However, the line d=d1 may intersect line s=s2 at (d1,s2). That's the only possible intersection between the two sets? Could there be any other intersection? Consider a cell that lies on d=d1 and also on d=d2? impossible unless d1=d2. Similarly s=s1 and s=s2 impossible unless s1=s2. Could there be a cell that lies on d=d1 and also on s=s1? That's the bishop's own position, but that's in both sets? Actually that cell is in bishop1's set (since it's on both its lines) and also bishop2's set? It would be in bishop2's set only if it lies on d=d2 or s=s2. So it's not a common cell unless the bishop's own square is also on bishop2's diagonals, which would mean d1=d2 or s1=s2. So indeed, the only possible common cells are (d1,s2) and (d2,s1). So disjointness condition is exactly: (d1,s2) and (d2,s1) are not valid board points.
Now the question: Are there two distinct points (d1,s1) and (d2,s2) in the board (with parity) such that both (d1,s2) and (d2,s1) are not in the board? If yes, then we could have same-color valid placement.
Let's analyze the constraints for (d1,s2) to be a valid board point: i = (s2+d1)/2 must be between 1 and n, and j = (s2-d1)/2 between 1 and n. Equivalently: 1 ≤ (s2+d1)/2 ≤ n and 1 ≤ (s2-d1)/2 ≤ n.
Let’s denote A = s2 + d1, B = s2 - d1. Conditions: 2 ≤ A ≤ 2n and 2 ≤ B ≤ 2n, and also A and B have same parity as s2 and d1 (they will be even because s2 and d1 have same parity). So the condition for (d1,s2) to be inside is: both A/2 and B/2 are in [1, n].
Now note that A/2 + B/2 = s2 (since (s2+d1)/2 + (s2-d1)/2 = s2) and A/2 - B/2 = d1. So essentially the point is inside if (s2+d1)/2 in [1,n] and (s2-d1)/2 in [1,n].
Given that s2 is between 2 and 2n, and d1 between -(n-1) and (n-1). The condition is that both (s2 ± d1) are between 2 and 2n. This is equivalent to: |d1| ≤ s2 - 2 and |d1| ≤ 2n - s2? Wait we need (s2 + d1) ≥ 2 and ≤ 2n, and (s2 - d1) ≥ 2 and ≤ 2n. Since s2 is between 2 and 2n, s2 + d1 ≥ 2 is automatically satisfied if d1 ≥ -(s2-2). Similarly s2 + d1 ≤ 2n if d1 ≤ 2n - s2. s2 - d1 ≥ 2 if d1 ≤ s2 - 2. s2 - d1 ≤ 2n if d1 ≥ -(2n - s2). So overall we need |d1| ≤ s2 - 2 and |d1| ≤ 2n - s2. Actually from s2 + d1 ≥ 2 => d1 ≥ 2 - s2 => since s2≥2, 2-s2 ≤0, so this is a lower bound. But the stricter lower bound likely from s2 - d1 ≤ 2n? That gives -d1 ≤ 2n - s2 => d1 ≥ s2 - 2n, which is ≤0. The strongest lower bound is d1 ≥