#include #include #include #include using namespace std; struct Pos { int x, y; Pos(){} Pos(int xx, int yy) : x(xx), y(yy) {} bool operator <(const Pos& b) const { if(x != b.x) return x < b.x; return y < b.y; } }; int n, c; int data[12][12]; inline int& Data(const Pos& p) { return data[p.x][p.y]; } int adjx[] = {-1, 0, -1, 1, 0, 1}; int adjy[] = {-1, -1, 0, 0, 1, 1}; int Count() { set up; bool check[12][12]; memset(check, 0, sizeof(check)); for(int i = 0; i < 12; ++i) for(int j = 0; j < 12; ++j) if(data[i][j] == 0) up.insert(Pos(i, j)); while(!up.empty()) { Pos p = *up.begin(); up.erase(up.begin()); if(Data(p) < 0 || check[p.x][p.y]) continue; check[p.x][p.y] = true; for(int i = 0; i < 6; ++i) { Pos q(p.x + adjx[i], p.y + adjy[i]); if(Data(p) == 0 || Data(p) == Data(q)) up.insert(q); } } int cnt = 0; for(int i = 0; i < 12; ++i) for(int j = 0; j < 12; ++j) { if(!check[i][j]) { if(data[i][j] == c) --cnt; else if(data[i][j] > 0) ++cnt; } } //cout << cnt << endl; return cnt; } int main() { while(cin >> n >> c && n) { int init[12][12]; memset(init, -1, sizeof(init)); for(int i = 1; i <= n; ++i) for(int j = 1; j <= i; ++j) { cin >> init[i][j]; } int ans = -10000000; //cout << "--" << endl; for(int i = 1; i <= n; ++i) for(int j = 1; j <= i; ++j) if(init[i][j] == 0) { memcpy(data, init, sizeof(init)); data[i][j] = c; ans = max(ans, Count()); } if(ans == -10000000) ans = 0; cout << ans << endl; //cout << "--" << endl; } }