시간 제한메모리 제한제출정답맞힌 사람정답 비율
40 초 (추가 시간 없음) 1024 MB111100.000%

문제

Supervin loves to eat candies. Today, his favorite candy shop is offering N candies, which are arranged in a line. The i-th candy in the line (counting starting from 1) has a sweetness level Si. Note that the sweetness level of a candy might be negative, which means the candy tastes bitter.

Supervin likes to eat sweet candies. However, candies with a combined sweetness level of more than D would be too much sweetness even for him. Supervin also realises that a candy with an odd sweetness level is "odd", and he does not want to eat more than O odd candies. In other words, an odd candy is a candy with a sweetness level that is not evenly divisible by 2. Additionally, since Supervin is in a rush, he can only eat a single contiguous subset of candies.

Therefore, he wants to eat a contiguous non-empty subset of candies in which there are at most O odd candies and the total sweetness level is maximized, but not more than D. Help Supervin to determine the maximum total sweetness level he can get, or return IMPOSSIBLE if there is no contiguous subset satisfying these constraints.

입력

The first line of the input gives the number of test cases, TT test cases follow. Each test case contains two lines. The first line contains three integers NO, and D, as described above. The second line contains seven integers X1X2ABCML; these values are used to generate the values Si, as follows:

We define:

  • Xi = (A × Xi - 1 + B × Xi - 2 + C) modulo M, for i = 3 to N.
  • Si = Xi + L, for i = 1 to N.

출력

For each test case, output one line containing Case #x: y, where x is the test case number (starting from 1) and y is the maximum total sweetness level Supervin can get, or IMPOSSIBLE if there is no possible contiguous subset satisfying the problem constraints.

제한

  • 1 ≤ T ≤ 100.
  • 2 ≤ N ≤ 5 × 105.
  • 0 ≤ O ≤ N.
  • -1015 ≤ D ≤ 1015.
  • 0 ≤ X1X2ABC ≤ 109.
  • 1 ≤ M ≤ 109.

Test Set 1 (10점)

  • L = 0.

Test Set 2 (15점)

  • -5 × 108 ≤ L ≤ 0.

예제 입력 1

2
6 1 1000000000000000
1 1 1 1 0 100 0
6 1 -100
1 1 1 1 0 100 0

예제 출력 1

Case #1: 13
Case #2: IMPOSSIBLE

In Sample Case #1, the generated array of sweetness values Si is: [11, 2, 35, 8], where the bold and underlined numbers are the odd numbers. Since Supervin can only eat one odd candy, he can get a maximum total sweetness level by taking the fifth and the sixth candies.

In Sample Case #2, the generated array of sweetness values Si is the same as in Sample Case #1. However, this time Supervin cannot eat candies with a total sweetness level of more than -100, so no contiguous subset of candies satisfies the constraints.

Note: We do not recommend using interpreted/slower languages for the Large dataset of this problem.

예제 입력 2

3
10 1 8
4 3 4 1 5 20 -10
10 2 8
4 3 4 1 5 20 -10
10 1 8
4 3 4 1 5 20 -19

예제 출력 2

Case #1: 7
Case #2: 8
Case #3: -5

In Sample Case #1, the generated array of sweetness values Si is: [-6, -7-9, 2, 4, 31, -8, -6, -7], where the bold and underlined numbers are the odd numbers. Since Supervin can only eat one odd candy and he cannot eat candies with a total sweetness level of more than 8, he can get the maximum total sweetness level by taking the fifth and the sixth candies.

In Sample Case #2, the generated array of sweetness values Si is the same as in Sample Case #1. However, this time Supervin can eat two odd candies. Therefore, he can get a maximum total sweetness level by taking the fifth, the sixth, and the seventh candies.

In Sample Case #3, the generated array of sweetness values Si is: [-15, -16, -18, -7-5, -6, -8, -17-15, -16] where the bold and underlined numbers are the odd numbers. Note that it is possible for the maximum total sweetness level to be negative.

채점 및 기타 정보

  • 예제는 채점하지 않는다.