#include <iostream>
using namespace std;
int main ()
{
    int N,M,P,sum=0;
    cin>>M>>N>>P;
    int m[N][N],a=N-1,b=N-1,c=0,d=0;
    for (int j=c;j<=a;j++)
    {
        m[d][j]=M;
        M++;
    }
    for (int i=d;i<=b;i++)
    {
        m[a][i]=M;
        M++;
    }
    for (int j=a;j>=c;j--)
    {
        m[b][j]=M;
        M++;
    }
    d++;
    for (int i=b;i>=d;i--)
    {
        m[c][i]=M;
        M++;
    }
    a--;
    for (int j=c;j<=a;j++)
    {
        m[d][j]=M;
        M++;
    }
    b--;
    c--;
    for (int i=0;i<N;i++)
    {
        for (int j=0;j<N;j++)
        {
            cout<<m[i][j];
        }
        cout<<endl;
    }
    for (int i=0;i<N;i++)
    {
        sum+=m[P][i];
    }
    cout<<sum;
    return 0;
}