#K73757. Minimizing Array Operation Result

    ID: 34046 Type: Default 1000ms 256MiB

Minimizing Array Operation Result

Minimizing Array Operation Result

You are given an array of N integers and an integer K representing the maximum number of operations you can perform. Your task is to apply a sequence of at most K operations to minimize the value of the function

f(B)=i=1N1(BiBi+1)2,f(B)=\sum_{i=1}^{N-1}(B_i - B_{i+1})^2,

where B is the resulting array after applying the operations. There are two possible operations:

  • swap i j: Swap the elements at positions i and j (1-indexed).
  • replace i x: Replace the element at position i with the integer x.

After performing your operations, output each operation on a separate line. If at least one operation is performed, the last line of your output must be end. If no operations are needed or allowed, output nothing.

Note: The operations do not need to be optimal as long as they decrease the objective function according to the heuristic described. The judging system will run several test cases using standard input and standard output.

inputFormat

The input is given via standard input. The first line contains two integers N and K separated by a space, where N is the length of the array and K is the maximum number of operations allowed. The second line contains N space-separated integers representing the array.

outputFormat

Output the sequence of operations (one per line) that you apply to the array. Each operation should be of the format swap i j or replace i x (with 1-indexed positions). If at least one operation was performed, print an additional line containing the word end at the end. If no operation is performed (for example, when K is 0), produce no output.

## sample
2 0
1 1