#include #include using namespace std; #define DEB(x) cout << #x << " = " << x << endl; int p[1001][1001]; bool fK(int x1, int y1, int x2, int y2) { return (abs(x1 - x2) < 2 && abs(y1 - y2) < 2); } bool fN(int x1, int y1, int x2, int y2) { return (abs(x1 - x2) * abs(y1 - y2) == 2); } bool fB(int x1, int y1, int x2, int y2) { return (abs(x1 - x2) == abs(y1 - y2)); } bool fR(int x1, int y1, int x2, int y2) { return (abs(x1 - x2) * abs(y1 - y2) == 0); } bool (*fch)(int, int, int, int) = NULL; bool check(int ti, int tj) { for (int i = 0; i <= ti; i++) { for (int j = 0; j < tj; j++) { if (p[i][j] == p[ti][tj] && fch(i, j, ti, tj)) { return false; } } } return true; } int main(void) { int n; char c; while (scanf("%d %c", &n, &c) == 2) { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { p[i][j] = 0; } } switch (c) { case 'R': fch = fR; break; case 'K': fch = fK; break; case 'B': fch = fB; break; case 'N': fch = fN; break; } if (c == 'R') { printf("%d\n", n); continue; } else if (c == 'B') { printf("%d\n", n); continue; } else if (c == 'K') { int r; if (n % 2 == 1) { n++; } printf("%d\n", (n * n) / 4); continue; } int teams = 0; bool ok = false; while (!ok) { teams++; ok = true; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (p[i][j] == 0) { p[i][j] = teams; if (!check(i, j)) { p[i][j] = 0; /*if (c == 'R') { } else if (c == 'B') { } else if (c == 'N') { } else if (c == 'K') { }*/ ok = false; } } } } } printf("%d\n", teams); } return 0; }