#include <bits/stdc++.h>
using namespace std;
int n;
char s[2002];
bool mp[8001][8001], mp1[8001][8001];
long long ans;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%s", s + 1);
    for (int j = 1; j <= n / 4; ++j) {
      int cur = s[j] >= '0' && s[j] <= '9' ? s[j] - '0' : s[j] - 'A' + 10;
      for (int k = 0; k < 4; ++k)
        mp1[i][j * 4 - k] = mp[i][j * 4 - k] = cur >> k & 1;
    }
  }
  ans = (614ll * n + 1) * n * (n - 1) / 2;
  for (int i = 1; i <= n; ++i) {
    int ed = 0, p = 0;
    for (int j = 1; j <= n; ++j)
      if (mp[i][j] && (!ed || mp[ed][j])) ed = j;
    for (int j = 1; j <= n; ++j)
      if (!mp[i][j] && mp[ed][j]) {
        ans -= 614 * n - 2;
        mp1[i][j] = 1;
        if (!p || mp[j][p]) p = j;
      }
    for (int j = 1; j <= n; ++j)
      if (!mp1[i][j] && i != j && mp[p][j]) ans -= 614 * n - 3;
  }
  printf("%lld", ans);
  return 0;
}
