Under construction

Still being built. Things may change

Chance! 2

Time limit2sMemory limit1024 MB

Summary
Check, for each allowed spell count K, whether complex a can reach complex b using exactly K moves of +1, doubling, or multiplying by i.
Level

Medium7 of 10

Topics
BFS, Graph, Math
Solved
No attempts yet

Problem

The informatics teachers at Daegu Science High School decided that starting in the second semester of 20242024, test scores will be complex numbers, which have no order, to prevent excessive competition among students. On the data structures exam, Eunseong scored aa and Sanghun scored bb. Both aa and bb are complex numbers. Eunseong admires Sanghun greatly and wants to make his score the same as Sanghun's. So Eunseong learned a spell that changes his score and can now use three spells:

  • Give water: the number increases by 11.
  • Give rice: the number doubles.
  • Chance!: shout Chance! at the number, and it is multiplied by ii (i=−1i=\sqrt{-1}).

For example, if a=1−3ia=1-3i and b=6+4ib=6+4i, Eunseong can use the give water, give rice, and Chance! spells in that order to change his score to 2−3i2-3i, then 4−6i4-6i, then 6+4i6+4i. There is no limit on how many times the spells are used, but after each spell, the real part and the imaginary part of Eunseong's score must each have absolute value at most 500500. Eunseong loves the NN positive integers K1,K2,…,KNK_1, K_2, \ldots, K_N, so he wants the number of spells used to be one of them. For each 1≤j≤N1\leq j\leq N, determine whether Eunseong can turn his score into bb using exactly KjK_j spells in total across all three spells.

Input

The first line contains the real part and the imaginary part of Eunseong's score aa, separated by a space. The second line contains the real part and the imaginary part of Sanghun's score bb, separated by a space. The third line contains the number of positive integers NN that Eunseong likes. The fourth line contains the positive integers K1,K2,…,KNK_1, K_2, \ldots, K_N that Eunseong likes, separated by spaces, in ascending order.

Output

Print NN lines. On line jj, print YES if Eunseong can change aa into bb using exactly KjK_j spells, and NO otherwise.

Constraints

  • The real part and the imaginary part of aa each have absolute value at most 500500.
  • The real part and the imaginary part of bb each have absolute value at most 500500.
  • 1≤N≤100001 \leq N \leq 10000
  • 1≤K1<K2<⋯<KN≤1091 \leq K_1 < K_2 < \cdots < K_N \leq 10^9
  • All given numbers are integers.

Examples2

  1. Example 1

    Input
    1 -3
    6 4
    3
    3 5 7
    
    Expected output
    YES
    NO
    YES
    
  2. Example 2

    Input
    -1 0
    -1 0
    4
    1 2 3 4
    
    Expected output
    NO
    YES
    NO
    YES