#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, m, temp;     cin >> n >> m;     bool grid[n][m];     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> temp;         grid[i][j] = (bool)temp;       }     }     vector<vector<int>> dp(n, vector<int>(m));     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (grid[i][j]) {           int k = j - 1;           while (k >= 0) {             if (grid[i][k] == 1) break;             dp[i][k]++;             k--;           }           k = j + 1;           while (k < m) {             if (grid[i][k] == 1) break;             dp[i][k]++;             k++;           }           k = i - 1;           while (k >= 0) {             if (grid[k][j] == 1) break;             dp[k][j]++;             k--;           }           k = i + 1;           while (k < n) {             if (grid[k][j] == 1) break;             dp[k][j]++;             k++;           }         }       }     }     int answer = 0;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) answer += dp[i][j];     cout << answer << endl;     return;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     long long int T = 1;     while (T--) {       solve();     }     return 0;   }   