/*
#include <stdio.h>
int h[80001] = { 0 };
int stack[80001] = { 0 };
int top = 0;
int n;
void push(int k)
{
stack[top++] = k;
}
int clean()
{
for (int i = 0; i < n; i++)
{
stack[i] = 0;
}
top = 0;
}
int see(int k)
{
clean();
for (int i = k+1; i < n; i++)
{
if (h[k] > h[i])
{
push(h[i]);
}
else
{
return top;
}
}
return top;
}
int main()
{
scanf("%d", &n);
for (int i = 0; i < n; i++)
{
scanf("%d", &h[i]);
}
int sum = 0;
for (int i = 0; i < n; i++)
{
sum += see(i);
}
printf("%d", sum);
}
*/
/*
#include <stdio.h>
int num[500001] = {};
int stack[500001] = {};
int top = 0;
int pop()
{
int k = stack[top];
stack[top] = 0;
top--;
return k;
}
int main()
{
int n;
scanf("%d", &n);
for (int i=0; i<n; i++)
{
scanf("%d", &stack[i]);
top++;
}
for (int i=top; i>0; i--)
{
if (stack[i]<stack[i-1])
{
num[i] = i;
pop();
}
else
{
int k = i-1;
while (stack[i]>=stack[k])
{
num[i]=k;
k--;
if (k==-1)
{
pop();
num[i]=0;
break;
}
}
}
}
for (int i=0; i<n; i++)
{
printf("%d ", num[i]);
}
}
*/
/*
#include <stdio.h>
int main()
{
int n;
scanf("%d", &n);
int arr[n];
int top = -1;
int sum = 0;
for (int i=0; i<n; i++)
{
scanf("%d", &arr[i]);
if (top==-1)
{
top++;
arr[top] = arr[i];
continue;
}
else if(arr[top] <= arr[i])
{
while (top != -1 && (arr[top]<=arr[i]))
{
arr[top] = 0;
top--;
}
}
top++;
arr[top] = arr[i];
sum += top;
}
printf("%d", sum);
}
*/
/*
#include <stdio.h>
char stack[50001] = {};
int top = -1;
void push(int k)
{
stack[++top] = k;
}
int pop()
{
int k = stack[top];
stack[top] = 0;
top--;
return k;
}
int main()
{
char sen[50001];
scanf("%s", sen);
for (int i=0; i<strlen(sen); i++)
{
if (sen[0] == ')')
{
printf("bad");
return;
}
else if (sen[i]=='(')
{
push(sen[i]);
}
else if (sen[i]==')')
{
if (stack[top] == '(')
{
pop();
}
else push(sen[i]);
}
}
if (strlen(stack)==0)
{
printf("good");
}
else printf("bad");
}
*/
/*
#include <stdio.h>
char a[101]={0};
char b[101]={0};
int top = -1;
int aa[200] = {0};
int bb[200] = {0};
int sum[200] = {0};
int main()
{
scanf("%s", a);
scanf("%s", b);
int k = strlen(a) > strlen(b)? strlen(a) : strlen(b);
for (int i=strlen(a)-1; i>=0; i--)
{
aa[strlen(a)-1-i] = a[i]-'0';
}
for (int i=strlen(b)-1; i>=0; i--)
{
bb[strlen(b)-1-i] = b[i]-'0';
}
for (int i=0; i<k; i++)
{
sum[i] += aa[i] + bb[i];
top = i;
if (sum[i]>9)
{
sum[i] -= 10;
sum[i+1] += 1;
top+=1;
}
}
for (int i=top; i>=0; i--)
{
printf("%d", sum[i]);
}
}
*/
#include <stdio.h>
int map[27][27] = {0};
int k = 0, s=0;
int queue[100000][2] = {0}; // x, y
int front=0, rear=0;
void calcu(int x, int y) {
s++;
map[x][y] = k+1;
if(map[x-1][y]==1) {
queue[front][0] = x-1;
queue[front][1] = y;
front++;
}
if(map[x-1][y]==1) {
queue[front][0] = x-1;
queue[front][1] = y;
front++;
}
if(map[x-1][y]==1) {
queue[front][0] = x-1;
queue[front][1] = y;
front++;
}
if(map[x-1][y]==1) {
queue[front][0] = x-1;
queue[front][1] = y;
front++;
}
}
void bfs() {
while(front!=rear) {
int x = queue[rear][0];
int y = queue[rear][1];
calcu(x, y);
rear++;
}
}
void dfs(int x, int y, int p) {
//^^ㅗ
map[x][y] = p;
s++;
if(map[x-1][y]==1)
{
dfs(x-1, y, p);
}
if(map[x+1][y]==1)
{
dfs(x+1, y, p);
}
if(map[x][y-1]==1)
{
dfs(x, y-1, p);
}
if(map[x][y+1]==1)
{
dfs(x, y+1, p);
}
}
int main()
{
int num, i, j;
int p = 2;
int result[1000] = {0};
scanf("%d", &num);
for(i=1; i<=num; i++) {
for(j=1; j<=num; j++) {
scanf("%1d", &map[i][j]);
}
}
// for(i=1; i<=num; i++) {
// for(j=1; j<=num; j++) {
// if(map[i][j]==1) {
// k++;
// s = 0;
// dfs(i, j, p);
// p++;
// result[k] = s;
//
// }
// // printf("%d", map[i][j]);
// }
// // printf("\n");
// }
for (i=1; i<=num; i++)
{
for (j=1; j<=num; j++)
{
if(map[i][j]==1) {
front = 0;
rear = 0;
k++;
queue[front][0] = i;
queue[front][1] = j;
front++;
bfs();
}
//bfs(i, j);
}
}
// printf("%d\n", k);
//
// for(i=0; i<10; i++) {
// printf("%d\n", result[i]);
// }
printf("%d", s);
}



