#include <stdio.h>

void spread(int masu[12][12], int check[12][12], int x, int y) {                
    check[y][x] = 1;                                                            
    if (x > 0 && masu[y][x-1] == 1 && check[y][x-1] == 0) {                     
        spread(masu, check, x-1, y);                                            
    }                                                                           
    if (x < 11 && masu[y][x+1] == 1 && check[y][x+1] == 0) {                    
        spread(masu, check, x+1, y);                                            
    }                                                                           
    if (y > 0 && masu[y-1][x] == 1 && check[y-1][x] == 0) {                     
        spread(masu, check, x, y-1);                                            
    }                                                                           
    if (y < 11 && masu[y+1][x] == 1 && check[y+1][x] == 0) {                    
        spread(masu, check, x, y+1);                                            
    }                                                                           
}

int calc(int masu[12][12]) {                                                    
    int num = 0;                                                                
    int check[12][12] = {};                                                     
    int x, y;                                                                   
                                                                                
    for (x = 0; x < 12; x++) {                                                  
        for (y = 0; y < 12; y++) {                                              
            if (masu[y][x] == 1 && check[y][x] == 0) {                          
                spread(masu, check, x, y);                                      
                num++;                                                          
            }                                                                   
        }                                                                       
    }                                                                           
    return num;                                                                 
}

int main(void) {                                                                
    int i, j;                                                                   
    int masu[12][12];                                                           
    char str[100];                                                              
                                                                                
    while (!feof(stdin)) {                                                      
        for (i = 0; i < 12; i++) {                                              
            fgets(str, 100, stdin);                                             
            for (j = 0; j < 12; j++) {                                          
                masu[i][j] = str[j] - '0';                                      
            }                                                                   
        }                                                                       
        printf("%d\n", calc(masu));                                             
        fgets(str, 100, stdin);                                                 
    }                                                                           
                                                                                
    return 0;                                                                   
}

Measured memory_bytes: 532