#include <iostream>
using namespace std;
int arr[101][101][101];
int ar[3][1000000];
int rear=0,front=0,max,num=0;
int m,n,h;
void pluss()
{
int max=front-1;
cout << "----------------\n";
for(int i=rear; i<front; i++) {
cout << ar[0][i] << ',' << ar[1][i] << ',' << ar[2][i] << endl;
}
cout << "----------------\n";
for(int i=rear; i<=max; i++)
{
int a = ar[0][i];
int b = ar[1][i];
int c = ar[2][i];
cout<< i<< ':' <<a<<' '<<b<<' '<<c<<endl;
cout << "1 "<< arr[a][b-1][c]<<endl;
if(arr[a][b-1][c]==0 && b-1 >=0)
{
cout << "b-1"<<endl;
ar[0][front] = a;
ar[1][front] = b-1;
ar[2][front] = c;
arr[a][b-1][c] = 1;
front++;
}
cout <<"Step1";
if(arr[a][b+1][c]==0 && b+1 < n)
{
cout << "b+1"<<endl;
ar[0][front] = a;
ar[1][front] = b+1;
ar[2][front] = c;
arr[a][b+1][c] = 1;
front++;
}
cout <<"Step2";
if(arr[a+1][b][c]==0 && a+1 < m)
{
cout << "a+1"<<endl;
ar[0][front] = a+1;
ar[1][front] = b;
ar[2][front] = c;
arr[a+1][b][c] = 1;
front++;
}
cout << "Step3";
if(arr[a-1][b][c]==0 && a-1 >=0)
{
cout << "a-1"<<endl;
ar[0][front] = a-1;
ar[1][front] = b;
ar[2][front] = c;
arr[a-1][b][c] = 1;
front++;
}
cout<<"Step4";
if(arr[a][b][c+1]==0 && c+1 < h)
{
cout << "c+1"<<endl;
ar[0][front] = a;
ar[1][front] = b;
ar[2][front] = c+1;
arr[a][b][c+1] = 1;
front++;
}
cout<<"Step5";
if(arr[a][b][c-1]==0 && c-1 >= 0)
{
cout << "c-1"<<endl;
ar[0][front] = a;
ar[1][front] = b;
ar[2][front] = c-1;
arr[a][b][c-1] = 1;
front++;
}
cout << "IOASUDASUD"<<endl;
rear++;
}
for(int k=0; k<m; k++)
{
for(int i=0; i<n; i++)
{
for(int j=0; j<h; j++)
{
cout << arr[k][i][j] << ' ';
}
cout << endl;
}
}
system("pause");
cout<<'*'<<front<<' '<<rear<<endl;
}
void fuc1()
{
while(1)
{
if(rear==front)
return ;
else
pluss();
}
}
void fuc2()
{
for(int k=0; k<m; k++)
{
for(int i=0; i<n; i++)
{
for(int j=0; j<h; j++)
{
if(arr[k][i][j] == 1)
{
ar[0][front] = k;
ar[1][front] = i;
ar[2][front] = j;
front++;
num++;
}
}
}
}
fuc1();
}
int main()
{
cin>>h>>n>>m;
for(int k=0; k<m; k++)
{
for(int i=0; i<n; i++)
{
for(int j=0; j<h; j++)
{
cin>>arr[k][i][j];
}
}
}
fuc2();
cout<<endl;
for(int k=0; k<m; k++)
{
for(int i=0; i<n; i++)
{
for(int j=0; j<h; j++)
{
cout<<arr[k][i][j]<<' ';
}
cout<<endl;
}
}
cout<<num;
}