1. Abridged Problem Statement
Given an n×m grid of nonnegative integers h[i][j], where each cell represents a stack of h[i][j] unit cubes, compute the total surface area of the 3D structure. You must count top and bottom faces of every nonempty column, plus all exposed side faces (any difference in heights between adjacent cells, treating out-of-bounds as height 0).

2. Detailed Editorial

Overview
We need the total area of all outer faces: top, bottom, and sides. Each cell (i,j) with height H=h[i][j] contributes:
  - 2 for its top and bottom faces (if H > 0).
  - For each of the four directions (up, down, left, right), the exposed side area is max(0, H − neighbor_height).

Steps
1. Read n, m and the grid h[][] of heights.
2. Initialize answer = 0.
3. Iterate over all cells (i=0…n−1, j=0…m−1):
   a. Let H = h[i][j]. If H=0, skip (no cubes, no faces).
   b. Add 2 for the top and bottom faces.
   c. For each neighbor offset (dx,dy) in {(-1,0),(1,0),(0,-1),(0,1)}:
      i. Compute neighbor coordinates (ni=i+dx, nj=j+dy).
      ii. If (ni,nj) is inside the grid, let Hn = h[ni][nj]; otherwise Hn = 0.
      iii. If H > Hn, add (H − Hn) to answer (the exposed vertical wall).
4. Output answer.

Correctness
By summing top+bottom for each nonempty column and summing all positive height differences side-by-side, we exactly count every unit square of surface that is exposed to air. Shared walls between two columns of equal height contribute zero since neither side is exposed.

Complexity
We process each cell in O(1) time (constant 4 neighbors), so total time is O(n·m), which is efficient for n,m up to 100.

3. C++ Solution

```cpp
#include <bits/stdc++.h>

using namespace std;

template<typename T1, typename T2>
ostream& operator<<(ostream& out, const pair<T1, T2>& x) {
    return out << x.first << ' ' << x.second;
}

template<typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& x) {
    return in >> x.first >> x.second;
}

template<typename T>
istream& operator>>(istream& in, vector<T>& a) {
    for(auto& x: a) {
        in >> x;
    }
    return in;
};

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& a) {
    for(auto x: a) {
        out << x << ' ';
    }
    return out;
};

int n, m;
vector<string> s;

void read() {
    cin >> n >> m;
    s.resize(n);
    cin >> s;
}

void solve() {
    // Surface area of a heightfield of unit cubes. Each non-empty cell
    // contributes 2 for its top and bottom facets. For each of the four
    // horizontal neighbours, the exposed side wall equals max(0, height -
    // neighbour_height); cells outside the grid count as height 0, which
    // exposes the full outer wall. Summing this over every cell gives the
    // total paintable area.

    int ans = 0;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            if(s[i][j] == '0') {
                continue;
            }

            ans += 2;
            int curr = s[i][j] - '0';
            for(auto [dx, dy]:
                vector<pair<int, int>>{{-1, 0}, {0, -1}, {1, 0}, {0, 1}}) {
                int x = i + dx;
                int y = j + dy;

                int other = 0;
                if(x < n && y < m && x >= 0 && y >= 0) {
                    other = s[x][y] - '0';
                }

                ans += max(0, curr - other);
            }
        }
    }

    cout << ans << '\n';
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int T = 1;
    // cin >> T;
    for(int test = 1; test <= T; test++) {
        read();
        // cout << "Case #" << test << ": ";
        solve();
    }

    return 0;
}
```

4. Python Solution

```python
import sys

def main():
    data = sys.stdin.read().split()
    # First two tokens: n and m
    n, m = map(int, data[:2])
    # Next n tokens: each is a string of m digits
    grid = data[2:]

    total = 0

    # Direction offsets: up, down, left, right
    dirs = [(-1,0), (1,0), (0,-1), (0,1)]

    # Loop through every cell
    for i in range(n):
        row = grid[i]
        for j in range(m):
            h = int(row[j])
            if h == 0:
                # no cubes, skip
                continue
            # top and bottom faces add 2
            total += 2
            # check four sides
            for dx, dy in dirs:
                ni, nj = i + dx, j + dy
                # neighbor height or 0 if out of bounds
                hn = int(grid[ni][nj]) if 0 <= ni < n and 0 <= nj < m else 0
                # exposed side = positive difference
                if h > hn:
                    total += (h - hn)
    # print the result
    print(total)

if __name__ == "__main__":
    main()
```

5. Compressed Editorial
- Each nonzero cell contributes 2 for top+bottom.
- For each of 4 neighbors, add max(0, h[i][j] − h[neighbor]).
- Treat out-of-bounds neighbor height as 0.
- Sum over all cells in O(n·m).
