Theater stage is a rectangular field of size n × m. The director gave you the stage's plan which actors will follow. For each cell it is stated in the plan if there would be an actor in this cell or not.

You are to place a spotlight on the stage in some good position. The spotlight will project light in one of the four directions (if you look at the stage from above) — left, right, up or down. Thus, the spotlight's position is a cell it is placed to and a direction it shines.

A position is good if two conditions hold:   there is no actor in the cell the spotlight is placed to;  there is at least one actor in the direction the spotlight projects. 

Count the number of good positions for placing the spotlight. Two positions of spotlight are considered to be different if the location cells or projection direction differ.


-----Input-----

The first line contains two positive integers n and m (1 ≤ n, m ≤ 1000) — the number of rows and the number of columns in the plan.

The next n lines contain m integers, 0 or 1 each — the description of the plan. Integer 1, means there will be an actor in the corresponding cell, while 0 means the cell will remain empty. It is guaranteed that there is at least one actor in the plan.


-----Output-----

Print one integer — the number of good positions for placing the spotlight.


-----Examples-----
Input
2 4
0 1 0 0
1 0 1 0

Output
9

Input
4 4
0 0 0 0
1 0 0 1
0 1 1 0
0 1 0 0

Output
20



-----Note-----

In the first example the following positions are good:  the (1, 1) cell and right direction;  the (1, 1) cell and down direction;  the (1, 3) cell and left direction;  the (1, 3) cell and down direction;  the (1, 4) cell and left direction;  the (2, 2) cell and left direction;  the (2, 2) cell and up direction;  the (2, 2) and right direction;  the (2, 4) cell and left direction. 

Therefore, there are 9 good positions in this example.

Source: codeforces | Difficulty: EASY
Tags: Dynamic programming

Implementation


Solutions:
(n, m) = map(int, input().split())
t = []
for k in range(n):
	t.append(list(map(int, input().split())))
T = []
TB = []
for i in range(n):
	u = []
	for j in range(m):
		if j == 0:
			u.append(t[i][j])
		else:
			u.append(u[-1] + t[i][j])
	T.append(u)
	v = []
	for s in range(m - 1, -1, -1):
		if s == m - 1:
			v.append(t[i][s])
		else:
			v.append(v[-1] + t[i][s])
	TB.append(v[::-1])
f = []
for j in range(m):
	u = []
	for i in range(n):
		u.append(t[i][j])
	f.append(u)
UT = []
UB = []
for i in range(m):
	u = []
	for j in range(n):
		if j == 0:
			u.append(f[i][j])
		else:
			u.append(u[-1] + f[i][j])
	UT.append(u)
	v = []
	for k in range(n - 1, -1, -1):
		if k == n - 1:
			v.append(f[i][k])
		else:
			v.append(v[-1] + f[i][k])
	UB.append(v[::-1])
p = 0
for i in range(n):
	for j in range(m):
		if t[i][j] == 0:
			if T[i][j] > 0:
				p += 1
			if TB[i][j] > 0:
				p += 1
			if UT[j][i] > 0:
				p += 1
			if UB[j][i] > 0:
				p += 1
print(p)


(n, m) = map(int, input().split())
(a, b) = ([], [[] for i in range(m)])
for i in range(n):
	a += [list(map(int, input().split()))]
	for j in range(m):
		b[j] += [a[i][j]]

def count(arr):
	(l, r) = (-1, -1)
	for i in range(len(arr)):
		if arr[i] == 1:
			l = i
			break
	for i in range(len(arr) - 1, -1, -1):
		if arr[i] == 1:
			r = i
			break
	if l == -1:
		return 0
	return l + (len(arr) - r - 1) + 2 * sum((arr[i] == 0 for i in range(l + 1, r)))
print(sum((count(a[i]) for i in range(n))) + sum((count(b[j]) for j in range(m))))


def run(l):
	r = 0
	for i in range(len(l)):
		b = False
		for j in l[i]:
			if j == '1':
				b = True
			if j == '0' and b == True:
				r += 1
	return r
(a, b) = map(int, input().split())
r = [''.join(input().split()) for i in range(a)]
l = [i[::-1] for i in r]
u = [''.join([i[j] for i in r]) for j in range(b)]
d = [i[::-1] for i in u]
print(run(l) + run(r) + run(u) + run(d))


class CodeforcesTask729BSolution:

	def __init__(self):
		self.result = ''
		self.n_m = []
		self.plan = []

	def read_input(self):
		self.n_m = [int(x) for x in input().split(' ')]
		for x in range(self.n_m[0]):
			self.plan.append([int(y) for y in input().split(' ')])

	def process_task(self):
		left_rows = [[0] * self.n_m[1] for x in range(self.n_m[0])]
		right_rows = [[0] * self.n_m[1] for x in range(self.n_m[0])]
		top_cols = [[0] * self.n_m[1] for x in range(self.n_m[0])]
		bottom_cols = [[0] * self.n_m[1] for x in range(self.n_m[0])]
		for y in range(self.n_m[0]):
			left_rows[y][0] = self.plan[y][0]
		for x in range(1, self.n_m[1]):
			for y in range(self.n_m[0]):
				left_rows[y][x] = self.plan[y][x] + left_rows[y][x - 1]
		for y in range(self.n_m[0]):
			right_rows[y][-1] = self.plan[y][-1]
		for x in range(self.n_m[1] - 2, -1, -1):
			for y in range(self.n_m[0]):
				right_rows[y][x] = self.plan[y][x] + right_rows[y][x + 1]
		for x in range(self.n_m[1]):
			top_cols[0][x] = self.plan[0][x]
		for x in range(self.n_m[1]):
			for y in range(1, self.n_m[0]):
				top_cols[y][x] = self.plan[y][x] + top_cols[y - 1][x]
		for x in range(self.n_m[1]):
			bottom_cols[-1][x] = self.plan[-1][x]
		for x in range(self.n_m[1]):
			for y in range(self.n_m[0] - 2, -1, -1):
				bottom_cols[y][x] = self.plan[y][x] + bottom_cols[y + 1][x]
		cnt = 0
		ways = [[0] * self.n_m[1] for x in range(self.n_m[0])]
		for x in range(self.n_m[1]):
			for y in range(self.n_m[0]):
				if not self.plan[y][x]:
					if left_rows[y][x]:
						cnt += 1
						ways[y][x] += 1
					if right_rows[y][x]:
						cnt += 1
						ways[y][x] += 1
					if top_cols[y][x]:
						cnt += 1
						ways[y][x] += 1
					if bottom_cols[y][x]:
						cnt += 1
						ways[y][x] += 1
		self.result = str(cnt)

	def get_result(self):
		return self.result
Solution = CodeforcesTask729BSolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


(n, m) = map(int, input().split())
s = [input().split() for i in range(n)]
ans = 0
for i in range(n):
	cur_r = s[i]
	prev_1 = 0
	prev_0 = 0
	for j in cur_r:
		if j == '1':
			ans += prev_0
			prev_0 = 0
			prev_1 = 1
		else:
			ans += prev_1
			prev_0 += 1
for i in range(m):
	prev_1 = 0
	prev_0 = 0
	for t in range(n):
		j = s[t][i]
		if j == '1':
			ans += prev_0
			prev_0 = 0
			prev_1 = 1
		else:
			ans += prev_1
			prev_0 += 1
print(ans)


(s, r) = map(int, input().split())
v = []
for i in range(s):
	v += [list(map(int, input().split()))]
ans = 0
p = [(0, 1), (0, -1), (1, 0), (-1, 0)]
for i in range(s):
	if v[i].count(1) == 0:
		continue
	if v[i].count(1) == 1:
		ans += r - 1
	else:
		a = v[i].index(1)
		b = v[i][::-1].index(1)
		ans += 2 * r - a - b - 2 * v[i].count(1)
v1 = []
for i in range(r):
	v1 += [[v[j][i] for j in range(s)]]
for i in range(r):
	if v1[i].count(1) == 0:
		continue
	if v1[i].count(1) == 1:
		ans += s - 1
	else:
		a = v1[i].index(1)
		b = v1[i][::-1].index(1)
		ans += 2 * s - a - b - 2 * v1[i].count(1)
print(ans)


(n, m) = map(int, input().split())
x = []
f = []
r = []
kk = []
ff = [0, 0, 0, 0]
for _ in range(n):
	a = list(map(int, input().split()))
	kk = []
	for i in range(len(a)):
		kk.append(ff.copy())
	f.append(kk)
	x.append(a)
for i in range(len(f)):
	for j in range(len(f[i])):
		try:
			if f[i - 1][j][2] == 1:
				f[i][j][2] = 1
			else:
				f[i][j][2] = 0
		except:
			altu = 'jalaltu'
		try:
			if f[i][j - 1][0] == 1:
				f[i][j][0] = 1
			else:
				f[i][j][0] = 0
		except:
			altu = 'jaldu'
		if x[i][j] == 1:
			f[i][j][0] = 1
			f[i][j][2] = 1
for i in range(len(f) - 1, -1, -1):
	for j in range(len(f[i]) - 1, -1, -1):
		try:
			if f[i + 1][j][3] == 1:
				f[i][j][3] = 1
			else:
				f[i][j][3] = 0
		except:
			altu = 'jalaltu'
		try:
			if f[i][j + 1][1] == 1:
				f[i][j][1] = 1
			else:
				f[i][j][1] = 0
		except:
			altu = 'jaldu'
		if x[i][j] == 1:
			f[i][j][1] = 1
			f[i][j][3] = 1
c = 0
for i in range(len(f)):
	for j in range(len(f[i])):
		gggg = sum(f[i][j])
		if gggg != 4:
			c += gggg
		if gggg == 4 and x[i][j] == 0:
			c += gggg
print(c)


(a, b) = map(int, input().split())
scene = [list(map(int, input().split())) for i in range(a)]
ans = 0
for i in range(a):
	first = 0
	between = 0
	last = 0
	isactor = False
	for j in range(b):
		if scene[i][j] == 0 and isactor == False:
			first += 1
		elif isactor == True and scene[i][j] == 0:
			last += 1
		elif isactor == True and scene[i][j] == 1:
			between += last
			last = 0
		elif isactor == False and scene[i][j] == 1:
			isactor = True
	if isactor == True:
		ans += first + 2 * between + last
for j in range(b):
	first = 0
	between = 0
	last = 0
	isactor = False
	for i in range(a):
		if scene[i][j] == 0 and isactor == False:
			first += 1
		elif isactor == True and scene[i][j] == 0:
			last += 1
		elif isactor == True and scene[i][j] == 1:
			between += last
			last = 0
		elif isactor == False and scene[i][j] == 1:
			isactor = True
	if isactor == True:
		ans += first + 2 * between + last
print(ans)


m_n = [int(i) for i in input().split()]
temp = [[int(j) for j in input().split()] for i in range(m_n[0])]
flag = 0
count = 0
for i in range(m_n[0]):
	flag = 0
	for j in range(m_n[1]):
		if temp[i][j] == 0:
			if flag:
				count = count + 1
		else:
			flag = 1
flag = 0
for i in range(m_n[1]):
	flag = 0
	for j in range(m_n[0]):
		if temp[j][i] == 0:
			if flag:
				count = count + 1
		else:
			flag = 1
for i in range(m_n[0] - 1, -1, -1):
	flag = 0
	for j in range(m_n[1] - 1, -1, -1):
		if temp[i][j] == 0:
			if flag:
				count = count + 1
		else:
			flag = 1
flag = 0
for i in range(m_n[1] - 1, -1, -1):
	flag = 0
	for j in range(m_n[0] - 1, -1, -1):
		if temp[j][i] == 0:
			if flag:
				count = count + 1
		else:
			flag = 1
print(count)


def go(s):
	(l, r) = (s.find('1'), s.rfind('1'))
	if l == -1:
		return 0
	else:
		return l + len(s) - r - 1 + 2 * sum((s[i] == '0' for i in range(l + 1, r)))
(n, m) = map(int, input().split())
a = [''.join(input().split()) for i in range(n)]
r = sum((go(s) for s in a))
c = sum((go(''.join((a[i][j] for i in range(n)))) for j in range(m)))
print(r + c)


(n, m) = map(int, input().split())
a = []
count = 0
p = 0
for i in range(n):
	a.append(list(map(int, input().split())))
	p += a[i].count(1)
for i in range(n):
	for j in range(m):
		if a[i][j] == 1:
			count += m - j
			break
	for j in range(m - 1, -1, -1):
		if a[i][j] == 1:
			count += j + 1
			break
for i in range(m):
	for j in range(n):
		if a[j][i] == 1:
			count += n - j
			break
	for j in range(n - 1, -1, -1):
		if a[j][i] == 1:
			count += j + 1
			break
ans = count - 4 * p
print(ans)


import sys
input = sys.stdin.readline
(n, m) = list(map(int, input().split()))
itog = 0
mass = []
for _ in range(n):
	a = list(map(int, input().split()))
	new = a.count(1)
	last = 0
	count = 0
	mass.append(a)
	for i in a:
		if i == 1:
			new -= 1
			last += 1
		elif last == 0 and new > 0 or (new == 0 and last > 0):
			count += 1
		elif last > 0 and new > 0:
			count += 2
	itog += count
for i in range(m):
	a = []
	for j in range(n):
		a.append(mass[j][i])
	new = a.count(1)
	last = 0
	count = 0
	for i in a:
		if i == 1:
			new -= 1
			last += 1
		elif last == 0 and new > 0 or (new == 0 and last > 0):
			count += 1
		elif last > 0 and new > 0:
			count += 2
	itog += count
print(itog)


import math
import collections
import bisect

def arrPrint(a):
	return ' '.join([str(i) for i in a])

def gridPrint(a):
	return '\n'.join([' '.join([str(j) for j in a[i]]) for i in range(len(a))])

def isPalindrome(s):
	for i in range(len(s) // 2):
		if not s[i] == s[-i - 1]:
			return False
	return True

def solve(n, m, a):
	dp = [[0 for j in range(m)] for i in range(n)]
	for i in range(n):
		good = False
		for j in range(m):
			if a[i][j] == 1:
				good = True
			elif good:
				dp[i][j] += 1
	for i in range(n):
		good = False
		for j in range(m - 1, -1, -1):
			if a[i][j] == 1:
				good = True
			elif good:
				dp[i][j] += 1
	for j in range(m):
		good = False
		for i in range(n):
			if a[i][j] == 1:
				good = True
			elif good:
				dp[i][j] += 1
	for j in range(m):
		good = False
		for i in range(n - 1, -1, -1):
			if a[i][j] == 1:
				good = True
			elif good:
				dp[i][j] += 1
	return sum([sum(i) for i in dp])
(n, m) = [int(s) for s in input().split()]
a = [[int(s) for s in input().split()] for i in range(n)]
result = solve(n, m, a)
print(result)


from sys import stdin, stdout
from math import gcd, sqrt, factorial, pi, inf
from collections import deque, defaultdict
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
L = lambda : list(R())
P = lambda x: stdout.write(str(x) + '\n')
lcm = lambda x, y: x * y // gcd(x, y)
hg = lambda x, y: (y + x - 1) // x * x
pw = lambda x: 1 if x == 1 else 1 + pw(x // 2)
chk = lambda x: chk(x // 2) if not x % 2 else True if x == 1 else False
sm = lambda x: (x ** 2 + x) // 2
N = 10 ** 9 + 7
(x, y) = R()
a = [L() for i in range(x)]
ans = 0
for i in range(x):
	n = m = 0
	for j in range(y):
		n = max(a[i][j], n)
		m = max(a[i][-1 - j], m)
		if not a[i][j]:
			ans += n
		if not a[i][-1 - j]:
			ans += m
for j in range(y):
	n = m = 0
	for i in range(x):
		n = max(a[i][j], n)
		m = max(a[-1 - i][j], m)
		if not a[i][j]:
			ans += n
		if not a[-1 - i][j]:
			ans += m
print(ans)


(n, m) = list(map(int, input().split()))
plan = []
for i in range(n):
	plan.append(input().split())
plan2 = list(map(list, list(zip(*plan))))

def findLeft(string):
	i = 0
	while i < len(string):
		if string[i] == '1':
			return i
		else:
			i += 1

def findRight(string):
	i = len(string) - 1
	while i >= 0:
		if string[i] == '1':
			return i
		else:
			i -= 1
count = 0
for each in plan:
	if each.count('1') == 1:
		count += each.count('0')
	elif each.count('1') > 1:
		l = findLeft(each)
		r = findRight(each)
		count += each[:l].count('0') + 2 * each[l + 1:r].count('0') + each[r + 1:].count('0')
for each in plan2:
	if each.count('1') == 1:
		count += each.count('0')
	elif each.count('1') > 1:
		l = findLeft(each)
		r = findRight(each)
		count += each[:l].count('0') + 2 * each[l + 1:r].count('0') + each[r + 1:].count('0')
print(count)


(n, m) = map(int, input().split())
a = [''.join(input().split()) for i in range(n)]
columns = []
c = 0
for i in a:
	f = i.find('1')
	s = i.rfind('1')
	if f != -1 and s != -1:
		c += i[f:].count('0') + i[:s + 1].count('0')
for i in range(m):
	column = ''
	for j in range(n):
		column += a[j][i]
	columns.append(column)
for column in columns:
	f = column.find('1')
	s = column.rfind('1')
	if f != -1 and s != -1:
		c += column[f:].count('0') + column[:s + 1].count('0')
print(c)


(n, m) = map(int, input().split())
s = 0
v = [0 for i in range(m)]
for i in range(m):
	v[i] = [-1, 0]
for i in range(n):
	l = list(map(int, input().split()))
	c0 = -1
	c2 = 0
	for j in range(m):
		if l[j] == 1:
			if c0 == -1:
				c0 = j
			else:
				s -= 2
			if v[j][0] > -1:
				s -= 2
			else:
				v[j][0] = i
			v[j][1] = i
			c2 = j
	if c0 > -1:
		s += c0 + (c2 - c0) * 2 + m - c2 - 1
for i in range(m):
	if v[i][0] > -1:
		s += v[i][0] + (v[i][1] - v[i][0]) * 2 + n - v[i][1] - 1
print(s)


import os
import sys
from io import BytesIO, IOBase
import threading
from collections import defaultdict, Counter
from math import factorial as fac

def main():
	(n, m) = map(int, input().split())
	mat = []
	for i in range(n):
		li = list(map(int, input().split()))
		mat.append(li)
	ans = 0
	for i in range(n):
		left = False
		for j in range(m):
			if mat[i][j] == 0 and left == True:
				ans += 1
			if mat[i][j] == 1:
				left = True
	for i in range(n):
		right = False
		for j in range(m):
			if mat[i][m - j - 1] == 0 and right == True:
				ans += 1
			if mat[i][m - j - 1] == 1:
				right = True
	for i in range(m):
		up = False
		for j in range(n):
			if mat[j][i] == 0 and up == True:
				ans += 1
			if mat[j][i] == 1:
				up = True
	for i in range(m):
		down = False
		for j in range(n):
			if mat[n - j - 1][i] == 0 and down == True:
				ans += 1
			if mat[n - j - 1][i] == 1:
				down = True
	print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from sys import stdin, stdout
import math, sys, heapq
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict
from os import path
import random
import bisect as bi

def yes():
	print('YES')

def no():
	print('NO')
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

	def I():
		return int(input())

	def In():
		return map(int, input().split())
else:

	def I():
		return int(stdin.readline())

	def In():
		return map(int, stdin.readline().split())

def dict(a):
	d = {}
	for x in a:
		if d.get(x, -1) != -1:
			d[x] += 1
		else:
			d[x] = 1
	return d

def find_gt(a, x):
	i = bi.bisect_left(a, x)
	if i != len(a):
		return i
	else:
		return -1

def main():
	try:
		(n, m) = In()
		ans = 0
		l = []
		for x in range(n):
			l.append(list(In()))
		(Y, X) = ([], [])
		for i in range(n):
			pre_x = 0
			for j in range(m):
				pre_x += l[i][j]
			X.append(pre_x)
		for i in range(m):
			pre_y = 0
			for j in range(n):
				pre_y += l[j][i]
			Y.append(pre_y)
		for i in range(n):
			pre_x = 0
			for j in range(m):
				if l[i][j] == 0:
					if pre_x:
						ans += 1
					if X[i] - pre_x:
						ans += 1
				else:
					pre_x += 1
		for j in range(m):
			pre_y = 0
			for i in range(n):
				if l[i][j] == 1:
					pre_y += 1
				else:
					if pre_y:
						ans += 1
					if Y[j] - pre_y:
						ans += 1
		print(ans)
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(1):
	main()


(n, m) = [int(x) for x in input().split()]
a = []
for _ in range(n):
	a.append([int(x) for x in input().split()])
top = [0] * m
bottom = [0] * m
for row in a:
	for (j, x) in enumerate(row):
		bottom[j] += x
pos_count = 0
for row in a:
	left = 0
	right = sum(row)
	for (j, x) in enumerate(row):
		right -= x
		bottom[j] -= x
		if x == 0:
			if left > 0:
				pos_count += 1
			if right > 0:
				pos_count += 1
			if top[j] > 0:
				pos_count += 1
			if bottom[j] > 0:
				pos_count += 1
		left += x
		top[j] += x
print(pos_count)


(n, m) = map(int, input().split())
s = [list(map(int, input().split())) for i in range(n)]
r = [[0] * m for i in range(n)]
l = [[0] * m for i in range(n)]
u = [[0] * m for i in range(n)]
d = [[0] * m for i in range(n)]
for i in range(n):
	for j in range(m):
		if s[i][j] == 1:
			r[i][j] = 1
			l[i][j] = 1
			u[i][j] = 1
			d[i][j] = 1
for i in range(n):
	for j in range(m - 1)[::-1]:
		r[i][j] += r[i][j + 1]
for i in range(n):
	for j in range(1, m):
		l[i][j] += l[i][j - 1]
for j in range(m):
	for i in range(n - 1)[::-1]:
		d[i][j] += d[i + 1][j]
for j in range(m):
	for i in range(1, n):
		u[i][j] += u[i - 1][j]
ans = 0
for i in range(n):
	for j in range(m):
		l[i][j] = min(1, l[i][j])
		r[i][j] = min(1, r[i][j])
		u[i][j] = min(1, u[i][j])
		d[i][j] = min(1, d[i][j])
		if s[i][j] == 0:
			ans += l[i][j] + r[i][j] + u[i][j] + d[i][j]
print(ans)


def solve(n, m, ar):
	ans = 0
	f = False
	for i in range(0, n):
		f = False
		for j in range(0, m):
			if ar[i][j] == 0 and f is True:
				ans += 1
			if ar[i][j] == 1:
				f = True
			else:
				continue
		f = False
		for j in range(m - 1, -1, -1):
			if ar[i][j] == 0 and f is True:
				ans += 1
			if ar[i][j] == 1:
				f = True
			else:
				continue
	for j in range(0, m):
		f = False
		for i in range(0, n):
			if ar[i][j] == 0 and f is True:
				ans += 1
			if ar[i][j] == 1:
				f = True
			else:
				continue
		f = False
		for i in range(n - 1, -1, -1):
			if ar[i][j] == 0 and f is True:
				ans += 1
			if ar[i][j] == 1:
				f = True
			else:
				continue
	print(ans)
(n, m) = map(int, input().split())
ar = []
for i in range(n):
	ar.append([int(j) for j in input().split()])
solve(n, m, ar)


(n, m) = map(int, input().split())
s = 0
dic1 = {}
dic2 = {}
arr = []
for i in range(n):
	a = input().split()
	arr.append(a)
	cond = False
	for j in range(m):
		if a[j] == '1':
			cond = True
			dic1[j] = True
		else:
			if cond:
				s += 1
			if j in dic1:
				s += 1
for i in range(n - 1, -1, -1):
	cond = False
	for j in range(m - 1, -1, -1):
		if arr[i][j] == '1':
			dic2[j] = 1
			cond = True
		else:
			if j in dic2:
				s += 1
			if cond:
				s += 1
print(s)


from sys import stdin

def main():
	(r, c) = stdin_get_ints_from_line()
	a = []
	for _ in range(r):
		a.append(stdin_get_ints_list_from_line())
	good = 0
	col_have = [0] * 1000
	row_have = [0] * 1000
	zeros_left = [0] * 1000
	zeros_up = [0] * 1000
	for row in range(r):
		for col in range(c):
			if a[row][col] == 1:
				row_have[row] = 1
				col_have[col] = 1
				good += zeros_left[row]
				zeros_left[row] = 0
				good += zeros_up[col]
				zeros_up[col] = 0
				continue
			zeros_left[row] += 1
			zeros_up[col] += 1
			if row_have[row] == 1:
				good += 1
			if col_have[col] == 1:
				good += 1
	print(good)

def stdin_get_ints_from_line():
	return (int(x) for x in stdin.readline().strip().split(' '))

def stdin_get_ints_list_from_line():
	return list((int(x) for x in stdin.readline().strip().split(' ')))

def stdin_get_string_from_line():
	return stdin.readline().strip()

def __starting_point():
	main()
__starting_point()


I = lambda : input().split()
(n, m) = map(int, I())
(A, p) = ([I() for _ in range(n)], 0)
for x in range(n):
	for y in range(m):
		if A[x][y] == '1':
			for (dx, dy) in ((-1, 0), (1, 0), (0, -1), (0, 1)):
				k = 0
				while 0 <= x + (k + 1) * dx < n and 0 <= y + (k + 1) * dy < m and (A[x + (k + 1) * dx][y + (k + 1) * dy] == '0'):
					k += 1
				p += k
print(p)


import sys
import math
import bisect

def solve(A):
	n = len(A)
	m = len(A[0])
	X = []
	Y = []
	for i in range(n):
		X.append([])
	for j in range(m):
		Y.append([])
	for i in range(n):
		for j in range(m):
			if A[i][j]:
				X[i].append(j)
				Y[j].append(i)
	ans = 0
	for i in range(n):
		for j in range(m):
			if A[i][j] == 0:
				if len(X[i]) and X[i][0] < j:
					ans += 1
				if len(X[i]) and X[i][-1] > j:
					ans += 1
				if len(Y[j]) and Y[j][0] < i:
					ans += 1
				if len(Y[j]) and Y[j][-1] > i:
					ans += 1
	return ans

def main():
	(n, m) = map(int, input().split())
	A = []
	for i in range(n):
		A.append(list(map(int, input().split())))
	ans = solve(A)
	print(ans)
main()


(n, m) = map(int, input().split())
scene = [None] * n
dp_row = [None] * n
dp_col = [None] * n
for i in range(n):
	line = list(map(int, input().split()))
	scene[i] = line.copy()
	dp_row[i] = line.copy()
	dp_col[i] = line.copy()
for i in range(n):
	for j in range(m):
		if j > 0:
			dp_row[i][j] = dp_row[i][j - 1] + scene[i][j]
		if i > 0:
			dp_col[i][j] = dp_col[i - 1][j] + scene[i][j]
cnt = 0
for i in range(n):
	for j in range(m):
		if scene[i][j] == 0:
			if dp_row[i][j] > 0:
				cnt += 1
			if dp_col[i][j] > 0:
				cnt += 1
			if dp_row[i][j] < dp_row[i][-1]:
				cnt += 1
			if dp_col[i][j] < dp_col[-1][j]:
				cnt += 1
print(cnt)


def p_a():
	line = input()
	(hour, min_) = list(map(int, line.split(' ')))
	delta_min = 60 * hour + min_
	delta_min -= 45
	delta_min %= 24 * 60
	print(delta_min // 60, delta_min % 60)

def p_b():
	line = input()
	(lhs, rhs) = list(map(int, line[::-1].split(' ')))
	print(lhs if lhs > rhs else rhs)

def ascii_deltas(data):
	return [data[i] - data[i - 1] for i in range(1, len(data))]

def p_c():
	num_lines = int(input())
	for i in range(num_lines):
		str_ = ''.join(sorted(input()))
		deltas = ascii_deltas(list(map(ord, str_)))
		if not len(deltas):
			print('yes')
		elif any(map(lambda x: not x, deltas)):
			print('no')
		elif all(map(lambda x: x == 1, deltas)):
			print('yes')
		else:
			print('no')

def count_positions(data):
	ret = 0
	ret += 2 * sum((1 for x in data if not x))
	start = {-1: len(data) - 1, 1: 0}
	end = {-1: 0 - 1, 1: len(data)}
	for mode in range(-1, 1 + 1, 2):
		for i in range(start[mode], end[mode], mode):
			if not data[i]:
				ret -= 1
			else:
				break
	return ret

def p_d():
	(m, n) = list(map(int, input().split(' ')))
	data = []
	for i in range(m):
		data.append(list(map(int, input().split(' '))))
	ret = 0
	for row in data:
		ret += count_positions(row)
	data = zip(*data)
	for row in data:
		ret += count_positions(row)
	print(ret)

def main():
	p_d()
main()


def calc(s, length):
	l = s.find('1')
	if l == -1:
		return 0
	r = s.rfind('1')
	return l + length - 1 - r + 2 * sum((s[i] == '0' for i in range(l + 1, r)))
(n, m) = list(map(int, input().split()))
dp = []
num = 0
for i in range(n):
	dp.append(''.join(input().split()))
	num += calc(dp[i], m)
num += sum((calc(''.join((dp[i][j] for i in range(n))), n) for j in range(m)))
print(num)


import sys
input = sys.stdin.readline

def main():
	(n, m) = map(int, input().split())
	tab = [list(map(int, input().split())) for x in range(n)]
	co = 0
	tab1 = [[0] * (m + 1) for x in range(n + 1)]
	tab2 = [[0] * (m + 1) for x in range(n + 1)]
	for indLig in range(n):
		for indCol in range(m):
			tab1[indLig][indCol] = tab1[indLig][indCol - 1] + tab[indLig][indCol]
	for indCol in range(m):
		for indLig in range(n):
			tab2[indLig][indCol] = tab2[indLig - 1][indCol] + tab[indLig][indCol]
	for x in range(n):
		for y in range(m):
			if tab[x][y] == 1:
				continue
			if tab1[x][y] >= 1:
				co += 1
			if tab2[x][y] >= 1:
				co += 1
			if tab1[x][m - 1] - tab1[x][y] > 0:
				co += 1
			if tab2[n - 1][y] - tab2[x][y] > 0:
				co += 1
	print(co)
main()


import math
import sys
from bisect import bisect_right, bisect_left, insort_right
from collections import Counter, defaultdict
from heapq import heappop, heappush
from itertools import accumulate
from sys import stdout
R = lambda : map(int, input().split())
(n, m) = R()
arr = [None] * n
for i in range(n):
	arr[i] = list(R())
cnt = 0
acc = 0
for i in range(n):
	cnt += sum((min(1, a) - b for (a, b) in zip(accumulate(arr[i]), arr[i])))
	rev = arr[i][::-1]
	cnt += sum((min(1, a) - b for (a, b) in zip(accumulate(rev), rev)))
for j in range(m):
	col = [arr[i][j] for i in range(n)]
	rev = col[::-1]
	cnt += sum((min(1, a) - b for (a, b) in zip(accumulate(col), col)))
	cnt += sum((min(1, a) - b for (a, b) in zip(accumulate(rev), rev)))
print(cnt)


def run(l):
	r = 0
	for i in range(len(l)):
		b = False
		for j in l[i]:
			if j == '1':
				b = True
			if j == '0' and b == True:
				r += 1
	return r
(a, b) = map(int, input().split())
right = [''.join(input().split()) for i in range(a)]
left = [i[::-1] for i in right]
up = [''.join([i[j] for i in right]) for j in range(b)]
down = [i[::-1] for i in up]
print(run(left) + run(right) + run(up) + run(down))


(n, m) = map(int, input().split())
a = []
t_a = []
ans = 0
for i in range(n):
	x = list(map(int, input().split()))
	a.append(x)
t_a = list(map(list, zip(*a)))
for i in range(n):
	c = a[i].count(1)
	if c > 1:
		l = a[i].index(1)
		r = m - a[i][::-1].index(1) - 1
		ans += l + (m - r - 1) + (m - c - (l + (m - r - 1))) * 2
	elif c == 1:
		ans += m - 1
for i in range(m):
	c = t_a[i].count(1)
	if c > 1:
		l = t_a[i].index(1)
		r = n - t_a[i][::-1].index(1) - 1
		ans += l + (n - r - 1) + (n - c - (l + (n - r - 1))) * 2
	elif c == 1:
		ans += n - 1
print(ans)


(n, m) = list(map(int, input().split()))
(s, x) = (0, [])
for i in range(m):
	x.append([-1, 0])
for i in range(n):
	y = list(map(int, input().split()))
	(a, b) = (-1, 0)
	for j in range(m):
		if y[j] == 1:
			if a == -1:
				a = j
			else:
				s -= 2
			if x[j][0] > -1:
				s -= 2
			else:
				x[j][0] = i
			x[j][1] = i
			b = j
	if a > -1:
		s += a + (b - a) * 2 + m - b - 1
for i in range(m):
	if x[i][0] > -1:
		s += x[i][0] + (x[i][1] - x[i][0]) * 2 + n - x[i][1] - 1
print(s)


(row, column) = map(int, input().split())
alongy = [[] for c in range(column)]
(count, zeros) = (0, set())
for r in range(row):
	interim = ''.join(input().split())
	first = interim.find('1')
	if first != -1:
		second = interim.rfind('1')
		for val in range(column):
			if interim[val] == '0':
				if val > first and val < second:
					count += 2
				elif val < first or val > second:
					count += 1
				zeros.add(val)
			alongy[val].append(interim[val])
	else:
		for v in range(column):
			if interim[v] == '0':
				zeros.add(v)
			alongy[v].append(interim[v])
for values in zeros:
	interim2 = ''.join(alongy[values])
	first2 = interim2.find('1')
	if first2 != -1:
		second2 = interim2.rfind('1')
		for (index, val) in enumerate(interim2):
			if val == '0':
				if index > first2 and index < second2:
					count += 2
				elif index < first2 or index > second2:
					count += 1
print(count)


(n, m) = list(map(int, input().split()))
arr = []
for i in range(n):
	arr.append(list(map(int, input().split())))
c = 0
for i in range(n):
	was = 0
	for g in range(m):
		if not was:
			was = arr[i][g]
		else:
			c += arr[i][g] == 0
	was = 0
	for g in range(m - 1, -1, -1):
		if not was:
			was = arr[i][g]
		else:
			c += arr[i][g] == 0
for i in range(m):
	was = 0
	for g in range(n):
		if not was:
			was = arr[g][i]
		else:
			c += arr[g][i] == 0
	was = 0
	for g in range(n - 1, -1, -1):
		if not was:
			was = arr[g][i]
		else:
			c += arr[g][i] == 0
print(c)


(n, m) = map(int, input().split())
stage_matrix = []
dp_row = [[0 for i in range(m + 1)] for j in range(n + 1)]
dp_col = [[0 for i in range(n + 1)] for j in range(m + 1)]
for i in range(n):
	stage_matrix.append(list(map(int, input().split())))
for i in range(1, n + 1):
	for j in range(1, m + 1):
		if stage_matrix[i - 1][j - 1] == 1:
			dp_row[i][j] = dp_row[i][j - 1] + 1
		else:
			dp_row[i][j] = dp_row[i][j - 1]
for i in range(1, m + 1):
	for j in range(1, n + 1):
		if stage_matrix[j - 1][i - 1] == 1:
			dp_col[i][j] = dp_col[i][j - 1] + 1
		else:
			dp_col[i][j] = dp_col[i][j - 1]
c = 0
for i in range(n):
	for j in range(m):
		if stage_matrix[i][j] == 0:
			if dp_col[j + 1][i] > 0:
				c = c + 1
			if dp_col[j + 1][n] - dp_col[j + 1][i + 1] > 0:
				c = c + 1
			if dp_row[i + 1][j] != 0:
				c = c + 1
			if dp_row[i + 1][m] - dp_row[i + 1][j + 1] != 0:
				c = c + 1
print(c)


(n, m) = map(int, input().split())
a = [0] * n
ans = 0
for i in range(n):
	a[i] = list(map(int, input().split()))
	w = 0
	for j in a[i]:
		w |= j
		if j == 0 and w == 1:
			ans += 1
for i in range(n):
	w = 0
	for z in range(m - 1, -1, -1):
		j = a[i][z]
		w |= j
		if j == 0 and w == 1:
			ans += 1
for z in range(m):
	w = 0
	for i in range(n - 1, -1, -1):
		j = a[i][z]
		w |= j
		if j == 0 and w == 1:
			ans += 1
for z in range(m):
	w = 0
	for i in range(n):
		j = a[i][z]
		w |= j
		if j == 0 and w == 1:
			ans += 1
print(ans)


(n, m) = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(n)]
B = [[0] * (m + 1)]
for c in A:
	B.append([0] + c)
for i in range(1, n + 1):
	for j in range(1, m + 1):
		B[i][j] += B[i][j - 1] + B[i - 1][j] - B[i - 1][j - 1]
cnt = 0
for i in range(1, n + 1):
	for j in range(1, m + 1):
		if A[i - 1][j - 1] == 0:
			if B[i][j] - B[i - 1][j]:
				cnt += 1
			if B[i][m] - B[i][j - 1] - B[i - 1][m] + B[i - 1][j - 1]:
				cnt += 1
			if B[i][j] - B[i][j - 1]:
				cnt += 1
			if B[n][j] - B[i - 1][j] - B[n][j - 1] + B[i - 1][j - 1]:
				cnt += 1
print(cnt)


(n, m) = map(int, input().split())
l = []
for i in range(n):
	k = list(map(int, input().split()))
	l.append(k)
ans = 0
for i in range(n):
	for j in range(m):
		if l[i][j] == 1:
			for k in range(j, m):
				if l[i][k] == 0:
					ans = ans + 1
			break
for i in range(n):
	for j in range(m - 1, -1, -1):
		if l[i][j] == 1:
			for k in range(j - 1, -1, -1):
				if l[i][k] == 0:
					ans = ans + 1
			break
for i in range(m):
	for j in range(n):
		if l[j][i] == 1:
			for k in range(j + 1, n):
				if l[k][i] == 0:
					ans = ans + 1
			break
for i in range(m):
	for j in range(n - 1, -1, -1):
		if l[j][i] == 1:
			for k in range(j - 1, -1, -1):
				if l[k][i] == 0:
					ans = ans + 1
			break
print(ans)


from collections import deque as de
import math
import re
from collections import Counter as cnt
from functools import reduce
from typing import MutableMapping
from itertools import groupby as gb
from fractions import Fraction as fr
from bisect import bisect_left as bl, bisect_right as br

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

class My_stack:

	def __init__(self):
		self.data = []

	def my_push(self, x):
		return self.data.append(x)

	def my_pop(self):
		return self.data.pop()

	def my_peak(self):
		return self.data[-1]

	def my_contains(self, x):
		return self.data.count(x)

	def my_show_all(self):
		return self.data

	def isEmpty(self):
		return len(self.data) == 0
arrStack = My_stack()

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def binarytodecimal(n):
	return int(n, 2)

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def get_prime_factors(number):
	prime_factors = []
	while number % 2 == 0:
		prime_factors.append(2)
		number = number / 2
	for i in range(3, int(math.sqrt(number)) + 1, 2):
		while number % i == 0:
			prime_factors.append(int(i))
			number = number / i
	if number > 2:
		prime_factors.append(int(number))
	return prime_factors

def get_frequency(list):
	dic = {}
	for ele in list:
		if ele in dic:
			dic[ele] += 1
		else:
			dic[ele] = 1
	return dic

def Log2(x):
	return math.log10(x) / math.log10(2)

def isPowerOfTwo(n):
	return math.ceil(Log2(n)) == math.floor(Log2(n))

def ceildiv(x, y):
	return (x + y - 1) // y

def di():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))
(n, m) = di()
tt = [li() for i in range(n)]
ans = 0
for row in tt:
	ele = []
	elecount = []
	zc = 0
	oc = 0
	for (key, count) in gb(row):
		temp = len(list(count))
		if key == 0:
			zc += temp
		if key == 1:
			oc += temp
		ele.append(key)
		elecount.append(temp)
	if oc >= 1:
		ans += zc
	if oc >= 2:
		for i in range(len(ele) - 2):
			if ele[i] == ele[i + 2] == 1:
				ans += elecount[i + 1]
for i in range(m):
	columnlist = [row[i] for row in tt]
	ele = []
	elecount = []
	zc = 0
	oc = 0
	for (key, count) in gb(columnlist):
		temp = len(list(count))
		if key == 0:
			zc += temp
		if key == 1:
			oc += temp
		ele.append(key)
		elecount.append(temp)
	if oc >= 1:
		ans += zc
	if oc >= 2:
		for i in range(len(ele) - 2):
			if ele[i] == ele[i + 2] == 1:
				ans += elecount[i + 1]
print(ans)


from sys import *
(n, m) = (int(z) for z in stdin.readline().split())
ans = 0
mat = []
for i in range(n):
	mat.append([int(z) for z in stdin.readline().split()])
	fst = m
	lst = -1
	nu = 0
	for j in range(m):
		if mat[-1][j] == 1:
			nu += 1
			lst = j
			if not fst - m:
				fst = j
	ans += lst + 1 - nu
	ans += m - fst - nu
for i in range(m):
	fst = n
	lst = -1
	nu = 0
	for j in range(n):
		if mat[j][i] == 1:
			nu += 1
			lst = j
			if not fst - n:
				fst = j
	ans += lst + 1 - nu
	ans += n - fst - nu
print(ans)


(n, m) = map(int, input().split())
d = []
res = 0
for i in range(n):
	s = input()
	if s.count('1') != 0:
		l = s.find('1')
		r = s.rfind('1')
		res += s[:l].count('0')
		res += s[r + 1:].count('0')
		res += s[l + 1:r].count('0') * 2
	d.append(s)
for i in range(0, m * 2, 2):
	ss = ''
	for k in range(n):
		ss += d[k][i]
	if ss.count('1') != 0:
		l = ss.find('1')
		r = ss.rfind('1')
		res += ss[:l].count('0')
		res += ss[r + 1:].count('0')
		res += ss[l + 1:r].count('0') * 2
print(res)


(n, m) = list(map(int, input().split()))
mat = []
for i in range(n):
	mat.append(list(map(int, input().split())))
ans = [[0 for i in range(m)] for j in range(n)]
for i in range(n):
	f = 0
	for j in range(m):
		if mat[i][j] == 0:
			ans[i][j] += f
		if mat[i][j] == 1:
			f = 1
	f = 0
	for j in range(m - 1, -1, -1):
		if mat[i][j] == 0:
			ans[i][j] += f
		if mat[i][j] == 1:
			f = 1
for i in range(m):
	f = 0
	for j in range(n):
		if mat[j][i] == 0:
			ans[j][i] += f
		if mat[j][i] == 1:
			f = 1
	f = 0
	for j in range(n - 1, -1, -1):
		if mat[j][i] == 0:
			ans[j][i] += f
		if mat[j][i] == 1:
			f = 1
cnt = 0
for i in ans:
	cnt += sum(i)
print(cnt)


num_input = input()
num_input = num_input.split(' ')
n = int(num_input[0])
m = int(num_input[1])
arr = []
for i in range(0, n):
	arr.append(input().split(' '))
t_arr = list(map(list, zip(*arr)))
res = 0
for i in range(0, n):
	num_1 = arr[i].count('1')
	if num_1 > 0:
		l = arr[i].index('1')
		r = m - 1 - arr[i][::-1].index('1')
		res += l
		res += m - 1 - r
		res += (r - l + 1 - num_1) * 2
for i in range(0, m):
	num_1 = t_arr[i].count('1')
	if num_1 > 0:
		l = t_arr[i].index('1')
		r = n - 1 - t_arr[i][::-1].index('1')
		res += l
		res += n - 1 - r
		res += (r - l + 1 - num_1) * 2
print(res)


(n, m) = [int(i) for i in input().split()]
A = [0] * n
ones = 0
for i in range(n):
	a = [int(i) for i in input().split()]
	A[i] = a
	ones += a.count(1)
ans = 0
for i in range(n):
	for j in range(m):
		if A[i][j] == 1:
			ans += m - j
			break
	for j in range(m - 1, -1, -1):
		if A[i][j] == 1:
			ans += j + 1
			break
for i in range(m):
	for j in range(n):
		if A[j][i] == 1:
			ans += n - j
			break
	for j in range(n - 1, -1, -1):
		if A[j][i] == 1:
			ans += j + 1
			break
print(ans - 4 * ones)


(n, m) = map(int, input().split())
a = ['' for _ in range(n)]
for i in range(n):
	for j in input().split():
		a[i] += j
aa = a.copy()
ans = 0
for i in aa:
	i = i.strip('0')
	if i == '':
		continue
	ans += m - len(i) + 2 * i.count('0')
aa = ['' for _ in range(m)]
for i in range(n):
	for j in range(m):
		aa[j] += a[i][j]
for i in aa:
	i = i.strip('0')
	if i == '':
		continue
	ans += n - len(i) + 2 * i.count('0')
print(ans)


(n, m) = map(int, input().split())
a = [[]] * n
up = [[]] * n
down = [[]] * n
left = [[]] * n
right = [[]] * n
for i in range(n):
	a[i] = list(map(int, input().split()))
	up[i] = [0] * m
	down[i] = [0] * m
	left[i] = [0] * m
	right[i] = [0] * m
for i in range(n):
	val = 0
	for j in range(m):
		val = max(val, a[i][j])
		left[i][j] = val
for i in range(n):
	val = 0
	for j in range(m - 1, -1, -1):
		val = max(val, a[i][j])
		right[i][j] = val
for j in range(m):
	val = 0
	for i in range(n):
		val = max(val, a[i][j])
		up[i][j] = val
for j in range(m):
	val = 0
	for i in range(n - 1, -1, -1):
		val = max(val, a[i][j])
		down[i][j] = val
ans = 0
for i in range(n):
	for j in range(m):
		if a[i][j] == 0:
			ans += up[i][j] + down[i][j] + left[i][j] + right[i][j]
print(ans)


(n, m) = map(int, input().split())
c = 0
matrix = []
ans = 0
for i in range(n):
	a = list(map(int, input().split()))
	matrix.append(a)
for i in range(n):
	flag = 0
	c = 0
	for j in range(m):
		if matrix[i][j] == 1 and flag == 0:
			ans = ans + c
			c = 0
			flag = 1
		elif matrix[i][j] == 1 and flag == 1:
			ans = ans + 2 * c
			c = 0
		else:
			c = c + 1
	if c > 0 and flag == 1:
		ans = ans + c
for j in range(m):
	c = 0
	flag = 0
	for i in range(n):
		if matrix[i][j] == 1 and flag == 0:
			ans = ans + c
			c = 0
			flag = 1
		elif matrix[i][j] == 1 and flag == 1:
			ans = ans + 2 * c
			c = 0
		else:
			c = c + 1
	if c > 0 and flag == 1:
		ans = ans + c
print(ans)


(n, m) = map(int, input().split())
cols = [''] * m
count = 0
for i in range(n):
	line = input().split()
	if '0' in line and '1' in line:
		count += line.count('0')
		start = line.index('1') + 1
		end = m - line[::-1].index('1') - 1
		count += line[start:end].count('0')
	for j in range(m):
		cols[j] += line[j]
for i in range(m):
	cur = cols[i]
	if '0' in cur and '1' in cur:
		count += cur.count('0')
		start = cur.index('1') + 1
		end = n - cur[::-1].index('1') - 1
		count += cur[start:end].count('0')
print(count)


inp = lambda : map(int, input().rstrip().split())
(n, m) = inp()
mat = []
row = []
col = []
for i in range(n):
	mat += [list(inp())]
	row += [[0] * m]
	col += [[0] * m]
for i in range(n):
	t = 0
	for j in range(m):
		if mat[i][j] == 1:
			t += 1
		row[i][j] = t
for j in range(m):
	t = 0
	for i in range(n):
		if mat[i][j] == 1:
			t += 1
		col[i][j] = t
ans = 0
for i in range(n):
	for j in range(m):
		if mat[i][j] == 0:
			if row[i][m - 1] - row[i][j] > 0:
				ans += 1
			if row[i][j] > 0:
				ans += 1
			if col[n - 1][j] - col[i][j] > 0:
				ans += 1
			if col[i][j] > 0:
				ans += 1
print(ans)


import math
(n, m) = map(int, input().split())
r = []
answer = 0
for i in range(n):
	a = list(map(int, input().split()))
	r.append(a)
	count = 0
	mn = 1000
	mx = -1
	for j in range(m):
		if a[j] == 1:
			mn = min(mn, j)
			mx = j
			count += 1
	if count == 1:
		answer += m - count
	elif count >= 2:
		answer += 2 * m - 2 * count - m + 1 + mx - mn
for i in range(m):
	count = 0
	mn = 1000
	mx = -1
	for j in range(n):
		if r[j][i] == 1:
			mn = min(mn, j)
			mx = j
			count += 1
	if count == 1:
		answer += n - count
	elif count >= 2:
		answer += 2 * n - 2 * count - n + 1 + mx - mn
print(answer)


def f():
	(n, m) = map(int, input().split())
	S = [list(map(int, input().split())) for i in range(n)]
	strp = [[S[i][0]] for i in range(n)]
	for i in range(n):
		for j in range(1, m):
			strp[i].append(strp[i][j - 1] + S[i][j])
	stbp = [[S[0][j]] for j in range(m)]
	for j in range(m):
		for i in range(1, n):
			stbp[j].append(stbp[j][i - 1] + S[i][j])

	def good(x, y, d):
		if S[x][y] == 1:
			return False
		else:
			d = 'ruld'.find(d)
			if not d % 2:
				return bool(strp[x][y] if d == 0 else strp[x][-1] - strp[x][y])
			else:
				return bool(stbp[y][x] if d == 1 else stbp[y][-1] - stbp[y][x])
	cnt = 0
	for x in range(n):
		for y in range(m):
			cnt += good(x, y, 'r') + good(x, y, 'u') + good(x, y, 'l') + good(x, y, 'd')
	print(cnt)
f()


(r, c) = map(int, input().split())
a = []
b = []
for i in range(c):
	b.append([])
for i in range(r):
	n = list(input().split())
	a.append(n)
	for (k, v) in enumerate(n):
		b[k].append(v)
total = 0
for i in a:
	if '1' in i:
		t = i[i.index('1'):''.join(i).rindex('1')].count('0')
		total += t * 2 + i.count('0') - t
for i in b:
	if '1' in i:
		t = i[i.index('1'):''.join(i).rindex('1')].count('0')
		total += t * 2 + i.count('0') - t
print(total)


from sys import stdin as fin
(n, m) = map(int, fin.readline().split())
mtrx = [list(map(int, fin.readline().split())) for i in range(n)]
(lines, cols) = ([[0] * m for i in range(n)], [[0] * n for i in range(m)])
for i in range(n):
	for j in range(m):
		if mtrx[i][j] == 1:
			lines[i][j] = 1
			cols[j][i] = 1
for i in range(n):
	for j in range(1, m):
		lines[i][j] += lines[i][j - 1]
for j in range(m):
	for i in range(1, n):
		cols[j][i] += cols[j][i - 1]
cnt = 0
for i in range(n):
	for j in range(m):
		if mtrx[i][j] == 0:
			cnt += (1 if lines[i][j] else 0) + (1 if lines[i][m - 1] - lines[i][j] else 0) + (1 if cols[j][i] else 0) + (1 if cols[j][n - 1] - cols[j][i] else 0)
print(cnt)


(n, m) = map(int, input().split())
a = [[int(i) for i in input().split()] for _ in range(n)]
left = [[0 for _ in range(m)] for _ in range(n)]
right = [[0 for _ in range(m)] for _ in range(n)]
up = [[0 for _ in range(m)] for _ in range(n)]
down = [[0 for _ in range(m)] for _ in range(n)]
for i in range(n):
	for j in range(m):
		left[i][j] = a[i][j]
		if j > 0:
			left[i][j] |= left[i][j - 1]
for i in range(n):
	for j in range(m - 1, -1, -1):
		right[i][j] = a[i][j]
		if j + 1 < m:
			right[i][j] |= right[i][j + 1]
for j in range(m):
	for i in range(n):
		up[i][j] = a[i][j]
		if i > 0:
			up[i][j] |= up[i - 1][j]
for j in range(m):
	for i in range(n - 1, -1, -1):
		down[i][j] = a[i][j]
		if i + 1 < n:
			down[i][j] |= down[i + 1][j]
ways = 0
for i in range(n):
	for j in range(m):
		if a[i][j] == 0:
			ways += left[i][j] + right[i][j] + up[i][j] + down[i][j]
print(ways)


from sys import stdin
(n, m) = [int(x) for x in stdin.readline().split()]
plan = [[int(x) for x in stdin.readline().split()] for _ in range(n)]
prowsum = [[0 for _ in range(m)] for _ in range(n)]
for i in range(n):
	prowsum[i][0] = plan[i][0]
	for j in range(1, m):
		prowsum[i][j] = prowsum[i][j - 1] or plan[i][j]
srowsum = [[0 for _ in range(m)] for _ in range(n)]
for i in range(n):
	srowsum[i][m - 1] = plan[i][m - 1]
	for j in range(m - 2, -1, -1):
		srowsum[i][j] = srowsum[i][j + 1] or plan[i][j]
pcolsum = [[0 for _ in range(m)] for _ in range(n)]
for j in range(m):
	pcolsum[0][j] = plan[0][j]
	for i in range(1, n):
		pcolsum[i][j] = pcolsum[i - 1][j] or plan[i][j]
scolsum = [[0 for _ in range(m)] for _ in range(n)]
for j in range(m):
	scolsum[n - 1][j] = plan[n - 1][j]
	for i in range(n - 2, -1, -1):
		scolsum[i][j] = scolsum[i + 1][j] or plan[i][j]
ans = 0
for i in range(n):
	for j in range(m):
		if plan[i][j] == 1:
			continue
		if i > 0 and pcolsum[i - 1][j]:
			ans += 1
		if i < n - 1 and scolsum[i + 1][j]:
			ans += 1
		if j > 0 and prowsum[i][j - 1]:
			ans += 1
		if j < m - 1 and srowsum[i][j + 1]:
			ans += 1
print(ans)


(n, m) = map(int, input().split())
ls = []
for i in range(n):
	temp = list(map(int, input().split()))
	ls.append(temp)
row = []
for i in range(n):
	temp = []
	for j in range(m):
		if ls[i][j] == 1:
			temp.append(j)
	if len(temp) == 0:
		row.append([-1, -1])
	else:
		row.append([temp[0], temp[-1]])
col = []
for i in range(m):
	temp = []
	for j in range(n):
		if ls[j][i] == 1:
			temp.append(j)
	if len(temp) == 0:
		col.append([-1, -1])
	else:
		col.append([temp[0], temp[-1]])
ans = 0
for i in range(n):
	for j in range(m):
		if ls[i][j] == 0:
			if row[i] != [-1, -1]:
				if row[i][0] < j:
					ans += 1
				if row[i][1] > j:
					ans += 1
			if col[j] != [-1, -1]:
				if col[j][0] < i:
					ans += 1
				if col[j][1] > i:
					ans += 1
print(ans)


import os
import sys
from io import BytesIO, IOBase
from functools import lru_cache

def main():
	(n, m) = map(int, input().split())
	arr = []
	for _ in range(n):
		arr.append(list(map(int, input().split())))
	ans = 0
	for c in range(m):
		flag = 0
		for r in range(n):
			if arr[r][c] == 1:
				flag = 1
				continue
			if flag:
				ans += 1
	for c in range(m):
		flag = 0
		for r in range(n - 1, -1, -1):
			if arr[r][c] == 1:
				flag = 1
				continue
			if flag:
				ans += 1
	for r in range(n):
		flag = 0
		for c in range(m):
			if arr[r][c] == 1:
				flag = 1
				continue
			if flag:
				ans += 1
	for r in range(n):
		flag = 0
		for c in range(m - 1, -1, -1):
			if arr[r][c] == 1:
				flag = 1
				continue
			if flag:
				ans += 1
	print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


(n, m) = list(map(int, input().split()))
ss = [list(map(int, input().split())) for _ in range(n)]
ll = []
ll.append([ss[i][j] for i in range(n) for j in range(m)])
ll.append([ss[i][j] for i in range(n) for j in range(m - 1, -1, -1)])
ll.append([ss[i][j] for j in range(m) for i in range(n)])
ll.append([ss[i][j] for j in range(m) for i in range(n - 1, -1, -1)])
cnt = 0
for t in range(4):
	l = ll[t]
	(run, nor) = (m, n) if t < 2 else (n, m)
	for r in range(nor):
		rs = r * run
		ho = 0
		for i in range(run):
			if l[rs + i] == 1:
				ho = 1
				continue
			cnt += ho
print(cnt)


(n, m) = map(int, input().split())
jadval = []
for i in range(n):
	jadval.append(list(input().replace(' ', '')))
s = 0
for i in range(n):
	f = 0
	for j in range(m):
		if jadval[i][j] == '1':
			f = 1
		elif f == 1:
			s += 1
for i in range(n):
	f = 0
	j = m - 1
	while j >= 0:
		if jadval[i][j] == '1':
			f = 1
		elif f == 1:
			s += 1
		j -= 1
for j in range(m):
	f = 0
	for i in range(n):
		if jadval[i][j] == '1':
			f = 1
		elif f == 1:
			s += 1
for j in range(m):
	f = 0
	i = n - 1
	while i >= 0:
		if jadval[i][j] == '1':
			f = 1
		elif f == 1:
			s += 1
		i -= 1
print(s)


(n, m) = map(int, input().split())
a = []
r = []
for i in range(n):
	tmp = list(map(int, input().split()))
	x = [tmp[0]]
	for j in range(1, m):
		x.append(tmp[j] + x[-1])
	r.append(x)
	a.append(tmp)
c = []
x = [a[0][0]]
for i in range(1, m):
	x.append(a[0][i])
c.append(x)
for i in range(1, n):
	x = []
	for j in range(m):
		x.append(c[i - 1][j] + a[i][j])
	c.append(x)
ans = 0
for i in range(n):
	for j in range(m):
		if a[i][j] == 0:
			if i == 0:
				if j == 0:
					if r[i][-1] != 0:
						ans += 1
					if c[-1][j] != 0:
						ans += 1
				else:
					if r[i][j] != 0:
						ans += 1
					if r[i][j] != r[i][-1]:
						ans += 1
					if c[-1][j] != 0:
						ans += 1
			elif j == 0:
				if i == n - 1:
					if c[i][j] != 0:
						ans += 1
					if r[-1][-1] != 0:
						ans += 1
				else:
					if r[i][-1] != 0:
						ans += 1
					if c[i][j] != 0:
						ans += 1
					if c[-1][j] != c[i][j]:
						ans += 1
			elif i == n - 1:
				if j == m - 1:
					if r[i][j] != 0:
						ans += 1
					if c[i][j] != 0:
						ans += 1
				else:
					if r[i][j] != 0:
						ans += 1
					if r[-1][-1] != r[i][j]:
						ans += 1
					if c[i][j] != 0:
						ans += 1
			elif j == m - 1:
				if r[i][j] != 0:
					ans += 1
				if c[i][j] != 0:
					ans += 1
				if c[-1][j] != c[i][j]:
					ans += 1
			else:
				if r[i][j] != 0:
					ans += 1
				if r[i][-1] != r[i][j]:
					ans += 1
				if c[i][j] != 0:
					ans += 1
				if c[-1][j] != c[i][j]:
					ans += 1
print(ans)


(n, m) = list(map(int, input().split()))
l = []
from collections import defaultdict
d = defaultdict(lambda : [9999999999999999, -9999999999999999])
dd = defaultdict(list)
for i in range(n):
	ll = list(map(int, input().split()))
	l.append(ll)
	p = []
	for j in range(m):
		if ll[j] == 1:
			p.append(j)
			d[j][0] = min(d[j][0], i)
			d[j][1] = max(d[j][1], i)
	if len(p) > 0:
		dd[i].append([p[0], p[-1]])
s = 0
for i in range(n):
	for j in range(m):
		if l[i][j] == 0:
			if len(dd[i]) > 0:
				z = dd[i][0]
				if z == z[-1]:
					s += 1
				elif j < z[-1] and j > z[0]:
					s += 2
				else:
					s += 1
			z = d[j]
			if z[0] != 9999999999999999 and z[-1] != -9999999999999999:
				if z == z[-1]:
					s += 1
				elif i < z[-1] and i > z[0]:
					s += 2
				else:
					s += 1
print(s)


mod = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())

def gcnt(s):
	(l, r) = (s.find('1'), s.rfind('1'))
	if l == -1:
		return 0
	else:
		return l + len(s) - r - 1 + 2 * sum((s[i] == '0' for i in range(l + 1, r)))
(n, m) = f()
l = [''.join(input().split()) for i in range(n)]
sm = 0
sm += sum((gcnt(j) for j in l))
for j in range(m):
	x = ''
	for i in range(n):
		x += l[i][j]
	sm += gcnt(x)
print(sm)


(n, m) = map(int, input().split())
M = [[0 for i in range(m)] for i in range(n)]
L = [list(map(int, input().split())) for i in range(n)]
for i in range(n):
	p = 0
	for j in range(m):
		if L[i][j] == 1:
			p = 1
		elif p == 1:
			M[i][j] += 1
	p = 0
	for j in range(m - 1, -1, -1):
		if L[i][j] == 1:
			p = 1
		elif p == 1:
			M[i][j] += 1
for i in range(m):
	p = 0
	for j in range(n):
		if L[j][i] == 1:
			p = 1
		elif p == 1:
			M[j][i] += 1
	p = 0
	for j in range(n - 1, -1, -1):
		if L[j][i] == 1:
			p = 1
		elif p == 1:
			M[j][i] += 1
k = 0
for i in range(n):
	for j in range(m):
		k += M[i][j]
print(k)


(n, m) = map(int, input().split())
grid = [[i for i in map(int, input().split())] for _ in range(n)]
good_spots = 0
found1 = False
for row in grid:
	found1 = False
	if sum(row) == 0:
		continue
	last_one = len(row) - row[::-1].index(1) - 1
	for (idx, num) in enumerate(row):
		if num == 0:
			if idx < last_one:
				good_spots += 1
			if found1:
				good_spots += 1
		else:
			found1 = True
for c in range(m):
	found1 = False
	col = [row[c] for row in grid]
	if sum(col) == 0:
		continue
	last_one = len(col) - col[::-1].index(1) - 1
	for (idx, num) in enumerate(col):
		if num == 0:
			if idx < last_one:
				good_spots += 1
			if found1:
				good_spots += 1
		else:
			found1 = True
print(good_spots)


(n, m) = map(int, input().split())
a = []
for i in range(n):
	a.append(list(map(int, input().split())))
count = 0
for i in range(n):
	flag = 0
	for j in range(m):
		if a[i][j] == 0:
			flag += 1
		else:
			count += flag
			flag = 0
count1 = 0
for i in range(n):
	flag = 0
	for j in range(m):
		if a[i][j] == 1:
			flag = 1
		elif a[i][j] == 0 and flag == 1:
			count1 += 1
count2 = 0
for i in range(m):
	flag = 0
	for j in range(n):
		if a[j][i] == 0:
			flag += 1
		else:
			count2 += flag
			flag = 0
count3 = 0
for i in range(m):
	flag = 0
	for j in range(n):
		if a[j][i] == 1:
			flag = 1
		elif a[j][i] == 0 and flag == 1:
			count3 += 1
print(count + count1 + count2 + count3)


(n, m) = list(map(int, input().split()))
minn_g = [1001] * n
maxx_g = [-1] * n
minn_v = [1001] * m
maxx_v = [-1] * m
size_g = [0] * n
size_v = [0] * m
for i in range(n):
	o = list(map(int, input().split()))
	for j in range(m):
		if o[j] == 1:
			size_g[i] += 1
			size_v[j] += 1
			minn_g[i] = min(minn_g[i], j)
			minn_v[j] = min(minn_v[j], i)
			maxx_g[i] = max(maxx_g[i], j)
			maxx_v[j] = max(maxx_v[j], i)
res = 0
for i in range(n):
	if size_g[i] != 0:
		res += m - size_g[i] - minn_g[i]
		res += maxx_g[i] + 1 - size_g[i]
for i in range(m):
	if size_v[i] != 0:
		res += n - size_v[i] - minn_v[i]
		res += maxx_v[i] + 1 - size_v[i]
print(res)


(n, m) = map(int, input().split())
a = []
for i in range(n):
	w = list(map(str, input().split()))
	a.append(w)

def check(s):
	c = 0
	left = s.find('1')
	right = s.rfind('1')
	c += s[:left].count('0')
	c += 2 * s[left:right].count('0')
	c += s[right:].count('0')
	return c
cnt = 0
for i in range(n):
	x = ''.join(a[i])
	if '1' not in x:
		continue
	cnt += check(x)
b = [['0' for i in range(n)] for j in range(m)]
for i in range(m):
	for j in range(n):
		b[i][j] = a[j][i]
for i in range(m):
	x = ''.join(b[i])
	if '1' not in x:
		continue
	cnt += check(x)
print(cnt)


import random

def print_arrary(temp_array):
	for row in range(len(temp_array)):
		print(temp_array[row])

def count_best_positions():
	result = 0
	for i in range(count_rows):
		found = False
		start = -1
		end = -1
		result_hor = 0
		for j in range(count_cols):
			if input_array[i][j] == 1:
				if not found:
					found = True
					start = j
				else:
					result_hor += 1
				end = j
		if found:
			if start != end:
				result += count_cols - start + end - 1 - result_hor * 2
			else:
				result += start + (count_cols - 1 - end)
	for j in range(count_cols):
		found = False
		start = -1
		end = -1
		result_vert = 0
		for i in range(count_rows):
			if input_array[i][j] == 1:
				if not found:
					found = True
					start = i
				else:
					result_vert += 1
				end = i
		if found:
			if start != end:
				result += count_rows - start + end - 1 - result_vert * 2
			else:
				result += start + (count_rows - 1 - end)
	return result
input_array = []
temp_array_string = input().split()
count_rows = int(temp_array_string[0])
count_cols = int(temp_array_string[1])
for row in range(count_rows):
	temp_array_string = [int(cell) for cell in input().split()]
	temp_row = []
	for col in range(count_cols):
		temp_row.append(temp_array_string[col])
	input_array.append(temp_row)
print(count_best_positions())
print()


import math as mt
import sys, string, bisect
input = sys.stdin.readline
import random
from collections import deque, defaultdict
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())
(n, m) = M()
rows = []
columns = []
l = []
for i in range(n):
	l.append(L())
for i in range(n):
	x = [0, l[i][0]]
	for j in range(1, m):
		x.append(x[-1] + l[i][j])
	x.append(x[-1])
	rows.append(x)
for i in range(m):
	x = [0, l[0][i]]
	for j in range(1, n):
		x.append(x[-1] + l[j][i])
	x.append(x[-1])
	columns.append(x)
s = 0
for i in range(n):
	for j in range(m):
		if l[i][j] == 0:
			if rows[i][j + 1] - rows[i][0] > 0:
				s += 1
			if rows[i][-1] - rows[i][j + 1] > 0:
				s += 1
			if columns[j][i + 1] - columns[j][0] > 0:
				s += 1
			if columns[j][-1] - columns[j][i + 1] > 0:
				s += 1
print(s)


import os.path
from math import gcd, floor, ceil
from collections import *
import sys
mod = 1000000007
INF = float('inf')

def st():
	return list(sys.stdin.readline().strip())

def li():
	return list(map(int, sys.stdin.readline().split()))

def mp():
	return map(int, sys.stdin.readline().split())

def inp():
	return int(sys.stdin.readline())

def pr(n):
	return sys.stdout.write(str(n) + '\n')

def prl(n):
	return sys.stdout.write(str(n) + ' ')
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def solve():
	(n, m) = mp()
	l = []
	up = []
	down = []
	left = []
	right = []
	zero = [0] * m
	for i in range(n):
		x = li()
		l.append(x)
		up.append(list(zero))
		down.append(list(zero))
		left.append(list(zero))
		right.append(list(zero))
		left[i][0] = x[0]
		right[i][-1] = x[-1]
		for j in range(1, m):
			left[i][j] = x[j] + left[i][j - 1]
			right[i][m - 1 - j] = x[m - 1 - j] + right[i][m - j]
	for i in range(m):
		up[0][i] = l[0][i]
		down[-1][i] = l[-1][i]
		for j in range(1, n):
			up[j][i] = l[j][i] + up[j - 1][i]
			down[n - j - 1][i] = l[n - 1 - j][i] + down[n - j][i]
	ans = 0
	for i in range(n):
		for j in range(m):
			if l[i][j] != 1:
				c = 0
				c += min(1, up[i][j])
				c += min(1, down[i][j])
				c += min(1, left[i][j])
				c += min(1, right[i][j])
				ans += c
	pr(ans)
for _ in range(1):
	solve()


from sys import stdin, stdout
input = stdin.readline
(n, m) = map(int, input().split())
arr = []
for i in range(n):
	arr.append(list(map(int, input().split())))
dp = [[0 for i in range(m)] for j in range(n)]
for i in range(n):
	t = 0
	for j in range(m):
		if arr[i][j] == 0:
			dp[i][j] += t
		else:
			t = 1
	t = 0
	for j in range(m - 1, -1, -1):
		if arr[i][j] == 0:
			dp[i][j] += t
		else:
			t = 1
for i in range(m):
	t = 0
	for j in range(n):
		if arr[j][i] == 0:
			dp[j][i] += t
		else:
			t = 1
	t = 0
	for j in range(n - 1, -1, -1):
		if arr[j][i] == 0:
			dp[j][i] += t
		else:
			t = 1
ans = 0
for i in dp:
	ans += sum(i)
print(ans)