Under construction

Still being built. Things may change

First Solved, Last Coded

Interview

Time limit2sMemory limit1024 MB

Summary
Given sequences a and b, find push and pop actions on a stack that turn a into b, or report NO if impossible.
Level

Medium4 of 10

Topics
Stack, Greedy, Simulation
Solved
No attempts yet

문제

In ICPC, teamwork is everything. That is why everyone on your team has a well-defined role: Sol the Solver can solve any problem in the problem set, Codie the Coder can implement any solution that Sol comes up with, and you are the glue that holds everything together. Sol and Codie are very picky about the order in which they solve and code problems, and your job is to satisfy their preferences.

There will be nn problems in the upcoming contest, and you know the general topic of each problem: greedy, geometry, graphs, and so on. For simplicity, each topic is represented by an integer from 11 to nn. These integers do not have to be distinct, so multiple problems can share the same topic.

Sol wants to solve problems in a specific order of topics: first the problem with topic a1a_1, then the problem with topic a2a_2, and so on, and finally the problem with topic ana_n. Codie has a preference list b1,b2,…,bnb_1, b_2, \ldots, b_n and will only code problems in that order of topics.

Your job during the contest is to take solution sheets from Sol and hand them to Codie in the correct order. Your team has only one table, so there is not enough space to arrange all solutions neatly. Instead, you follow this workflow: you ask Sol for solutions (who hands them to you in order a1,a2,…,ana_1, a_2, \ldots, a_n), store them in a stack on your part of the table, and hand them to Codie in order b1,b2,…,bnb_1, b_2, \ldots, b_n.

Formally, at any moment you can take one of two actions:

  • If unsolved problems remain, ask Sol for another solution and put it on top of your stack. This action is denoted by the character "S".
  • If your stack is not empty, take the solution sheet from the top of the stack and give it to Codie. This action is denoted by the character "C".

For the given preference lists, find a sequence of actions that ensures all problems are solved and coded in the correct order. Assume that solving and coding take no time.

입력

If the task is impossible, print "NO". Otherwise, print "YES" on the first line, followed by the sequence of actions on the second line: a string of 2n2n characters "S" or "C" (nn of each), describing your actions in order.

You may not ask Sol for more solutions after all nn problems have been solved, and you may not give Codie a solution with the wrong topic. If there are multiple answers, print any of them.

Examples2

  1. Example 1

    Input
    4
    4 1 2 2
    1 2 4 2
    
    Expected output
    YES
    SSCSCCSC
    
  2. Example 2

    Input
    3
    2 3 1
    1 2 3
    
    Expected output
    NO