#ifdef LOGX
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;

/*---------macro---------*/
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define unless(x) if(!(x))
#define until(x) while(!(x))
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define mybit(i,j) (((i)>>(j))&1)

/*---------type/const---------*/
const int big=1000000007;
//const int big=998244353;
const double EPS=1e-8; //適宜変える
typedef long long ll;
typedef unsigned long long ull;
typedef std::string::const_iterator state; //構文解析
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const char newl='\n';
struct{
    constexpr operator int(){return -int(1e9)-10;}
    constexpr operator ll(){return -ll(1e18)-10;}
}neginf;
struct{
    constexpr operator int(){return int(1e9)+10;}
    constexpr operator ll(){return ll(1e18)+10;}
    constexpr auto operator -(){return neginf;}
}inf;

/*---------debug---------*/
#ifdef LOGX
#include <template/debug.hpp>
#else
#define dbg(...) ;
#define dbgnewl ;
#define prt(x) ;
#define _prt(x) ;
#endif

/*---------function---------*/
template<typename T> T max(const std::vector<T> &a){T ans=a[0];for(T elem:a){ans=max(ans,elem);}return ans;}
template<typename T> T min(const std::vector<T> &a){T ans=a[0];for(T elem:a){ans=min(ans,elem);}return ans;}
template<typename T,typename U> bool chmin(T &a,const U b){if(a>b){a=b;return true;}return false;}
template<typename T,typename U> bool chmax(T &a,const U b){if(a<b){a=b;return true;}return false;}
bool valid(int i,int j,int h,int w){return (i>=0 && j>=0 && i<h && j<w);}
template<class T,class U>T expm(T x,U y,const ll mod=big){T res=1;while(y){if(y&1)(res*=x)%=mod;(x*=x)%=mod;y>>=1;}return res;}
template<class T,class U>T exp(T x,U y){T res=1;while(y){if(y&1)res*=x;x*=x;y>>=1;}return res;}



int main(){
    //std::ios::sync_with_stdio(false);
    //std::cin.tie(nullptr);
    std::cout.precision(10);
/*------------------------------------*/
    
    ll n,k;cin >> n >> k;
    vector<vector<ll>> a(n,vector<ll>(n));
    rep(i,n)rep(j,n)cin >> a[i][j];
    ll ng=-1;
    ll ok=inf;
    //中央値をok以下にできる
    while(abs(ng-ok)>1){
        ll x=(ng+ok)/2;
        vector<vector<ll>> sum(n+1,vector<ll>(n+1));
        rep(i,n)rep(j,n){
            sum[i+1][j+1]=(a[i][j]<=x ? -1:1);
        }
        dbg(x,sum);
        rep(i,n)rep(j,n+1)sum[i+1][j]+=sum[i][j];
        rep(i,n+1)rep(j,n)sum[i][j+1]+=sum[i][j];
        bool can=false;
        rep(i,n-k+1)rep(j,n-k+1){
            if(sum[i+k][j+k]+sum[i][j]-sum[i+k][j]-sum[i][j+k]<=0)can=true;
        }
        (can ? ok:ng)=x;
    }
    cout << ok << newl;
}
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
typedef long long ll;
typedef std::vector<int> P;
typedef unsigned un;
ll read()
{
    ll x=0,f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();
    return f*x;
}
using std::min;
using std::max;
template<typename T>bool umin(T& a,T t){if(a>t)return a=t,1;return 0;}
template<typename T>bool umax(T& a,T t){if(a<t)return a=t,1;return 0;}

const int MAXN = 111;
int a[MAXN],b[MAXN];
char s[MAXN];
int main()
{
	int n=read();
	scanf("%s",s+1);
	for(int i=1;i<=n+1;++i)a[i]=read();
	for(int k=10000;k;--k)
	{
		bool fail=0;
		for(int i=1;i<=k&&!fail;++i)
		{
			b[1]=(a[1]/k+(i<=a[1]%k));
			for(int j=2;j<=n+1;++j)
			{
				b[j]=(a[j]/k+(i<=a[j]%k));
				if(s[j-1]=='>')fail|=b[j-1]<=b[j];
				else fail|=b[j-1]>=b[j];
			}
		}
		if(!fail)
		{
			printf("%d\n",k);
			for(int i=1;i<=k;puts(""),++i)
				for(int j=1;j<=n+1;++j)printf("%d ",a[j]/k+(i<=a[j]%k));
			return 0;
		}
	}
	puts("0");
	return 0;
}

