This page is still under construction.

Parts of this page are still being built. What you see may change.

Minimal Product

Time limit2sMemory limit512 MB

Summary
Generate a pseudorandom array and find indices i<j with a_i<a_j minimizing the product a_i*a_j, or report IMPOSSIBLE.
Level

Medium6 of 10

Topics
Implementation, Greedy, Math, Array
Solved
No attempts yet

Problem

You are given an array of integers a1,a2,…,ana_1, a_2, \dots, a_n. Find two indices ii and jj such that i<ji < j, ai<aja_i < a_j, and the product ai⋅aja_i \cdot a_j is as small as possible.

Input

The input consists of several tests. The first line contains a single integer tt, the number of tests (1≤t≤1041 \leq t \leq 10^4). Each of the following tt lines describes one test.

Each test is generated using the following algorithm. The test is described by integers nn, ll, rr, xx, yy, zz, b1b_1, b2b_2 (2≤n≤1072 \leq n \leq 10^7, −2⋅109≤l≤r≤2⋅109-2\cdot10^9 \leq l \leq r \leq 2\cdot10^9, 0≤x,y,z,b1,b2<2320 \leq x, y, z, b_1, b_2 < 2^{32}), where nn is the length of the array.

First, the sequence bib_i of length nn is generated. The elements b1b_1 and b2b_2 are given. For i>2i > 2, let bi=(bi−2x+bi−1y+z) mod 232b_i = (b_{i-2}x + b_{i-1}y + z) \bmod 2^{32}. For each ii between 11 and nn, ai=(bi mod (r−l+1))+la_i = (b_i \bmod (r - l + 1)) + l (thus, −2⋅109≤ai≤2⋅109-2\cdot10^9 \leq a_i \leq 2\cdot10^9).

Use 64-bit integers to generate the sequence and avoid integer overflow.

The sum of nn over all tests does not exceed 2⋅1072 \cdot 10^7.

Output

For each test, print the smallest possible product ai⋅aja_i \cdot a_j on a separate line. If there are no indices ii and jj such that i<ji < j and ai<aja_i < a_j, print "IMPOSSIBLE".

Hint

Consider how the array is generated in the first test.

First, the sequence bb is generated.

  • b1=0b_1 = 0
  • b2=3b_2 = 3
  • b3=(11⋅0+13⋅3+17) mod 232=56b_3 = (11\cdot 0 + 13\cdot 3 + 17) \bmod 2^{32} = 56
  • b4=(11⋅3+13⋅56+17) mod 232=778b_4 = (11\cdot 3 + 13\cdot 56 + 17) \bmod 2^{32} = 778

Then it is used to generate aa.

  • a1=(0 mod (5−(−5)+1))+(−5)=(0 mod 11)−5=−5a_1 = (0 \bmod (5 - (-5) + 1)) + (-5) = (0 \bmod 11) - 5 = -5
  • a2=(3 mod 11)−5=−2a_2 = (3 \bmod 11) - 5 = -2
  • a3=(56 mod 11)−5=−4a_3 = (56 \bmod 11) - 5 = -4
  • a4=(778 mod 11)−5=3a_4 = (778 \bmod 11) - 5 = 3

Thus, a=[−5,−2,−4,3]a = [-5, -2, -4, 3]. The answer is −5⋅3=−15-5 \cdot 3 = -15.

In the second test the array is [42,42,42,42,42][42, 42, 42, 42, 42].

Examples1

  1. Example 1

    Input
    2
    4 -5 5 11 13 17 0 3
    5 0 100 0 1 0 42 42
    
    Expected output
    -15
    IMPOSSIBLE