1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class tas {

	public static void main(String[] args) throws IOException {

		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String[] nt = reader.readLine().split(" ");
		int n = Integer.parseInt(nt[0]);
		int t = Integer.parseInt(nt[1]);

		String lineOfNumbers = reader.readLine();

		if (t % 2 == 0) {
			System.out.println(lineOfNumbers);
		} else {
			int numberOfCharsToWrite = lineOfNumbers.length();
			char[] characters = new char[numberOfCharsToWrite + 1];

			int k = numberOfCharsToWrite - 1;
			int indexOfCharToWrite = 0;
			while (numberOfCharsToWrite >= 0) {
				while (k >= 0 && lineOfNumbers.charAt(k) != ' ')
					--k;
				for (int p = k + 1; p < numberOfCharsToWrite; ++p)
					characters[indexOfCharToWrite++] = lineOfNumbers.charAt(p);
				characters[indexOfCharToWrite++] = ' ';
				numberOfCharsToWrite = k--;
			}
			System.out.println(characters);
		}
	}
}