P6586 "JROI-1" Konjac Hotpot Feast

Background

Click to expand for a better reading experience. The background is not related to solving the problem. ---------- It is said that there is a poem in front of the konjac hotpot restaurant that serves immortals: Before the stove, uselessly boiling green mountains, not knowing the divine furnace as one comes and goes. With jade bowls and fine wine, who begs for gifts? With a jeweled zither and silver arrows, who can climb? Wind rises, night air connects to the Milky Way, rain stops, autumn light reaches the blue bay. Yet he laughs at the old servant’s truly tired eyes, in this empty heart there is only a ball of leisure. ---- Qiuly is the head chef of Luogu’s famous restaurant “Konjac Hotpot Restaurant”. There are many helpers, such as the silly Aw Dundun, the clever Cocoly1990, and the cute 45dino. Qiuly likes to have Dundun prepare rich and diverse ingredients. The essentials for making hotpot include (but are not limited to) seven-star octopus and wasabi caviar, and of course, all kinds of rare and strange ingredients: - Konjac dumplings made from konjac jelly. - Glutinous rice (mist) qingtuan made from glutinous rice. - “Caiji cake” made from Aw Dundun. - Bamboo (45dino). These ingredients are hard to collect, but the immortal Qiuly still got them all. Next, she wants Dundun to **classify these ingredients**. But Dundun is a “caiji” (pinyin: càijī; meaning a newbie) and cannot classify them at all, so he breaks down. Then he asks you, an IOI AKer, to help him classify these ingredients. Because this problem is related to Qiuly’s result (IOI first place or second place), you must do it as soon as possible. Each ingredient has all kinds of weird properties. Based on these properties, Aw Dundun consulted experts from all over the world and obtained **a deliciousness score** for an ingredient. With this score, one can **classify ingredients effectively**. If you cannot give the answer **within $\bf 400$ milliseconds**, you will become an ingredient and sink gloriously into the soup base carefully prepared by Qiuly.

Description

There are $n$ distinct integers. Now there are $m$ integers that belong to the set $G$. Aw Dundun defines this set with the following rules: - If $x \in G$, then $x + a \in G$. - If $x + a$ is not among the $n$ integers, then do nothing. - If for a set $G$ 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 $n$, meaning there are $n$ integers in total. The next line contains $n$ integers $A_i$ separated by spaces, **all distinct**. The next line is a positive integer $m$, meaning there are $m$ integers in the set $G$, and all of them are among the $n$ integers. The next line contains $m$ integers separated by spaces. The last line is a positive integer $a$.

Output Format

If this set is already complete, output `Great Set!`. Otherwise, output the number of integers needed to make this set complete.

Explanation/Hint

### Sample Explanation #### Sample 1 Explanation This set contains $1, 3, 5$. Here, $1 + 2 = 3$, $3 + 2 = 5$, and $5 + 2 = 7$ does not exist, so this set is complete. #### Sample 2 Explanation All remaining integers belong to this set. ### Constraints - $1 \le m < n \le 6 \times 10^4$. - $1 \le A_i \le n$. - $0 \le a \le 10^4$. ### Bundled Testcases | Test Point ID | Time Limit | Score Allocation | $n, m \le$ | |:------------:|:----------:|:----------------:|:----------:| | $\rm Subtask 1$ | $\rm 400ms$ | $\rm 10pts$ | $10^3$ | | $\rm Subtask 2$ | $\rm 400ms$ | $\rm 15pts$ | $10^4$ | | $\rm Subtask 3$ | $\rm 400ms$ | $\rm 35pts$ | $3 \times 10^4$ | | $\rm Subtask 4$ | $\rm 400ms$ | $\rm 40pts$ | $6 \times 10^4$ | $\rm P.S.$ The time limit for this problem has been set to $\bf 15$ times that of $\rm std$. Some test points are included in the attachment. Translated by ChatGPT 5