#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>

int convert(int x, int n){
    int y=0, i=0, z;
    while(x > 0){
        z = x%n;
        if(z == 1){
          z = 2;
        }else if(z==2){
          z = 1;
        }
        y += z*pow(n, i);
        x = x/n;
        i++;
    }
    return y;
}

int main()
{
  int n;
  scanf("%d", &n);
  char t[200001];
  scanf("%s", t);

  int shuturyoku1, shuturyoku2;
    for(int j = 0; j < strlen(t); j = j+2){
      shuturyoku1 = j;
      shuturyoku2 = j+1;
      if(t[j] == 'S'){
        shuturyoku1 = convert(shuturyoku1, 3);
        shuturyoku2 = convert(shuturyoku2, 3);
      }else if(t[j] == 'R'){
        if(shuturyoku1 == pow(3,n)-1){
          shuturyoku1 = 0;
          shuturyoku2 = shuturyoku2+1;
        }else if(shuturyoku2 == pow(3,n)-1){
          shuturyoku2 = 0;
          shuturyoku1 = shuturyoku1+1;
        }else{
          shuturyoku1 = shuturyoku1+1;
          shuturyoku2 = shuturyoku2+1;
        }
      } 
      // printf("%d ", shuturyoku);
    }
    printf("%d ", shuturyoku1);
    printf("%d ", shuturyoku2);
    // printf("\n");
  printf("\n");
  return 0;
}