const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;

void (async function () {
  // Write your code here
  let n = parseInt(await readline());
  let str = await readline();
  let count = 1; //记录当前选中歌曲的编号
  let position = 1; //记录当前选中歌曲在屏幕当中的位置,1234
  for (let i = 0; i < str.length; i++) {
    if (str[i] == "U") {
      count--;//向上编号减1
      if (count == 0) count = n;//减到0,跳到最后
      position--;//向上位置减1
      if (position == 0 && count == n) position = 4;//光标在第一首歌曲上,用户按Up键后,屏幕要显示最后一页,同时光标放到最后一首歌上
      if (position == 0 && count !== n) position = 1;//普通的,到顶了位置一直为1
    } else {
      count++;//向下编号加1
      if (count > n) count = 1;//最后一首跳到第一首
      position++;//向下位置加1
      if (position == 5 && count == 1) position = 1;//光标在最后一首歌曲上,用户按Down键,屏幕要显示第一页,光标挪到第一首歌上
      if (position == 5 && count !== 1) position = 4;//普通的,到底一直为4
    }
  }

  let arr = [];
  if (n <= 4) {
    for (let i = 1; i <= n; i++) {
      arr.push(i);
    }
    console.log(arr.join(" "));
  } else {
    switch(position){
        case 1:
            console.log(`${count} ${count+1} ${count+2} ${count+3}`)
            break
        case 2:
            console.log(`${count-1} ${count} ${count+1} ${count+2}`)
            break;
        case 3:
            console.log(`${count-2} ${count-1} ${count} ${count+1}`)
            break;
        case 4:
            console.log(`${count-3} ${count-2} ${count-1} ${count}`)
    }

  }

  console.log(count);
})();