We need to understand the problem: Bob has square tiles split diagonally into white and black parts. Each tile can be rotated in four ways. So essentially, each tile is a square with a diagonal dividing it into two triangles: one white, one black. The orientation of the diagonal can be either from top-left to bottom-right () or from top-right to bottom-left (/). However, because rotation includes four ways, but the diagonal only has two distinct orientations (the two diagonals) and also the assignment of colors (which half is white and which is black) is fixed relative to the orientation? Wait, the tile is described as "a square tile that is diagonally split into white and black part as depicted in the figure below." Typically, such a tile has a fixed pattern: e.g., white on one side of the diagonal, black on the other. Rotating the tile rotates the entire pattern, so the diagonal orientation changes, and also the colors swap positions relative to the fixed axes? But the figure likely shows a specific pattern: maybe the top triangle is white and bottom triangle is black? Actually, the image not provided. But from typical puzzles: tile is a square divided by a diagonal into two right triangles, one white, one black. The tile can be rotated, so there are 4 orientations, but due to symmetry, there are only 2 distinct configurations regarding which edges have which colors? However, since the tile has two colors, and adjacency constraint is about colors on shared edges: two adjacent tiles must not share a color on the edge. That means, on each side (edge) of a tile, the color at that edge (since the tile's edge is split into two halves by the diagonal's endpoint? Actually, the tile is a square, its edge is a line segment. However, because the tile is split diagonally, each edge of the square is divided into two segments: one part from one triangle and the other part from the other triangle. So along the edge, there is a color change at the midpoint (where the diagonal meets the edge). So each tile's side has two colors: one color on the left half and another color on the right half (if vertical side), or top half and bottom half (if horizontal side). But the adjacency constraint: "two adjacent tiles must not share a colour on the edge — i.e. one of the tiles must have a white colour on the shared border, and the second one must be black." That suggests that along the entire shared edge, the colors should be opposite? But since each tile's edge is split into two halves, possibly the colors on each half must be opposite? The phrasing: "two adjacent tiles must not share a colour on the edge — i.e. one of the tiles must have a white colour on the shared border, and the second one must be black." This is ambiguous: does it mean that for each point along the border, the colors from the two tiles are different? Or does it mean that the entire shared edge must be of opposite colors? But because each edge has two halves, it's possible that one tile has white on the left half and black on the right half, while the neighboring tile might have black on the left half and white on the right half, so at each half the colors are opposite. Alternatively, the constraint might be that the colors on the two sides of the edge must be complementary, i.e., each tile's edge color pattern is monochrome? But the tile's edge is not monochrome; it has two colors. Actually, is the edge considered as a whole? The typical puzzle with diagonal tiles often considers that the diagonal divides the square into two triangles, and when two tiles are placed side by side, their adjacent edges meet. At the meeting, the colors on the boundary should match or be opposite? Wait, let's recall known problems: There is a known problem: "Tiles" with a diagonal split, and adjacency condition that colors on shared edge must be different. Often, each tile has two halves, and along the edge, the colors on either side of the diagonal meeting point must be opposite? But there is also a known problem "Colored Tilings" or "A. Tiling with Dominoes"? Not exactly.
Let's search memory: This problem might be from Codeforces or similar. I recall a Codeforces problem "Boboniu Chats with Du" no. Maybe "Bob's tile"? I think there is a known problem: "Kitchen" perhaps? But I need to deduce.
Alternative interpretation: Each tile is a square with two colors: white and black, split by a diagonal. When placed, the tile's sides each have a single color? Actually, if the diagonal runs from one corner to the opposite, then each side of the square is entirely in one color? No: Consider a square with a diagonal from top-left to bottom-right. The left side: the left side is a vertical edge from top-left to bottom-left. The diagonal meets the top-left corner and bottom-left corner? Actually, the diagonal goes from top-left to bottom-right, so it does not meet the left edge except at the top-left corner? Wait: The left edge is from (0,0) to (0,1). The diagonal from (0,0) to (1,1) only touches the left edge at (0,0) (top-left corner). So the left edge is not intersected elsewhere. So the entire left edge lies within the triangle that is above the diagonal or below? For a diagonal from top-left to bottom-right, the triangle on the left? Actually, let's define coordinates: square with corners: (0,0) top-left, (1,0) top-right, (0,1) bottom-left, (1,1) bottom-right. Diagonal from (0,0) to (1,1) splits into two triangles: one is below the diagonal? Usually, triangle with vertices (0,0), (1,0), (1,1) is the upper-right? And triangle (0,0), (0,1), (1,1) is left-bottom? Let's be precise: Points satisfying y <= x? Actually, line from (0,0) to (1,1) has equation y = x. The region where y <= x includes points below the line? If y is vertical axis downward? Usually in graphics, y increases downward, but doesn't matter. But for a diagonal, the square is divided into two right triangles. One triangle includes the top edge and left edge? Actually, the diagonal from top-left to bottom-right: one triangle is top-right (with vertices top-left, top-right, bottom-right) and the other is bottom-left (with vertices top-left, bottom-left, bottom-right). So the left edge: from top-left to bottom-left: the top-left corner is on diagonal, but the rest of left edge (except bottom-left? bottom-left is (0,1) not on diagonal because diagonal goes to (1,1) bottom-right, so bottom-left is not on diagonal) belongs to the bottom-left triangle. So the left edge is entirely in the bottom-left triangle (except the top-left point). Similarly, the top edge is entirely in the top-right triangle? Top edge from (0,0) to (1,0): except top-left, top-right is (1,0) which is not on diagonal? Actually diagonal goes to (1,1), so top-right is not on diagonal. So top edge belongs to top-right triangle. The right edge belongs to top-right triangle? Right edge from (1,0) to (1,1): top-right is (1,0) not on diagonal, bottom-right (1,1) is on diagonal. So right edge belongs to top-right triangle except bottom-right. The bottom edge belongs to bottom-left triangle. So essentially, each edge is fully within one of the two colored triangles (except at the endpoints). So for a diagonal orientation, each side of the tile is entirely of one color (white or black), because the entire side lies in one triangle. Similarly, for the other diagonal (top-right to bottom-left), the sides would be colored differently.
Thus, each tile can be seen as having a color assignment to its four sides: each side is either white or black, determined by which side of the diagonal it lies on. For the diagonal from top-left to bottom-right: left side and bottom side are one color (say black), and top side and right side are the other color (say white). But we need to know which color is which: The tile is split into white and black parts. The figure likely shows a specific assignment: maybe the triangle that is white is the one on the top-left? Actually, typical figure: tile with a diagonal from top-left to bottom-right, white on the left-bottom? Hard to guess. However, since rotations are allowed, the relative assignment of colors to sides is determined by the orientation of the diagonal and which triangle is white.
But because the tile can be rotated, any configuration where each tile has exactly two adjacent sides of one color and the other two adjacent sides of the other color (i.e., the colors on the four sides follow a pattern: either the colors are arranged such that opposite sides have the same color? Let's analyze: For a diagonal split, the two triangles are opposite corners: one triangle covers two adjacent sides? Actually, each triangle touches two sides: For diagonal TL-BR, triangle TL-BR (top-left to bottom-right) includes top edge and right edge? Wait, let's define: triangle A: vertices TL, TR, BR: that triangle touches top edge (from TL to TR) and right edge (TR to BR). Triangle B: TL, BL, BR: touches left edge (TL to BL) and bottom edge (BL to BR). So indeed, each triangle covers two sides that meet at a corner. So for a given tile, two adjacent sides are of one color (the color of that triangle), and the other two adjacent sides are of the other color. And note that opposite sides are of opposite colors? For TL-BR diagonal: top and right are same color (say white), left and bottom are same color (black). So top and left are different, top and bottom are opposite? Actually, top (white) vs bottom (black) are opposite, left (black) vs right (white) are opposite. So opposite sides have opposite colors. For the other diagonal (TR-BL): triangle TR-BL (top-right to bottom-left) would have top and left? Let's compute: vertices TR, TL, BL? Actually, diagonal from TR to BL splits into triangle TR, TL, BL (covering top edge and left edge) and triangle TR, BR, BL (covering right edge and bottom edge). So for that orientation, top and left are same color, right and bottom are same color. So again, opposite sides have opposite colors. So in both diagonal orientations, the pattern is: each tile has two opposite sides of one color, and the other two opposite sides of the other color? No, in TL-BR: top and right are same (adjacent), left and bottom are same (adjacent). That yields opposite sides: top vs bottom: different; left vs right: different. So opposite sides are different. In TR-BL: top vs bottom: top is from one triangle, bottom from other, so different; left vs right: different. So indeed, for both diagonals, opposite sides have opposite colors. So the property is: each tile is bipartite in terms of side colors: sides are colored such that opposite sides have opposite colors. Moreover, adjacent sides have the same color? Actually, in both patterns, adjacent sides are sometimes same and sometimes different? Let's check TL-BR: top and right are same (adjacent at top-right corner), top and left are different (adjacent at top-left), bottom and left are same, bottom and right are different. So two adjacent sides share a corner: at each corner, the two sides meeting there are either both the same color or opposite depending on which diagonal. In TL-BR: at TL corner, top and left meet: they are different (top white, left black). At TR corner, top and right: same (both white). At BL corner, left and bottom: same (both black). At BR corner, bottom and right: different (bottom black, right white). So it's not uniform. In TR-BL: at TL corner: top and left: same; at TR: top and right: different; at BL: left and bottom: different; at BR: bottom and right: same. So each tile has two corners where the two sides are same color, and two corners where they are different. But does this matter? The adjacency condition only concerns edges, not corners.
Given that each edge is entirely one color (since the side lies entirely in one triangle, except the endpoints which are points), the condition "two adjacent tiles must not share a colour on the edge" means that along the shared edge, the color on tile A's side must be different from the color on tile B's side. So it's a simple constraint: for each pair of neighboring tiles (horizontally or vertically), the colors on their abutting edges must be opposite (one white, one black).
Thus, the tiling problem reduces to: We have a grid of w x h tiles. Each tile can be in one of several orientations (4 possible). Each orientation determines a coloring of its four edges (up, right, down, left) with colors white (W) or black (B), such that the coloring satisfies: opposite edges have opposite colors? Actually, from the tile structure, is that always true? Let's derive all possible colorings from the tile and rotations.
We have a square tile with a diagonal split into white and black halves. The halves are fixed: i.e., one triangle is white, the other black. The tile can be rotated by multiples of 90 degrees. So we need to enumerate the four orientations. The underlying pattern is not symmetric under swapping colors because the colors are assigned: one triangle is white, the other black. However, rotating the tile preserves the assignment relative to the tile. So each orientation yields a mapping of which edges get which color.
We need to deduce the pattern from the figure description: "a square tile that is diagonally split into white and black part as depicted". There is likely a standard orientation: Perhaps the tile is drawn with the diagonal from top-left to bottom-right, and the top-left triangle is white? Or maybe the figure shows something. But the problem statement includes two example tilings for 3x2 showing valid/invalid. The left picture shows a valid tiling of a 3x2 kitchen. The right picture shows an invalid arrangement because the bottom two tiles touch with their white parts. We don't see the pictures, but we can infer from the description: "the bottom two tiles touch with their white parts." That suggests that the shared edge between two adjacent tiles is entirely white on both sides, violating the condition. So that indicates that each tile's edge is a single color.
Thus, the problem is to count the number of ways to assign to each cell a tile orientation such that for every adjacent pair, the colors on the shared edge are opposite.
This is reminiscent of a 2-coloring constraint on edges of a grid graph, but with internal degrees of freedom.
We can think of each tile as a "vertex" with four incident edges, each of which must be assigned a color (W/B) that comes from the tile's orientation. The tile's orientation determines the pattern of colors on its four sides. So we need to count assignments of orientations to all vertices such that for every edge (neighboring pair), the colors assigned by the two endpoints to that edge are opposite.
This is similar to a "edge coloring" or "spin" model, but with constraints per vertex from a set of allowed spin assignments (the four orientations). Since w and h up to 1000, we need a formula or combinatorial recurrence.
Let's attempt to characterize the allowed color patterns on a tile. Represent colors as binary: 0 for white, 1 for black (or vice versa). For each tile, its sides: up (U), right (R), down (D), left (L). The tile's pattern must come from the diagonal split. Let's set coordinate: tile is square; the diagonal split into two triangles: one white, one black.
Define the two possible diagonals: \ or /. But also, we can rotate the tile, which effectively generates four patterns. However, we need to consider that rotating a tile with a fixed color assignment (i.e., which triangle is white) yields four distinct patterns? Let's enumerate.
Suppose the base tile (orientation 0) has the diagonal from top-left to bottom-right () and the triangle on the top-right is white (or maybe the other). Without loss, we can define colors arbitrarily because flipping colors globally might not matter if we treat colors as absolute? But the condition requires opposite colors on shared edges, so colors are absolute. However, the tile's pattern has fixed assignment: one triangle is white, the other black. So we need to know which is which. But we can define the colors relative; the count of tilings may depend on that assignment? Probably not because if we swapped colors globally (all white become black, all black become white), it would still be a valid tiling because the condition is symmetric: it requires them to be different, not which is which. So the total number should be same regardless of which triangle is white in the base tile. But we need to be precise: the four orientations generate four specific colorings.
Let's assume the tile in its reference orientation (no rotation) has diagonal from top-left to bottom-right, and the top-right triangle is white, bottom-left triangle is black. Then its side colors: top side lies in the top-right triangle, so white; right side lies in top-right triangle, white; left side lies in bottom-left triangle, black; bottom side lies in bottom-left triangle, black. So pattern: U=W, R=W, D=B, L=B. (U and R same color; D and L same color; opposite sides: U vs D opposite, L vs R opposite; adjacent sides: U and R same, L and D same, U and L opposite, R and D opposite).
Now, if we rotate this tile 90 degrees clockwise: the diagonal now becomes from top-right to bottom-left? Actually, rotating the tile 90° clockwise will map the original top to right, right to bottom, bottom to left, left to top. So the pattern becomes: new U = old R = W; new R = old D = B; new D = old L = B; new L = old U = W. So pattern: U=W, R=B, D=B, L=W. That is: U and L are W; R and D are B. So opposite sides: U vs D (W vs B) opposite; L vs R (W vs B) opposite; adjacent: U and R: W vs B diff; U and L: same; D and L: B vs W diff; D and R: same.
If we rotate 180 degrees: pattern: U= old D = B; R= old L = B; D= old U = W; L= old R = W. So U=B,R=B,D=W,L=W.
Rotate 270 degrees: pattern: U= old L = B; R= old U = W; D= old R = W; L= old D = B. So U=B,R=W,D=W,L=B.
Thus, the four patterns are:
- (U,R,D,L) = (W,W,B,B)
- (W,B,B,W)
- (B,B,W,W)
- (B,W,W,B)
These are the four orientations. Notice they are cyclic shifts? Actually, they are the four patterns where two opposite sides are one color and the other two opposite sides the other color, but also the pattern of adjacent sides alternates. In fact, these are exactly the four ways to assign colors to the four sides such that opposite sides are opposite and that the pattern is "balanced"? Let's see: The condition that opposite sides are opposite is necessary from the geometry? Check each pattern: U opposite D: in pattern1: W vs B -> opposite; pattern2: W vs B? pattern2 U=W, D=W? Wait pattern2: U=W, D=W? Actually pattern2: (W,B,B,W): D=B? Wait pattern2: U=W, R=B, D=B, L=W -> U=W, D=B -> opposite. So yes. In pattern3: U=B, D=W opposite. In pattern4: U=B, D=W opposite. Also L vs R: pattern1: L=B,R=W opposite; pattern2: L=W,R=B opposite; pattern3: L=W,R=B? pattern3: U=B,R=B? Wait pattern3: (B,B,W,W): R=B, L=W -> opposite; pattern4: (B,W,W,B): R=W,L=B opposite. So indeed opposite sides are opposite in all four patterns.
But is that condition also sufficient? Would any assignment of colors to four sides with opposite sides opposite arise from a tile orientation? Let's see: There are 2^4 = 16 assignments, but with constraint opposite sides opposite: that means U != D and L != R. That gives 2 choices for U (W/B), then D forced opposite, and 2 choices for L, then R forced opposite, so total 4 assignments. Indeed, these four assignments exactly match the four patterns we have. So the set of allowed colorings for a tile is precisely: assign a color to the top side and a color to the left side; then the bottom side is opposite top, right side is opposite left. So there are 4 possibilities: (U,L) can be (W,W), (W,B), (B,W), (B,B). But are all four actually realizable by rotating the physical tile? In our derived patterns, we have:
- (U,L) = (W,W) corresponds to pattern? Check: pattern1: U=W, L=B -> no, (W,W) not pattern1; pattern2: U=W, L=W -> yes pattern2 is (W,B,B,W) -> U=W, L=W. So pattern2 gives (U,L) = (W,W). Pattern3: (B,B,W,W) gives U=B,L=W -> (B,W). Pattern4: (B,W,W,B) gives U=B,L=B -> (B,B). Pattern1: (W,W,B,B) gives U=W,L=B -> (W,B). So indeed all four (U,L) pairs are covered. So equivalently, each tile can be described by two independent bits: the color of its top edge (say a) and the color of its left edge (say b). Then the bottom edge is opposite of a, right edge is opposite of b.
Thus, the tile's orientation is fully determined by the colors assigned to its top and left edges. Conversely, given any choice of colors for top and left edges, there is a unique orientation that yields those colors? Check: In our enumeration, each (U,L) pair appears exactly once. So yes, for each tile, we can independently choose the colors of its top and left edges (each either white or black), and that determines the tile's orientation (and also the colors of its bottom and right edges accordingly). But is that physically possible? The tile pattern has constraints linking top and left? For a diagonal split tile, can we have (U,L) both white? In pattern2 we saw that's possible, which corresponds to diagonal orientation? pattern2 came from rotation of the base tile. So yes.
Thus, the tiling problem reduces to: For each cell (i,j) in a w x h grid (w columns, h rows), we choose two bits: t(i,j) = color of its top edge, l(i,j) = color of its left edge. Then automatically the bottom edge color = opposite of t(i,j), and right edge color = opposite of l(i,j). However, we must also satisfy adjacency constraints:
- For vertical adjacency (cell (i,j) above cell (i,j+1) maybe? Let's define: rows indexed 1..h from top to bottom, columns 1..w from left to right. Cell at row r, column c. Its top edge is the border with the cell above (if any). Its bottom edge with cell below. Its left edge with cell left, right edge with cell right.
Constraint: For each pair of adjacent cells horizontally (left-right), the right edge of the left cell must be opposite to the left edge of the right cell. Similarly, for vertical adjacency, the bottom edge of the upper cell must be opposite to the top edge of the lower cell.
Given that right edge of a cell = opposite of l(i,j) (its left edge color). And left edge of right neighbor = l(i,j+1). So the horizontal constraint between cell (c,r) and (c+1,r) is:
opposite(l(c,r)) != l(c+1,r) ? Actually, condition: they must be different. So we need opposite(l(c,r)) != l(c+1,r) ? Wait, condition: one must be white, the other black. So if right edge of left cell is color X, and left edge of right cell is color Y, we require X != Y. Since X = opposite(l_left), we require opposite(l_left) != l_right => that is equivalent to l_left == l_right? Because opposite(l_left) != l_right means l_left == l_right? Let's check: if l_left = W, then opposite(l_left)=B. For them to be different, l_right must be not B => l_right must be W? Actually, we need opposite(l_left) != l_right. If l_left = W, opposite = B. For B != l_right, l_right must be not B, i.e., l_right = W. So l_right = W = l_left. If l_left = B, opposite = W, then l_right must be not W => l_right = B = l_left. So condition is l_left == l_right. Because opposite(l_left) and l_right must be different, which forces l_right to equal l_left. So the horizontal constraint becomes: l(c,r) == l(c+1,r). That is, left edge colors of adjacent horizontally neighboring cells must be equal.
Now, vertical constraint: between cell (c,r) and cell (c,r+1) (r row from top), bottom edge of top cell = opposite(t(c,r)) and top edge of bottom cell = t(c,r+1). Condition: opposite(t(c,r)) != t(c,r+1). By same reasoning, this forces t(c,r) == t(c,r+1). Because opposite(t_top) != t_bottom => t_bottom must equal t_top? Let's check: t_top = W => opposite = B, require B != t_bottom => t_bottom != B => t_bottom = W = t_top. Similarly if t_top = B => t_bottom = B. So we get t(c,r) == t(c,r+1).
Thus, constraints are: All tiles in the same row must have the same left-edge color? Actually, horizontally adjacent cells must have equal left-edge colors. By transitivity along a row, all cells in a given row must have the same l value. Similarly, vertically adjacent cells must have the same t value, so all cells in a given column must have the same t value.
But careful: The constraints are only between adjacent cells. However, along a row, if we have w cells, the constraints l1 == l2, l2 == l3, ..., l_{w-1} == l_w, so indeed all l's in that row are equal. Similarly, along a column, all t's in that column are equal. But what about interactions between rows and columns? There might be additional constraints? The corner cells also have relationships via both dimensions? Actually, there is no direct constraint linking l of one cell to t of another cell. However, there is an indirect constraint because each cell itself has both l and t values that are independent? But there might be consistency constraints from the tile's internal structure? We already used the tile's pattern: given l and t, the tile is defined. There's no further constraint linking l and t within a cell; they can be chosen independently. So each cell can have any combination (l,t) from {0,1}^2.
But wait: is there any global condition that arises from the fact that the edges around the boundary are not constrained? The problem only imposes adjacency constraints between tiles; there is no condition on the outer edges. So that seems fine.
Thus, the constraints imply that for the entire grid, there exists a row-common left color value for each row, and a column-common top color value for each column. Specifically, define for each row r (1..h) a variable L_r = l(c,r) for all c (since all cells in row r have same l). Define for each column c (1..w) a variable T_c = t(c,r) for all r (since all cells in column c have same t). Then for the cell at (c,r), we have l(c,r) = L_r and t(c,r) = T_c. So the configuration is determined by: choose L_1,...,L_h ∈ {0,1} and T_1,...,T_w ∈ {0,1}. Then for each cell, we set its l = L_r, t = T_c. That yields a valid tiling because all adjacency constraints are satisfied: horizontal: between (c,r) and (c+1,r), l values both equal L_r (since same row) => constraint satisfied. Vertical: between (c,r) and (c,r+1), t values both equal T_c => satisfied.
Thus, number of tilings would be number of assignments to L_r and T_c, i.e., 2^{h} * 2^{w} = 2^{w+h}. However, the examples show: Input 2 2, output 16. 2^{2+2}=16, matches. Input 2 4, output 64. 2^{2+4}=64, matches. So that fits perfectly.
Thus, the answer is 2^{w+h} mod 998244353.
But wait, we need to double-check: Is there any hidden nuance? Are there any additional constraints from the tile's geometry that might restrict some combinations of (L_r, T_c)? For example, we assumed that any combination (t,l) yields a valid tile orientation. But does the tile's physical pattern allow all four? Yes, we derived four orientations. However, is there any distinction between the two colors? The tile's pattern has a fixed assignment of which triangle is white; we assumed a specific assignment. But if we change the base assignment (swap white and black), the set of four patterns would be the complement? Actually, if the base tile had the opposite coloring (top-right triangle black, bottom-left white), then the base pattern would be (U= B, R= B, D= W, L= W). Then the rotations would yield the complement set: essentially all colors flipped. But the set of patterns would be the same as before? Let's check: Starting with (B,B,W,W) (pattern3 in our earlier set). Rotating yields patterns: 90: (B,W,W,B) (pattern4), 180: (W,W,B,B) (pattern1), 270: (W,B,B,W) (pattern2). So the set is exactly the same four patterns! Indeed, the set of four patterns is closed under color inversion (since it's the set of all assignments with opposite sides opposite). So regardless of which triangle is white originally, the four orientations produce the same set of four colorings. So it's consistent.
Thus, the counting seems trivial: 2^{w+h}. But wait, is there any possibility of other tile rotations? The tile can be rotated in one of four ways. That's exactly the four orientations. So the set of allowed edge colorings is exactly the four described. So indeed each tile can be represented by two independent bits (top and left colors). That leads to the simple solution.
But is there any hidden twist? The problem might be more complicated if the adjacency condition also considered the diagonal meeting points, i.e., the colors along the edge are not uniform because the edge is split into two halves? But we argued that each side lies entirely in one triangle, so the entire side is a single color. However, is that always true? Re-examine: In a square with a diagonal, does the side lie entirely in one triangle? For a diagonal from top-left to bottom-right, left side from top-left to bottom-left: top-left is on the diagonal, bottom-left is not. The line from top-left to bottom-left: interior points have x=0, y from 0 to 1. The diagonal equation y=x. For interior points on left edge (x=0, y>0), they satisfy y>0=x so y > x, so they are below the line if we consider y increasing downward? Actually, define coordinate: origin at top-left, x right, y down. Then top-left = (0,0). diagonal from (0,0) to (1,1): line y=x. Points on left edge: (0, y) with y>0. Compare y and x: y > 0 = x? So y > x, meaning they are below the line (since y is larger). So these points lie in the region below the diagonal. Which triangle is that? The diagonal divides the square into two triangles: one where y <= x (above or on the line) and one where y >= x (below or on the line). Which one is white? That depends. But the left edge points (except top-left) are all with y>0, x=0 => y > x, so they are in the region y >= x, i.e., the triangle containing bottom-left and bottom-right? Actually, bottom-left (0,1) has y=1 > x=0, so it's in the region y >= x. So the left edge (except the endpoint) lies entirely in the y >= x region. Similarly, bottom edge (x from 0 to1, y=1) satisfies 1 >= x? For x<1, y=1 > x, so points are in y >= x region as well. So left and bottom edges are in the same region. The top edge (y=0, x>0) has y=0 < x, so in y <= x region. Right edge (x=1, y<1) has y < 1 = x? Actually at (1, y) with y<1, compare y and x: y < 1 => y < x, so in y <= x region. So indeed each entire side (excluding endpoints) is within one triangle. So the side is uniformly one color. Good.
What about the other diagonal (top-right to bottom-left)? Similar property holds.
Thus, the problem is indeed trivial: number of tilings = 2^{w+h} mod mod.
But is that always correct for any w, h? Let's test with small values manually to be sure.
Consider w=1, h=1: a single tile. The number of ways to place the tile satisfying no adjacency constraints (since there are no neighbors) is just number of orientations: 4. Our formula gives 2^{1+1}=4. Good.
Consider w=1, h=2: vertical stack of two tiles. Our constraints: All cells in the same column have same t? Since w=1, we have one column. t for each cell? Actually, each cell has t (top edge) and l (left edge). Since w=1, only one column, the horizontal constraints are nonexistent (no right neighbor). But vertical constraints: between top and bottom, t values must be equal? Let's derive using our variables: For column c=1, we have t(c,r) = T_1 for all r? Actually, from column commonality: T_c is the top color for all cells in that column. That arises from vertical constraints: between row r and r+1, we need t(c,r) == t(c,r+1). So by induction, all rows in same column have same t. So indeed T_1 is common. Left edge colors: For each row r, we have L_r. Since w=1, there is only one cell per row, and there is no horizontal constraint to force equality across rows; L_r can be independent. So total assignments: choose T_1 (2 choices) and L_1, L_2 (2 each) => 2^3 = 8. Our formula gives 2^{1+2}=8. But are there indeed 8 tilings? Let's manually think: For 1x2 grid, we have two tiles stacked. Each tile can be in 4 orientations. However, adjacency condition: bottom edge of top tile must be opposite color to top edge of bottom tile. Does that restrict? Let's count manually: For top tile, choose orientation (4). Then its bottom edge color is determined (since bottom edge = opposite of its top). For bottom tile, its top edge color must be opposite of that. But bottom tile's top edge color is determined by its orientation (specifically its t = top edge). So for a given top tile orientation, bottom tile orientation must be one of those that have top edge equal to the opposite of top tile's bottom edge. How many orientations satisfy a given top edge color? Since each orientation is defined by (U,L) pair: top edge can be either W or B, each with two possible left edge colors. So for a given desired top color, there are exactly 2 orientations (the two choices for left edge). So total tilings: 4 (top) * 2 (bottom) = 8. Indeed matches.
Consider w=2, h=1: similarly 8? Actually formula gives 2^{2+1}=8. For two tiles side by side: left tile orientation (4). Its right edge color = opposite of its left edge. Right tile's left edge must be equal to that? Actually constraint: right edge of left tile must be opposite of left edge of right tile => opposite(l_left) != l_right => l_left == l_right. So left tile's left edge color must equal right tile's left edge color. For left tile, left edge is part of its orientation. For right tile, left edge is also part of orientation. So given left tile, l_left is fixed; then right tile must have l_right = l_left. For a given l value, how many orientations have that left edge? left edge can be W or B, each with two possible top edge choices. So 2 orientations per l value. Thus total 4 * 2 = 8. Good.
Thus formula holds for these.
Now, is there any subtlety for larger grids? Our derivation using variables L_r and T_c seems sound. However, we must check if there are any additional constraints at the corners where both horizontal and vertical constraints might interact to force something like L_r and T_c must satisfy something for each cell? The adjacency constraints only involve edges between cells. There is no direct constraint linking L_r and T_c. But does the tile's internal geometry impose any relation between L_r and T_c? No, because for a given cell, (l, t) can be chosen independently; we already verified all four combos exist as tile orientations.
Thus, the counting is straightforward.
But wait, let's think about the possibility of flipping the tile over? The tile is not necessarily symmetric under reflection; but rotations only (90-degree increments). We considered rotations only. Could there be also the possibility of reflecting the tile (i.e., flipping) if you could physically flip it over? Usually, tiles can be rotated but not flipped if the back side is different. The problem says "each tile can be rotated in one of four ways." So only rotations, no flips. That yields exactly the four patterns we enumerated. So it's fine.
One more nuance: The tile is split diagonally into white and black part. The diagonal might be from one corner to the opposite, but the tile might have the two halves fixed, so rotating 180 degrees yields a pattern where the white and black triangles swap positions relative to the grid? But our enumeration accounted for that.
Thus, the answer is simply 2^{(w+h)} mod mod.
But wait, examples: Input "2 2" Output "16". 2^{4}=16. Input "2 4" Output "64". 2^{6}=64. Works.
Double-check with w=3 h=3: 2^6=64. Could test mental: but not needed.
Thus, solution: read w and h, compute pow(2, w+h, mod).
But is mod prime? 998244353 is prime, but we just compute modular exponent.
Edge case: w and h up to 1000, so exponent up to 2000, safe.
But let's read the problem statement again to ensure no trick: "Bob is decorating his kitchen, more precisely, the floor. He has found a prime candidate for the tiles he will use. They come in a simple form factor — a square tile that is diagonally split into white and black part as depicted in the figure below. The dimension of this tile is perfect for this kitchen, as he will need exactly w × h tiles without any scraps. That is, the width of the kitchen is w tiles, and the height of the kitchen is h tiles. As each tile can be rotated in one of four ways, he still needs to decide on how exactly he will tile the floor. There is a single aesthetic criterion that he wants to fulfil: two adjacent tiles must not share a colour on the edge — i.e. one of the tiles must have a white colour on the shared border, and the second one must be black. The picture on the left shows one valid tiling of a 3 × 2 kitchen. The picture on the right shows an invalid arrangement, as the bottom two tiles touch with their white parts. Find the number of possible tilings. As this number may be large, output its remainder when divided by 998244353 (a prime number). Input: The only line contains two space separated integers w, h (1 ≤ w,h ≤ 1 000) — the width and height of the kitchen, measured in tiles. Output: Output a single integer n — the remainder of the number of tilings when divided by 998244353."
All consistent.
However, I recall a known Codeforces problem "Kitchen" maybe? Actually, I think this is problem "A. Tiling" from some contest. But the solution is indeed 2^{w+h} mod mod. But I'm surprised that such a trivial solution would be used for a problem with constraints up to 1000, maybe it's intentionally easy. But perhaps there is a twist: The tiles are placed on a floor, but maybe the orientation also matters relative to the room? Or maybe the condition applies to all four sides including boundaries? But boundaries are not constrained.
Let's double-check the adjacency condition: "two adjacent tiles must not share a colour on the edge — i.e. one of the tiles must have a white colour on the shared border, and the second one must be black." This could be interpreted as: For each point along the shared border, the colors on the two sides must be opposite. Since the edge of each tile is half white and half black (if the diagonal meets the edge at its midpoint), then the condition would be more complex. But we argued the diagonal does not meet the edge at its midpoint; it meets at the corners. Actually, we need to verify: In a square, a diagonal goes from one corner to the opposite corner. It meets the sides only at the corners. So the sides are not split into two halves by the diagonal; they are wholly within one triangle. So the entire edge is a single color. That is true. But wait, what about the other diagonal? That also goes corner to corner. So same. So there is no half-color edges; each side is fully in one triangle. So the color of an edge is uniform. So our interpretation is correct.
But is there any possibility that the tile is split by a line from the midpoint of one side to the midpoint of the opposite side? That would split the square into two rectangles, not triangles. The description says "diagonally split", so it's a diagonal, thus corner to corner.
Thus, answer is 2^{w+h}.
But I recall a problem: "Bob is decorating his kitchen floor with tiles that are split diagonally into black and white. Count number of tilings such that adjacent tiles don't share color on the edge." And I think I've seen a solution like 2^{w+h}. However, some might think it's 2^{(w*h)}? No.
Let's attempt to reason from the constraints: For each cell, choose the colors of top and left edges arbitrarily, and the rest follow, and constraints force row consistency for left edges and column consistency for top edges. That yields 2^{h} * 2^{w} = 2^{w+h}. Yes.
But wait, is there any dependency that each cell's top and left colors must be consistent with each other? Not from adjacency. But are there any constraints that involve both dimensions? For instance, consider a 2x2 grid. Our model gives 2^{4}=16. Could we manually verify 16? Let's try to list: For 2x2, we have variables: L1 (row1 left color), L2 (row2 left color), T1 (col1 top color), T2 (col2 top color). Each cell's orientation is determined by (T_c, L_r). That yields a tile with top = T_c, left = L_r. Is each such combination indeed a valid tile orientation? Yes, because (T_c, L_r) can be any of four combos, and we have a tile for each. So total tilings = 2^4 = 16. Let's attempt to count directly: For each of the 4 tiles, we have to assign orientations. Number of assignments that satisfy constraints? Possibly 16 indeed. Let's try to simulate small: For 2x2, we can try to count using backtracking: each tile 4 orientations. But we trust the logic.
Thus, solution is straightforward.
But is there any scenario where the row and column consistency might be over-constrained? For instance, consider a cell at (c,r). Its right edge is opposite(L_r) and the neighbor's left edge is L_r (since same row) => constraint satisfied. Its bottom edge is opposite(T_c) and neighbor's top edge is T_c (since same column) => satisfied. So all good.
What about the corner where four cells meet? No constraints there.
Thus, answer is indeed 2^{w+h} mod 998244353.
But wait, maybe the tile's orientation also includes flipping? Actually, the tile can be rotated, but cannot be reflected. However, the set of four patterns we enumerated is exactly all assignments with opposite sides opposite, which is 4. And those correspond to the four rotations. So correct.
One more check: Could there be any parity constraints from the fact that the tiles are placed on a grid and we might consider the global pattern being consistent? For instance, consider a cycle around a 2x2 block: Going around, we might get a consistency condition? Let's see: For a 2x2 block, we have four cells. Their edge colors must satisfy constraints. Our model yields assignments consistent. But if we try to assign individually without the row/column pattern, would we ever get a configuration that satisfies constraints but does not conform to row/column consistency? Possibly not. Let's try to see if there exists a configuration that satisfies constraints but where not all left edges in a row are equal. According to our deduction, from horizontal constraints, all left edges in a row are equal. That is forced. Similarly, from vertical constraints, all top edges in a column are forced equal. So any valid configuration must have that property. So indeed, the set of valid configurations is exactly the product of row and column bits.
Thus, answer is correct.
Given the simplicity, this problem is likely from a contest where many participants might overcomplicate, but the solution is indeed 2^{w+h}. However, we must double-check the modulus: 998244353 is prime, and exponent up to 2000, so we can compute pow(2, w+h, 998244353) using fast exponentiation or Python's built-in pow.
But wait, the input constraints: w, h up to 1000, so w+h up to 2000, which is small; we could precompute or just compute directly.
Thus, the solution in code: read w, h; compute ans = pow(2, w+h, 998244353); print ans.
But hold on: Could there be any twist about the orientation count? Let's double-check the enumeration of tile orientations: Could there be also the possibility of placing the tile with the diagonal swapped? Actually, the tile is split into white and black parts. The diagonal split is fixed; you cannot flip the tile over because the backside might be different (the tile has a front side). But rotating gives four orientations. However, note that a 180-degree rotation of a tile with a fixed diagonal (say from top-left to bottom-right) would result in the diagonal from bottom-right to top-left, which is the same line as the original diagonal? Actually, the line from top-left to bottom-right is same as from bottom-right to top-left, so the diagonal orientation is the same as the original? Wait, that's interesting: A 180-degree rotation of a square maps the diagonal from TL-BR to... The square rotated 180°, the corner mapping: TL -> BR, BR -> TL. So the diagonal from TL-BR becomes a line from BR to TL, which is the same set of points as the original diagonal. So the diagonal is unchanged in terms of its orientation (it's still the same line). However, the colors on the two triangles might be swapped because the white triangle that was originally on the top-right may now be rotated to bottom-left? Let's examine: In our base pattern (TL-BR diagonal, top-right white, bottom-left black). After 180°, the tile is upside down. The original top-right corner goes to bottom-left. So the white triangle (which originally was adjacent to top and right edges) will now be adjacent to bottom and left edges. So the pattern becomes: bottom and left edges white, top and right edges black. That is exactly pattern (B,B,W,W) if we assign white=W? Actually, pattern we had earlier: (U=W,R=W,D=B,L=B) after 180 yields (U=B,R=B,D=W,L=W). So indeed it's a different pattern. So even though the diagonal line is the same set, the color assignment to sides changes. So the orientation is distinct. So there are four distinct orientations, each corresponding to a distinct mapping of colors to sides.
Now, is it possible that the tile also allows a reflection (flip) which would swap the two triangles? But if you flip the tile over (like turning it over), the colors might reverse if the back is the opposite? Actually, if you flip it over, the white and black parts would swap because the tile is not symmetric if it's two-colored on one side only? Typically, tiles are colored on the top surface; flipping would put the colored side down, which is not allowed. So only rotations are allowed.
Thus, the four patterns are exactly as enumerated.
Now, verify if the mapping between (U,L) and orientations is bijective: Yes.
Thus, the final answer is 2^{w+h} mod 998244353.
One more sanity check: For 3x2 kitchen, the valid tiling shown in the left picture, and invalid shown on the right. According to our formula, total tilings = 2^{5}=32. Is that plausible? Possibly.
Hence, solution done.
But wait, there might be a nuance: The kitchen dimensions: width w tiles, height h tiles. Usually, width is columns, height is rows. We used that.
Now, some might interpret adjacency as including diagonal adjacency? The statement says "two adjacent tiles must not share a colour on the edge — i.e. one of the tiles must have a white colour on the shared border, and the second one must be black." That clearly refers to edge adjacency (sharing a side), not corner adjacency.
Thus, solution stands.
Now, we can implement. In Python:
def solve():
import sys
MOD = 998244353
w, h = map(int, sys.stdin.readline().split())
ans = pow(2, w+h, MOD)
print(ans)
That's it.
But I'm cautious: The problem might be from Codeforces Round #1462 or something, I recall a problem "A. Filling Diamonds" no. Actually, there is a problem "B. Boboniu Plays Chess" no. But anyway.
Double-check the example: Input "2 2" yields 16. Good.
Edge: w=1000, h=1000 => exponent=2000, pow mod works fine.
Thus, answer is simple.
But wait, I recall a known problem "Kitchen" from AtCoder? Actually, there is an AtCoder problem "ABC 043 D"? Not sure.
Given the simplicity, maybe there's a twist: The tile can be rotated in four ways, but maybe the tile is not symmetric under 90-degree rotation because the two triangles are not necessarily congruent? But they are congruent; they are right triangles, equal area. So 90-degree rotation yields a different orientation as we considered.
Thus, final.
Now, as a responsible solver, let's also consider if there is any alternative interpretation that could lead to a different counting. Some might think the colors on the edge are not uniform because the diagonal might intersect the edge at the midpoint if the diagonal is drawn from midpoint to opposite midpoint? But the phrase "diagonally split" suggests corner to corner. In geometry, diagonal of a square is usually corner to corner. If it were split by a line connecting midpoints, it would be called "split horizontally" or "vertically" or "cut in half". So diagonal means corner-to-corner. So correct.
Thus, answer: 2^{w+h}.
So final solution is trivial.
Given that, I'll produce the solution.
But the instruction: "Output a single integer n — the remainder of the number of tilings when divided by 998244353." So just that.
Now, I'll write the final answer.
But the user is expecting the solution? The conversation appears as a problem statement and a request for solution? Actually, the user wrote: "Bob is decorating his kitchen..." That's the problem statement, and then there is a "Input" and "Output" with examples. Usually, this is a problem statement from coding contest. The user might be asking to solve it. In this environment, I need to provide the answer: the code? Usually, we provide explanation and final code. The instruction says: "You are an AI". I should provide a response that includes reasoning and final answer (the code). Possibly they want the solution.
Thus, I'll produce a response: Explanation that the number is 2^{w+h} mod 998244353, and provide code.
I will also mention the derivation.
I'll now write final answer. The valid tilings correspond to independent choices of colors for the top edge of each column and the left edge of each row.
Each such choice determines a unique orientation for every tile and satisfies the adjacency condition.
Hence the number of tilings is (2^{w+h}).
import sys
MOD = 998244353
w, h = map(int, sys.stdin.readline().split())
print(pow(2, w + h, MOD))