Problem p03364 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <locale>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <vector>
using namespace std;
#define MS0(I) memset(I, 0, sizeof(I));
#define MS1(I) memset(I, -1, sizeof(I));
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, s, n) for (int i = (s); i < (n); ++i)
#define per1(i, a, b) for (int i = a; i >= b; --i)
#define DRI(A)                                                                 \
  int A;                                                                       \
  scanf("%d", &A);
#define DRII(A, B)                                                             \
  int A, B;                                                                    \
  scanf("%d %d", &A, &B);
#define DRIII(A, B, C)                                                         \
  int A, B, C;                                                                 \
  scanf("%d %d %d", &A, &B, &C);
#define MP make_pair
#define pb push_back
#define F first
#define S second
#define ALL(I) (I).begin(), (I).end()
typedef const void CV;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
const int INF = (int)1e9;
const int mod = (int)1e9 + 7;
const int MAX = (int)1e2 + 5;
char store[MAX][MAX];
int main(void) {
  DRI(n);
  rep(i, n) scanf("%s", store[i]);
  LL ans = 0;
  rep(i, n) {
    bool flag = 1;
    rep(j, n) {
      if (!flag)
        break;
      rep(k, n) {
        if (store[j][k] != store[(k + n - i) % n][(i + j) % n]) {
          flag = 0;
          break;
        }
      }
    }
    if (flag)
      ans++;
  }

  printf("%lld", ans * n);
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <locale>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <vector>
using namespace std;
#define MS0(I) memset(I, 0, sizeof(I));
#define MS1(I) memset(I, -1, sizeof(I));
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, s, n) for (int i = (s); i < (n); ++i)
#define per1(i, a, b) for (int i = a; i >= b; --i)
#define DRI(A)                                                                 \
  int A;                                                                       \
  scanf("%d", &A);
#define DRII(A, B)                                                             \
  int A, B;                                                                    \
  scanf("%d %d", &A, &B);
#define DRIII(A, B, C)                                                         \
  int A, B, C;                                                                 \
  scanf("%d %d %d", &A, &B, &C);
#define MP make_pair
#define pb push_back
#define F first
#define S second
#define ALL(I) (I).begin(), (I).end()
typedef const void CV;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
const int INF = (int)1e9;
const int mod = (int)1e9 + 7;
const int MAX = (int)3e2 + 5;
char store[MAX][MAX];
int main(void) {
  DRI(n);
  rep(i, n) scanf("%s", store[i]);
  LL ans = 0;
  rep(i, n) {
    bool flag = 1;
    rep(j, n) {
      if (!flag)
        break;
      rep(k, n) {
        if (store[j][k] != store[(k + n - i) % n][(i + j) % n]) {
          flag = 0;
          break;
        }
      }
    }
    if (flag)
      ans++;
  }

  printf("%lld", ans * n);
  return 0;
}