func_code_string: #include <bits/stdc++.h>   using namespace std;   char s[100010], a[110], b[110];   int pa[110], pb[110];   int main() {     scanf( %s%s%s , s, a, b);     int i, j;     j = -1;     pa[0] = -1;     int lena = strlen(a);     for (i = 1; i < lena; i++) {       while (j > -1 && a[j + 1] != a[i]) j = pa[j];       if (a[j + 1] == a[i]) j++;       pa[i] = j;     }     j = -1;     pb[0] = -1;     int lenb = strlen(b);     for (i = 1; i < lenb; i++) {       while (j > -1 && b[j + 1] != b[i]) j = pb[j];       if (b[j + 1] == b[i]) j++;       pb[i] = j;     }     int len = strlen(s);     int minn = len + 1;     j = -1;     for (i = 0; i < len; i++) {       while (j > -1 && a[j + 1] != s[i]) j = pa[j];       if (a[j + 1] == s[i]) j++;       if (j == lena - 1) {         minn = i;         break;       }     }     bool flag1 = false, flag2 = false;     j = -1;     for (i = minn + 1; i < len; i++) {       while (j > -1 && b[j + 1] != s[i]) j = pb[j];       if (b[j + 1] == s[i]) j++;       if (j == lenb - 1) {         flag1 = true;         break;       }     }     for (i = 0; i < len / 2; i++) swap(s[i], s[len - i - 1]);     j = -1;     minn = len;     for (i = 0; i < len; i++) {       while (j > -1 && a[j + 1] != s[i]) j = pa[j];       if (a[j + 1] == s[i]) j++;       if (j == lena - 1) {         minn = i;         break;       }     }     j = -1;     for (i = minn + 1; i < len; i++) {       while (j > -1 && b[j + 1] != s[i]) j = pb[j];       if (b[j + 1] == s[i]) j++;       if (j == lenb - 1) {         flag2 = true;         break;       }     }     if (flag1 && flag2)       printf( both n );     else if (flag1)       printf( forward n );     else if (flag2)       printf( backward n );     else       printf( fantasy n );     return 0;   }   