#CSPS2021C. 回文 (Palindrome)
回文 (Palindrome)
Description
You are given a positive integer and a sequence of integers . The numbers each occur exactly twice in these numbers. Create a sequence of the same length by performing operations. Initially, is an empty sequence. One of the following two operations can be performed at a time:
- Add the first element of the sequence to the end of and remove it from .
- Add the last element of the sequence to the end of and remove it from .
The goal is to make a palindrome, i.e., for all , should be satisfied. Find whether this goal can be achieved, and if so, find the lexicographically smallest sequence of operations as described in the output format.
Input Format
The first line contains an integer denoting the number of test cases. The first line of each test case contains a positive integer and the second line contains space-separated integers .
Output Format
Print one line for each test case. If a palindrome can't be generated, print . Otherwise, print a string of length consisting of the characters and (without spaces), where represents operation and represents operation . The string should be the lexicographically smallest among the strings corresponding to all the sequences of operations that achieve the goal. A string is lexicographically smaller than if and only if there exists a position such that , and .
2
5
4 1 2 4 5 3 1 2 3 5
3
3 2 1 2 1 3
LRRLLRRRRL
‐1
In the first test case, the generated sequence is $4\space 5\space 3\space 1\space 2\space 2\space 1\space 3\space 5\space 4$. It can be seen that this is a palindrome. Another possible sequence of operations is , but it is lexicographically larger than the answer sequence.
Sample 2
See palin2.in and palin2.ans.
Constraints
Let denote the sum of over all test cases. It is guaranteed that for each test file, , , and .
Tests | Special nature | |||
---|---|---|---|---|
No | ||||
Yes | ||||
No |
Special nature: If we delete two adjacent and equal numbers in at a time, there is a way to delete the entire sequence (e.g., ).