#include #include using namespace std; int toutatsu[15][15]; bool adj_zero; int N; int sum(const vector >& table, int n, int x, int y); int kotae(const vector >& table, int n) { int ret = 0; memset(toutatsu, 0, sizeof(toutatsu)); for (int i = 0; i < table.size(); i++) { for (int j = 0; j < table[i].size(); j++) { adj_zero = false; int tmp = sum(table, table[i][j], i, j); if (adj_zero) { continue; } if (n == table[i][j]) { ret -= tmp; } else if (table[i][j] == 0) { continue; } else { ret += tmp; } } } return ret; } int sum(const vector >& table, int n, int x, int y) { if (x < 0 || x >= table.size()) { return 0; } if (y < 0 || y >= table.size()) { return 0; } if (x < y) { return 0; } if (table[x][y] == 0) { adj_zero = true; } else if (table[x][y] == n) { if (toutatsu[x][y] == -1) { return 0; } toutatsu[x][y] = -1; return (sum(table, n, x - 1, y - 1) + sum(table, n, x - 1, y) + sum(table, n, x, y - 1) + sum(table, n, x, y + 1) + sum(table, n, x + 1, y) + sum(table, n, x + 1, y + 1) + 1); } else { return 0; } } int main() { int C; while (cin >> N >> C) { if (N == 0 && C == 0) { break; } vector > table; for (int i = 1; i <= N; i++) { vector tmp; for (int j = 0; j < i; j++) { int a; cin >> a; tmp.push_back(a); } table.push_back(tmp); } int ans = -9999; for (int i = 0; i < table.size(); i++) { for (int j = 0; j < table[i].size(); j++) { if (table[i][j] == 0) { table[i][j] = C; ans = max(ans, kotae(table, C)); table[i][j] = 0; } } } if (ans == -9999) { ans = 0; } cout << ans << endl; } return 0; }