Eerie Strings

All submissions for this problem are available.
Panda loves strings a lot. He has a kind of strange affinity with strings.
He has been trying to solve several problems of strings for quite a while, and got stuck at one of them.
The problem requires Panda to input two strings A and B each of length N and he needs to make setA for all substrings of string A, and similarly setB for all substrings of string B
His dilemma doesn’t end here. To add the twist to the problem, a value K is also provided to Panda such that he needs to find the answer to four types of queries:
Since, Panda is a weak coder and he needs to solve large number of such queries, help him to solve this problem.
Note
The set will always have distinct substrings.
Input
The first and second lines of the input contain string A and string B respectively.
The third line contains an integer Q denoting the number of queries.
Thereafter, Q lines follow where each line is having two values as input in the form of query.
Each query can be represented as
X K
Where X denotes the type of query
and K denotes the length of the substrings.
Output
For each of the Q queries, you need to output answer on a separate line.
Constraints
Example
Input: abab baba 4 1 2 2 4 3 2 4 4 Output: 2 1 0 2
Explanation
You are provided with strings abab and baba.
All possible substrings of A in set 1 are { a, b, ab, ba , aba, bab , abab }.
All possible substrings of B in set 2 are { a, b , ab , ba , aba , bab , baba }.
We have four queries.
 First one requires to output the number of substrings of length 2 which are in both setA and setB. We have {ab,ba} as required substrings . The answer is 2.
 Second one requires to output the number of substrings of length 4 which are in setA but not in setB. We have {abab} as required substring. The answer is 1.
 Third one requires to output the number of substrings of length 2 which are in setB but not in setA. As, all of 2 length substrings in both the sets are same, the answer is 0.
 Fourth one requires to output the number of substrings of length 4 which are in setA or in setB but not in both. We have {abab, baba} as required substrings. The answer is 2.
Author:  codaitya 
Tags  codaitya 
Date Added:  5032016 
Time Limit:  1 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYP3 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 