#include<bits/stdc++.h>
using namespace std;

#define int long long
#define uint unsigned long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint=vector<int>;
using vvint=vector<vint>;
using pint=pair<int, int>;
using vpint=vector<pint>;
template<typename T> using priority_queue_rev=priority_queue<T, vector<T>, greater<T>>;
constexpr double pi = 3.1415926535897932384626433832795028;
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T1, typename T2> bool chmax(T1 &a, const T2 &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> bool chmin(T1 &a, const T2 &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct Setup {
    static constexpr int PREC = 20;
    Setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

struct RollingHash2D {
    using ull=unsigned long long;
    static constexpr ull MASK30 = (1ULL << 30) - 1;
    static constexpr ull MASK31 = (1ULL << 31) - 1;
    static constexpr ull MOD = (1ULL << 61) - 1;
    static constexpr ull POSITIVIZER = MOD << 2;
    static std::vector<std::pair<ull, ull>> powBaseY, powBaseX;
    int h, w;
    std::vector<std::vector<std::pair<ull, ull>>> hash;
    static ull rng() {
        std::random_device rd;
        return std::uniform_int_distribution<ull>(MOD >> 1, MOD - 1)(rd);
    }
    static ull mul(ull a, ull b) {
        ull au = a >> 31;
        ull ad = a & MASK31;
        ull bu = b >> 31;
        ull bd = b & MASK31;
        ull mid = ad * bu + au * bd;
        return (au * bu << 1) + (mid >> 30) + ((mid & MASK30) << 31) + ad * bd;
    }
    static ull calcMod(ull val) {
        val = (val & MOD) + (val >> 61);
        if (val >= MOD) { val -= MOD; }
        return val;
    }
    static std::pair<ull, ull> connectY(const std::pair<ull, ull> &uhs, const std::pair<ull, ull> &dhs, int dh) {
        return {calcMod(mul(uhs.first, powBaseY[dh].first) + dhs.first),
                calcMod(mul(uhs.second, powBaseY[dh].second) + dhs.second)};
    }
    static std::pair<ull, ull> connectX(const std::pair<ull, ull> &lhs, const std::pair<ull, ull> &rhs, int rw) {
        return {calcMod(mul(lhs.first, powBaseX[rw].first) + rhs.first),
                calcMod(mul(lhs.second, powBaseX[rw].second) + rhs.second)};
    }
    template<typename Itr> RollingHash2D(Itr begin, Itr end): h(end - begin), w(begin->end() - begin->begin()) {
        hash.push_back(std::vector<std::pair<ull, ull>>(w + 1));
        for (auto itrY = begin; itrY != end; itrY++) {
            hash.push_back(std::vector<std::pair<ull, ull>>(1));
            for (auto itrX = itrY->begin(); itrX != itrY->end(); itrX++) {
                hash.back().push_back({calcMod((mul(hash.back().back().first, powBaseX[1].first) + *itrX)),
                                       calcMod((mul(hash.back().back().second, powBaseX[1].second) + *itrX))});
            }
        }
        for (int i = 0; i < h; i++) {
            for (int j = 1; j <= w; j++) {
                hash[i + 1][j] = {calcMod((mul(hash[i][j].first, powBaseY[1].first) + hash[i + 1][j].first)),
                                  calcMod((mul(hash[i][j].second, powBaseY[1].second) + hash[i + 1][j].second))};
            }
        }
        while (powBaseY.size() <= h) {
            powBaseY.push_back({calcMod(mul(powBaseY.back().first, powBaseY[1].first)),
                                calcMod(mul(powBaseY.back().second, powBaseY[1].second))});
        }
        while (powBaseX.size() <= w) {
            powBaseX.push_back({calcMod(mul(powBaseX.back().first, powBaseX[1].first)),
                                calcMod(mul(powBaseX.back().second, powBaseX[1].second))});
        }
    }
    std::pair<ull, ull> get(int y1, int x1, int y2, int x2) const {
        std::pair<ull, ull> hl
            = {calcMod(POSITIVIZER - mul(hash[y1][x1].first, powBaseY[y2 - y1].first) + hash[y2][x1].first),
               calcMod(POSITIVIZER - mul(hash[y1][x1].second, powBaseY[y2 - y1].second) + hash[y2][x1].second)};
        std::pair<ull, ull> hr
            = {calcMod(POSITIVIZER - mul(hash[y1][x2].first, powBaseY[y2 - y1].first) + hash[y2][x2].first),
               calcMod(POSITIVIZER - mul(hash[y1][x2].second, powBaseY[y2 - y1].second) + hash[y2][x2].second)};
        return {calcMod(POSITIVIZER - mul(hl.first, powBaseX[x2 - x1].first) + hr.first),
                calcMod(POSITIVIZER - mul(hl.second, powBaseX[x2 - x1].second) + hr.second)};
    }
};
std::vector<std::pair<RollingHash2D::ull, RollingHash2D::ull>> RollingHash2D::powBaseY{{1, 1}, {rng(), rng()}};
std::vector<std::pair<RollingHash2D::ull, RollingHash2D::ull>> RollingHash2D::powBaseX{{1, 1}, {rng(), rng()}};

int N;
string S[330], T[330];
signed main() {
    cin >> N;
    rep(i, N) { cin >> S[i]; }
    rep(i, N) {
        rep(j, N) {
            T[i] += S[j][i];
        }
    }
    using RH=RollingHash2D;
    RH Sh(S, S + N), Th(T, T + N);
    int ans = 0;
    rep(i, N) {
        rep(j, N) {
            auto S_ = RH::connectX(RH::connectY(Sh.get(i, j, N, N), Sh.get(0, j, i, N), i),
                                   RH::connectY(Sh.get(i, 0, N, j), Sh.get(0, 0, i, j), i), j);
            auto T_ = RH::connectX(RH::connectY(Th.get(j, i, N, N), Th.get(0, i, j, N), j),
                                   RH::connectY(Th.get(j, 0, N, i), Th.get(0, 0, j, i), j), i);
            if (S_ == T_) { ans++; }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 5504