Problem:


魚の生息範囲 (Fish) 

  問題

オーストラリア大陸の西には，広いインド洋が広がっている．海洋研究者である JOI 氏は，インド洋に生息しているある N 種類の魚の性質について研究している．

それぞれの魚の種類に対して，海の中に直方体状の生息範囲が定まっている．魚は境界も含めて生息範囲の中のどの場所にも移動できるが，生息範囲の外に出ることは決してない．海の中の点は，3 つの実数 (x, y, d) によって表される： (x, y, d) は，上空から見たときにある地点を基準にして東に x，北に y 進んだ位置であり，海面からの深さが d の点を表す．ただし，海面は平面であるとする．

JOI 氏は，K 種類以上の魚の生息範囲が重なる場所がどのくらいあるかを知りたい．そのような場所全体の体積を求めるプログラムを作成せよ．

  入力

入力は 1 + N 行からなる．

1 行目には，2 つの整数 N, K (1 ≦ K ≦ N ≦ 50) が空白を区切りとして書かれている．これは，魚が N 種類であり，K 種類以上の魚の生息範囲が重なる場所の体積を求めたいことを表す．

続く N 行のうちの i 行目 (1 ≦ i ≦ N) には，6 つの整数 Xi,1, Yi,1, Di,1, Xi,2, Yi,2, Di,2 (0 ≦ Xi,1 ＜ Xi,2 ≦ 1000000 (= 106)，0 ≦ Yi,1 ＜ Yi,2 ≦ 1000000 (= 106)，0 ≦ Di,1 ＜ Di,2 ≦ 1000000 (= 106)) が書かれている．これは，i 種類目の魚の生息範囲が

8 点 (Xi,1, Yi,1, Di,1), (Xi,2, Yi,1, Di,1), (Xi,2, Yi,2, Di,1), (Xi,1, Yi,2, Di,1), (Xi,1, Yi,1, Di,2), (Xi,2, Yi,1, Di,2), (Xi,2, Yi,2, Di,2), (Xi,1, Yi,2, Di,2) を頂点とする直方体であることを表す．

  出力

K 種類以上の魚の生息範囲が重なる場所全体の体積を 1 行で出力せよ．

  入出力例

入力例 1

  

3 2
30 50 0 50 70 100
10 20 20 70 90 60
40 60 20 90 90 70

出力例 1

   

49000

入出力例 1 において，例えば，点 (45, 65, 65) は 1 種類目の魚と 3 種類目の魚の生息範囲であるので，条件を満たす場所である．一方，点 (25, 35, 45) は 2 種類目の魚のみの生息範囲であるので，条件を満たす場所ではない．また，魚の生息範囲は下の図のようになっている．点 O は海面上の基準の地点を表す．

	

入力例 2
  
  

1 1
0 0 0 1000000 1000000 1000000

出力例 2

   

1000000000000000000

問題文と自動審判に使われるデータは、情報オリンピック日本委員会が作成し公開している問題文と採点用テストデータです。



Sample input:
3 2
30 50 0 50 70 100
10 20 20 70 90 60
40 60 20 90 90 70


Sample output:
49000

Submission status: Wrong Answer

Solution code:
import sys
import array

input_lines = sys.stdin.read().splitlines()
N, K = [int(x) for x in input_lines[0].split(' ')]
x_grid = set()
y_grid = set()
d_grid = set()
for line in input_lines[1:]:
    x1, y1, d1, x2, y2, d2 = [int(x) for x in line.split(' ')]
    x_grid.add(x1)
    x_grid.add(x2)
    y_grid.add(y1)
    y_grid.add(y2)
    d_grid.add(d1)
    d_grid.add(d2)

x_grid = sorted(x_grid)
y_grid = sorted(y_grid)
d_grid = sorted(d_grid)
x_grid_index = {x[1]:x[0] for x in enumerate(x_grid)}
y_grid_index = {y[1]:y[0] for y in enumerate(y_grid)}
d_grid_index = {d[1]:d[0] for d in enumerate(d_grid)}

fish_dist = array.array('i', [0 for x in range(len(x_grid) * len(y_grid) * len(d_grid))])

def index2arr(x, y, d):
    return x + len(x_grid) * y + len(x_grid) * len(y_grid) * d

def arr2index(index):
    x = index % len(x_grid)
    y = ((index - x) // len(x_grid)) % len(y_grid)
    d = (index - x - len(x_grid) * y) // len(x_grid) // len(d_grid)
    return x, y, d

for line in input_lines[1:]:
    x1, y1, d1, x2, y2, d2 = [int(x) for x in line.split(' ')]
    x1_index = x_grid_index[x1]
    x2_index = x_grid_index[x2]
    y1_index = y_grid_index[y1]
    y2_index = y_grid_index[y2]
    d1_index = d_grid_index[d1]
    d2_index = d_grid_index[d2]
    for x in range(x1_index, x2_index):
        for y in range(y1_index, y2_index):
            for d in range(d1_index, d2_index):
                fish_dist[index2arr(x,y,d)] += 1

volume = 0
for index, num in [x for x in enumerate(fish_dist) if x[1] >= K]:
    x_index, y_index, d_index = arr2index(index)
    x_begin = x_grid[x_index]
    y_begin = y_grid[y_index]
    d_begin = d_grid[d_index]
    x_end = x_grid[x_index + 1]
    y_end = y_grid[y_index + 1]
    d_end = d_grid[d_index + 1]
    volume += (x_end - x_begin) * (y_end - y_begin) * (d_end - d_begin)
print(volume)

Submission status: Wrong Answer

Solution code:
def main():
  n, k = map(int, input().split())
  
  plst = []
  xlst = []
  ylst = []
  dlst = []
  
  for i in range(n):
    x1,y1,d1,x2,y2,d2 = map(int, input().split())
    plst.append((x1,y1,d1,x2,y2,d2))
    xlst.append(x1)
    xlst.append(x2)
    ylst.append(y1)
    ylst.append(y2)
    dlst.append(d1)
    dlst.append(d2)
  
  xlst = list(set(xlst))
  ylst = list(set(ylst))
  dlst = list(set(dlst))
  
  xlst.sort()
  ylst.sort()
  dlst.sort()
  
  xdic = {}
  ydic = {}
  ddic = {}
  
  for i, v in enumerate(xlst):
    xdic[v] = i
  for i, v in enumerate(ylst):
    ydic[v] = i
  for i, v in enumerate(dlst):
    ddic[v] = i
  
  new_map = [[[0] * len(dlst) for _ in ylst] for _ in xlst]
  
  for p in plst:
    x1, y1, d1, x2, y2, d2 = p
    x1, y1, d1, x2, y2, d2 = xdic[x1], ydic[y1], ddic[d1], xdic[x2], ydic[y2], ddic[d2]
    for x in range(x1, x2):
      for y in range(y1, y2):
        for d in range(d1, d2):
          new_map[x][y][d] += 1
  
  ans = 0
  for i in range(len(xlst) - 1):
    xlsti = xlst[i]
    xlsti1 = xlst[i - 1]
    x = xdic[xlsti]
    for j in range(len(ylst) - 1):
      ylstj = ylst[j]
      ylstj1 = ylst[j - 1]
      y = ydic[ylstj]
      for z in range(len(dlst) - 1):
        dlstz = dlst[z]
        dlstz1 = dlst[z - 1]
        d = ddic[dlstz]
        if new_map[x][y][d] >= k:
          ans += (xlsti1 - xlsti) * (ylstj1 - ylstj) * (dlstz1 - dlstz)
  print(ans)

main()

Submission status: Accepted

Solution code:
import sys
import itertools

input_lines = sys.stdin.read().splitlines()
N, K = [int(x) for x in input_lines[0].split(' ')]
x_grid = set()
y_grid = set()
d_grid = set()
for line in input_lines[1:]:
    x1, y1, d1, x2, y2, d2 = [int(x) for x in line.split(' ')]
    x_grid.add(x1)
    x_grid.add(x2)
    y_grid.add(y1)
    y_grid.add(y2)
    d_grid.add(d1)
    d_grid.add(d2)

x_grid = sorted(x_grid)
y_grid = sorted(y_grid)
d_grid = sorted(d_grid)
x_grid_index = {x[1]:x[0] for x in enumerate(x_grid)}
y_grid_index = {y[1]:y[0] for y in enumerate(y_grid)}
d_grid_index = {d[1]:d[0] for d in enumerate(d_grid)}

fish_dist = [[[0 for i in range(len(d_grid))] for i in range(len(y_grid))] for i in range(len(x_grid))]

for line in input_lines[1:]:
    x1, y1, d1, x2, y2, d2 = [int(x) for x in line.split(' ')]
    x1_index = x_grid_index[x1]
    x2_index = x_grid_index[x2]
    y1_index = y_grid_index[y1]
    y2_index = y_grid_index[y2]
    d1_index = d_grid_index[d1]
    d2_index = d_grid_index[d2]
    for x, y, d in itertools.product( range(x1_index, x2_index), range(y1_index, y2_index), range(d1_index, d2_index) ):
        fish_dist[x][y][d] += 1

volume = 0
for x_index, y_index, d_index in itertools.product(range(len(x_grid)), range(len(y_grid)), range(len(d_grid))):
    if fish_dist[x_index][y_index][d_index] >= K:
        x_begin = x_grid[x_index]
        y_begin = y_grid[y_index]
        d_begin = d_grid[d_index]
        x_end = x_grid[x_index + 1]
        y_end = y_grid[y_index + 1]
        d_end = d_grid[d_index + 1]
        volume += (x_end - x_begin) * (y_end - y_begin) * (d_end - d_begin)
print(volume)

Submission status: Accepted

Solution code:
import itertools

def main():
    input_lines = []
    input_lines.append(input())
    N, K = [int(x) for x in input_lines[0].split(' ')]
    for i in range(N):
        input_lines.append(input())

    grid = [set() for i in range(3)]
    data = []
    for line in input_lines[1:]:
        x1, y1, d1, x2, y2, d2 = [int(x) for x in line.split(' ')]
        data.append((x1, y1, d1, x2, y2, d2))
        grid[0].add(x1)
        grid[0].add(x2)
        grid[1].add(y1)
        grid[1].add(y2)
        grid[2].add(d1)
        grid[2].add(d2)

    grid = [sorted(g) for g in grid]
    grid_index = [{x[1]:x[0] for x in enumerate(g)} for g in grid]
    grid_len = [len(g) for g in grid]

    fish_dist = [[[0 for i in range(grid_len[2])] for i in range(grid_len[1])] for i in range(grid_len[0])]

    for x1, y1, d1, x2, y2, d2 in data:
        x1_index = grid_index[0][x1]
        x2_index = grid_index[0][x2]
        y1_index = grid_index[1][y1]
        y2_index = grid_index[1][y2]
        d1_index = grid_index[2][d1]
        d2_index = grid_index[2][d2]
        for x_index, y_index, d_index in itertools.product( range(x1_index, x2_index), range(y1_index, y2_index), range(d1_index, d2_index) ):
            fish_dist[x_index][y_index][d_index] += 1

    volume = 0
    for x_index, y_index, d_index in itertools.product(range(grid_len[0]), range(grid_len[1]), range(grid_len[2])):
        if fish_dist[x_index][y_index][d_index] >= K:
            x_begin = grid[0][x_index]
            y_begin = grid[1][y_index]
            d_begin = grid[2][d_index]
            x_end = grid[0][x_index + 1]
            y_end = grid[1][y_index + 1]
            d_end = grid[2][d_index + 1]
            volume += (x_end - x_begin) * (y_end - y_begin) * (d_end - d_begin)
    print(volume)

main()

Submission status: Accepted

Solution code:
n, k = map(int, input().split())

plst = []
xlst = []
ylst = []
dlst = []

for i in range(n):
  x1,y1,d1,x2,y2,d2 = map(int, input().split())
  plst.append((x1,y1,d1,x2,y2,d2))
  xlst.append(x1)
  xlst.append(x2)
  ylst.append(y1)
  ylst.append(y2)
  dlst.append(d1)
  dlst.append(d2)

xlst = list(set(xlst))
ylst = list(set(ylst))
dlst = list(set(dlst))

xlst.sort()
ylst.sort()
dlst.sort()

xdic = {}
ydic = {}
ddic = {}

for i, v in enumerate(xlst):
  xdic[v] = i
for i, v in enumerate(ylst):
  ydic[v] = i
for i, v in enumerate(dlst):
  ddic[v] = i

new_map = [[[0] * len(dlst) for _ in ylst] for _ in xlst]

for p in plst:
  x1, y1, d1, x2, y2, d2 = p
  x1, y1, d1, x2, y2, d2 = xdic[x1], ydic[y1], ddic[d1], xdic[x2], ydic[y2], ddic[d2]
  for x in range(x1, x2):
    for y in range(y1, y2):
      for d in range(d1, d2):
        new_map[x][y][d] += 1

ans = 0
for i in range(len(xlst) - 1):
  for j in range(len(ylst) - 1):
    for z in range(len(dlst) - 1):
      x, y, d = xdic[xlst[i]], ydic[ylst[j]], ddic[dlst[z]]
      if new_map[x][y][d] >= k:
        ans += (xlst[i + 1] - xlst[i]) *(ylst[j + 1] - ylst[j]) * (dlst[z + 1] - dlst[z])
print(ans)

Submission status: Accepted

Solution code:
def main():
  n, k = map(int, input().split())
  
  plst = []
  xlst = []
  ylst = []
  dlst = []
  
  for i in range(n):
    x1,y1,d1,x2,y2,d2 = map(int, input().split())
    plst.append((x1,y1,d1,x2,y2,d2))
    xlst.append(x1)
    xlst.append(x2)
    ylst.append(y1)
    ylst.append(y2)
    dlst.append(d1)
    dlst.append(d2)
  
  xlst = list(set(xlst))
  ylst = list(set(ylst))
  dlst = list(set(dlst))
  
  xlst.sort()
  ylst.sort()
  dlst.sort()
  
  xdic = {}
  ydic = {}
  ddic = {}
  
  for i, v in enumerate(xlst):
    xdic[v] = i
  for i, v in enumerate(ylst):
    ydic[v] = i
  for i, v in enumerate(dlst):
    ddic[v] = i
  
  new_map = [[[0] * len(dlst) for _ in ylst] for _ in xlst]
  
  for p in plst:
    x1, y1, d1, x2, y2, d2 = p
    x1, y1, d1, x2, y2, d2 = xdic[x1], ydic[y1], ddic[d1], xdic[x2], ydic[y2], ddic[d2]
    for x in range(x1, x2):
      for y in range(y1, y2):
        for d in range(d1, d2):
          new_map[x][y][d] += 1
  
  ans = 0
  for i in range(len(xlst) - 1):
    xlsti = xlst[i]
    xlsti1 = xlst[i + 1]
    x = xdic[xlsti]
    for j in range(len(ylst) - 1):
      ylstj = ylst[j]
      ylstj1 = ylst[j + 1]
      y = ydic[ylstj]
      for z in range(len(dlst) - 1):
        dlstz = dlst[z]
        dlstz1 = dlst[z + 1]
        d = ddic[dlstz]
        if new_map[x][y][d] >= k:
          ans += (xlsti1 - xlsti) * (ylstj1 - ylstj) * (dlstz1 - dlstz)
  print(ans)

main()

Submission status: Accepted

Solution code:
def main():
  n, k = map(int, input().split())
  
  plst = []
  xlst = []
  ylst = []
  dlst = []
  
  for i in range(n):
    x1,y1,d1,x2,y2,d2 = map(int, input().split())
    plst.append((x1,y1,d1,x2,y2,d2))
    xlst.append(x1)
    xlst.append(x2)
    ylst.append(y1)
    ylst.append(y2)
    dlst.append(d1)
    dlst.append(d2)
  
  xlst = list(set(xlst))
  ylst = list(set(ylst))
  dlst = list(set(dlst))
  
  xlst.sort()
  ylst.sort()
  dlst.sort()

  lx = len(xlst)
  ly = len(ylst)
  ld = len(dlst)
  
  xdic = {}
  ydic = {}
  ddic = {}
  
  for i, v in enumerate(xlst):
    xdic[v] = i
  for i, v in enumerate(ylst):
    ydic[v] = i
  for i, v in enumerate(dlst):
    ddic[v] = i
  
  new_map = [[[0] * ld for _ in range(ly)] for _ in range(lx)]
  
  for p in plst:
    x1, y1, d1, x2, y2, d2 = p
    x1, y1, d1, x2, y2, d2 = xdic[x1], ydic[y1], ddic[d1], xdic[x2], ydic[y2], ddic[d2]
    for x in range(x1, x2):
      for y in range(y1, y2):
        for d in range(d1, d2):
          new_map[x][y][d] += 1
  
  ans = 0
  for i in range(lx - 1):
    xlsti = xlst[i]
    xlsti1 = xlst[i + 1]
    x = xdic[xlsti]
    for j in range(ly - 1):
      ylstj = ylst[j]
      ylstj1 = ylst[j + 1]
      y = ydic[ylstj]
      for z in range(ld - 1):
        dlstz = dlst[z]
        dlstz1 = dlst[z + 1]
        d = ddic[dlstz]
        if new_map[x][y][d] >= k:
          ans += (xlsti1 - xlsti) * (ylstj1 - ylstj) * (dlstz1 - dlstz)
  print(ans)

main()

Submission status: Accepted

Solution code:
# copy
n, k = map(int, input().split())
plst = []
xlst = []
ylst = []
dlst = []

for _ in range(n):
    x1, y1, d1, x2, y2, d2 = map(int, input().split())
    plst.append((x1, y1, d1, x2, y2, d2))
    xlst.append(x1)
    xlst.append(x2)
    ylst.append(y1)
    ylst.append(y2)
    dlst.append(d1)
    dlst.append(d2)

xlst = list(set(xlst))
ylst = list(set(ylst))
dlst = list(set(dlst))

xlst.sort()
ylst.sort()
dlst.sort()

lx = len(xlst)
ly = len(ylst)
ld = len(dlst)

xdic = dict(reversed(t) for t in enumerate(xlst))
ydic = dict(reversed(t) for t in enumerate(ylst))
ddic = dict(reversed(t) for t in enumerate(dlst))

new_map = [[[0] * ld for _ in range(ly)] for _ in range(lx)]

for p in plst:
    x1, y1, d1, x2, y2, d2 = p
    x1, y1, d1, x2, y2, d2 = \
        xdic[x1], ydic[y1], ddic[d1], xdic[x2], ydic[y2], ddic[d2]
    for x in range(x1, x2):
        for y in range(y1, y2):
            for d in range(d1, d2):
                new_map[x][y][d] += 1

ans = 0
for i in range(lx - 1):
    xlsti = xlst[i]
    xlsti1 = xlst[i + 1]
    x = xdic[xlsti]
    for j in range(ly - 1):
        ylstj = ylst[j]
        ylstj1 = ylst[j + 1]
        y = ydic[ylstj]
        for z in range(ld - 1):
            dlstz = dlst[z]
            dlstz1 = dlst[z + 1]
            d = ddic[dlstz]
            if new_map[x][y][d] >= k:
                ans += (xlsti1 - xlsti) * (ylstj1 - ylstj) * (dlstz1 - dlstz)
print(ans)

Submission status: Runtime Error

Solution code:
input_str = raw_input()
N, K = [int(x) for x in input_str[0].split(' ')]

x_grid = set()
y_grid = set()
d_grid = set()

for line in input_str[1:]:
    x1, y1, d1, x2, y2, d2 = [int(x) for x in line.split(' ')]
    x_grid.add(x1)
    x_grid.add(x2)
    y_grid.add(y1)
    y_grid.add(y2)
    d_grid.add(d1)
    d_grid.add(d2)

x_grid = sorted(x_grid)
y_grid = sorted(y_grid)
d_grid = sorted(d_grid)
x_grid_index = {x[1]:x[0] for x in enumerate(x_grid)}
y_grid_index = {y[1]:y[0] for y in enumerate(y_grid)}
d_grid_index = {d[1]:d[0] for d in enumerate(d_grid)}

fish_dist = np.zeros( (len(x_grid), len(y_grid), len(d_grid)), dtype=int )

for line in input_str[1:]:
    x1, y1, d1, x2, y2, d2 = [int(x) for x in line.split(' ')]
    x1_index = x_grid_index[x1]
    x2_index = x_grid_index[x2]
    y1_index = y_grid_index[y1]
    y2_index = y_grid_index[y2]
    d1_index = d_grid_index[d1]
    d2_index = d_grid_index[d2]
    fish_dist[x1_index:x2_index, y1_index:y2_index, d1_index:d2_index] += 1

volume = 0
for (x_index, y_index, d_index), num in np.ndenumerate(fish_dist):
    if num >= K:
        x_begin = x_grid[x_index]
        y_begin = y_grid[y_index]
        d_begin = d_grid[d_index]
        x_end = x_grid[x_index + 1]
        y_end = y_grid[y_index + 1]
        d_end = d_grid[d_index + 1]
        volume += (x_end - x_begin) * (y_end - y_begin) * (d_end - d_begin)
print volume

Submission status: Runtime Error

Solution code:
import numpy as np

input_str = raw_input()
N, K = [int(x) for x in input_str.split(' ')]
input_lines = []
for n in range(N):
    input_str = raw_input()
    input_lines.append(input_str)
x_grid = set()
y_grid = set()
d_grid = set()
for line in input_lines:
    x1, y1, d1, x2, y2, d2 = [int(x) for x in line.split(' ')]
    x_grid.add(x1)
    x_grid.add(x2)
    y_grid.add(y1)
    y_grid.add(y2)
    d_grid.add(d1)
    d_grid.add(d2)

x_grid = sorted(x_grid)
y_grid = sorted(y_grid)
d_grid = sorted(d_grid)
x_grid_index = {x[1]:x[0] for x in enumerate(x_grid)}
y_grid_index = {y[1]:y[0] for y in enumerate(y_grid)}
d_grid_index = {d[1]:d[0] for d in enumerate(d_grid)}

fish_dist = np.zeros( (len(x_grid), len(y_grid), len(d_grid)), dtype=int )

for line in input_lines:
    x1, y1, d1, x2, y2, d2 = [int(x) for x in line.split(' ')]
    x1_index = x_grid_index[x1]
    x2_index = x_grid_index[x2]
    y1_index = y_grid_index[y1]
    y2_index = y_grid_index[y2]
    d1_index = d_grid_index[d1]
    d2_index = d_grid_index[d2]
    fish_dist[x1_index:x2_index, y1_index:y2_index, d1_index:d2_index] += 1

volume = 0
for (x_index, y_index, d_index), num in np.ndenumerate(fish_dist):
    if num >= K:
        x_begin = x_grid[x_index]
        y_begin = y_grid[y_index]
        d_begin = d_grid[d_index]
        x_end = x_grid[x_index + 1]
        y_end = y_grid[y_index + 1]
        d_end = d_grid[d_index + 1]
        volume += (x_end - x_begin) * (y_end - y_begin) * (d_end - d_begin)
print(volume)

Submission status: Runtime Error

Solution code:
import sys
import array

input_lines = sys.stdin.read().splitlines()
N, K = [int(x) for x in input_lines[0].split(' ')]
x_grid = set()
y_grid = set()
d_grid = set()
for line in input_lines[1:]:
    x1, y1, d1, x2, y2, d2 = [int(x) for x in line.split(' ')]
    x_grid.add(x1)
    x_grid.add(x2)
    y_grid.add(y1)
    y_grid.add(y2)
    d_grid.add(d1)
    d_grid.add(d2)

x_grid = sorted(x_grid)
y_grid = sorted(y_grid)
d_grid = sorted(d_grid)
x_grid_index = {x[1]:x[0] for x in enumerate(x_grid)}
y_grid_index = {y[1]:y[0] for y in enumerate(y_grid)}
d_grid_index = {d[1]:d[0] for d in enumerate(d_grid)}

fish_dist = array.array('i', [0 for x in xrange(len(x_grid) * len(y_grid) * len(d_grid))])

def index2arr(x, y, d):
    return x + len(x_grid) * y + len(x_grid) * len(y_grid) * d

def arr2index(index):
    x = index % len(x_grid)
    y = ((index - x) / len(x_grid)) % len(y_grid)
    d = (index - x - len(x_grid) * y) / len(x_grid) / len(d_grid)
    return x, y, d

for line in input_lines[1:]:
    x1, y1, d1, x2, y2, d2 = [int(x) for x in line.split(' ')]
    x1_index = x_grid_index[x1]
    x2_index = x_grid_index[x2]
    y1_index = y_grid_index[y1]
    y2_index = y_grid_index[y2]
    d1_index = d_grid_index[d1]
    d2_index = d_grid_index[d2]
    for x in xrange(x1_index, x2_index):
        for y in xrange(y1_index, y2_index):
            for d in xrange(d1_index, d2_index):
                fish_dist[index2arr(x,y,d)] += 1

volume = 0
for index, num in [x for x in enumerate(fish_dist) if x[1] >= K]:
    x_index, y_index, d_index = arr2index(index)
    x_begin = x_grid[x_index]
    y_begin = y_grid[y_index]
    d_begin = d_grid[d_index]
    x_end = x_grid[x_index + 1]
    y_end = y_grid[y_index + 1]
    d_end = d_grid[d_index + 1]
    volume += (x_end - x_begin) * (y_end - y_begin) * (d_end - d_begin)
print(volume)