Developing tools for creation of locations maps for turn-based fights in a new game, Petya faced the following problem.
A field map consists of hexagonal cells. Since locations sizes are going to be big, a game designer wants to have a tool for quick filling of a field part with identical enemy units. This action will look like following: a game designer will select a rectangular area on the map, and each cell whose center belongs to the selected rectangle will be filled with the enemy unit.
More formally, if a game designer selected cells having coordinates (x1, y1) and (x2, y2), where x1 ≤ x2 and y1 ≤ y2, then all cells having center coordinates (x, y) such that x1 ≤ x ≤ x2 and y1 ≤ y ≤ y2 will be filled. Orthogonal coordinates system is set up so that one of cell sides is parallel to OX axis, all hexagon centers have integer coordinates and for each integer x there are cells having center with such x coordinate and for each integer y there are cells having center with such y coordinate. It is guaranteed that difference x2 - x1 is divisible by 2.
Working on the problem Petya decided that before painting selected units he wants to output number of units that will be painted on the map.
Help him implement counting of these units before painting.
The only line of input contains four integers x1, y1, x2, y2 ( - 109 ≤ x1 ≤ x2 ≤ 109, - 109 ≤ y1 ≤ y2 ≤ 109) — the coordinates of the centers of two cells.
Output
Output one integer — the number of cells to be filled.
Examples
Input
1 1 5 5
Output
13
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
We are given a hexagonal grid with centers at integer coordinates. The orientation: one of the cell sides is parallel to the OX axis. That implies a particular type of hexagonal tiling. Typically, there are two common orientations for hex grids: pointy-top (with vertical sides) or flat-top (with horizontal sides). Here "one of cell sides is parallel to OX axis" suggests that a side is horizontal. That is typical for a flat-top hex orientation, where hexagons are oriented with a flat top and bottom (i.e., sides are vertical? Actually, a regular hexagon has six sides; if one side is parallel to OX axis, that could be the top and bottom sides are horizontal if the hex is oriented with pointy top, or the sides are vertical if flat top? Let's examine.
In many grid representations, there are two common coordinate systems: axial/cube coordinates. For a hex grid with horizontal sides (flat top), the hexagons have horizontal top and bottom edges, and slanted sides. For a hex grid with vertical sides (pointy top), the hexagons have vertical left and right edges, and slanted top and bottom. The statement says "one of cell sides is parallel to OX axis". That means at least one side is horizontal. In a regular hexagon, if it's oriented with a flat top, the top and bottom sides are horizontal. If it's oriented with pointy top, the sides are slanted and the left/right are vertical; no side is horizontal. So the orientation must be flat-top: hexagons have horizontal top and bottom edges. So the hexes are arranged in rows where the centers are aligned horizontally, but every other row is offset by half a hex width? Actually, typical flat-top hex grid: centers form rows that are offset horizontally by half a cell width. Often coordinates: x axis along the horizontal direction, y axis vertical. But we need to understand how the centers are placed: "all hexagon centers have integer coordinates and for each integer x there are cells having center with such x coordinate and for each integer y there are cells having center with such y coordinate." That means the set of all center coordinates is Z × Z (all integer pairs). That's interesting: In a typical hex grid, not all integer pairs are centers because of staggering. However, if we allow centers at all integer points, then the grid must be such that hexagons are arranged like a regular tiling with each hex centered at integer lattice points, but hexes must be sized such that they tile the plane without overlap. Is that possible? For a hex grid with flat-top orientation, the centers of adjacent hexes horizontally are at distance something (maybe 2 units if we use "double-width" coordinates). Actually, there are multiple coordinate systems for hex grids: offset coordinates, axial coordinates, cube coordinates. Some map integer pairs to hex centers, but not all integer pairs correspond to valid hexes in a given tiling. But here it says for each integer x there exists cells with that x coordinate, and for each integer y there exists cells with that y coordinate. That means the set of centers includes all integer pairs? Or does it mean that for any integer x, there is at least one cell whose center has that x coordinate (maybe not for every y simultaneously)? The phrasing: "all hexagon centers have integer coordinates and for each integer x there are cells having center with such x coordinate and for each integer y there are cells having center with such y coordinate." This could be interpreted as: The set of possible x-coordinates of centers is all integers, i.e., the projection onto x is all Z; similarly, the projection onto y is all Z. But it does not necessarily mean that every pair (x,y) integer is a center; it means that for any given integer x, there is some cell (maybe with some y) that has that x; and for any integer y, there is some cell (with some x) that has that y. So the grid may be such that centers exist on a subset of Z^2 that is like a checkerboard pattern? But that would not satisfy both properties: For each integer x, there is at least one cell with that x; that can hold if the grid is, say, all points where x and y have same parity, then for any integer x, you can pick y = x (or something) to get a point with that x. Actually, if the set is like {(x,y): x+y even} then for a given x, there are y such that x+y even, so there exist cells. Similarly, for a given y, there exist x such that x+y even, so there exist cells. So that's possible. But the statement also says: "difference x2 - x1 is divisible by 2". That might be a clue about parity constraints.
Maybe we need to determine which integer lattice points correspond to hex centers. Given the description: orthogonal coordinate system is set up so that one of cell sides is parallel to OX axis, all hexagon centers have integer coordinates, and for each integer x there are cells having center with such x coordinate and for each integer y there are cells having center with such y coordinate. That essentially says that the grid of centers is a subset of Z^2 that is "dense" in both coordinates, but not necessarily all points. However, the rectangle selection: we select a rectangle [x1,x2] × [y1,y2] (including boundaries). All cells whose center lies inside that rectangle (including on edges) will be filled. We need to count how many hex centers lie inside that axis-aligned rectangle. But the twist is that not all integer points are centers; there is some pattern. The fact that x2 - x1 is divisible by 2 is given. Perhaps because the rectangle's width is even, the number of centers inside is something like area / something? But we need to derive the exact count.
We need to understand the hex tiling and which integer points correspond to hex centers. The typical representation for a hex grid with flat top (horizontal sides) using axial coordinates: We have coordinates (q, r) where q and r are integers. But those coordinates are not Cartesian; they are in a skewed coordinate system. However, we can map them to Cartesian coordinates using a transformation. For a hex with side length? If we set the distance between adjacent centers horizontally to be 1? But then they wouldn't be integer coordinates because of vertical offset.
Alternatively, there is a common "offset coordinates" approach: For a flat-top hex grid, we can use (x, y) where x is column, y is row. But even rows might be offset by 0.5. In that system, the centers have coordinates like (x + (y mod 2) * 0.5, y * sqrt(3)/2). Not integer.
But the problem statement says "all hexagon centers have integer coordinates". So the centers are integer lattice points. This suggests that the hex grid is not the usual one with side length 1? Perhaps the hexes are not regular? But the shape is a hexagon, with one side parallel to OX. The centers are integer points. The hexagons tile the plane. Could it be that the hex grid is essentially a square grid but with hexagons? No, hexagons cannot tile with all centers on integer lattice if hexes are regular? Actually, there is a known coordinate system for hex grids called "axial coordinates" where (x, y) are integers but they satisfy x+y+z=0 in cube coordinates. In that system, the centers in Cartesian coordinates are not integer unless we scale appropriately. The axial coordinates (q, r) can be used to compute Cartesian coordinates: x = (3/2)q, y = sqrt(3)(q/2 + r). That gives non-integer unless q,r are scaled.
Alternatively, maybe the integer coordinates are not Cartesian coordinates but the coordinates along the axes of the hex grid? But the problem says "Orthogonal coordinates system is set up so that one of cell sides is parallel to OX axis". That implies the coordinate axes are orthogonal (standard Cartesian). So the centers have integer (x,y) in that Cartesian system. How can a hex tiling have all centers at integer points? Consider a regular hexagon with side length s. The distance between centers horizontally (to a neighbor in the east-west direction) is 2s? Actually, in a flat-top hex grid, the horizontal distance between centers of adjacent hexes in the same row is 2s * cos(30°) = sqrt(3)*s? Wait, let's derive.
Standard flat-top hex grid: hexagons are oriented with flat top and bottom. The distance from center to a flat side is the apothem = (sqrt(3)/2)*s? Actually, for a regular hexagon with side length a, the distance from center to each side is the apothem = a * sqrt(3)/2. The distance from center to a vertex is a. The horizontal distance between centers of two adjacent hexes in the same row (east-west direction) is the width of the hex: 2 * apothem? Actually, the width of a flat-top hexagon (horizontal distance from leftmost to rightmost point) is 2a? Let's be systematic.
Better: There are two common neighbor directions: east-west (horizontal), and diagonal directions. In a flat-top orientation, the neighbors to the east and west are at displacement (2a cos 30°, 0) = (a√3, 0). Actually, if the hex is flat-top, the sides are horizontal top and bottom. The hexagon's vertices are at angles 0°, 60°, 120°, 180°, 240°, 300°? For a pointy-top, top vertex at 90°. For flat-top, one vertex at 0° (right). Let's set center at (0,0). The vertices are at angles 0°, 60°, 120°, 180°, 240°, 300° if the hex is oriented with a vertex pointing right? That would be pointy-top with point to the right; sides are slanted. Actually, flat-top means the top and bottom are flat (sides are horizontal). That corresponds to having vertices at angles 30°, 90°, 150°, 210°, 270°, 330° (or maybe 0°? Let's recall: For a hexagon with flat top, the top side is horizontal, so the vertices at the top-left and top-right are at angles 120° and 60°? I'm mixing.
Let's draw: A regular hexagon with flat top: The top side is horizontal, so the hexagon has two vertices above that side? Actually, no, a hexagon has six sides. If the top is flat, then there is a horizontal top side. Adjacent to that top side, there are two vertices: one at the top-left corner and one at the top-right corner, which are above the ends of the top side? Actually, the top side is horizontal; the vertices are at the ends of that side. So the top side connects the top-left vertex to the top-right vertex. So the top side is horizontal, thus the two vertices are at the same y-coordinate. So the top side is the uppermost part; the vertices are not above it; the vertices are the endpoints. So the hexagon extends upward only to the y-coordinate of that side; there is no point above it. So the shape above that side is slanted sides meeting at a vertex? Wait, if the top side is horizontal, then the hexagon's top is flat: the highest y coordinate is constant along that side. The vertices at the ends of that side are the highest y, and then the sides from those vertices go downwards at an angle. So the vertices are at the topmost y, not above. So the top side is the topmost edge. That is consistent: flat-top hexagon.
Now, what are the coordinates of the vertices relative to center? Suppose the distance from center to each side is R (apothem). Then the width (horizontal extent) is 2R? Actually, the distance from center to a flat side is the apothem, and the distance from center to a vertex is something else. For a regular hexagon, the ratio: side length a = (2/√3) * apothem? Since apothem = (√3/2) a. So a = (2/√3)apothem. The width (horizontal) for flat-top orientation is 2apothem? Let's compute: The hexagon is symmetric. The flat sides are horizontal: top and bottom. The left and right boundaries are not vertical but slanted. The horizontal distance from leftmost point to rightmost point is 2*apothem? Actually, the distance from center to leftmost point is the distance to the vertex at 180°? For flat-top, the vertices are at angles 30°, 90°, 150°, 210°, 270°, 330°? Or maybe 0°, 60°, 120°, 180°, 240°, 300°? Let's figure.
If the hexagon has flat top, then the top side is horizontal. The top side is between two vertices that are at some angles. The normal to the top side points upward; the side is perpendicular to that normal. Since it's a regular hexagon, the normals to the sides point in directions that are multiples of 60°. For a flat top, the top side's normal points straight up (90°). The sides of a hexagon are perpendicular to the direction to the center? Actually, in a regular hexagon centered at origin, the sides are lines at distances equal to apothem from the origin, with normals pointing at angles multiples of 60°. For a flat top, the top side's normal points to 90° (vertical up). So the normals are at 90°, 150°, 210°, 270°, 330°, 30°? That gives six directions. The vertices are at intersections of adjacent sides, thus are at angles that are 30° offset from the normals. So vertices are at angles 60°, 120°, 180°, 240°, 300°, 360° (0°). That would place a vertex at angle 0° (to the right), a vertex at 60°, 120°, etc. That yields a pointy-top hexagon with a vertex at the top? Actually, vertex at 90° would be top. If vertices are at 0°, 60°, 120°, etc., then the top vertex is at 90°? No 90° not present. So that's not flat top.
Alternatively, if normals are at 0°, 60°, 120°, 180°, 240°, 300°, then vertices are at 30°, 90°, 150°, 210°, 270°, 330°. In this case, the top vertex is at 90° (pointy top). So to have flat top, we want a side horizontal, so its normal is vertical. So we want normals at 90°, 150°, 210°, 270°, 330°, 30°. That gives vertices at 60°, 120°, 180°, 240°, 300°, 0° (or 360°). That's a flat top: the top side is between vertices at 60° and 120°? Wait, the side is perpendicular to its normal. The normal at 90° points up; the side is perpendicular, so horizontal. The side is located at distance apothem from origin along the normal direction (positive y). The endpoints of that side are intersections with adjacent sides whose normals are at 30° and 150°. Those intersections yield vertices at 60° and 120°. So yes, vertices at 60° and 120° are at the ends of the top side. So the top side is horizontal between those vertices. So the hexagon's topmost y coordinate is at y = apothem, and that is constant along the top side. The vertices at 60° and 120° also have y = apothem? Actually, the vertex coordinates: For a vertex at angle θ, the distance from center to vertex is the circumradius, which is (2/√3)apothem? Wait, for a regular hexagon, the distance from center to a vertex (circumradius) is equal to side length? Actually, side length a = circumradius? In a regular hexagon inscribed in a circle of radius R, the side length equals R. Because the chord of a 60° angle is R. Yes, in a regular hexagon, the vertices lie on a circle, and the distance from center to each vertex is the same, called circumradius. The side length equals the circumradius (since central angle 60°). So the circumradius = side length a. And the apothem = a * cos(30°) = a * √3/2. So a = (2/√3)apothem. So the vertices are at distance a from center, which is greater than apothem. The top side is at y = apothem. The vertices at 60° and 120° have coordinates: (a cos60°, a sin60°) = (a0.5, a√3/2). Their y-coordinate is a*√3/2 = ( (2/√3)*apothem ) * √3/2 = apothem. Yes! So indeed, the vertices at 60° and 120° also have y = apothem. So the top side and its endpoints all have the same y. Good. So the hexagon's top is flat.
Now, the horizontal distance between adjacent centers: Consider a neighbor to the east (right). In a flat-top hex grid, moving east (along the direction of positive x) corresponds to moving to the neighbor in the direction of the vertex at 0°? Actually, from the center, the directions to neighboring centers are: east (0° direction) and west (180°), northeast (60°) and southwest (240°), northwest (120°) and southeast (300°). Wait, careful: The centers are arranged such that each hex is surrounded by six neighbors. For a flat-top orientation, the directions to neighboring centers are at angles 0°, 60°, 120°, 180°, 240°, 300°. That's typical for axial coordinates: q direction (east-west) at 0°, r direction (northwest-southeast?) Actually, there are two axes. But let's confirm: The neighbor to the east would be to the right, along the direction of a vertex at 0°? In our vertex set, vertices are at 0°, 60°, 120°, etc. So yes, there is a vertex at 0°. The line from center to that vertex is at angle 0°, but the neighbor center is not at the vertex; it's at some distance. In a regular tiling, the distance between centers is equal to the distance from center to a vertex? Actually, if you tile hexagons, the centers are spaced by the same distance as the distance between adjacent vertices of the same hex? Consider two adjacent hexagons sharing a side. Their centers are separated by a distance equal to twice the distance from center to a side? Actually, if two hexagons share a side, the line connecting their centers passes through the midpoint of the shared side, and is perpendicular to that side. The distance between centers is 2 * apothem. Because the center to side distance is apothem, and two opposite sides are 2apothem apart, and neighboring hexagons' centers are on opposite sides of the shared side, so distance = apothem + apothem = 2apothem. So the distance between centers is 2*apothem. That is not equal to the circumradius a; indeed a > apothem. In fact, a = (2/√3)apothem, so 2apothem = √3 * a. So the neighbor centers are at distance √3 * a.
So in a flat-top tiling, the vector to the east neighbor is (2apothem, 0) = (√3 * a, 0). That is horizontal, so the x-coordinate difference is 2apothem. To have integer centers, we could set apothem to be something like 0.5? But we need integer coordinates.
But the problem states: "all hexagon centers have integer coordinates". So the centers are integer lattice points. That suggests that the distance between neighboring centers is an integer. If we set the scale appropriately, we can have the horizontal spacing between centers in the same row be, say, 2 units (if apothem = 1). Then the centers would have integer x coordinates? But then the vertical spacing between rows would be something else, maybe 1? Let's compute.
For a flat-top hex grid, the vertical spacing between rows (i.e., the y-difference between centers of adjacent rows) is 1.5 * something? Actually, the centers of adjacent rows are offset: the row above is located such that the line connecting centers is at 60° or 120° direction, which has a vertical component. For example, the neighbor in the north-east direction (60° direction) has displacement: (apothem? Actually, from center to neighbor in direction 60°, the vector is (apothem, ?). Let's derive.
We have centers at distance d = 2*apothem from each other. The directions: The neighbor at 0° is (d, 0). The neighbor at 60°: angle 60°, so displacement (d cos60°, d sin60°) = (d/2, d√3/2). The neighbor at 120°: (d cos120°, d sin120°) = (-d/2, d√3/2). The neighbor at 180°: (-d,0). The neighbor at 240°: (-d/2, -d√3/2). The neighbor at 300°: (d/2, -d√3/2).
So the vertical spacing between rows: If we consider rows of hexes where centers have the same y coordinate? In flat-top orientation, the rows are usually defined by constant y? Actually, the centers of hexes in the same row (the ones that are horizontally aligned) are those that can be reached by moving east-west only. That row has constant y. The row above would consist of centers that are shifted up by d√3/2 and left/right by d/2. So not constant y. But there is a pattern: The set of centers may be represented as: either all points (x, y) where x and y are integers satisfying some parity condition, after scaling.
Let d be the distance between centers. For integer coordinates, we want d, d/2, d√3/2 to be integers? That seems impossible unless we scale d appropriately. But the problem says centers have integer coordinates. That suggests we might be using a different coordinate system: maybe the axes are not orthogonal? But it says orthogonal coordinate system. So the (x,y) are Cartesian coordinates. For the centers to be integer points, the geometry must be such that the hexagon tiling yields centers at integer lattice points. That is possible if we choose d such that both d and d√3/2 are integers. But √3 is irrational, so d√3/2 cannot be integer unless d=0. So that's not possible. Therefore, the integer coordinates cannot be Cartesian coordinates with Euclidean geometry if hexagons are regular? But the problem says "hexagonal cells". Probably it's a grid like in many board games: the cells are hexagons arranged in a "hex grid" but they are not regular in Euclidean metric; it's more of a combinatorial grid, and the coordinates are just an abstract labeling. The fact that the centers have integer coordinates and the rectangle is defined in that coordinate system means we don't need to consider actual geometry beyond the adjacency pattern. The key is: which integer lattice points are actually valid cell centers? Perhaps all integer points are valid? But then the hex grid would be essentially a square grid, not hexagonal. But the selection is "cells whose center belongs to the selected rectangle" - if all integer points are centers, then the count would be just (x2 - x1 + 1) * (y2 - y1 + 1). That would be trivial, but the problem is more interesting; also they guarantee that x2-x1 is even, which hints parity.
So the set of centers is not all integer points; it's something like a staggered grid where every other column or row is missing. In many hex grid representations using "offset coordinates", the centers have integer x and y, but half of them are missing depending on parity. E.g., for a flat-top hex grid with odd-r offset: centers at (x, y) where y is integer, x is integer, and maybe x mod 2 = y mod 2? Let's check typical "odd-r" horizontal layout: In such layout, each row y has cells at columns x; the rows are offset by half a cell horizontally. The centers in that layout, if we take the coordinate system where the unit is the width and height such that horizontal spacing between adjacent cells in the same row is, say, 1, then the centers have coordinates (x, y) with y integer, x integer, but the actual positions: x coordinate = x + (y mod 2)*0.5, y coordinate = y * sqrt(3)/2. But those are not integer.
But here we have integer coordinates for centers. So perhaps the coordinate system is not the geometric one; it's an abstract coordinate system used for addressing hex cells, like axial coordinates but mapped to integers via a transformation that makes them integer pairs. For instance, we can use cube coordinates (q, r, s) with q+r+s=0, and then map to integer coordinates by taking (x = q, y = r) discarding s. Then all integer pairs (x, y) are possible? Actually, in cube coordinates, each hex corresponds to a triple (q, r, s) with q+r+s=0, and q,r,s are integers. The pair (q, r) uniquely identifies the hex, and both are integers. So the set of all such (q, r) is all integer pairs, but with the constraint that s = -q - r is also integer (automatically). So actually any integer pair (q, r) corresponds to a valid cube coordinate? Because given any integers q, r, set s = -q - r, then q+r+s=0. So yes, all integer pairs (q, r) are valid cube coordinates. So the set of hex centers in axial coordinates is Z^2, without restriction. However, in that coordinate system, the geometry (Cartesian positions) is not simply (q, r); they are skewed. But the problem says "Orthogonal coordinates system is set up so that one of cell sides is parallel to OX axis". That suggests they are using a coordinate system where the axes are orthogonal, but they may have defined the positions accordingly. However, if we take axial coordinates (q, r) and then plot them as Cartesian coordinates after a linear transformation, we can have an orthogonal coordinate system where the centers are not integer, unless the transformation maps integer lattice to integer lattice? If the transformation matrix has integer entries, then integer (q,r) map to integer (x,y). For example, we could define x = q, y = r, and then say the geometry is such that the hex grid is not regular Euclidean? But the problem likely expects a combinatorial answer based on parity constraints.
Let's think about typical problems: Counting hex cells in a rectangle on a hex grid defined by integer coordinates with a parity condition. I recall a Codeforces problem: "Hexagonal Tiles" maybe? There is a known problem: "Petya and Hexagons" or something. Actually, there is a problem from Russian contests: "Hexagonal Battlefield" etc. But I need to find the exact counting formula.
The input gives x1, y1, x2, y2, and says difference x2 - x1 is divisible by 2. So maybe the rectangle is aligned with the axes, and the hex centers lie on integer lattice points but only those where x and y have same parity? Or maybe where x and y have same parity because the hex grid is like a checkerboard. Let's test with the example: Input 1 1 5 5 Output 13.
If we consider all integer points (x, y) with x from 1 to 5 inclusive, y from 1 to 5 inclusive, that's 5*5 = 25. That's not 13.
If we consider only points where x and y have the same parity (i.e., both even or both odd). Count from 1 to 5: x values: 1 odd,2 even,3 odd,4 even,5 odd. y same. Count points (x,y) with parity match. Odd-odd: there are 3 odd x's and 3 odd y's = 9. Even-even: there are 2 even x's and 2 even y's = 4. Total = 13. Yes! That matches example output 13. So the set of centers is exactly the integer lattice points where x and y have the same parity (both even or both odd). That is a common representation: a hex grid can be represented as a subset of a square grid by removing half the squares, creating a checkerboard pattern. Indeed, if you take a checkerboard pattern on a square grid, the centers of the black squares can be seen as a hexagonal tiling? Actually, a checkerboard pattern (like a chessboard) of squares yields a pattern where each cell has six neighbors? Let's examine: On a square grid, each cell has up to 8 neighbors (including diagonals). If we consider only black squares, the adjacency can be defined such that they form a hex grid? I'm not sure, but it's known that a hexagonal grid can be mapped to a subset of a square grid with parity condition. More formally, using axial coordinates (q, r) and mapping to Cartesian (x = q + r, y = r) yields coordinates where the set is all integer (x,y) with x+y even? Wait, axial to offset: In many game representations, to store a hex grid in a 2D array, they use "odd-q" or "even-q" offset. But there is also a representation: For a hex grid with flat top, if you take coordinates (x, y) where x and y are integers and (x+y) mod 2 = 0, then these represent hex centers in a "rotated" square lattice. Actually, the condition x+y even is equivalent to x and y having same parity: because parity of sum even means both even or both odd. So yes, same parity condition.
Let's test: For (x,y) integer, parity same => x mod 2 = y mod 2. Equivalent to x-y even? But x+y even is equivalent to x and y same parity? Because if both odd: odd+odd=even; both even: even+even=even. Yes. So condition: x+y even. That's common.
But is there any other possibility? The example matches same parity. So likely the set of centers is: { (x,y) ∈ Z^2 : x + y ≡ 0 (mod 2) }? That yields exactly half the integer lattice points, and the number of such points in a rectangle [x1,x2] × [y1,y2] depends on parity of boundaries. In the example, x1=1,y1=1,x2=5,y2=5. Among 25 points, half would be 12.5 but we get 13, so it's either ceil or floor depending. Actually, number of integer points with even sum in an m×n rectangle where m = x2-x1+1, n = y2-y1+1. If both m and n are odd, then the count is (mn+1)/2? Because the pattern alternates, and if both dimensions are odd, there will be one more of one parity. In the example, m=5, n=5, mn=25, (25+1)/2=13. Yes. So it's consistent.
But is there any reason why the condition is x+y even? Because of the hex grid orientation? Let's verify with hex geometry: If we take a square grid and remove half the squares in a checkerboard pattern, the remaining squares each have six neighbors? Actually, consider the centers of black squares on a checkerboard; each black square is surrounded by black squares diagonally? Let's see: On a square lattice, each point has neighbors at (±1,0) and (0,±1) and diagonals (±1,±1). If we restrict to same parity, then the points with same parity have a distance of sqrt(2) for diagonal neighbors and distance 2 for orthogonal neighbors? Actually, points (x,y) and (x+1,y) have opposite parity? Because if (x,y) same parity then (x+1,y) will have opposite parity: x+1 flips parity, so not in set. So orthogonal neighbors are not allowed. Diagonal neighbors: (x+1,y+1) both coordinates shift by 1, parity remains same (since both flips), so that is allowed. Also (x+1,y-1) allowed, (x-1,y+1), (x-1,y-1). So each point has up to 4 diagonal neighbors. That gives a connectivity like a grid rotated 45 degrees. But a hex grid has six neighbors, not four. However, if you also consider (x+2,y) maybe? Not.
But there is another representation: Consider the set of points where x and y are integers and x mod 2 = 0 maybe? Actually, a common mapping for hex grids to a "doubled" coordinate system: use coordinates (x, y) where x and y are integers, and then the hex cells are those where x mod 2 = y mod 2. Then the neighbors are: (x±2, y), (x±1, y±1). That yields six directions: east, west, northeast, northwest, southeast, southwest. Let's check: If we define that each hex cell is represented by coordinates (x, y) and its neighbors are: (x+2, y), (x-2, y), (x+1, y+1), (x-1, y+1), (x+1, y-1), (x-1, y-1). This is a known representation: "double-width" coordinates, where the horizontal spacing is 2, and vertical spacing is 1, with offset rows. But here x and y both integers, but the condition x mod 2 = y mod 2 ensures that the neighbor definitions are consistent? Actually, if we allow all integer points, the neighbor set might be defined as above. But the condition might be inherent from the adjacency? In many game implementations, hex grids are stored in a 2D array by using every other column. For example, coordinates (x,y) with x even for all y, etc. But the problem statement says: "all hexagon centers have integer coordinates and for each integer x there are cells having center with such x coordinate and for each integer y there are cells having center with such y coordinate." This holds if we take all integer points but restrict parity? Because for any given x, there is some y such that parity matches: if x is even, pick y even; if x odd, pick y odd. So yes, there exists a cell with that x coordinate. Similarly for any given y. So condition holds.
Also, "difference x2 - x1 is divisible by 2". Why is that guaranteed? Possibly because the rectangle selection by a game designer is such that it respects the parity? But they say "It is guaranteed that difference x2 - x1 is divisible by 2." This is given as a condition on the input. That could be because the rectangle is selected by a tool that ensures even width? Or because of the way the selection works: they select two cells (centers) and then consider the rectangle with those as corners; the condition that x2-x1 is divisible by 2 might be due to the fact that the two selected cells are both centers, so their coordinates satisfy something? If centers have same parity? Actually, if both (x1,y1) and (x2,y2) are centers, then they satisfy x1+y1 even and x2+y2 even? But that doesn't guarantee x2-x1 even; for example, (1,1) and (2,2) both have even sum? 1+1=2 even, 2+2=4 even, x2-x1=1 odd. So not guarantee. But maybe the selection is by picking two cells and then the rectangle is aligned to axes; they guarantee that x2-x1 is even to make counting nice? Might be because they want the rectangle to include a symmetric set of centers? The problem statement: "a game designer will select a rectangular area on the map, and each cell whose center belongs to the selected rectangle will be filled with the enemy unit. More formally, if a game designer selected cells having coordinates (x1, y1) and (x2, y2), where x1 ≤ x2 and y1 ≤ y2, then all cells having center coordinates (x, y) such that x1 ≤ x ≤ x2 and y1 ≤ y ≤ y2 will be filled." Actually, there is ambiguity: "selected cells having coordinates (x1, y1) and (x2, y2)" suggests that the designer selects two cells (by their center coordinates), not arbitrary rectangle corners. Those two cells are centers, so they belong to the set of valid cells. So they are both centers. Then the rectangle defined by these two points as opposite corners (with sides parallel to axes) is considered. So the rectangle's x-range is from x1 to x2, y-range from y1 to y2. Since both (x1,y1) and (x2,y2) are centers, they satisfy the parity condition (if it exists). That does not force x2-x1 even, but the problem statement explicitly says: "It is guaranteed that difference x2 - x1 is divisible by 2." So they are imposing an extra guarantee. Possibly because the selection tool ensures that the rectangle's width is even, maybe to keep symmetry? Or because of the way the grid works, selecting two cells might naturally yield even width? Let's see: If both are centers, they satisfy x1 ≡ y1 (mod 2) and x2 ≡ y2 (mod 2) under the same parity condition. So x1 and y1 same parity; x2 and y2 same parity. Then x2 - x1 and y2 - y1 have the same parity? Because parity: x2 - x1 ≡ y2 - y1 (mod 2) because x2≡y2, x1≡y1 => x2-x1≡ y2-y1 mod2. But not forced to be even. However, the guarantee says x2-x1 is divisible by 2. So it's an extra condition, maybe to simplify counting.
Given the example: (1,1) and (5,5): x2-x1=4 even. So that fits.
Thus it's plausible that the valid centers are those where x and y have the same parity. Then we need to count the number of integer lattice points (x,y) with x1 ≤ x ≤ x2, y1 ≤ y ≤ y2 and (x+y) even (or equivalently x and y same parity). And we have guarantee that x2 - x1 is even.
But is that the only interpretation? Let's test with some other potential cases: If the condition was x + y even, then number of such points in an interval can be computed. But is there any other plausible condition like x even only? That would give for each integer x, there is a cell with that x? If only x even are centers, then for a given x odd, there is no cell with that x coordinate, violating "for each integer x there are cells having center with such x coordinate". So that condition fails. So parity condition must be such that projection onto x is all integers; that requires that for each integer x, there exists at least one y such that (x,y) is a center. If we take condition x ≡ y (mod 2), then for any x, we can pick y = x (or any with same parity) to get a center. So that works. Similarly, projection onto y works. If we took condition x even (or any fixed parity), then for x odd, no center, fails. If we took condition x+y ≡ 0 (mod 3) or something, projection onto x would still cover all integers? Possibly, but would be more complicated. But simplest is parity.
Also typical representation of a hexagonal grid as a subset of Z^2 is exactly that: coordinates (x,y) with x+y even. Because then the neighbors are (x±1,y±1) and (x±2,y). But wait, (x±2,y) yields same parity? If x+y even, then (x+2)+y = x+y+2 even, so okay. So six neighbors: (x+2,y), (x-2,y), (x+1,y+1), (x-1,y+1), (x+1,y-1), (x-1,y-1). That's a valid hexagonal connectivity: each hex has six neighbors: east, west, northeast, northwest, southeast, southwest. The distances: horizontal neighbor two units away, diagonal neighbor one unit in both axes. That matches the geometry of a hex grid if we imagine the hexes are stretched: the centers are arranged such that horizontally they are spaced by 2, vertically by 1, and rows are offset. In that representation, the centers are at integer coordinates satisfying parity condition. And the "one of cell sides is parallel to OX axis" would correspond to flat-top orientation? Let's check: If horizontal neighbors are 2 apart, vertical neighbors? The neighbors at (x+1,y+1) have displacement (1,1). That's not vertical; it's diagonal. The actual geometry of such a representation: If we map these integer coordinates to Cartesian coordinates by scaling: (x', y') = (x * w, y * h) where w and h are appropriate distances, but then the neighbor (2,0) maps to (2w,0) horizontal, neighbor (1,1) maps to (w,h). For it to be a regular hexagon, we need the distances between centers to be equal: sqrt((2w)^2) = 2w must equal sqrt(w^2 + h^2). So we need 2w = sqrt(w^2 + h^2) => 4w^2 = w^2 + h^2 => 3w^2 = h^2 => h = w√3. So if we set h = √3 w, then distances are equal. Then the actual positions would not have integer y if w is integer, because h would be irrational. However, the problem does not require Euclidean distances; it's just about counting cells based on coordinates. So it's fine.
Thus, we adopt the model: The centers of hex cells are exactly the integer lattice points (x, y) such that x + y is even (or equivalently x and y have same parity). This matches the example, and also explains the guarantee that x2 - x1 is even: because if (x1,y1) and (x2,y2) are both centers, then x1+y1 even, x2+y2 even. But that doesn't force x2-x1 even; but the guarantee is separate. However, maybe the guarantee ensures that the rectangle includes whole number of hexes in each row? Let's analyze the counting formula.
Given rectangle from (x1, y1) to (x2, y2) inclusive, count points with same parity. Let dx = x2 - x1, dy = y2 - y1. Both are non-negative integers. We have guarantee that dx is even. But dy may be odd or even? Not guaranteed. In example dx=4 even, dy=4 even.
We need to output number of integer points (x,y) in that rectangle with parity condition. This is a standard combinatorial count. For any integer interval, the count of integers with given parity depends on start and end.
Let’s define: For x in [x1, x2], there are Nx_even = number of even x, Nx_odd = number of odd x. Similarly for y. But the condition is x and y same parity, so count = (# even x)(# even y) + (# odd x)(# odd y). Because even x must pair with even y, odd with odd.
Thus total = E_x * E_y + O_x * O_y, where E_x = count of even integers in [x1,x2], O_x = count of odd integers in [x1,x2], similarly E_y, O_y.
We can compute these counts: The number of integers in [L,R] inclusive is R-L+1. The count of even numbers: if L and R are both even? There is formula: floor((R)/2) - floor((L-1)/2). But simpler: If we know the first even in the interval (if any), we can compute.
Given dx even, that means the length of interval in x (number of integer x) = dx+1. Since dx even, dx+1 is odd. So number of x values is odd. Does that affect parity distribution? If the length is odd, then the counts of evens and odds differ by 1. Specifically, if x1 and x2 have same parity, then the interval has odd length and the count of numbers with that parity is one more than the other. If x1 and x2 have different parity, then length is even and counts are equal. Since dx = x2-x1 is even, x1 and x2 have same parity (because difference even => same parity). So x1 and x2 same parity. Thus the number of x values: let n_x = dx+1 (odd). Among these, the number of evens and odds: if x1 is even, then there will be (n_x+1)/2 evens and (n_x-1)/2 odds? Let's check: Example: x1=1 odd, x2=5 odd, n_x=5, odds: 3 (1,3,5), evens:2 (2,4). That's (n_x+1)/2 odds = (5+1)/2=3, evens (n_x-1)/2=2. So indeed, the parity that matches x1 (and x2) appears one more time. So E_x = (n_x + (if x1 even? 1 else 0)?) But we can compute directly: E_x = floor((x2)/2) - floor((x1-1)/2). Similarly O_x = n_x - E_x.
Same for y, but note dy may not be even; y1 and y2 may not have same parity. However, the guarantee only on x. So we need to compute E_y and O_y generally.
But we might also need to consider that both selected cells are centers, so (x1,y1) and (x2,y2) are in the set, meaning they satisfy x1 ≡ y1 (mod 2) and x2 ≡ y2 (mod 2). This gives additional parity constraints: y1 parity same as x1, y2 parity same as x2. Since x1 and x2 same parity (dx even), that implies y1 and y2 also same parity as each other? Actually, from x1≡y1 and x2≡y2, and x1≡x2 (since dx even), we get y1≡x1≡x2≡y2, so y1≡y2. So dy = y2 - y1 is even as well? Because if y1 and y2 have same parity, their difference is even. So from the fact that both points are centers and dx even, we can deduce that dy is even as well? Let's check: x1≡y1 mod2, x2≡y2 mod2, and x1≡x2 mod2 (since dx even) => y1≡y2 mod2. So y1 and y2 have same parity, hence dy is even. But the problem statement didn't guarantee that, but it follows from the given conditions? Actually, it says "It is guaranteed that difference x2 - x1 is divisible by 2." It does not say anything about dy. But if (x1,y1) and (x2,y2) are centers, they must satisfy parity condition. So if x2-x1 even, then x1 and x2 same parity, and then y1 = parity of x1, y2 = parity of x2, so y1 and y2 same parity, so dy even. So indeed dy is also even. But is it guaranteed that the two selected cells are centers? Yes, because the designer selects two cells (by their centers). So the input coordinates are centers. So if the model is parity condition, then indeed x1≡y1 and x2≡y2. And given dx even, we get dy even. So the rectangle dimensions in both directions are even. So dx and dy are both even. In the example, both 4. So we can assume both even? Let's test with a potential case: suppose input: x1=1,y1=1 (center), x2=3,y2=2? But 3,2: is that a center? 3+2=5 odd -> not center, so not allowed because selected cells must be cells. So input will always be centers. So if the parity condition is necessary, then x1≡y1, x2≡y2. Also, dx even is guaranteed. So then x1≡x2, therefore y1≡y2, so dy even. So effectively both differences are even. But the problem only explicitly guarantees dx even, maybe because it's enough to deduce something, but dy being even follows implicitly, but they didn't need to state it. However, we should not rely solely on that deduction without confirming the model. But given example, it matches.
So likely both dx and dy are even. In that case, the rectangle's side lengths in terms of number of integer points are odd: dx+1 odd, dy+1 odd. And the counts of evens and odds in each dimension are: if x1 is even, then even count = (dx+1+1)/2 = (dx)/2 + 1? Let's derive: n_x = dx+1. Since x1 and x2 have same parity, the number of integers with that parity is (n_x+1)/2, and the other parity count is (n_x-1)/2. So if x1 even, then E_x = (n_x+1)/2, O_x = (n_x-1)/2. If x1 odd, then O_x = (n_x+1)/2, E_x = (n_x-1)/2.
Similarly for y.
Since x1 and y1 have same parity (center condition), we know that the parity of x1 and y1 are equal. So the larger parity count will align: For example, if x1 is odd, then O_x = (n_x+1)/2, and since y1 is odd, O_y = (n_y+1)/2. So the total count = O_x * O_y + E_x * E_y.
Now we can compute a formula. Let n_x = dx+1, n_y = dy+1. Then:
If x1 odd: O_x = (n_x+1)/2, E_x = (n_x-1)/2.
If x1 even: E_x = (n_x+1)/2, O_x = (n_x-1)/2.
But we can also compute total = ceil(n_x/2)*ceil(n_y/2) + floor(n_x/2)*floor(n_y/2) if x1 and y1 both odd? Wait, careful: The parity pattern depends on starting parity. Since the interval starts at x1, the count of numbers with parity p (p = x1 mod 2) is ceil(n_x/2) because n_x is odd, so ceil(n_x/2) = (n_x+1)/2, floor(n_x/2) = (n_x-1)/2. So the parity of the starting point gets the ceil count. So we can say:
Let count_parity_start_x = ceil(n_x/2)
Let count_other_x = floor(n_x/2)
Similarly for y: count_parity_start_y = ceil(n_y/2) if y1 parity is the starting parity? But we need to align the parity categories: we need to match the parity of x and y. Since x1 and y1 have same parity, the "starting parity" for x and y are the same (both equal to p = x1 mod 2 = y1 mod 2). Therefore, the number of x with parity p is ceil(n_x/2), and number of y with parity p is ceil(n_y/2). The number with opposite parity is floor for each. So total cells = ceil(n_x/2)*ceil(n_y/2) + floor(n_x/2)*floor(n_y/2).
That is a nice formula. For example, n_x=5, n_y=5, ceil(5/2)=3, floor=2, product sum = 33+22=9+4=13.
If n_x and n_y were even, the formula would be different because the starting parity might not determine ceil/floor because counts are equal. But in our scenario, n_x and n_y are odd (since dx, dy even? Actually, if dx even, n_x = dx+1 is odd; similarly dy even? We argued dy is even as well, so n_y odd). So both odd. So formula works.
But is it always the case that dy is even? Let's check: The problem statement only guarantees that x2-x1 is divisible by 2. It does not say that the selected points are necessarily centers? It says: "if a game designer selected cells having coordinates (x1, y1) and (x2, y2), where x1 ≤ x2 and y1 ≤ y2, then all cells having center coordinates (x, y) such that x1 ≤ x ≤ x2 and y1 ≤ y ≤ y2 will be filled." So the selected cells are cells, so yes (x1,y1) and (x2,y2) are centers. So they satisfy the parity condition (assuming our model). Then if dx is even, x1 and x2 same parity, so y1 = parity of x1, y2 = parity of x2 (since each is a center), so y1 and y2 same parity, so dy even. So indeed dy is even. So we can rely on that.
But wait, is it possible that the parity condition is x+y even? Then for a center, x+y even. Then if we have two centers (x1,y1) and (x2,y2) both satisfying x1+y1 even, x2+y2 even. If x2-x1 even, that implies x1 and x2 same parity? Actually, even difference => same parity. So x1≡x2 mod2. Then from parity of sums: (x1+y1) even and (x2+y2) even => y1≡x1 mod2? Not exactly: If x1+y1 even, then y1≡x1 mod2? Because even sum means x1 and y1 have same parity. Yes, because even sum <=> same parity. So indeed y1≡x1. Similarly y2≡x2. So with x1≡x2, we get y1≡y2. So dy even. So consistent.
Thus we can assume both dx and dy are even, both n_x and n_y are odd.
But what if dx is even but n_x = dx+1 is odd, okay. So we have the formula total = ceil(n_x/2)ceil(n_y/2) + floor(n_x/2)floor(n_y/2). Which simplifies to: ((n_x+1)/2)((n_y+1)/2) + ((n_x-1)/2)((n_y-1)/2). That equals (n_x n_y + 1)/2? Let's compute: Let a = (n_x+1)/2, b = (n_x-1)/2, similarly for y. Then total = a*a_y? Actually, a_x = (n_x+1)/2, b_x = (n_x-1)/2, a_y = (n_y+1)/2, b_y = (n_y-1)/2. Then total = a_x * a_y + b_x * b_y = ( (n_x+1)(n_y+1)/4 + (n_x-1)(n_y-1)/4 ) = ( (n_x n_y + n_x + n_y +1 + n_x n_y - n_x - n_y +1) /4 ) = ( (2 n_x n_y + 2) /4 ) = (n_x n_y + 1)/2. Indeed total = (n_x * n_y + 1)/2.
Check: n_x=5, n_y=5 => (25+1)/2=13. Good. So a very simple formula: total number of centers in the axis-aligned rectangle with odd side lengths (both odd) and with the property that the two corner points are centers (i.e., start parity same) is ( (dx+1)*(dy+1) + 1 ) / 2. But is that always correct? Let's test with another example: Suppose x1=0,y1=0 (center, even+even=even), x2=2,y2=2 (both even, dx=2 even, dy=2 even). Then n_x=3, n_y=3, total = (9+1)/2=5. Let's enumerate: points (0,0) (0,1?) (0,1) sum 1 odd not center, so only those with same parity: evens: (0,0),(0,2),(2,0),(2,2) -> 4; odds: (1,1) -> 1; total 5. Yes.
If x1=0,y1=0, x2=4,y2=0? That would have dy=0, even; n_x=5, n_y=1. Then total = (5*1+1)/2=3. Enumeration: x from 0 to4, y=0 only. Centers: require x even (since y=0 even) -> x=0,2,4 -> 3. Yes. Good.
If dy=0 and n_y=1, formula holds.
Now test a case where x1,y1 are centers but dx even? Already covered. But what if the rectangle is such that n_x and n_y are odd, but the formula (n_x n_y + 1)/2 gives integer. Since n_x n_y is odd product (odd*odd=odd), odd+1=even, /2 integer.
But is there any scenario where dx is even but dy is odd? We argued it's impossible because both corners are centers. Let's double-check: Could there be a model where centers are not defined by parity but some other condition, and yet the input could have dx even and dy odd while both points are centers? Let's try to conceive: Suppose centers are points where x is integer and y is integer, but maybe condition is x mod 2 = 0? But then for any integer x there is a center? If centers only when x even, then for x odd there is no center, contradicting "for each integer x there are cells having center with such x coordinate". So that fails. Another possibility: condition is y mod 2 = 0. Similarly fails. Another: condition is x + y ≡ 0 (mod 3) perhaps? Could that satisfy that for each integer x there exists a y? For given x, we need y ≡ -x (mod 3). There exists integer y with that property (e.g., y = -x). So projection onto x is okay; similarly for y. So that could be possible. In that model, both (x1,y1) and (x2,y2) are centers, so x1+y1 ≡ 0 mod 3, x2+y2 ≡ 0 mod 3. If x2-x1 is even, does that force y2-y1 even? Not necessarily. For example, take (x1,y1) = (0,0) (sum0 mod3), (x2,y2) = (2,1) sum=3 mod3=0. dx=2 even, dy=1 odd. Both are centers under mod3 condition. So dy could be odd. So in that model, the guarantee that dx is even does not force dy even. So the problem's explicit guarantee that dx is even might be needed to avoid parity issues in counting, but they didn't guarantee dy even, so we cannot assume dy even unless derived from the specific condition.
Thus we need to figure out the actual condition for valid centers. The example suggests parity condition. But let's ensure it's not mod3 or something else. How could we determine? Possibly from the statement "one of cell sides is parallel to OX axis". That geometry likely leads to the parity condition. Let's derive from geometry.
We need to model the hex grid in the plane with centers at integer coordinates. The condition that all centers have integer coordinates suggests that we use an axial coordinate system where centers are at (x, y) with x and y integers, but the actual geometric positions might be (x * w, y * h) or something. However, the requirement that one side is parallel to OX axis imposes constraints on the shape of the hexagon. In many games, they use a "skewed" coordinate system: (x, y) are integer, and the hexagons are drawn such that the centers at (x, y) are placed at (x * a + (y mod 2) * a/2, y * b). But then the centers are not integer coordinates unless a and b are chosen appropriately and we consider only the integer (x,y) as indices. But here they explicitly say centers have integer coordinates. So maybe the integer coordinates are not the actual geometric coordinates but rather an abstract coordinate system. However, the selection rectangle is defined in that same coordinate system (the integer coordinates). So we don't need the actual geometry.
Given that the problem is from a contest (likely Codeforces or something), it's typical to have a hex grid problem where the cells are the points with x+y even. For example, Codeforces problem 630C "Hexagons"? I recall a problem "Petya and Hexagons" maybe? Actually, I recall a Codeforces problem 1191B? Not sure. But I've seen a problem: "Honeycomb" or "Hexagonal Tiling" where cells correspond to (x,y) with (x+y) mod 2 = 0. And counting cells in a rectangle leads to a formula like ( (x2-x1+1)*(y2-y1+1) + 1 ) / 2 when (x1+y1) even and (x2-x1) even? But not exactly.
Let's search memory: There is an Open Cup problem or something: "Hexagonal Battlefield" but that's different.
Given the simplicity of the example and the formula, it's highly likely that the set of centers is all integer points with same parity. Let's test with another random input to see if the formula (n_x n_y + 1)/2 holds under the condition that both corners are centers and dx even. But is it always that n_x and n_y are odd? If both corners are centers and dx even, then x1 and x2 same parity. Since each corner is a center, y1 parity = x1 parity, y2 parity = x2 parity => y1 parity = y2 parity. So dy even. So both n_x and n_y are odd. So (n_x n_y + 1)/2 is integer.
Thus, for any valid input (two centers with dx even), the count should be ( (x2-x1+1)*(y2-y1+1) + 1 ) / 2.
But wait, could there be a scenario where x1 and y1 have different parity but still both are centers under a different rule? That seems unlikely if the rule is parity-based. But if the rule were something else like x mod 2 = 0 and y mod 2 = 0 (both even), then corners would both be even coordinates, so dx even? If x1 and x2 both even, dx even; y1,y2 both even, dy even. Then number of centers in rectangle would be count of points where both coordinates even. That count = ceil(n_x/2) * ceil(n_y/2) if we define appropriately? Actually, if x1 and x2 are even, then even numbers in interval: number of evens = (dx/2)+1 = (n_x+1)/2? Let's check: x1 even, x2 even, n_x = dx+1, which is odd? If dx even, n_x odd. For example, x1=0,x2=2,n_x=3, evens:0,2 => 2 = (3+1)/2? (3+1)/2=2, yes. So number of evens = (n_x+1)/2. Similarly odds count = (n_x-1)/2. If we require both coordinates even, then total = (# even x)(# even y) = ((n_x+1)/2)((n_y+1)/2). That would be, for example, 1 1 5 5? But (1,1) not both even, so that corner wouldn't be a center if centers require both even. So input wouldn't be valid. So under that model, the example input wouldn't be valid because (1,1) not both even. So not that.
What about centers requiring x + y ≡ 0 mod 3? Then (1,1): sum=2 mod3 !=0, so (1,1) not a center, so invalid input. So that can't be.
Thus, the only simple condition consistent with the example and the statements is that centers are points where x and y have same parity (or x+y even). So we adopt that.
Now we need to produce a formula to count these points in the axis-aligned rectangle.
But we must consider that the rectangle boundaries are inclusive, and the selected corners are centers. Also guaranteed that x2-x1 is even.
Case: x1=0,y1=0,x2=2,y2=1. Check if (2,1) is center? 2+1=3 odd -> not center. So such input wouldn't appear because both selected cells must be centers. So not allowed.
Case: x1=0,y1=0,x2=0,y2=1. (0,1) sum=1 odd -> not center, invalid.
Thus all valid inputs have both corners centers, so parity condition holds.
But we should also consider if the rectangle could be such that the parity pattern might start differently? However, the formula we derived (n_x n_y + 1)/2 assumes that the number of points with same parity is one more than the opposite parity? Actually, it's exactly that: total = ceil(n_x/2)*ceil(n_y/2) + floor(n_x/2)*floor(n_y/2). But that equals (n_x n_y + 1)/2 only when n_x and n_y are odd. If n_x and n_y were even, the formula would be (n_x n_y)/2. But we argued n_x and n_y are odd. So it's fine.
But is it possible that n_x and n_y are odd but the starting parity is not the same for x and y? However, we know that x1 and y1 have same parity because (x1,y1) is a center. So the "dominant" parity (the one with ceil count) is the parity of x1 (and y1). So the formula ceil(n_x/2)*ceil(n_y/2) + floor(n_x/2)*floor(n_y/2) is correct. Since n_x and n_y are odd, ceil = (n+1)/2, floor = (n-1)/2. So total = ((n_x+1)(n_y+1) + (n_x-1)(n_y-1))/4 = (n_x n_y + 1)/2.
Alternatively, we could derive directly: Among all integer lattice points in the rectangle, exactly half are centers (rounded up) if the rectangle has an odd number of points? But careful: In an odd×odd grid, the checkerboard pattern yields (total+1)/2 of one color and (total-1)/2 of the other. Since the corners (both centers) are the same color? In an odd×odd grid, the two opposite corners have the same color if both dimensions are odd? Actually, in a chessboard coloring, opposite corners have the same color if the total number of squares is odd? Let's recall: In a standard chessboard 8x8 (even×even), opposite corners are same color. In an odd×odd board, the number of squares is odd, and opposite corners are also same color? For example, 3x3 board: top-left black, bottom-right? If we color by parity of sum, (1,1) sum=2 even -> black; (3,3) sum=6 even -> black. So yes, same color. So if both corners are centers (same color), then the number of centers (that color) is (total+1)/2, because the board has odd number of squares, so one color has one more than the other. And since corners are that color, it must be the majority color. So answer = (total_points + 1)/2.
Given the input constraints, we need to use 64-bit integers because product can be up to (2*10^9+1)^2 ≈ 4e18, which fits in 64-bit signed (max 9e18). So use long long in C++.
But is there any nuance about inclusive boundaries? Yes, they are inclusive.
Now, check if the problem might have a different interpretation: maybe the rectangle is selected by two points that are not necessarily centers? The statement: "if a game designer selected cells having coordinates (x1, y1) and (x2, y2)" suggests they select two cells (by clicking on them), so those two are indeed cells, hence centers. So that's consistent.
Thus the solution is extremely simple: read x1, y1, x2, y2, compute w = x2 - x1 + 1, h = y2 - y1 + 1, answer = (w * h + 1) / 2. Print.
But wait, we haven't used the guarantee that x2 - x1 is divisible by 2. That guarantee ensures that w is odd. Indeed, if dx is even, then w = dx+1 is odd. So product wh could be odd h. But h might be even? But we argued h is also odd because dy even (since both corners are centers). But do we need to rely on dy even? Let's check: if dy is odd, then h = dy+1 is even. Then w is odd, product odd*even = even. Then (product+1)/2 would be fractional? Actually, if product even, product+1 is odd, divided by 2 gives .5, not integer. But answer must be integer. So h must be odd to make product odd? But product could be even, then (product+1)/2 is not integer. So either the formula is different, or dy must be even. Since we are guaranteed only dx even, but we deduced dy even from the parity condition and the fact both points are centers. However, if for some reason the parity condition is not exactly same parity but something else, maybe dy could be odd? But the problem statement says "It is guaranteed that difference x2 - x1 is divisible by 2." It does not say anything about y difference. So maybe they didn't want to guarantee dy even, but from the condition that both points are centers, it might automatically be even if we assume the parity condition. But is it possible that the parity condition is different such that both points are centers but dy may be odd even with dx even? Let's explore other models.
Model 1: Centers are points where x is integer and y is integer, no further restriction. Then answer = w*h. But example gives 13 not 25, so no.
Model 2: Centers are points where x+y even. Then we deduced dy even. So dx even, dy even.
Model 3: Centers are points where x is integer and y is integer, but maybe the hex grid is oriented such that the side parallel to OX implies a different parity condition? Could it be that centers are all integer points, but the rectangle selection is interpreted differently: only those cells whose entire hexagon lies within the rectangle? That would be different. But problem says "each cell whose center belongs to the selected rectangle will be filled". So center-based.
Another possibility: The condition might be that x and y have same parity OR maybe x and y have different parity? Let's test: Suppose centers are points where x+y odd. Then (1,1) sum=2 even -> not center, so (1,1) wouldn't be a center. So example input invalid. So not.
Thus the only viable model consistent with example is same parity.
So we can safely assume dy even as well. But the problem statement didn't explicitly guarantee it, but it follows from the model and the fact that input coordinates are centers. Since problem statements often omit obvious derived guarantees, it's fine.
But to be thorough, we should consider: is it possible that the input could have dy odd but still both points are centers under the same parity condition? Let's try: Suppose (x1,y1) = (0,0) center; (x2,y2) = (2,1). Check (2,1): 2+1=3 odd -> not center. So not both centers. So impossible. So indeed dy must be even. So we can rely on that.
Thus answer = ((x2-x1+1)*(y2-y1+1) + 1) // 2.
But wait, could there be a scenario where the rectangle is such that the number of centers is not (total+1)/2? Suppose the corners are both centers, but the rectangle's dimensions are such that the number of points with even sum is not the majority? For odd×odd board, the two colors differ by 1. Which color is majority? It depends on the coloring and the corners. Since both corners are the same color, that color appears one more than the other. Let's prove: In a grid of odd×odd points, the number of points of each color differ by 1. If the two opposite corners are the same color, then that color has the extra one. Because if you walk along rows, the pattern alternates. In an odd×odd grid, the number of rows is odd, each row has alternating colors; if the first cell of first row is color A, then row has (number of columns) cells; if number of columns is odd, then row ends with color A. So all rows start and end with color A if number of columns is odd and first row start is A. Then since number of rows is odd, the last row also starts and ends with A. So the corners (first row first col, last row last col) are both A. So A is the majority color by one. So indeed number of A = (total+1)/2. So formula holds.
Thus answer is ( (x2-x1+1)*(y2-y1+1) + 1 ) / 2.
Now, is there any tricky case where the rectangle is not aligned with the axes? It is axis-aligned as described.
Thus solution is trivial.
But the problem might be more complex if we consider that the hex grid coordinates might be offset such that the set of centers is all integer points (x,y) where x mod 2 = 0 (or something). But example disproves.
I'll double-check with another random test using parity condition and compute manually with small numbers to see if formula holds.
Take x1=2,y1=3 (both odd? 2 even,3 odd -> parity different -> not center. So invalid.
Take x1=2,y1=2 (both even) center. Choose x2=4,y2=4 (both even). dx=2 even, dy=2 even. Points: (2,2),(2,3? no),(2,4),(3,2? 3+2=5 odd no),(3,3? 6 even yes),(3,4? 7 odd no),(4,2?6 even yes),(4,3?7 odd no),(4,4?8 even yes). So centers: (2,2),(2,4),(3,3),(4,2),(4,4) => 5 points. n_x=3,n_y=3,total=9, (9+1)/2=5. Works.
Take x1=2,y1=2, x2=6,y2=2 (only one row). dx=4 even, dy=0 even. n_x=5,n_y=1. centers: x must be even? y=2 even, so x even: 2,4,6 => 3. (5*1+1)/2=3. Good.
Take x1=2,y1=2, x2=4,y2=6. dx=2 even, dy=4 even. n_x=3,n_y=5. total points 15. (15+1)/2=8. Let's enumerate quickly: x=2,3,4; y=2,3,4,5,6. Centers where parity same: x and y both even or both odd. Even x:2,4; even y:2,4,6 => 23=6. Odd x:3; odd y:3,5 => 12=2. Total=8. Works.
Thus formula is correct.
Now, could there be any scenario where dx is even but the corners are not of same parity? That would require that the parity condition is not about sum even but something else. But as argued, the condition must be such that both corners are centers. So they must satisfy whatever condition defines centers. So corners share the property. If the condition is x mod 2 = y mod 2, then they have same parity, so if dx even, x1 and x2 same parity, then automatically y1 and y2 same parity, and dy even. So consistent.
Thus answer is simply computed.
But before finalizing, let's consider if there's any alternative interpretation: maybe the rectangle selection is done on the map (visual) and the cells whose center falls inside are selected, but the rectangle is defined by two points that are not necessarily centers. The problem says "selected cells having coordinates (x1, y1) and (x2, y2)". It could be ambiguous: It might mean that the designer selects two cells (by clicking on them) and then the tool considers the rectangular area spanned by those two cells' centers. That's what we used.
Alternatively, it could mean the designer selects a rectangular area by specifying two points (x1,y1) and (x2,y2) on the plane (maybe not necessarily centers), but the statement "selected cells having coordinates (x1, y1) and (x2, y2)" suggests those are cells. So it's fine.
Now, the problem says "It is guaranteed that difference x2 - x1 is divisible by 2." Why would they need to guarantee that? Possibly because the rectangle is defined by two cells, and they want to ensure that the rectangle's width is even so that the number of centers inside is integer with the formula? But under our model, it's already integer even without guarantee? Actually, if the two cells are centers, then x1 and x2 have same parity, so dx is even? Wait: If two centers have coordinates (x1,y1) and (x2,y2) under parity condition, does dx have to be even? Not necessarily: two centers can have x1 and x2 with opposite parity. For example, (0,0) center, (1,1) center? 1+1=2 even, so (1,1) is a center. dx=1 odd. So two centers can have odd difference in x. So why do they guarantee it's even? Because they want the rectangle's x-range to have even width, maybe to simplify counting? Or maybe because the rectangle selection tool always selects corners such that x-range is even? Could be a design choice. In any case, they guarantee it.
If dx were odd, then n_x = dx+1 would be even. Then the counts of evens and odds in x would be equal (n_x/2 each). Since x1 and x2 have opposite parity (because dx odd), but they are both centers, so their parity differs, meaning one is even and the other odd? But then what about y? For each to be center, y must match parity of its x. So y1 parity matches x1, y2 matches x2, so y1 and y2 have opposite parity. Then dy = y2-y1 would be odd? Because difference of opposite parity numbers is odd. So dy odd, and n_y = dy+1 even. So both n_x and n_y even. Then total points = n_x n_y (even). The number of centers would be? Under parity condition, centers are points where x and y same parity. In an even×even grid, the counts of the two colors are equal. But which color corresponds to centers? Both colors could be centers? Actually, both colors are either both centers or not? Under our model, centers are only one color (say black). The other color (white) are not centers. So the number of centers would be total/2. But is that consistent with the corners? If the corners are opposite colors (one black, one white), then the rectangle includes equal numbers of black and white. So number of centers = total/2. For example, take (0,0) and (1,1). dx=1 odd, dy=1 odd. n_x=2,n_y=2,total=4. Points: (0,0) black, (0,1) white? 0+1=1 odd not center, (1,0) 1+0=1 odd not center, (1,1) 2 even center. So centers: 2. That's total/2=2. So formula would be total/2. So if dx odd, answer = total/2.
But in the problem, they guarantee dx even, so we are in the case where both dimensions are odd, and answer = (total+1)/2.
Thus the guarantee simplifies the answer to always (total+1)/2, because they ensure both dimensions are odd? Actually, if dx even, then n_x odd. If also dy even (implied), then n_y odd, so total odd, answer = (total+1)/2. But if dy could be odd (contradicting both centers), then total might be even? But we argued dy must be even because both centers. So it's consistent.
But what if the grid condition were different such that both corners are centers but dx even does not force dy even? Then the answer might not be (total+1)/2. But given the example and the guarantee, the intended solution is likely the simple formula.
Let's search memory: There is a known Codeforces problem: "Petya and Square" maybe? Actually, I recall a problem from Codeforces Round #297 (Div. 2) "Panda and Puzzle"? Not. There's a problem "Petya and Chess" no.
I recall a problem "Petya and Hexagons" from some contest. Actually, there is a problem named "Petya and Origami" no.
Maybe it's from Russian contest, and the solution is indeed (x2 - x1 + 1) * (y2 - y1 + 1) + 1 >> 1.
But to be safe, we should derive a more general formula that works for any parity of dimensions, given that the two selected points are centers. Then we could implement a conditional based on parity of (x1+y1) maybe. However, since the problem guarantees dx even, we can rely on the simplified formula. But if the input always satisfies dx even, then we can just use that.
Given the problem statement: "It is guaranteed that difference x2 - x1 is divisible by 2." So we can trust that. However, does that guarantee that the corners are centers? The input provides the coordinates of two cells, so they are centers. So both are centers. So we know x1+y1 even and x2+y2 even. And dx even.
Now, we can compute answer as:
Let w = x2 - x1 + 1, h = y2 - y1 + 1.
Answer = (w * h + 1) / 2.
But is it always integer? w and h are both odd? Let's check: w = dx+1, dx even => w odd. h = dy+1, but is dy even? Not guaranteed by statement, but from centers condition? Let's verify: Since x1+y1 even and x2+y2 even, and dx even, then x1 and x2 have same parity. Then from x1+y1 even, we have y1 ≡ x1 (mod 2); from x2+y2 even, y2 ≡ x2 (mod 2). Since x1≡x2, we get y1≡y2. So dy = y2 - y1 is even. So indeed h is odd. So product oddodd = odd, so wh is odd, so (w*h+1) is even, division yields integer. So fine.
Thus answer is integer.
Now, why is the guarantee about x2-x1 even needed? Possibly to avoid handling the case where dx odd and dy odd, which would yield answer = total/2, which is also integer but different formula. Maybe they wanted to have a unique answer regardless of which corner is chosen? Or because the selection tool always selects corners such that the rectangle has even width? It doesn't matter.
Given that the problem is simple, likely the solution is as above.
But wait, could there be an alternative interpretation where the rectangle is inclusive of centers that are inside, but the rectangle might include points that are not integer? No, we only consider integer centers; the rectangle is defined by real coordinates? Actually, "each cell whose center belongs to the selected rectangle will be filled". The rectangle is defined by x1, x2, y1, y2, and we consider centers (x,y) with integer coordinates that satisfy x1 ≤ x ≤ x2, y1 ≤ y ≤ y2. So it's exactly integer points inside.
Thus, the solution is straightforward.
But let's double-check the problem statement: "if a game designer selected cells having coordinates (x1, y1) and (x2, y2), where x1 ≤ x2 and y1 ≤ y2, then all cells having center coordinates (x, y) such that x1 ≤ x ≤ x2 and y1 ≤ y ≤ y2 will be filled." So the rectangle's boundaries are the coordinates of the two selected cells. Since these cells are centers, the rectangle's sides are aligned with the axes and pass through these points. So the rectangle includes the boundaries. So inclusive.
Now, why would they need the guarantee about x2-x1 even? Possibly to avoid having to compute floor/ceil based on parity of x1. Because with dx even, the number of even and odd x can be expressed simply as (dx/2+1) and (dx/2). But anyway.
Given that the answer formula is simple, we can implement.
However, we must consider if there is any scenario where the rectangle includes points that are not centers because of the hex pattern? But we only fill cells that are centers (by definition, all cells are centers). So we count only those integer points that correspond to cells. So it's exactly the count of centers in the rectangle.
Thus solution: read x1,y1,x2,y2. Compute w = x2-x1+1, h = y2-y1+1. Answer = (w * h + 1) / 2. Print as integer.
But let's test on the example: w=5, h=5, product=25, (25+1)/2=13. OK.
Test on another: Input: -5 -5 -1 -1. x1=-5,y1=-5,x2=-1,y2=-1. dx=4 even, dy=4 even. w=5,h=5, answer=13. Let's manually check parity: both coordinates negative, parity defined as usual (even if divisible by 2). (-5,-5): both odd? -5 mod2 = -5 mod2? In programming, -5 % 2 = -1 in some languages, but parity is about evenness: -5 is odd because it's not divisible by 2. So (-5,-5) both odd -> sum -10 even -> center. (-1,-1) both odd -> center. So grid from -5 to -1 inclusive has 5 values each. Count of centers: need both same parity. Count odd x: from -5 to -1 odd numbers: -5,-3,-1 => 3 odd. Even x: -4,-2 => 2 even. Same for y. So odd-odd: 33=9, even-even:22=4 total 13. Good.
So formula works for negative numbers if we interpret parity normally (evenness). In programming, we can compute w and h as long long, use absolute values? Actually, w = x2 - x1 + 1, regardless of sign. That works.
But there is a nuance: The product might overflow 32-bit, so use 64-bit. In C++, use long long. In Python, int arbitrary.
Now, I think that's the solution.
But before finalizing, let's consider if the problem might be trickier: Could there be a scenario where the rectangle includes points that are not centers but are counted because they are integer points? No, we only count cells, which are exactly the centers that satisfy the hex grid condition. So we only count those points that are centers. So indeed we need to count only points with same parity.
But is it possible that the set of centers is not all same-parity points, but maybe a shifted version? For example, centers could be points where x+y is even, but also maybe include points where x is something? That would be the same.
Given the example, it's consistent.
But let's read the problem statement again: "all hexagon centers have integer coordinates and for each integer x there are cells having center with such x coordinate and for each integer y there are cells having center with such y coordinate." This is satisfied by same-parity condition: For each integer x, there exist y such that parity matches, so there is at least one cell with that x. But is it satisfied that for each integer x, there is a cell with that x regardless of y? Yes, pick y = x (or any with same parity). So there is at least one cell. Similarly for y.
If the condition were x+y even, then for a given x, we can choose y = x (since x+x=2x even), so yes. So that works.
Thus the condition does not force the set to be all same-parity points; it could be something like x ≡ 0 (mod 2) and y ≡ 0 (mod 2) fails because for x odd there is no y making both even? Actually, if we require both even, then for x odd, no y even? We could choose y even, but then (odd, even) sum odd, not both even. So both even fails "for each integer x there are cells" because if x is odd, there is no cell with that x coordinate. So not allowed.
Thus the only simple linear condition that gives a nonempty set for every x and every y is essentially an affine condition of the form parity: x ≡ y (mod 2). Because that yields for each x, choose y = x; for each y, choose x = y. So it's the only one with mod 2. Could also be condition like x ≡ y (mod 1) which is always true, meaning all points, but then the example would be 25, not 13. So not that. Could be condition like x ≡ y (mod k) for k>2? For example, x ≡ y (mod 3). For a given x, there exists y such that y ≡ x (mod 3) (just take y = x). So for each x, there is a cell with that x. Similarly for each y. So that also satisfies the existence condition. However, the example (1,1) and (5,5) would satisfy x≡y mod3? 1≡1 mod3, 5≡5 mod3 (5 mod3=2, wait 5 mod3=2, 5≡5 mod3 trivially? Actually, condition x ≡ y (mod 3) means y - x divisible by 3. For (1,1): 1-1=0 divisible by 3, ok. For (5,5): 0 divisible by 3, ok. So they are centers. Then what would be the count of centers in rectangle 1..5,1..5 under mod3 condition? We need to count integer points (x,y) where y ≡ x (mod 3). Let's compute: total points 25. Which ones satisfy? For each x, y = x, x±3, etc. So we can count: For x=1, y can be 1,4; x=2: y=2,5; x=3: y=3; x=4: y=1,4; x=5: y=2,5. So total = 2+2+1+2+2 = 9. Not 13. So not matching. So mod3 fails example.
What about condition x ≡ y (mod 4)? (1,1) ok, (5,5) ok? 5-5=0 mod4 ok. Count? For x=1: y=1,5; x=2: y=2; x=3: y=3; x=4: y=4; x=5: y=1,5 => total 2+1+1+1+2=7. Not 13.
So only mod2 gives 13? Let's check: x ≡ y (mod 2) yields exactly half the points (rounded appropriately). In 5x5, half of 25 is 12.5, but since corners are same parity, the majority count is 13. So yes.
Thus the condition is indeed mod2.
Thus answer formula stands.
Now, there is also the guarantee that x2 - x1 is divisible by 2. In the mod2 model, if two points satisfy x1≡y1 and x2≡y2, and x2-x1 even, then the rectangle has odd dimensions. But if x2-x1 were odd, then dimensions would be even and answer = (wh)/2. But they guarantee even width, so answer = (wh+1)/2 always.
Thus the solution is to compute ( (x2-x1+1)*(y2-y1+1) + 1 ) / 2.
Implementation details: Use 64-bit integers. Input may be negative, but w = x2 - x1 + 1 is fine even if x1 negative. For example, x1 = -5, x2 = -1 => x2 - x1 + 1 = (-1) - (-5) + 1 = 4+1=5. Works.
Thus code:
#include
using namespace std;
int main() {
long long x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
long long w = x2 - x1 + 1;
long long h = y2 - y1 + 1;
long long ans = (w * h + 1) / 2;
cout << ans << endl;
return 0;
}
But we need to be careful: The product w*h might exceed 32-bit. Use long long. In C++ long long is at least 64-bit.
Alternatively, we could compute as ((w) * (h) / 2) + ((w) * (h) % 2) but (w*h+1)/2 is fine if using integer division.
But note: (wh+1)/2 works because wh is odd, so +1 makes it even, division yields integer. However, if wh were even (which shouldn't happen given guarantees), then (wh+1)/2 would truncate (integer division) giving (wh)/2 if wh even? For example, wh=10, (10+1)/2=5 in integer division (since 11/2=5). That would be ceil(10/2)=5? Actually, 10/2=5, so same. But if wh even, the correct answer under parity condition with corners opposite? Actually, if wh even, the number of centers might be wh/2 exactly, but (wh+1)/2 would give (wh/2) + 0.5 truncated? Wait, integer division truncates toward zero, so (10+1)/2=5, same as 10/2=5. So it would still give 5. So it's safe? Let's test: Suppose w=2,h=2,total=4, centers count =2 (if corners opposite colors). (4+1)/2=2 (since 5/2=2). So it matches. So (wh+1)/2 actually gives the correct count for both odd and even total? For even total, (total+1)/2 is ceil(total/2). Ceil(4/2)=2, correct. For odd total, ceil(5/2)=3, (5+1)/2=3, correct. So the formula (total+1)/2 is actually ceil(total/2). So it's the count of cells when we always take the larger color? But if the corners are opposite colors, the counts are equal, so both are total/2, which equals ceil(total/2) only when total is even? For even total, total/2 = ceil(total/2). So indeed ceil(total/2) equals total/2 when total even, and (total+1)/2 when total odd. So (total+1)/2 computes ceil(total/2). Is that always the number of centers? Not necessarily; if the corners are opposite colors, the number of centers could be either color, but one of them is the color of the first corner? But we need to count the cells that are actually centers. Which color corresponds to centers? In the model, centers are those with same parity as the corners? Actually, the corners are centers, so they have a particular color (say black). The other color (white) are not centers. So the number of centers is the number of black squares. In a grid, if the two opposite corners are black and white respectively, then the numbers of black and white are equal. But then one of the corners is black, the other white. But both corners are centers, so that would require that both black and white are centers. That would mean all points are centers. That's not our model. So if both corners are centers, they must have the same color (both black). Because centers are only black squares. So the condition that both selected cells are centers implies they are the same color. Therefore, in a rectangular grid, if both opposite corners are black, then the number of black squares is ceil(total/2). Because in a grid with odd total (oddodd), black has one more; with even total, black equals white only if both dimensions even? Let's check: In a grid with even×even dimensions, opposite corners are the same color? In a standard chessboard with even number of squares on each side, opposite corners are the same color. For example, 2x2: (1,1) black, (2,2) black? Actually, if we color by sum parity, (1,1) sum=2 even black, (2,2) sum=4 even black. So both black. So in an even×even grid, opposite corners are same color. And number of black squares = total/2 (since total even, black=white). So black = total/2 = ceil(total/2) because total even. So indeed black = ceil(total/2) in both cases when opposite corners are same color. If opposite corners are different colors, that happens when the grid has one dimension even and the other odd? Actually, consider 2x3 grid: (1,1) black, (2,3): 2+3=5 odd -> white. So corners are different colors. In that case, black count = total/2 if total even? 2h/2) if (x1+y1) even? Not always; consider w=2,h=2, total=4, (x1+y1) even => points: (0,0) even, (0,1) odd, (1,0) odd, (1,1) even => 2 evens, which is total/2 = 2, ceil(4/2)=2. If (x1+y1) odd, then evens count would be? (0,1) odd? Actually, start (0,1) sum odd: points: (0,1) odd, (0,2) even, (1,1) even? Wait, compute: (0,1) odd, (0,2) even (0+2=2), (1,1) even (2), (1,2) odd (3) => evens=2, still 2. So for even total, evens = total/2 regardless of start parity. For odd total, say w=2,h=1: total=2 even? Actually 2h, with w = dx+1, h = dy+1. Since dx even, w odd; we deduced dy even, so h odd. So total is odd. So in this scenario, the count of even-sum points is (total+1)/2 = ceil(total/2). Yes, because start parity even gives majority.
If dx were odd (not guaranteed), then w even? Actually if dx odd, w = dx+1 even. And from centers, x1 and x2 have opposite parity? Wait, if both centers, x1+y1 even, x2+y2 even, dx odd => x1 and x2 opposite parity. Then what about dy? It could be odd or even? Possibly dy odd? Then total might be even, and count of even-sum points might be total/2. But the guarantee ensures we are in the odd-total, start-even case, so answer is (total+1)/2.
Thus the solution is straightforward.
I'll now produce final answer.
But before final, let's search for any alternative interpretation that would require more complex counting, such as the rectangle being defined in continuous coordinate system and we need to count hexagons whose centers lie inside, which is essentially integer lattice points, but maybe the hex centers are not all integer points, but we only consider those inside. But the problem says centers have integer coordinates, so they are integer.
One more nuance: Could the rectangle be defined by real coordinates (x1,y1) and (x2,y2) that are not necessarily integer? The statement says "selected cells having coordinates (x1, y1) and (x2, y2)". It explicitly says cells, so these are centers, so integer.
Thus all good.
Now, I'll produce final solution in the required format.
But wait, the problem statement: "Working on the problem Petya decided that before painting selected units he wants to output number of units that will be painted on the map." So we just output the number.
Thus solution is as above.
Now, just to be thorough, I'll consider if there could be any tricky off-by-one: The rectangle includes points where x1 ≤ x ≤ x2, y1 ≤ y ≤ y2. Since x1,x2,y1,y2 are integers (centers), it's inclusive. So w = x2 - x1 + 1, h = y2 - y1 + 1.
Answer = (w * h + 1) / 2.
But what about negative numbers? w and h computed as difference plus one works for negative as well. For example, x1 = -3, x2 = -1 => w = (-1) - (-3) + 1 = 2+1=3. Good.
Now, verify with an example where x1 > x2? Not, x1 ≤ x2.
Thus final.
Now, I'll write the explanation for the solution.
But the problem might be from a contest where the input coordinates are up to 10^9, and we need to output a 64-bit integer. So we should use long long.
Implementation in C++:
code
#include <bits/stdc++.h>
using namespace std;
int main() {
long long x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
long long w = x2 - x1 + 1;
long long h = y2 - y1 + 1;
cout << (w * h + 1) / 2 << endl;
return 0;
}
But maybe we need to handle potential overflow when multiplying two 10^9-range numbers: w and h could be up to 2*10^9+1, product up to ~4e18, fits in signed 64-bit (max 9.22e18). So safe.
Now, I'm ready to produce final answer.
But wait, I recall a similar problem: Codeforces 630A? No. Actually, there is a problem "Petya and Square" but not. The mention of Petya suggests it's a Codeforces problem? Many Codeforces problems feature Petya. But I'll check: There is a problem "Petya and Chessboard"? Hmm.
Nevertheless, solution is as above.
Now, maybe the twist is that the hex grid is not a simple checkerboard, but rather the centers are all integer points, but the rectangle selection is on the actual geometric map, and the cells whose center belongs to the rectangle are selected, and the rectangle is defined by two points that are not necessarily aligned with the grid coordinates? But the problem says "selected cells having coordinates (x1, y1) and (x2, y2)", so they are cells, so they are on the grid.
Now, I'll produce a final response with the solution explanation. We assume the hexagonal grid is represented by integer lattice points where a point (x, y) corresponds to a cell if and only if x and y have the same parity (equivalently, x + y is even).
The rectangle selected by the designer has its sides parallel to the axes and includes all integer points (x, y) with x1 ≤ x ≤ x2, y1 ≤ y ≤ y2. Since the two chosen corners are cells, they satisfy the parity condition, and the guarantee that x2 – x1 is even forces both dimensions of the rectangle (in number of integer points) to be odd.
In an odd×odd grid with the corners of the same color, the number of cells of that color is exactly half of the total number of points rounded up, i.e. (total + 1) / 2.
Let w = x2 – x1 + 1, h = y2 – y1 + 1. Then the total number of integer points is w·h, and the answer is (w·h + 1) / 2.
All calculations fit into 64‑bit integers.
cpp
#include <iostream>
using namespace std;
int main() {
long long x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
long long w = x2 - x1 + 1;
long long h = y2 - y1 + 1;
cout << (w * h + 1) / 2 << endl;
return 0;
}
3=6, black=3, white=3, equal. So black = total/2 = ceil(total/2) because total even. Actually, ceil(6/2)=3. So still black = ceil(total/2). Wait, black could be either floor or ceil? Let's compute: In a 2x3 grid, with coloring by sum parity, the numbers of black and white are equal (3 each). So black = 3 = ceil(6/2)=3. In a 1x2 grid: points (1,1) black, (1,2) white. total=2, black=1, ceil(2/2)=1. So black = ceil(total/2) always? Let's test 1x1: total=1, black=1, ceil(1/2)=1. 1x2: total=2, black=1, ceil(2/2)=1. 2x2: total=4, black=2, ceil(4/2)=2. 2x3: total=6, black=3, ceil(6/2)=3. So it seems that for a chessboard coloring (alternating), the number of black squares is always ceil(total/2). Because if total is even, black = total/2; if total is odd, black = (total+1)/2. So indeed black = ceil(total/2) always. So regardless of whether corners are same or different, the number of black squares is ceil(total/2). But does that hold for any rectangle? Yes, because in any grid, the difference between number of black and white is at most 1, and black is either the majority or equal. But is black always the color with the ceil? It depends on which color we define as black relative to the starting corner. But the definition of black is based on parity of coordinates. Typically, we define black = points where x+y even. Then in any axis-aligned rectangle of integer points, the count of such points is either ceil(total/2) or floor(total/2). Which one it is depends on the parity of the rectangle's dimensions and the parity of the top-left corner. Specifically, if (x1+y1) is even, then the number of even-sum points is ceil(total/2) if total is odd? Actually, we can compute exactly: Number = ((total+1)/2) if (x1+y1) even and total odd? Let's derive formula: For rectangle with w columns, h rows, starting at (x1,y1). The count of points where (x+y) even = ceil(w
1=2 even, not odd. w=1,h=2 total=2 even. To have odd total, need both w and h odd. Example w=3,h=3 total=9 odd. If start parity even: evens = 5 (majority). If start parity odd: evens = 4 (minority). So for odd total, the count of even-sum points depends on start parity. But in our problem, the corners (x1,y1) and (x2,y2) are both centers, so they have even sum (since center condition = x+y even). Therefore, (x1+y1) is even. So the start parity is even. And total = w