#include <bits/stdc++.h>
using namespace std;

int main() {
    int N,M,K,b;
    int d=0;
    string S,T;
    cin>>N>>S>>M>>T>>K;
    vector<int> A;
    for(int i=0;i<N;i++){
        if(S[i]==T[0]){
            A.push_back(i);
        }
    }
    for(int i=0;i<A.size();i++){
        int a=1;
        int c=0;
        for(int j=1;j<M;j++){
            if(A[i]+j>N*a){
                a++;
            }
            b=(A[i]+j)%N;
            if(S[b]!=T[j]){
                c=1;
            }
        }
        if(c==0&&a<=K){
            d=1;
        }
    }
    if(d==1){
        cout<<"Yes";
    }else{
        cout<<"No";
    }
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: