#include using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); string line; vector>> m; while (getline(cin, line) && !line.empty()) { istringstream l(line); char c; vector> mm; while (l >> c) { mm.push_back({c - '0', c == '9' ? 1 : 0}); } m.push_back(mm); } int xm = m.size(), ym = m[0].size(); for (int i = 9; i > 0; i--) { for (int x = 0; x < xm; x++) { for (int y = 0; y < ym; y++) { auto &[n, c] = m[x][y]; if (n != i) { continue; } vector> xxyy = { {x - 1, y}, {x + 1, y}, {x, y - 1}, {x, y + 1}}; for (auto &[xx, yy] : xxyy) { if (xx < 0 || yy < 0 || xx >= xm || yy >= ym) { continue; } auto &[nn, cc] = m[xx][yy]; if (nn == n - 1) { cc += c; } } } } } int sum = 0; for (auto &mm : m) { for (auto &[n, c] : mm) { if (n == 0) { sum += c; } } } cout << sum << '\n'; }