PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#CT0000129. Trò chơi khối hộp (Cuboid Game)

    ID: 1636 Loại: Thông thường 3000ms 256MiB Tried: 0 Đã chấp nhận: 0 Độ khó: 6 Đăng bởi: Nhãn>Complete SearchState-space searchGraph BasicsBreadth-first searchRange QueriesPrefix sumsDifference arrays

Bài tập này chưa được xếp vào lộ trình.

Trò chơi khối hộp (Cuboid Game)

Cuboid Game

Source: Bộ Giáo dục và Đào tạo

Version: Phuoc Hung OJ Extended

Problem Statement

The game uses a rectangular cuboid with edge lengths a×b×ca\times b\times c and a board HH of mm rows and nn columns. Rows increase from top to bottom, columns from left to right, both starting at 11.

Initially the cuboid rests on its a×ba\times b face, covering every cell in the rectangle from (1,1)(1,1) to (a,b)(a,b). In each move the player may slide the cuboid by one cell up, down, left, or right, or roll it over one of the four edges of its bottom face. Rolling may change which pair of dimensions forms the bottom face, but the same cuboid is used throughout.

Initially all cells under the cuboid are lit green, kk other cells are marked red, and the rest are unlit. A move is legal only if the new footprint lies completely inside the board and does not cover any red cell. Whenever a legal move finishes, all cells under the cuboid become green; previously green cells remain green.

Any sequence of legal moves may be performed, with no prescribed length. Find the maximum possible number of green cells.

Input

  • The first line contains six positive integers a,b,c,m,n,ka,b,c,m,n,k.
  • The next kk lines contain xs,ysx_s,y_s, the row and column of red cell ss.

Output

Print one integer: the maximum number of cells that can be lit green.

Subtasks

  • Subtask 1 (25 points): a=b=c=1a=b=c=1; 1≤m,n≤1001\le m,n\le100; 1≤a≤m1\le a\le m; 1≤b≤n1\le b\le n; c≥1c\ge1; 1≤k≤mn−ab1\le k\le mn-ab; red cells are distinct and outside the initial footprint.
  • Subtask 2 (25 points): a=b=ca=b=c; 1≤m,n≤1001\le m,n\le100; 1≤a≤m1\le a\le m; 1≤b≤n1\le b\le n; c≥1c\ge1; 1≤k≤mn−ab1\le k\le mn-ab; red cells are distinct and outside the initial footprint.
  • Subtask 3 (25 points): 1≤m,n≤1001\le m,n\le100; 1≤a≤m1\le a\le m; 1≤b≤n1\le b\le n; c≥1c\ge1; 1≤k≤mn−ab1\le k\le mn-ab; red cells are distinct and outside the initial footprint.
  • Subtask 4 (25 points): 1≤m,n≤10001\le m,n\le1000; 1≤a≤m1\le a\le m; 1≤b≤n1\le b\le n; c≥1c\ge1; 1≤k≤mn−ab1\le k\le mn-ab; red cells are distinct and outside the initial footprint.

Examples

Example 1

Input

1 2 1 3 3 2
2 2
3 3

Output

7

Explanation: The initial footprint covers (1,1)(1,1) and (1,2)(1,2). Red cells are (2,2)(2,2) and (3,3)(3,3). A legal sequence of rolls and slides reaches the other 77 cells, and no more than 77 is possible because 22 of the 99 board cells are red.