Under construction

Still being built. Things may change

XOR Pairing

Time limit2sMemory limit512 MB

Summary
Given N stones (N up to 74) with values up to 1000, pair them to minimize the sum of pairwise XORs, and count the minimum-cost pairings modulo 1e9+7.
Level

Medium7 of 10

Topics
Bit manipulation, Dynamic programming, Combinatorics
Solved
No attempts yet

Problem

There are NN stones, and each stone has a non-negative integer x0,…,xN−1x_0, \ldots, x_{N-1} written on it, where NN is even. Partition the stones into N/2N/2 pairs so that each stone belongs to exactly one pair. For each pair, compute xix_i XOR xjx_j: write each of xix_i and xjx_j in binary, take the exclusive-or of each pair of corresponding bits, and read the result as a binary number. Sum the values xix_i XOR xjx_j over all pairs. Find the minimum possible sum over all pairings, and the number of pairings that reach this minimum. Two pairings differ if one contains a pair of stones that the other does not. Two stones are different if they have different indices, even when the values on them match. The order of the pairs and the order of the stones within each pair do not matter. Since the count can be huge, output it modulo 109+710^9 + 7.

Input

The first line contains the even number NN, the number of stones, where 2≤N≤742 \le N \le 74. The second line contains the numbers x0,…,xN−1x_0, \ldots, x_{N-1} written on the stones. Each number satisfies 0≤xi≤10000 \le x_i \le 1000.

Output

Print one line with two numbers separated by a space. The first is the smallest possible sum of xix_i XOR xjx_j over all pairings. The second is the number of pairings that achieve this minimum, modulo 109+710^9 + 7.

Examples1

  1. Example 1

    Input
    6
    7 14 17 4 2 1
    
    Expected output
    31 3