#K69667. Divisible Sum Pairing

    ID: 33138 Type: Default 1000ms 256MiB

Divisible Sum Pairing

Divisible Sum Pairing

You are given two arrays arr1 and arr2 of equal length and an integer k. Your task is to rearrange arr2 (i.e. find a permutation) such that for each index i the sum arr1[i] + arr2[i] is divisible by k. If such a permutation exists, print the resulting pairs. Otherwise, print None.

Note: Each valid pair is printed as two numbers separated by a space on a new line. You must read input from stdin and output your answer to stdout.

Mathematically, for the found permutation p of indices, it must satisfy: $$ \forall\,i,\quad \; (arr1[i] + p(arr2)[i])\, \%\, k = 0. $$

inputFormat

The input consists of four lines:

  1. An integer n representing the number of elements in each array.
  2. n space-separated integers representing arr1.
  3. n space-separated integers representing arr2.
  4. An integer k, the divisor.

outputFormat

If a valid reordering of arr2 exists such that arr1[i] + arr2[i] is divisible by k for every index i, print each pair in a new line as a b (where a is from arr1 and b from the corresponding position in the rearranged arr2). If there is no valid pairing, print None.

## sample
4
1 2 3 4
4 3 2 1
5
1 4

2 3 3 2 4 1

</p>