Language: C++

// ConsoleApplication1.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//

#include <bits/stdc++,h>
//実装が重そうな問題はある程度考えてから書く
//初期化を忘れずに（特に二分探索とか）
//コーナーケースを考えて（特に場合分けとか）
//不可解すぎるバグは配列外参照（配列の長さ）を検討

#define YES "YES"
#define NO "NO"
#define YESNO OUT(three(solve(),YES,NO))
#define ECHO OUT(solve())
#define three(A,B,C) ((A)?(B):(C))
#define FOR(i,a,b)  for(LL i=(a);i< (LL)(b);i++)
#define EFOR(i,a,b) for(LL i=(a);i<=(LL)(b);i++)
#define RFOR(i,a,b) for(LL i=(a);i>=(LL)(b);i--)
#define REP(i,b) FOR(i,zero,b)
#define EREP(i,b) EFOR(i,zero,b)
#define RREP(i,b) RFOR(i,b,zero)
#define ALL(c) c.begin(),c.end()
#define UNIQUE(c) sort(ALL(c));c.erase(unique(ALL(c)),c.end())
#define MAX(c) (*max_element(ALL(c)))
#define MIN(c) (*min_element(ALL(c)))
#define MP make_pair
#define FI first
#define SE second
#define SI(x) (LL(x.size()))
#define PB push_back
#define DEBUG(a) OUT(a)
#define DEBUG2(a,b) OUT2(a,b)
#define cat cout << __LINE__ << endl
#define OUT(a) cout << (a) << endl
#define OUT2(a,b) cout << (a) <<" "<<(b) << endl
#define int LL
#define zero 0LL

using namespace std;
template<typename T> inline void maximize(T &a, T b) { a = max(a, b); }
template<typename T> inline void minimize(T &a, T b) { a = min(a, b); }
template<typename T> inline bool middle(T a, T b, T c) { return b <= a && a <= c; }
template<class T> inline bool MX(T &l, const T &r) { return l<r ? l = r, 1 : 0; }
template<class T> inline bool MN(T &l, const T &r) { return l>r ? l = r, 1 : 0; }
typedef long long LL;
typedef double ld;
typedef LL ut;
typedef vector<ut> VI;
typedef vector<VI> VII;
typedef pair<ut, ut> pr;
typedef pair<ut, pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef priority_queue<pr, Vpr, greater<pr> > PQ;
inline void outputVI(VI x) { REP(i, SI(x)) { cout << three(i, " ", "") << x[i]; }OUT(""); }
const int SIZE1 = 5 * 1e5 + 1000;
const int SIZE2 = 5010;
const int SIZE3 = 600;
const int SIZE = SIZE3;
const LL p = 7 + 1e9;
const LL INF = 1LL << 60;
const long double EPS = 1e-7;
string s;
ut N, M, K, X, L, Y;
// ut A,B,C,D,E,F,G,H,I,J,O,P,Q,R,T,U;
VI edges[SIZE];
LL vals[SIZE], nums[SIZE], maps[SIZE2][SIZE2], answer = zero;

////////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////////////
void init() {

}
LL ans = 0;
LL sum = 0;
bool reached[SIZE][SIZE];
int A[SIZE][SIZE];
LL dfs(int y,int x) {
	if (y > N or x > N) return 0;
	if (A[y][x] == 0) return 0;
	if (reached[y][x]) {
		return 0;
	}
	reached[y][x]=true;
	return dfs(y, x + 1) + dfs(y + 1, x) + A[y][x];
}
LL dfs2(int y, int x) {
	if (y > N or x > N) return 0;
//	cout << y << " " << x << endl;
	if (A[y][x] == 0) return 0;
	if (reached[y][x] == 0) return 0;
	if (reached[y - 1][x]) return 0;
	//cout << y << " " << x << endl;
	reached[y][x] = 0;
	LL ret = 0;
	ret += dfs2(y, x + 1);
	ret += dfs2(y + 1, x);

	return ret + A[y][x];
}
LL solve2(int x) {
	REP(i, SIZE) REP(j, SIZE) reached[i][j] = 0;
	sum = 0;
	EFOR(i,1, N) {
		sum+=dfs(x, i);
		ans +=( sum - A[x][i] )* A[x][i];
		//cout << ans << endl;
		reached[x][i] = false;
		sum-=dfs2(x+1, i)+A[x][i];
	}
	return ans;
}
LL solve() {
	cin >> N;
	EFOR(i,1,N){
		cin >> s;
		EFOR(j, 1, N) {
			if (s[j - 1] == '#')A[i][j] = 0;
			else A[i][j] = s[j - 1]-'0';
		}
	}
	EFOR(i, 1, N) solve2(i);
	return ans;
}
signed main() {

	cout << solve() << endl;
//	cin >> N;
	return 0;
}

Compiler output:
a.cc:4:10: fatal error: bits/stdc++,h: No such file or directory
    4 | #include <bits/stdc++,h>
      |          ^~~~~~~~~~~~~~~
compilation terminated.