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.

Difficulty: interview

Starter code:

Solutions:
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)

def f():
    n, m = list(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()


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)

n, m = list(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
        #print(res)
    d.append(s)
#print(d)
    
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(ss, res)
    
print(res)
    


# !!!!!!
from sys import stdin as fin
# fin = open("t2b.in")

# n = int(fin.readline())
n, m = map(int, fin.readline().split())
# line = fin.readline().strip()
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]
    # print(' '.join(str(n) for n in lines[i]))
# print()

for j in range(m):
    for i in range(1, n):
        cols[j][i] += cols[j][i - 1]
    # print(' '.join(str(n) for n in cols[j]))
# print()

cnt = 0
for i in range(n):
    for j in range(m):
        if mtrx[i][j] == 0:
            # print((i, j), lines[i][j], lines[i][m - 1] - lines[i][j], cols[j][i], cols[j][n - 1] - cols[j][i])
            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 = 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())
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)

#!/usr/bin/env python3

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()


# coding: utf-8

# In[134]:

n,m = list(map(int, input().split()))


# In[135]:

plan = []
for i in range(n):
    plan.append(input().split())


# In[136]:

plan2 = list(map(list,list(zip(*plan))))


# In[137]:

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


# In[138]:

def findRight(string):
    i = len(string)-1
    while i>=0:
        if string[i] == '1':
            return i
        else:
            i -= 1


# In[139]:

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')


# In[140]:

print(count)



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)

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)))
#print(a)
#print(t_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
        #print(l, r, ((m - c - (l + (m - r - 1)))))
        ans += l + (m - r - 1) + ((m - c - (l + (m - r - 1))) * 2)
    elif (c == 1):
        ans += m - 1
    #print(ans)
    
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)
print(ans)

def count_place(a, n, m):
    place = 0
    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
            #print(l, r, ((m - c - (l + (m - r - 1)))))
            place += l + (m - r - 1) + ((m - c - (l + (m - r - 1))) * 2)
        elif (c == 1):
            place += m - 1  
    return place

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)))
ans = count_place(a, n, m) + count_place(t_a, m, n)
print(ans)

n,m=list(map(int,input().split()))

jadval=[]
for i in range(n):
    jadval.append(list(input().replace(" ", "")))
s=0
#raste
for i in range(n):
    f=0
    for j in range(m):
        if jadval[i][j]=='1':
            f=1
        elif f==1:
            s+=1
#chape
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
#paeene
for j in range(m):
    f=0
    for i in range(n):
        if jadval[i][j]=='1':
            f=1
        elif f==1:
            s+=1
#balae
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)


def f(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(f(s) for s in a)
c = sum(f(''.join(a[i][j] for i in range(n))) for j in range(m))
print(r + c)

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
    #print(ans)
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,lst,fst,nu)
print(ans)

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)














"""
B. Прожекторы
ограничение по времени на тест
1 секунда
ограничение по памяти на тест
256 мегабайт
ввод
стандартный ввод
вывод
стандартный вывод

Театральная сцена представляет собой прямоугольное поле размером n × m. Директор театра выдал вам план сцены, согласно
которому на ней будут располагаться актёры. На плане отмечено в каких клетках будут стоять актёры, а в каких нет.

Прожектор, установленный на сцену, будет светить в одном из четырёх направлений (если смотреть на план сцены сверху) —
влево, вверх, вправо или вниз. Таким образом, под позицией прожектора понимается клетка,
в которую он установлен, а также направление, в котором он светит.

Перед вами стоит задача поставить на сцену прожектор в хорошую позицию.
Позиция называется хорошей, если одновременно выполняются два условия:

    в соответствующей ей клетке нет актёра;
    в направлении, в котором светит прожектор, находится хотя бы один актёр.

Перед вами стоит задача посчитать количество хороших позиций для установки прожектора.
Две позиции установки прожектора считаются различными, если отличаются клетки расположения прожектора,
или направление, в котором он светит.
Входные данные

В первой строке следует два целых положительных числа n и m (1 ≤ n, m ≤ 1000) —
количество строк и количество столбцов в плане.

В следующих n строках следует по m целых чисел, каждое равно либо 0, либо 1, —
описание плана. Если очередное число равно 1, то в соответствующей клетке находится актёр,
а если 0, то клетка останется пустой. Гарантируется, что в плане есть хотя бы один актёр.
Выходные данные

Выведите единственное целое число — количество хороших позиций для установки прожектора.
Примеры
Входные данные

2 4
0 1 0 0
1 0 1 0

Выходные данные

9

Входные данные

4 4
0 0 0 0
1 0 0 1
0 1 1 0
0 1 0 0

Выходные данные

20

Примечание

В первом примере хорошими позициями для установки прожектора являются:

    клетка (1, 1) и направление вправо;
    клетка (1, 1) и направление вниз;
    клетка (1, 3) и направление влево;
    клетка (1, 3) и направление вниз;
    клетка (1, 4) и направление влево;
    клетка (2, 2) и направление влево;
    клетка (2, 2) и направление вверх;
    клетка (2, 2) и направление вправо;
    клетка (2, 4) и направление влево.

Таким образом, в данном примере всего 9 хороших позиций.
"""
import random
# import time


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 += start + ((count_cols - 1) - end) + ((end - 1) - start - (result_hor - 1)) * 2
                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 += start + ((count_rows - 1) - end) + ((end - 1) - start - (result_vert - 1)) * 2
                result += count_rows - start + end - 1 - result_vert * 2
            else:
                result += start + ((count_rows - 1) - end)
    return result


input_array = []
# file = open('./input.txt')
# temp_array_string = file.readline().split()
temp_array_string = input().split()
count_rows = int(temp_array_string[0])  # i == n
count_cols = int(temp_array_string[1])  # j == m
for row in range(count_rows):
    # temp_array_string = [int(cell) for cell in file.readline().split()]
    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('Generation array.')
# input_array = []
# count_rows = 1000
# count_cols = 1
# for i in range(count_rows):
#     input_array.append([])
#     for j in range(count_cols):
#         input_array[i].append(random.randint(0, 0))
# input_array[999][0] = 1
# print('Array is Generated.')
# start_time = time.time()
# print(count_best_positions())
# end_time = time.time()
# print('Time = %s ms' % ((end_time - start_time) * 1000))
# file.close()

print()


def f(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(f(s) for s in a)
c = sum(f(''.join(a[i][j] for i in range(n))) for j in range(m))
print(r + c)

n, m = list(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)))
        


n, m = list(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)


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


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


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())
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)

def f(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 = list(map(int, input().split()))

a = [''.join(input().split()) for i in range(n)]

r = sum(f(s) for s in a)

c = sum(f(''.join(a[i][j] for i in range(n))) for j in range(m))

print(r + c)



# Made By Mostafa_Khaled