link
#include<bits/stdc++.h>
using namespace std;
int n,ans,flag;
int vis[1001][1001];
char a[1001][1001];
int xx[]={1,0,-1,0};
int yy[]={0,1,0,-1};
void dfs(int x,int y){
vis[x][y]=1;
if(a[x-1][y]=='#'&&a[x+1][y]=='#'&&a[x][y-1]=='#'&&a[x][y+1]=='#'){
flag=1;
//return;
}
for(int i=0;i<4;i++){
int dx=x+xx[i];
int dy=y+yy[i];
if(dx>=1&&dx<=n&&dy>=1&&dy<=n&&!vis[dx][dy]&&a[dx][dy]=='#'){
dfs(dx,dy);
}
}
}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
cin>>a[i][j];
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(a[i][j]=='#'&&!vis[i][j]){
flag=0;
dfs(i,j);
if(flag==0)ans++;
}
}
}
cout<<ans;
}
#include<bits/stdc++.h>
#define PII pair<int,int>
const int N=1e3+1;
using namespace std;
int n,cnt,flag,ans;
char a[N][N];
bool vis[N][N];
int xx[]={1,-1,0,0};
int yy[]={0,0,1,-1};
void bfs(int x,int y,int &sum,int &bound){
queue<PII>Q;
Q.push({x,y});
vis[x][y]=1;
flag=0;
while(!Q.empty()){
flag=0;
sum++;
for(int i=0;i<4;i++){
int dx=Q.front().first+xx[i];
int dy=Q.front().second+yy[i];
if(dx>=1&&dx<=n&&dy>=1&&dy<=n&&!vis[dx][dy]){
if(a[dx][dy]=='.'){flag=1;continue;}
vis[dx][dy]=1;
Q.push({dx,dy});
}
}
if(flag)bound++;
Q.pop();
}
}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
cin>>a[i][j];
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(a[i][j]=='#'&&!vis[i][j]){
int sum=0,bound=0;
bfs(i,j,sum,bound);
if(sum==bound)ans++;
}
}
}
cout<<ans;
}