Under construction

Still being built. Things may change

Surface Area of Cubes

Interview

Time limit5sMemory limit512 MB

Summary
Given an A x B x C block of unit cubes with N cubes removed (including interior ones), compute the total surface area including surfaces of interior cavities.
Level

Medium5 of 10

Topics
Hash map, Math, Implementation, Geometry
Solved
No attempts yet

Problem

Taro likes a single player game called "Surface Area of Cubes".

In this game, he initially has an A×B×CA \times B \times C rectangular solid formed by A×B×CA \times B \times C unit cubes (which are all 1 by 1 by 1 cubes). The center of each unit cube is placed at 3-dimensional coordinates (x,y,z)(x,y,z) where x,y,zx,y,z are all integers (0≤x≤A−1,0≤y≤B−1,0≤z≤C−1)(0\leq x\leq A-1, 0\leq y\leq B-1, 0\leq z\leq C-1). Then the game master removes NN distinct unit cubes from the rectangular solid. After the NN cubes are removed, he must state the total surface area of this object exactly in order to win the game.

The removal operation does not change the positions of the cubes that are not removed. Not only the cubes on the surface of the rectangular solid but also the cubes inside can be removed. The object can also be split into multiple parts by the removal of the cubes. A player of this game has to count the surface areas that are not accessible from the outside as well.

Taro knows how many cubes were removed and which ones, but this game is very difficult for him, so he wants to win by cheating! You are Taro's friend, and your job is to write a program that calculates the total surface area of the object on Taro's behalf when you are given the size of the rectangular solid and the coordinates of the removed cubes.

Input

The input is formatted as follows.

The first line of a test case contains four integers A,B,CA,B,C, and N(1≤A,B,C≤108,0≤N≤min⁡{1,000,A×B×C−1}).N (1\leq A,B,C\leq 10^8,0\leq N\leq \min \{1{,}000, A\times B\times C-1 \} ).

Each of the next NN lines contains non-negative integers x,yx,y, and zz which represent the coordinate of a removed cube. You may assume that these coordinates are distinct.

Output

Output the total surface area of the object from which the NN cubes were removed.

Examples3

  1. Example 1

    Input
    2 2 2 1
    0 0 0
    
    Expected output
    24
    
  2. Example 2

    Input
    1 1 5 2
    0 0 1
    0 0 3
    
    Expected output
    18
    
  3. Example 3

    Input
    3 3 3 1
    1 1 1
    
    Expected output
    60