#K76622. Array Manipulation Game

    ID: 34684 Type: Default 1000ms 256MiB

Array Manipulation Game

Array Manipulation Game

In this game, two players, Alice and Bob, play with an array of n integers. A move consists of selecting a contiguous subarray of length k and reversing its order.

The rules are as follows:

  • If the array is already sorted in non-decreasing order at the start, Alice cannot make any move and Bob is declared the winner.
  • If k equals 1, no reversal can change the array, so Bob wins.
  • Otherwise, the outcome is determined by counting the number of inversions in the array. An inversion is a pair of indices \( (i,j) \) such that \( i a[j] \). If the total number of inversions is odd, then Alice wins; if it is even, Bob wins.

Your task is to implement this game logic and determine the winner based on the input.

inputFormat

The first line contains two integers \( n \) and \( k \), where \( n \) is the length of the array and \( k \) is the length of the subarray that can be reversed.

The second line contains \( n \) space-separated integers representing the elements of the array \( a \).

outputFormat

Print a single integer: output 1 if Alice wins or 2 if Bob wins.

## sample
5 3
4 2 3 1 5
1

</p>