Imprecise Permutation Sort
This is an interactive problem.
A permutation of integers from to is hidden from you.
Your task is to sort it in ascending order by comparing and swapping pairs of elements. This problem could be pretty easy, but the jury member responsible for the problem was too concentrated on floating-point arithmetic in problems G and J and implemented an "imprecise" comparator:
if , then return ;
otherwise, if , then return ;
otherwise, return .
Your program can make queries to compare any two elements with this comparator, or to swap any two elements. After each swap, it will be told whether the permutation became sorted.
Sort a permutation of size up to using no more than queries.
Interaction
Receive an integer from the jury's program — the size of the permutation (). Then print queries and receive responses from the jury's program. After each query the output should be flushed and then a single integer should be read — the response to that query.
Comparison queries have a format "C i j
", and swap queries have a format "S i j
", where and are indices of two elements (). Making queries with is allowed.
The response to a comparison query is if "approximately equals" , otherwise: if , and if .
A swap query swaps values in and , and the response to a swap query is if after this swap the array became sorted in ascending order, and otherwise.
Your program should exit as soon as it receives as a response to a swap query.
The program should make at least one swap query. For example, if the hidden permutation is already sorted, it can make a query "S 1 1
", receive a , and exit.
The interactor is not adaptive. The initial permutation is chosen by the jury's program in advance, before you make your first query.