You are on page 1of 1

“Adolescent Grigore Moisil” International Programming Contest, ninth edition

Qualifying Round, April, 2023

Flip
Input file: standard input
Output file: standard output
Time limit: 2 seconds
Memory limit: 1024 MB

Having been an amazing skateboarder, you know how cool flips are: Heelflips, Kickflips, Frontflips and
so on. You know what it’s all about!
Because you retired, today you are going to have fun with a different type of flip.

You are given an array a of N numbers represented on K bits and a number P .


Exactly P times you have to pick a bit from a number and flip it (you are allowed to flip the same bit as
many times as you want) such that after you perform all the flips, the following sum is maximized:

P
ai ⊕ aj
1≤i<j≤N

where ⊕ represents the bit-wise xor operator.


In case there are multiple such solutions, you should print any.

Input
The first line contains integers N , K and P . It is guaranteed that 1 ≤ N ≤ 105 , 1 ≤ K ≤ 30 and
1 ≤ P ≤ N ∗ K.
The next line contains N integers, the array a. It is guaranteed that 0 ≤ ai < 2K for all 1 ≤ i ≤ N .

Output
The output file should contain exactly P lines each containing two integers i and j such that 1 ≤ i ≤ N
and 0 ≤ j < K, which represent flipping bit j of number ai . Namely, ai ⇐ ai ⊕ 2j .
You are allowed to flip the same bit multiple times. Any solution that maximizes the sum
is valid. The order in which you output the operations is not important.

Example
standard input standard output
4 2 2 4 0
0 0 2 2 3 0
2 5 1 1 0
0 31
5 6 4 5 5
63 15 0 10 5 4 5
4 4
5 4

Page 1 of 1

You might also like