kutije | 프로그래밍의 벗 PivotOJ
PivotOJ

kutije

시간 제한: 1000ms메모리 제한: 128MB출처: CHC 2006 National Competition #2 - SeniorsBOJ 3171

문제

There are N open boxes, arranged from left to right. There are exactly two balls in each box, and each ball is either white or black. 

There is a crane above the first (leftmost) box and we can operate the crane with the following commands: 

  • LIJEVO: move the crane one box to the left 
  • DESNO: move the crane one box to the right 
  • UZMI BIJELU: take the white ball from the box below 
  • UZMI CRNU: take the black ball from the box below 
  • SPUSTI BIJELU: drop the white ball to the box below 
  • SPUSTI CRNU: drop the black ball to the box below 

The crane can carry only two balls at the same time, but in each box we can put an unlimited number of balls. 

We say that the balls are "arranged" if all of the following statements are satisfied: 

  • there are exactly two balls in each box and they have the same color 
  • there is no box with black balls between any two boxes with white balls 
  • there is no box with white balls between any two boxes with black balls 

Write a program that will find some smallest sequence of commands that will arrange the balls so that the above rules are satisfied. 

Each command in your solution must be valid (the crane must not go left from the leftmost box, it must not carry more then two balls, etc...). 

입력

The first line of input contains an integer N, 2 ≤ N ≤ 500. 

The second line contains a sequence of N letters – the initial contents of the boxes. 

For each box (from left to the right) there are two letters 'B' or 'C'. The letter 'B' represents a white ball and the letter 'C' represents a black ball. 

출력

Output all of the commands, each on its own line. 

Note: the test data will be such that a solution, although not necessarily unique, will always exist. 

예제

예제 1

입력
3
CC BC BC
출력
DESNO
UZMI BIJELU
DESNO
SPUSTI BIJELU
UZMI CRNU
LIJEVO
SPUSTI CRNU

예제 2

입력
5
BC BB CB BB CC
출력
UZMI CRNU
DESNO
DESNO
UZMI CRNU
DESNO
SPUSTI CRNU
UZMI BIJELU
SPUSTI CRNU
UZMI BIJELU
LIJEVO
SPUSTI BIJELU
LIJEVO
LIJEVO
SPUSTI BIJELU

예제 3

입력
7
BB BC CC CC CC BC BB
출력
UZMI BIJELU
UZMI BIJELU
DESNO
DESNO
DESNO
DESNO
SPUSTI BIJELU
SPUSTI BIJELU
UZMI CRNU
UZMI CRNU
LIJEVO
LIJEVO
LIJEVO
LIJEVO
SPUSTI CRNU
SPUSTI CRNU
DESNO
UZMI BIJELU
DESNO
DESNO
DESNO
DESNO
SPUSTI BIJELU
UZMI CRNU
LIJEVO
LIJEVO
LIJEVO
LIJEVO
SPUSTI CRNU
이 문제는 채점 준비 중입니다. 테스트 데이터가 확보되면 제출이 가능합니다.