SAS003  Apoorv Loves Primes
Given two arrays A and B of size n and x.Apoorv is given an empty array P.He has to fill the array according to the following conditions:
for each i in range (0 to x1){
if b[i] is negative (insert the subarray from A[abs(B[i]] to A[n1] in P at the end)
else (insert the subarray from A[0]to A[B[i]] in P at the end)
}
Since Apoorv loves Prime numbers He wants to know the Kth prime number in P after the above operation is completed.
So given q queries Apoorv has to report the kth prime number in it.If kth prime doesn't exist print 1.
Note:Both A and B are 0 indexed.abs stands for absolute value.
Constraints:
1<=n<=100000
1<=x<=100000
1<=A[i]<=1000000
0<=abs(B[i])<=n1
1<=q<=10000
1<=k<=10000000000
Input
First line will contain n size of A.
Second line will contain n space separated integers denoting A[i].
Third line will contain x denoting size of B.
Fourth line will contain x space separated integers denoting B[i].
Fifth line will contain q denoting number of queries.
Sixth line will contain q space separated integers denoting k.
Output
Print q lines denoting output for each query.
Example
Input: 3
2 3 4
1
2
3
1 2 3
Output:
2
3
1
Explanation : P is [2,3,4] so for k=1 answer is 2 ,for k=2 answer is 3,for k=3 answer=1 because 3rd prime number doesn't exist.
hide comments
aman_sachin200:
20180618 14:09:51
Nice One SAS!! 

nadstratosfer:
20180609 22:07:35
Mehmet, try this:


mehmetin:
20180609 18:04:28
We have to find kth prime in array p according to insertion order or according to index of ordered primes?


nadstratosfer:
20180606 23:57:38
Is it meant to be solvable with Python, Sasmit? My mem use is quite disturbing but the nonO(1)answers approach will TLE for sure. Please increase the limit slightly if I'm following the right path.


hodobox:
20180606 14:18:37
Two comments: the code in the statement would probably look better preformatted. The constraints on B[i] are actually 0 <= abs(B[i]) <= n1.

Added by:  sas1905 
Date:  20180606 
Time limit:  1s 
Source limit:  50000B 
Memory limit:  1536MB 
Cluster:  Cube (Intel G860) 
Languages:  All 
Resource:  Other Contest. 