The hottest guy at DAIICT happens to be a pro-coder named Kabir. Your best friend has a huge crush on Kabir. Kabir is hot but he is weird too.He has decided that he will only date the girls who can convert a pseudo-code provided by him to an efficient running code.
if i is odd
t[i] = Prefix(i,S)
else
t[i]=Rev(Prefix(i,S))
He has provided a string S and t is an array of strings.
Prefix(i,s) is a function that returns the substring of s including characters 1 to i (both inclusive) in a 1-based indexing.
Rev(s) returns the reverse of string s.
You will be asked to run the following part q times (q -> No of queries to be provided). You will also be provided the value of k
Queue Q
for 1:n
Q.enqueue(t[i])
char cha
while(k!=0)
a := Q.dequeue()
cha := a.charAt(1)
if length of a is not equal to 1
Q.enqueue(substring(2,n,a))
k = k-1
print cha
substring (i,j,s) returns the substring of s including characters from i to j (both inclusive)
Your best-friend has asked for your help.Your task is to make sure she gets to go on a date with Kabir by implementing an efficient code.
Input:
The first line contains String S.
Second line contains queries q
Next q lines contain the values of k.
Output:
q lines containing the output of each case.
Constraints:
1 <=length of string S <= 1000007
1 <= q <= 10
1 <= k <= 10^12
Note: k will be such that output is always possible.
Setter : Jinesh Shah
abc the t[i] will be as follows :
a
ba
abc
first char saved in cha is a
sixth char saved in cha is c