#C4590. Sort Paintings

    ID: 48145 Type: Default 1000ms 256MiB

Sort Paintings

Sort Paintings

You are given an integer \( n \) and a list of \( n \) paintings. Each painting is represented by two integers corresponding to its height and width. You are also given a sorting criteria which is either "width" or "height". Your task is to sort the list of paintings in ascending order based on the specified criteria.

More formally, let each painting be represented as a tuple \( (h, w) \). If the sorting criteria is "width", sort the paintings so that \( w_1 \leq w_2 \leq \ldots \leq w_n \); if the criteria is "height", then sort them so that \( h_1 \leq h_2 \leq \ldots \leq h_n \).

inputFormat

The input is read from stdin and has the following format:

<n> <criteria>
<height_1> <width_1>
<height_2> <width_2>
... 
<height_n> <width_n>

Here, \( n \) is the number of paintings and criteria is a string that is either "width" or "height". Each subsequent line contains two integers representing the height and width of a painting.

outputFormat

Output the sorted list of paintings to stdout. For each painting, print the height and width on a separate line separated by a space.

## sample
4 width
90 120
85 135
90 130
60 140
90 120

90 130 85 135 60 140

</p>