#include <bits/stdc++.h>

#define ll long long
#define map unordered_map
#define set unordered_set
#define l_l pair<ll, ll>
#define P pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>
#define mp make_pair
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rev(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define revs(i, n) for (int i = ((int)(n)); i > 0; --i)

using namespace std;

const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);

// template <class T> void plus_mod(T &a, const T &b) {a = (a + b) % MOD;}

int main() {
  ll N;
  scanf("%lld", &N);

  struct record {
    ll t;
    ll l;
    ll r;
  };

  vector<record> rlist;
  rep(i, N) {
    ll t, l, r;
    scanf("%lld %lld %lld", &t, &l, &r);
    rlist.emplace_back(record{t, l, r});
  }

  ll ans = 0;

  for (ll i = 0; i < N - 1; i++) {
    for (ll j = i + 1; j < N; j++) {
      auto rec1 = rlist[i];
      auto rec2 = rlist[j];

      if (rec1.r < rec2.l || rec2.r < rec1.l) {
        // 全く重ならない
        continue;
      }
      // ちょうど重なるパターン
      if (rec1.r == rec2.l) {
        bool ok1 = (rec1.t == 1 || rec1.t == 3);
        bool ok2 = (rec2.t == 1 || rec2.t == 2);
        if (!(ok1 && ok2)) {
          continue;
        }
      }

      // ちょうど重なるパターン
      if (rec2.r == rec1.l) {
        bool ok1 = (rec2.t == 1 || rec2.t == 3);
        bool ok2 = (rec1.t == 1 || rec1.t == 2);
        if (!(ok1 && ok2)) {
          continue;
        }
      }

      //
      // cout << "i:" << (i) << ",j:" << (j) << endl;
      ans++;
    }
  }

  cout << ans << endl;
}

#include <bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fod(i,a,b) for(int i=a;i>=b;i--)
#define me0(a) memset(a,0,sizeof(a))
#define me1(a) memset(a,-1,sizeof(a))
#define op freopen("in.txt", "r", stdin)
#define op1 freopen("C:\\acm\\Cproj\\in.txt","r",stdin);
#define pr freopen("C:\\acm\\Cproj\\out.txt","w",stdout)
#define pr2 freopen("C:\\acm\\Cproj\\std.txt","w",stdout)
#define pii pair<int,int>
#define Please return
#define AC 0
using namespace std;
const int INF = 0x3f3f3f3f;
typedef long long LL;
template <class T>
void read(T &val) { T x = 0; T bz = 1; char c; for (c = getchar(); (c<'0' || c>'9') && c != '-'; c = getchar()); if (c == '-') { bz = -1; c = getchar(); }for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - 48; val = x * bz; }
const int mod=998244353;
const int maxn = 1e6+10;

int n,m,a[maxn],q,t,k;
char s[maxn];
int p[maxn];
char win[110][110];

char bat(char x,char y){
    if(x == y) return x;
    if(x == 'R' && y == 'S') return x;
    if(x == 'S' && y == 'P') return x;
    if(x == 'P' && y == 'R') return x;
    return y;
}

int main(){
    read(n);read(k);

    scanf("%s",s);
    p[0]=1;
    fo(i,1,k) p[i]=p[i-1]*2%n;
    fo(i,0,n-1) {
        win[i][0] = s[i];
    }

    fo(i,1,k){
        fo(j,0,n-1){
            win[j][i] = bat(win[j][i-1],win[(j+p[i-1])%n][i-1]);
        }
    }

    printf("%c\n",win[0][k]);
    Please AC;
}