#include<cstring>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
void FailureFunction(char P[], int F[],int m){
int i,j;
F[0]=0; // assignment is important!
j=0;
i=1;
while(i<m){ // that i is less than the length of pattern
if(P[i]==P[j]){
F[i]=j+1;
i++;
j++;