#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int dp[105][105];
int n;
string s;
int p[105];

int dfs(int l, int w){
    char c = s[l];
    int t;
    if(c == 'R') t = 0;
    if(c == 'P') t = 1;
    if(c == 'S') t = 2;
    if(w == 0){
        dp[0][l] = t;
        return t;
    }

    if(dp[w][l] != -1) return dp[w][l];
    int k = l + p[w-1];
    k %= n;
    int a = dfs(k, w-1);
    int b = dfs(l, w-1);
    int res;
    if(a == b) res = a;
    if(a == 0 && b == 1) res = b;
    if(a == 0 && b == 2) res = a;
    if(a == 1 && b == 0) res = a;
    if(a == 1 && b == 2) res = b;
    if(a == 2 && b == 0) res = b;
    if(a == 2 && b == 1) res = a;

    dp[w][l] = res;
    return res;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int k;
    cin >> n >> k;
    cin >> s;
    rep(i,105) rep(j,105) dp[i][j] = -1;
    p[0] = 1;
    rep(i,100) p[i+1] = p[i]*2, p[i+1] %= n;
    int ans = dfs(0, k);
    if(ans == 0) cout << 'R' << endl;
    if(ans == 1) cout << 'P' << endl;
    if(ans == 2) cout << 'S' << endl;
}
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define FOR(i, m, n) for(ll i = m; i < (n); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vii = vector<vi>;
using pii = pair<int, int>; 
using vl = vector<ll>;
using vll = vector<vl>;
using pll = pair<ll, ll>;

ll N, K;
vll T;
ll ans = 0;

void disp(vl arr){
    rep(i, arr.size()){
        cout << arr[i] << " ";
    }
    cout << '\n';
}

void f(vl p){
    ll tmp = 0;
    rep(i, N-1){
        tmp += T[p[i]][p[i+1]];
    }
    tmp += T[p[N-1]][p[0]];
    if(tmp == K){
        ans++;
    }
    return;
}

void dfs(vl now, ll n, ll m){
    if(n == 0){
        // 生成された順列に対して処理を行う関数(要定義)
        f(now);
        return;
    }
    for(ll v = 0; v < m; v++){
        bool con = false;
        for(auto nowv : now){
            if(nowv == v){
                con = true;
                break;
            } 
        }
        if(con) continue;
        vl next = now;
        next.push_back(v);
        dfs(next, n-1, m);
    }
}

int main() {
    cin >> N >> K;
    T.resize(N, vl(N));
    rep(i, N){
        rep(j, N){
            cin >> T[i][j];
        }
    }
    vl arg = {0};
    dfs(arg, N-1, N);
    cout << ans;
}