Consider following along the path in the figure above,
starting from and
moving to . Then
the path turns rightward toward , then sharp left to
and finally sharp
left again to . If
we use ‘L’ for left and ‘R’ for right, we see that the sequence of turn
directions is given by ‘RLL’. Notice
that the path does not cross itself: the only intersections of
segments are the connection points along the path.
Consider the reverse problem: Given points in an arbitrary
order, say , could
you find an ordering of the points so the turn directions along
the path are given by ‘RLL’? Of
course to follow the path in the figure, you would start with
the third point in the list , then the first , second , fourth , and fifth , so the permutation of the
points relative to the given initial order would be:
.
Input
The first line of the input contains an integer , specifying the number of points
such that . The following lines each describe a point using
two integers and
such that
. The points are distinct and no three are
collinear (i.e., on the same line). The last line contains a
string of
characters, each of which is either ‘L’ or ‘R’.
Output
A permutation of that corresponds to a nonintersecting path
satisfying the turn conditions. The numbers are to be displayed
with separating spaces. (There are always one or more possible
solutions, and any one may be used.)
Sample Input 1 |
Sample Output 1 |
5
2 5
1 6
4 4
5 0
4 2
RLL
|
3 1 2 4 5
|
Sample Input 2 |
Sample Output 2 |
4
1 1
2 1
1 2
2 2
LR
|
3 1 4 2
|