#include <stdio.h>
#define GL grid[
#define GI GL i]

char GL 4096]; // fixme.  why char?
int i, total;

#define RECURSE(_n) if (GL i+ _n ]==GI+1) path_count(i+ _n );
void path_count(int i) {
    if (GI == 57) total++;
    else { RECURSE(-64) RECURSE(64) RECURSE(-1) RECURSE(1) }
}

int main() {
    char *p=&(GL 64]);
    while(scanf("%s",p+=64) ==1);
    while(p+=4096,++i <= 4096) if (GI == 48) path_count(i);
    printf("%d", total);
}
