#include <cstdint>

namespace n91 {

constexpr std::uint_fast64_t totient(std::uint_fast64_t x) noexcept {
  using u64 = std::uint_fast64_t;
  u64 ret = x;
  for (u64 i = static_cast<u64>(2); i * i <= x; ++i) {
    if (x % i == static_cast<u64>(0)) {
      ret -= ret / i;
      x /= i;
      while (x % i == static_cast<u64>(0)) {
        x /= i;
      }
    }
  }
  if (x != static_cast<u64>(1)) {
    ret -= ret / x;
  }
  return ret;
}

template <std::uint_fast64_t Modulus,
          std::uint_fast64_t InverseExp =
              totient(Modulus) - static_cast<std::uint_fast64_t>(1)>
class modint {
  using u64 = std::uint_fast64_t;

  static_assert(Modulus < static_cast<u64>(1) << static_cast<u64>(32),
                "Modulus must be less than 2**32");

  u64 a;

  constexpr modint &negate() noexcept {
    if (a != static_cast<u64>(0)) {
      a = Modulus - a;
    }
    return *this;
  }

public:
  constexpr modint(const u64 x = static_cast<u64>(0)) noexcept
      : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+() const noexcept { return modint(*this); }
  constexpr modint operator-() const noexcept { return modint(*this).negate(); }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = InverseExp;
    while (exp) {
      if (exp % static_cast<u64>(2) != static_cast<u64>(0)) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= static_cast<u64>(2);
    }
    return *this;
  }
  constexpr bool operator==(const modint rhs) const noexcept {
    return a == rhs.a;
  }
  constexpr bool operator!=(const modint rhs) const noexcept {
    return a != rhs.a;
  }
};

template <class T, std::uint_fast64_t v> class modint_constant {
public:
  static constexpr T value = static_cast<T>(v);

  using value_type = T;
};
template <class T, std::uint_fast64_t v>
constexpr T modint_constant<T, v>::value;

} // namespace n91

#include <cstddef>
#include <vector>

template <class T, class BaseX, class BaseY> class rolling_hash_2d {
  std::vector<std::vector<T>> prefix;
  std::vector<T> power_x, power_y;

public:
  rolling_hash_2d(const std::vector<std::vector<T>> &table)
      : prefix(), power_x(), power_y() {
    const std::size_t h = table.size();
    const std::size_t w = table.empty() ? 0 : table.front().size();
    prefix.resize(h + 1, std::vector<T>(w + 1, 0));
    for (std::size_t i = 0; i != h; ++i) {
      for (std::size_t j = 0; j != w; ++j) {
        prefix[i + 1][j + 1] = -prefix[i][j] * BaseX::value * BaseY::value +
                               prefix[i][j + 1] * BaseX::value +
                               prefix[i + 1][j] * BaseY::value + table[i][j];
      }
    }
    power_x.resize(h + 1);
    power_x[0] = 1;
    for (std::size_t i = 0; i != h; ++i) {
      power_x[i + 1] = power_x[i] * BaseX::value;
    }
    power_y.resize(w + 1);
    power_y[0] = 1;
    for (std::size_t i = 0; i != w; ++i) {
      power_y[i + 1] = power_y[i] * BaseY::value;
    }
  }
  T operator()(const std::size_t l, const std::size_t d, const std::size_t r,
               const std::size_t u) const {
    return prefix[l][d] * power_x[r - l] * power_y[u - d] -
           prefix[l][u] * power_x[r - l] - prefix[r][d] * power_y[u - d] +
           prefix[r][u];
  }
};

#include <iostream>

int main() {
  using mint = n91::modint<4294967291>;
  int n;
  std::cin >> n;
  std::vector<std::vector<mint>> s(n * 2, std::vector<mint>(n * 2)), t = s;
  for (int i = 0; i != n; ++i) {
    char c;
    for (int j = 0; j != n; ++j) {
      std::cin >> c;
      const mint v = c - 'a';
      s[i][j] = v;
      s[i][n + j] = v;
      s[n + i][j] = v;
      s[n + i][n + j] = v;
      t[j][i] = v;
      t[j][n + i] = v;
      t[n + j][i] = v;
      t[n + j][n + i] = v;
    }
  }

  using BaseX = n91::modint_constant<mint, 2220012137>;
  using BaseY = n91::modint_constant<mint, 3036013432>;

  const rolling_hash_2d<mint, BaseX, BaseY> sh(s), th(t);

  int ans = 0;

  for (int i = 0; i != n; ++i) {
    for (int j = 0; j != n; ++j) {
      if (sh(i, j, n + i, n + j) == th(j, i, n + j, n + i)) {
        ++ans;
      }
    }
  }

  std::cout << ans << std::endl;
}

Measured memory_bytes: 11648