Problem: There is a farm whose length and width are A yard and B yard, respectively. A farmer, John, made a vertical road and a horizontal road inside the farm from one border to another, as shown below: (The gray part represents the roads.)    What is the area of this yard excluding the roads? Find it.

Submission attempts (in order):


# Acum[i2 + 1][j2 + 1] - Acum[i1][j2 + 1] - Acum[i2 + 1][j1] + Acum[i1][j1]
def two_dim_accumulate(a) -> list:
  h, w = len(a), len(a[0])
  acum = [[0 for _ in range(h + 1)] for _ in range(w + 1)]
  for i in range(h):
    for j in range(w):
      acum[i + 1][j + 1] = a[i][j]
  for i in range(1, h + 1):
    for j in range(1, w + 1):
      acum[i][j] += acum[i][j - 1]
  for j in range(1, w + 1):
    for i in range(1, h + 1):
      acum[i][j] += acum[i - 1][j]
  return acum

Acum = two_dim_accumulate(A)
Acum[q][q] - Acum[p - 1][q] - Acum[q][p - 1] + Acum[p - 1][p - 1]




# Acum[i2 + 1][j2 + 1] - Acum[i1][j2 + 1] - Acum[i2 + 1][j1] + Acum[i1][j1]
def two_dim_accumulate(a) -> list:
  h, w = len(a), len(a[0])
  acum = [[0 for _ in range(h + 1)] for _ in range(w + 1)]
  for i in range(h):
    for j in range(w):
      acum[i + 1][j + 1] = a[i][j]
  for i in range(1, h + 1):
    for j in range(1, w + 1):
      acum[i][j] += acum[i][j - 1]
  for j in range(1, w + 1):
    for i in range(1, h + 1):
      acum[i][j] += acum[i - 1][j]
  return acum

Acum = two_dim_accumulate(A)
Acum[q][q] - Acum[p - 1][q] - Acum[q][p - 1] + Acum[p - 1][p - 1]




# Acum[i2 + 1][j2 + 1] - Acum[i1][j2 + 1] - Acum[i2 + 1][j1] + Acum[i1][j1]
def two_dim_accumulate(a) -> list:
  h, w = len(a), len(a[0])
  acum = [[0 for _ in range(w + 1)] for _ in range(h + 1)]
  for i in range(h):
    for j in range(w):
      acum[i + 1][j + 1] = a[i][j]
  for i in range(1, h + 1):
    for j in range(1, w + 1):
      acum[i][j] += acum[i][j - 1]
  for j in range(1, w + 1):
    for i in range(1, h + 1):
      acum[i][j] += acum[i - 1][j]
  return acum

Acum = two_dim_accumulate(A)
#for a in Acum:
#  print(a)



# Acum[i2 + 1][j2 + 1] - Acum[i1][j2 + 1] - Acum[i2 + 1][j1] + Acum[i1][j1]
def two_dim_accumulate(a) -> list:
  h, w = len(a), len(a[0])
  acum = [[0 for _ in range(w + 1)] for _ in range(h + 1)]
  for i in range(h):
    for j in range(w):
      acum[i + 1][j + 1] = a[i][j]
  for i in range(1, h + 1):
    for j in range(1, w + 1):
      acum[i][j] += acum[i][j - 1]
  for j in range(1, w + 1):
    for i in range(1, h + 1):
      acum[i][j] += acum[i - 1][j]
  return acum

Acum = two_dim_accumulate(A)
#for a in Acum:
#  print(a)



# Acum[i2 + 1][j2 + 1] - Acum[i1][j2 + 1] - Acum[i2 + 1][j1] + Acum[i1][j1]
def two_dim_accumulate(a) -> list:
  h, w = len(a), len(a[0])
  acum = [[0 for _ in range(h + 1)] for _ in range(w + 1)]
  for i in range(h):
    for j in range(w):
      acum[i + 1][j + 1] = a[i][j]
  for i in range(1, h + 1):
    for j in range(1, w + 1):
      acum[i][j] += acum[i][j - 1]
  for j in range(1, w + 1):
    for i in range(1, h + 1):
      acum[i][j] += acum[i - 1][j]
  return acum

Acum = two_dim_accumulate(A)
Acum[q][q] - Acum[p - 1][q] - Acum[q][p - 1] + Acum[p - 1][p - 1]




# Acum[i2 + 1][j2 + 1] - Acum[i1][j2 + 1] - Acum[i2 + 1][j1] + Acum[i1][j1]
def two_dim_accumulate(a) -> list:
  h, w = len(a), len(a[0])
  acum = [[0 for _ in range(h + 1)] for _ in range(w + 1)]
  for i in range(h):
    for j in range(w):
      acum[i + 1][j + 1] = a[i][j]
  for i in range(1, h + 1):
    for j in range(1, w + 1):
      acum[i][j] += acum[i][j - 1]
  for j in range(1, w + 1):
    for i in range(1, h + 1):
      acum[i][j] += acum[i - 1][j]
  return acum

Acum = two_dim_accumulate(A)
Acum[q][q] - Acum[p - 1][q] - Acum[q][p - 1] + Acum[p - 1][p - 1]




# Acum[i2 + 1][j2 + 1] - Acum[i1][j2 + 1] - Acum[i2 + 1][j1] + Acum[i1][j1]
def two_dim_accumulate(a) -> list:
  h, w = len(a), len(a[0])
  acum = [[0 for _ in range(w + 1)] for _ in range(h + 1)]
  for i in range(h):
    for j in range(w):
      acum[i + 1][j + 1] = a[i][j]
  for i in range(1, h + 1):
    for j in range(1, w + 1):
      acum[i][j] += acum[i][j - 1]
  for j in range(1, w + 1):
    for i in range(1, h + 1):
      acum[i][j] += acum[i - 1][j]
  return acum

Acum = two_dim_accumulate(A)
#for a in Acum:
#  print(a)



# Acum[i2 + 1][j2 + 1] - Acum[i1][j2 + 1] - Acum[i2 + 1][j1] + Acum[i1][j1]
def two_dim_accumulate(a) -> list:
  h, w = len(a), len(a[0])
  acum = [[0 for _ in range(w + 1)] for _ in range(h + 1)]
  for i in range(h):
    for j in range(w):
      acum[i + 1][j + 1] = a[i][j]
  for i in range(1, h + 1):
    for j in range(1, w + 1):
      acum[i][j] += acum[i][j - 1]
  for j in range(1, w + 1):
    for i in range(1, h + 1):
      acum[i][j] += acum[i - 1][j]
  return acum

Acum = two_dim_accumulate(A)
#for a in Acum:
#  print(a)

A,B=map(int,input().split())
print((A-1)*(B-1))

A,B=map(int,input().split())
print((A-1)*(B-1))

A,B=map(int,input().split())
print((A-1)*(B-1))

A,B=map(int,input().split())
print((A-1)*(B-1))

Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Accepted

Accepted

Accepted

Accepted