#P6586. 『JROI-1』 蒟蒻火锅的盛宴

『JROI-1』 蒟蒻火锅的盛宴

Description

There are nn distinct integers. Now there are mm integers that belong to the set GG.

Aw Dundun defines this set with the following rules:

  • If xGx \in G, then x+aGx + a \in G.
  • If x+ax + a is not among the nn integers, then do nothing.
  • If for a set GG there are no elements that need to be added, then it is complete.

If the set is complete, output Great Set!. Otherwise, output at least how many more ingredients must be added according to the rules to make it complete.

Input Format

The first line is an integer nn, meaning there are nn integers in total.

The next line contains nn integers AiA_i separated by spaces, all distinct.

The next line is a positive integer mm, meaning there are mm integers in the set GG, and all of them are among the nn integers.

The next line contains mm integers separated by spaces.

The last line is a positive integer aa.

Output Format

If this set is already complete, output Great Set!.

Otherwise, output the number of integers needed to make this set complete.

5
1 2 3 4 5
3
1 3 5
2
Great Set!
15
13 2 10 3 1 12 8 4 5 7 9 6 15 14 11 
7
13 2 1 12 8 3 10 
2
8
50
13 2 10 50 1 28 37 32 30 46 19 47 33 41 24 34 27 42 49 18 9 48 23 35 31 8 7 12 6 5 3 22 43 36 11 40 26 4 44 17 39 38 15 14 25 16 29 20 21 45 
10
50 46 30 32 10 2 28 37 1 13 
3
31

Hint

Sample Explanation

Sample 1 Explanation

This set contains 1,3,51, 3, 5. Here, 1+2=31 + 2 = 3, 3+2=53 + 2 = 5, and 5+2=75 + 2 = 7 does not exist, so this set is complete.

Sample 2 Explanation

All remaining integers belong to this set.

Constraints

  • 1m<n6×1041 \le m < n \le 6 \times 10^4.
  • 1Ain1 \le A_i \le n.
  • 0a1040 \le a \le 10^4.

Bundled Testcases

Test Point ID Time Limit Score Allocation n,mn, m \le
Subtask1\rm Subtask 1 400ms\rm 400ms 10pts\rm 10pts 10310^3
Subtask2\rm Subtask 2 15pts\rm 15pts 10410^4
Subtask3\rm Subtask 3 35pts\rm 35pts 3×1043 \times 10^4
Subtask4\rm Subtask 4 40pts\rm 40pts 6×1046 \times 10^4

P.S.\rm P.S. The time limit for this problem has been set to 15\bf 15 times that of std\rm std. Some test points are included in the attachment.

Translated by ChatGPT 5