#include <iostream>
#include <cstring>
using namespace std;
char s[5001];
char w[5001];
struct node
{
node *pointer[2];
int count;
bool used;
node()
{
pointer[0] = pointer[1] = NULL;
used = false;
count = 0;
}
};
node root;
int dfs(node *cur)
{
if (cur==NULL || !cur->used)
{
return 0;
}
else
{
cur->count = 1 + dfs(cur->pointer[1]) + dfs(cur->pointer[0]);
return cur->count;
}
}
int ansSize = 0;
char ans[5001];
void go(node* cur, int k)
{
if (cur==NULL || k==0 || k>cur->count)
{
cout<<"ERROR"<<endl;
return;
}
if (k==1)
{
return;
}
k--;
if (cur->pointer[0]!=NULL && k<=cur->pointer[0]->count)
{
ans[ansSize++] = '0';
go(cur->pointer[0], k);
}
else
{
ans[ansSize++] = '1';
if (cur->pointer[0] != NULL)
{
k -= cur->pointer[0]->count;
}
go(cur->pointer[1], k);
}
}
int main()
{
int k;
cin>>s>>w>>k;
k++;
int n = strlen(s);
for (int i=0;i<n;i++)
{
node *cur = &root;
for (int j=i;j<n;j++)
{
char t = s[j]-'0';
if (cur->pointer[t]==NULL)
{
cur->pointer[t] = new node();
}
cur=cur->pointer[t];
}
}
n = strlen(w);
root.used = true;
for (int i=0;i<n;i++)
{
node *cur = &root;
for (int j=i;j<n;j++)
{
char t = w[j]-'0';
if (cur->pointer[t] == NULL)
{
break;
}
else
{
cur = cur->pointer[t];
cur->used = true;
}
}
}
dfs(&root);
go(&root, k);
cout<<ans<<endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y3N0cmluZz4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKY2hhciBzWzUwMDFdOwpjaGFyIHdbNTAwMV07CnN0cnVjdCBub2RlCnsKICAgIG5vZGUgKnBvaW50ZXJbMl07CiAgICBpbnQgY291bnQ7Cglib29sIHVzZWQ7Cglub2RlKCkKCXsKCQlwb2ludGVyWzBdID0gcG9pbnRlclsxXSA9IE5VTEw7CgkJdXNlZCA9IGZhbHNlOwoJCWNvdW50ID0gMDsKCX0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