#include<bits/stdc++.h>

using namespace std;

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, ans = 2 * 1e9 + 1e5;
  cin >> n;
  vector<string> vs(n);
  for (int i = 0; i < n; i++)
    cin >> vs[i];
  vector<vector<int>> v(n, vector<int>(n)), dp(n, vector<int>(n));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++)
      cin >> v[i][j];
  }
  dp[n - 1][n - 1] = v[n - 1][n - 1];
  for (int i = n - 2; i >= 0; i--)
    dp[i][n - 1] = v[i][n - 1] + dp[i + 1][n - 1];
  for (int i = n - 2; i >= 0; i--)
    dp[n - 1][i] = v[n - 1][i] + dp[n - 1][i + 1];
  for (int i = n - 2; i >= 0; i--) {
    for (int j = n - 2; j >= 0; j--)
      dp[i][j] = v[i][j] + min(dp[i][j + 1], dp[i + 1][j]);
  }
  cout << dp[0][0];
  return 0;
}