Problem:
String Search

Determine whether a text T includes a pattern P. Your program should answer for given queries consisting of P_i.

Input

In the first line, a text T is given. In the second line, an integer Q denoting the number of queries is given. In the following Q lines, the patterns P_i are given respectively.

Output

For each question, print 1 if the text includes P_i, or print 0 otherwise.

Constraints

1 ≤ length of T ≤ 1000000

1 ≤ length of P_i ≤ 1000

1 ≤ Q ≤ 10000

The input consists of alphabetical characters and digits

Sample Input 1

aabaaa
4
aa
ba
bb
xyz

Sample Output 1

1
1
0
0

Solution in C (judge verdict: Wrong Answer)

#include <stdio.h>
#include <string.h>
#include <limits.h>

// Pattern????????????32????¶?????????¨??????????????????

int BitapSearch(char *,char *);

int main(){

    char Text[1000001];
    char Pattern[1001];
    int n;
    int i;

    scanf("%s",Text);
    // printf("%s\n",Text);
    scanf("%d",&n);
    // printf("%d\n",n);
    for( i = 0 ; i < n ; i++ ){

        scanf("%s",Pattern);
        // printf("%s\n",Pattern);
        
        if( BitapSearch(Text,Pattern) == 1 ){
            printf("%d\n",1);
        }else{
            printf("%d\n",0);
        }
    }

    return 0;
}

int BitapSearch(char *Text, char *Pattern){
    
    long long R;
    long long pattern_mask[CHAR_MAX+1];
    int i;
    int m = strlen(Pattern);
    
    R = ~1;

    for( i = 0 ; i <= CHAR_MAX ; i++ ){
        pattern_mask[i] = ~0;
    }
    
    for( i = 0 ; i < m ; i++ ){
        pattern_mask[Pattern[i]] &= ~(1<<i);
    }

    for( i = 0 ; Text[i] != '\0' ; i++ ){
        R = R|pattern_mask[Text[i]];
        R = R << 1;
        if( (R & (1<<m)) == 0 ){
            return 1;
        }
    }
    
    return 0;
    
}