#include <bits/stdc++.h>   using namespace std;   namespace fft {   struct num {     double x, y;     num() { x = y = 0; }     num(double x, double y) : x(x), y(y) {}   };   inline num operator+(num a, num b) { return num(a.x + b.x, a.y + b.y); }   inline num operator-(num a, num b) { return num(a.x - b.x, a.y - b.y); }   inline num operator*(num a, num b) {     return num(a.x * b.x - a.y * b.y, a.x * b.y + a.y * b.x);   }   inline num conj(num a) { return num(a.x, -a.y); }   int base = 1;   vector<num> roots = {{0, 0}, {1, 0}};   vector<int> rev = {0, 1};   const double PI = acosl(-1.0);   void ensure_base(int nbase) {     if (nbase <= base) return;     rev.resize(1 << nbase);     for (int i = 0; i < (1 << nbase); i++)       rev[i] = (rev[i >> 1] >> 1) + ((i & 1) << (nbase - 1));     roots.resize(1 << nbase);     while (base < nbase) {       double angle = 2 * PI / (1 << (base + 1));       for (int i = 1 << (base - 1); i < (1 << base); i++) {         roots[i << 1] = roots[i];         double angle_i = angle * (2 * i + 1 - (1 << base));         roots[(i << 1) + 1] = num(cos(angle_i), sin(angle_i));       }       base++;     }   }   void fft(vector<num> &a, int n = -1) {     if (n == -1) n = a.size();     assert((n & (n - 1)) == 0);     int zeros = __builtin_ctz(n);     ensure_base(zeros);     int shift = base - zeros;     for (int i = 0; i < n; i++)       if (i < (rev[i] >> shift)) swap(a[i], a[rev[i] >> shift]);     for (int k = 1; k < n; k <<= 1) {       for (int i = 0; i < n; i += 2 * k) {         for (int j = 0; j < k; j++) {           num z = a[i + j + k] * roots[j + k];           a[i + j + k] = a[i + j] - z;           a[i + j] = a[i + j] + z;         }       }     }   }   vector<num> fa, fb;   vector<int> multiply_mod(vector<int> &a, vector<int> &b, int m, int eq = 0) {     int need = a.size() + b.size() - 1;     int nbase = 0;     while ((1 << nbase) < need) nbase++;     ensure_base(nbase);     int sz = 1 << nbase;     if (sz > (int)fa.size()) fa.resize(sz);     for (int i = 0; i < (int)a.size(); i++) {       int x = (a[i] % m + m) % m;       fa[i] = num(x & ((1 << 15) - 1), x >> 15);     }     fill(fa.begin() + a.size(), fa.begin() + sz, num{0, 0});     fft(fa, sz);     if (sz > (int)fb.size()) fb.resize(sz);     if (eq)       copy(fa.begin(), fa.begin() + sz, fb.begin());     else {       for (int i = 0; i < (int)b.size(); i++) {         int x = (b[i] % m + m) % m;         fb[i] = num(x & ((1 << 15) - 1), x >> 15);       }       fill(fb.begin() + b.size(), fb.begin() + sz, num{0, 0});       fft(fb, sz);     }     double ratio = 0.25 / sz;     num r2(0, -1), r3(ratio, 0), r4(0, -ratio), r5(0, 1);     for (int i = 0; i <= (sz >> 1); i++) {       int j = (sz - i) & (sz - 1);       num a1 = (fa[i] + conj(fa[j]));       num a2 = (fa[i] - conj(fa[j])) * r2;       num b1 = (fb[i] + conj(fb[j])) * r3;       num b2 = (fb[i] - conj(fb[j])) * r4;       if (i != j) {         num c1 = (fa[j] + conj(fa[i]));         num c2 = (fa[j] - conj(fa[i])) * r2;         num d1 = (fb[j] + conj(fb[i])) * r3;         num d2 = (fb[j] - conj(fb[i])) * r4;         fa[i] = c1 * d1 + c2 * d2 * r5;         fb[i] = c1 * d2 + c2 * d1;       }       fa[j] = a1 * b1 + a2 * b2 * r5;       fb[j] = a1 * b2 + a2 * b1;     }     fft(fa, sz);     fft(fb, sz);     vector<int> res(need);     for (int i = 0; i < need; i++) {       long long aa = fa[i].x + 0.5;       long long bb = fb[i].x + 0.5;       long long cc = fa[i].y + 0.5;       res[i] = (aa + ((bb % m) << 15) + ((cc % m) << 30)) % m;     }     return res;   }   vector<int> square_mod(vector<int> &a, int m) {     return multiply_mod(a, a, m, 1);   }   };  // namespace fft   const int N = 2e5 + 100;   const int H_NM = 1;   int seed[H_NM] = {(int)(1e3 + 7)};   int mod[H_NM] = {(int)(1e9 + 9)};   int pws[H_NM][N];   int add(int x, int y, int mod) {     x += y;     if (x >= mod) x -= mod;     return x;   }   int mul(int x, int y, int mod) { return ((long long)x * y) % mod; }   struct Hash {     int vals[H_NM];     int len;     Hash() {       len = 0;       memset(vals, 0, sizeof vals);     }     Hash(int te[]) {       for (int i = 0; i < H_NM; i++) {         vals[i] = te[i];       }     }     void push_back(int x) {       for (int i = 0; i < H_NM; i++) {         vals[i] = add(vals[i], mul(pws[i][len], x, mod[i]), mod[i]);       }       len++;     }     bool operator<(const Hash &oth) const {       for (int i = 0; i < H_NM; i++) {         if (vals[i] < oth.vals[i]) return 1;         if (vals[i] > oth.vals[i]) return 0;       }       return 1;     }     bool operator==(const Hash &oth) const {       for (int i = 0; i < H_NM; i++) {         if (vals[i] != oth.vals[i]) return 0;       }       return 1;     }   };   void init() {     for (int i = 0; i < H_NM; i++) {       pws[i][0] = 1;       for (int j = 1; j < N; j++) {         pws[i][j] = mul(pws[i][j - 1], seed[i], mod[i]);       }     }   }   char s[N];   char t[N];   int p[N];   void read() {     for (int i = 0; i < 26; i++) {       scanf( %d , &p[i]);       p[i]--;     }     scanf( %s , s);     scanf( %s , t);   }   vector<vector<int> > divAlpha() {     int vis[26] = {};     vector<vector<int> > res;     int sz = 2;     for (int i = 0; i < 26; i++) {       int x = i;       if (vis[x]) continue;       vis[x] = 1;       while (1) {         if (vis[p[x]]) {           if (vis[x] == vis[p[x]]) {             vis[x] = 3;             sz = 3;           }           break;         }         vis[p[x]] = vis[x] ^ 3;         x = p[x];       }     }     res.resize(sz);     for (int i = 0; i < 26; i++) {       res[vis[i] - 1].push_back(i);     }     return res;   }   Hash genHashVal(char *s, int n, vector<int> alpha) {     Hash res;     bool ok[26] = {};     for (auto a : alpha) ok[a] = 1;     for (int i = 0; i < n; i++) {       if (ok[s[i] -  a ])         res.push_back(s[i] -  a  + 1);       else         res.push_back(0);     }     return res;   }   int ans[N];   int n, m;   void pro(vector<int> &alpha) {     Hash val = genHashVal(s, n, alpha);     vector<int> res[H_NM];     bool ok[26] = {};     for (auto a : alpha) ok[a] = 1;     int vl[26] = {};     for (auto a : alpha) {       vl[a] = a + 1;       vl[p[a]] = a + 1;     }     for (int j = 0; j < H_NM; j++) {       vector<int> a;       vector<int> b;       int pw = 1;       for (int i = 0; i < n; i++) {         if (ok[s[i] -  a ])           a.push_back(pw);         else           a.push_back(0);         pw = mul(pw, seed[j], mod[j]);       }       for (int i = 0; i < m; i++) {         b.push_back(vl[t[i] -  a ]);       }       reverse(a.begin(), a.end());       res[j] = fft::multiply_mod(a, b, mod[j]);     }     for (int i = n - 1, it = 0; it < m - n + 1; i++, it++) {       int arr[H_NM];       for (int j = 0; j < H_NM; j++) {         arr[j] = res[j][i];       }       Hash te(arr);       if (!(te == val)) {         ans[it] = 0;       }     }   }   int main() {     init();     read();     n = strlen(s);     m = strlen(t);     for (int i = 0; i < m - n + 1; i++) {       ans[i] = 1;     }     vector<vector<int> > alphaParts = divAlpha();     for (auto alpha : alphaParts) {       pro(alpha);     }     for (int i = 0; i < m - n + 1; i++) printf( %d , ans[i]);     return 0;   }