#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::cerr;
using std::endl;

namespace chrono = std::chrono;
using namespace std::literals;

[[gnu::constructor]]
void fast_iostream() {
    std::ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cerr.tie(nullptr);
}
template <typename T, T Mod>
class zmod {
public:
    using number = T;
    static constexpr number mod = Mod;

    class valid_tag_t {};
    static valid_tag_t valid_tag;

    zmod() : m_value(0) {}

    zmod(number n) 
        : m_value(n)
    {
        normalize();
    }

    zmod(number n, valid_tag_t)
        : m_value(n)
    {}

    static zmod valid(number n) {
        return zmod(n, valid_tag);
    }

    zmod operator-() const noexcept {
        number value = mod - m_value;
        if (value == mod) {
            value = 0;
        }
        return zmod{value, valid_tag};
    }

    zmod inverse() const noexcept {
        return zmod{powmod(m_value, mod - 2), valid_tag};
    }

    zmod& operator+=(zmod other) noexcept {
        m_value += other.m_value;
        if (m_value >= mod){
            m_value -= mod;
        }
        return *this;
    }

    zmod& operator-=(zmod other) noexcept {
        return *this += -other;
    }

    zmod& operator *= (zmod other) noexcept {
        m_value = (m_value * other.m_value) % mod;
        return *this;
    }

    zmod& operator /= (zmod other) noexcept {
        return *this *= other.inverse();
    }

    number value() const noexcept {
        return m_value;
    }

    friend std::istream& operator>>(std::istream& is, zmod<T, mod>& u) {
        is >> u.m_value;
        u.normalize();
        return is;
    }

private:
    inline void normalize() {
        m_value %= mod;
        if (m_value < 0) {
            m_value += mod;
        }
    }

    static number powmod(number a, number x) {
        number result = 1;
        while (x > 0) {
            if (x % 2 == 1) {
                result = (result * a) % mod;
                x -= 1;
            } else {
                a = (a * a) % mod;
                x /= 2;
            }
        }
        return result;
    }

private:
    number m_value;
};

#define DEFINE_ZMOD_OPERATORS(OP, EQ_OP)                        \
    template <typename T, T mod, typename U>                    \
    zmod<T, mod> operator OP (U u, zmod<T, mod> v) {            \
        return zmod<T, mod>(u) EQ_OP v;                         \
    }                                                           \
    template <typename T, T mod, typename U>                    \
    zmod<T, mod> operator OP (zmod<T, mod> u, U v) {            \
        return u EQ_OP v;                                       \
    }                                                           \
    template <typename T, T mod>                                \
    zmod<T, mod> operator OP (zmod<T, mod> u, zmod<T, mod> v) { \
        return u EQ_OP v;                                       \
    }                                                           \

DEFINE_ZMOD_OPERATORS(+, +=)
DEFINE_ZMOD_OPERATORS(-, -=)
DEFINE_ZMOD_OPERATORS(*, *=)
DEFINE_ZMOD_OPERATORS(/, /=)

#undef DEFINE_ZMOD_OPERATORS

#define DEFINE_ZMOD_VALUE_OPERATORS(RET_TYPE, OP)                   \
    template <typename T, T mod, typename U>                        \
    RET_TYPE operator OP (zmod<T, mod> u, U v) {                    \
        return u.value() OP zmod<T, mod>(v).value();                \
    }                                                               \
    template <typename T, T mod, typename U>                        \
    RET_TYPE operator OP (U u, zmod<T, mod> v) {                    \
        return zmod<T, mod>(v).value() OP v.value();                \
    }                                                               \
    template <typename T, T mod>                                    \
    RET_TYPE operator OP (zmod<T, mod> u, zmod<T, mod> v) {         \
        return u.value() OP v.value();                              \
    }                                                               \

DEFINE_ZMOD_VALUE_OPERATORS(bool, ==)
DEFINE_ZMOD_VALUE_OPERATORS(bool, !=)

#undef DEFINE_ZMOD_VALUE_OPERATORS

template <typename T, T mod>
std::ostream& operator<<(std::ostream& os, zmod<T, mod> u) {
    return os << u.value();
}

using lmod7 = zmod<long long, 1000 * 1000 * 1000 + 7>;
using lmod9 = zmod<long long, 1000 * 1000 * 1000 + 9>;

int main() {
  int n; cin >> n;
  std::vector<std::string> a(2 * n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    a[i] += a[i];
    a[i + n] = a[i];
  }

  std::vector<std::vector<lmod7>> h7(2 * n, std::vector<lmod7>(n));
  std::vector<std::vector<lmod9>> h9(2 * n, std::vector<lmod9>(n));

  std::vector<std::vector<lmod7>> h7v(n, std::vector<lmod7>(2 * n));
  std::vector<std::vector<lmod9>> h9v(n, std::vector<lmod9>(2 * n));

  lmod7 p7 = 1;
  lmod9 p9 = 1;
  for (int i = 0; i + 1 < n; ++i) {
    p7 *= 26;
    p9 *= 26;
  }

  for (int i = 0; i < 2 * n; ++i) {
    h7[i][0] = 0;
    h9[i][0] = 0;
    h7v[0][i] = 0;
    h9v[0][i] = 0;

    lmod7 cp7 = 1;
    lmod9 cp9 = 1;
    for (int j = 0; j < n; ++j) {
      h7[i][0] += cp7 * (a[i][j] - 'a');
      h9[i][0] += cp9 * (a[i][j] - 'a');

      h7v[0][i] += cp7 * (a[j][i] - 'a');
      h9v[0][i] += cp9 * (a[j][i] - 'a');

      cp7 *= 26;
      cp9 *= 26;
    }
    for (int j = 1; j < n; ++j) {
      h7[i][j] = (h7[i][j - 1] - (a[i][j - 1] - 'a')) / 26 + p7 * (a[i][j + n - 1] - 'a');
      h9[i][j] = (h9[i][j - 1] - (a[i][j - 1] - 'a')) / 26 + p9 * (a[i][j + n - 1] - 'a');

      h7v[j][i] = (h7v[j - 1][i] - (a[j - 1][i] - 'a')) / 26 + p7 * (a[j + n - 1][i] - 'a');
      h9v[j][i] = (h9v[j - 1][i] - (a[j - 1][i] - 'a')) / 26 + p9 * (a[j + n - 1][i] - 'a');
    }
  }

  int ans = 0;
  for (int x = 0; x < n; ++x) {
    for (int y = 0; y < n; ++y) {
      bool flag = true;
      for (int i = 0; i < n; ++i) {
        if (h7[x + i][y] != h7v[x][y + i] || h9[x + i][y] != h9v[x][y + i]) {
          flag = false;
          break;
        }
      }
      ans += flag;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 6400