#include<iostream>
#include<cstdio>
#include<vector>
#include<bits/stdc++.h>
//length, compare, substring finding, delete, insert, replace, reverse
using namespace std;
int Length(string s)
{
int len = 0;
for(int i=0;s[i]!='\0';i++)
{
len++;
}
return len;
}
int Compare(string s1, string s2)
{
int lens1 = Length(s1);
int lens2 = Length(s2);
if(lens1 == lens2)
{
for(int i=0;i<lens1;i++)
{
if(s1[i] == s2[i])
continue;
else
{
if(s1[i] < s2[i])
{
return 1;
}
else
{
return -1;
}
}
}
return 0;
}
else
{
if(lens1 < lens2)
{
for(int i=0;i<lens1;i++)
{
if(s1[i] == s2[i])
{
continue;
}
else
{
if(s1[i] < s2[i])
{
return 1;
}
else
{
return -1;
}
}
}
return 1;
}
else
{
for(int i=0;i<lens2;i++)
{
if(s1[i] == s2[i])
{
continue;
}
else
{
if(s1[i] < s2[i])
{
return 1;
}
else
{
return -1;
}
}
}
return -1;
}
}
}
string Reverse(string s)
{
string res = "";
int len = Length(s);
for(int i=len-1;i>=0;i--)
{
res = res + s[i];
}
return res;
}
vector <int> SubStringFind(string s, string sub)
{
int lens = Length(s);
int lensub = Length(sub);
vector <int> pos;
int paisi = 0;
for(int i=0;i<=lens-lensub;i++)
{
int matched = 0;
for(int j=0;j<lensub;j++)
{
if(sub[j] == s[i+j])
{
matched++;
continue;
}
else
break;
}
if(matched == lensub)
{
pos.push_back(i);
}
}
return pos;
}
string Delete(string s, string sub)
{
int lens = Length(s);
int lensub = Length(sub);
vector <int> pos;
pos = SubStringFind(s,sub);
string res = "";
int kototomo = 0;
for(int i=0;i<lens;i++)
{
if(kototomo > pos.size() || i != pos[kototomo])
{
res = res + s[i];
}
else
{
i+= (lensub-1);
kototomo++;
}
}
return res;
}
string InsertAtPos(string s, int pos, string sub)
{
string res = "";
int lens = Length(s);
int lensub = Length(sub);
for(int i=0;i<pos;i++)
{
res = res + s[i];
}
res = res + sub;
for(int i=pos;i<lens;i++)
{
res = res + s[i];
}
return res;
}
string Replace(string s, string sub1, string sub2)
{
int lens = Length(s);
int lensub1 = Length(sub1);
int lensub2 = Length(sub2);
vector <int> pos;
pos = SubStringFind(s,sub1);
string res;
res = Delete(s,sub1);
for(int i=0;i<pos.size();i++)
{
res = InsertAtPos(res,pos[i]+(i*(lensub2-lensub1)),sub2);
}
return res;
}
int main()
{
//memset(kothay,100,-1);
vector <int> kothay;
string s,sub1,sub2;
int pos;
cin>>s>>sub1>>sub2;
string res = Replace(s,sub1,sub2);
cout<<res;
return 0;
}
I2luY2x1ZGU8aW9zdHJlYW0+CiNpbmNsdWRlPGNzdGRpbz4KI2luY2x1ZGU8dmVjdG9yPgojaW5jbHVkZTxiaXRzL3N0ZGMrKy5oPgovL2xlbmd0aCwgY29tcGFyZSwgc3Vic3RyaW5nIGZpbmRpbmcsIGRlbGV0ZSwgaW5zZXJ0LCByZXBsYWNlLCByZXZlcnNlCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgTGVuZ3RoKHN0cmluZyBzKQp7CiAgICBpbnQgbGVuID0gMDsKICAgIGZvcihpbnQgaT0wO3NbaV0hPSdcMCc7aSsrKQogICAgewogICAgICAgIGxlbisrOwogICAgfQogICAgcmV0dXJuIGxlbjsKfQppbnQgQ29tcGFyZShzdHJpbmcgczEsIHN0cmluZyBzMikKewogICAgaW50IGxlbnMxID0gTGVuZ3RoKHMxKTsKICAgIGludCBsZW5zMiA9IExlbmd0aChzMik7CgogICAgaWYobGVuczEgPT0gbGVuczIpCiAgICB7CiAgICAgICAgZm9yKGludCBpPTA7aTxsZW5zMTtpKyspCiAgICAgICAgewogICAgICAgICAgICBpZihzMVtpXSA9PSBzMltpXSkKICAgICAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgICBlbHNlCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIGlmKHMxW2ldIDwgczJbaV0pCiAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIDE7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBlbHNlCiAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIC0xOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiAwOwogICAgfQogICAgZWxzZQogICAgewogICAgICAgIGlmKGxlbnMxIDwgbGVuczIpCiAgICAgICAgewogICAgICAgICAgICBmb3IoaW50IGk9MDtpPGxlbnMxO2krKykKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgaWYoczFbaV0gPT0gczJbaV0pCiAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBlbHNlCiAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgaWYoczFbaV0gPCBzMltpXSkKICAgICAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiAxOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBlbHNlCiAgICAgICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4gLTE7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIHJldHVybiAxOwogICAgICAgIH0KICAgICAgICBlbHNlCiAgICAgICAgewogICAgICAgICAgICBmb3IoaW50IGk9MDtpPGxlbnMyO2krKykKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgaWYoczFbaV0gPT0gczJbaV0pCiAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBlbHNlCiAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgaWYoczFbaV0gPCBzMltpXSkKICAgICAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiAxOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBlbHNlCiAgICAgICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4gLTE7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIHJldHVybiAtMTsKICAgICAgICB9CiAgICB9Cn0Kc3RyaW5nIFJldmVyc2Uoc3RyaW5nIHMpCnsKICAgIHN0cmluZyByZXMgPSAiIjsKICAgIGludCBsZW4gPSBMZW5ndGgocyk7CiAgICBmb3IoaW50IGk9bGVuLTE7aT49MDtpLS0pCiAgICB7CiAgICAgICAgcmVzID0gcmVzICsgc1tpXTsKICAgIH0KICAgIHJldHVybiByZXM7Cn0KCnZlY3RvciA8aW50PiBTdWJTdHJpbmdGaW5kKHN0cmluZyBzLCBzdHJpbmcgc3ViKQp7CiAgICBpbnQgbGVucyA9IExlbmd0aChzKTsKICAgIGludCBsZW5zdWIgPSBMZW5ndGgoc3ViKTsKICAgIHZlY3RvciA8aW50PiBwb3M7CiAgICBpbnQgcGFpc2kgPSAwOwogICAgZm9yKGludCBpPTA7aTw9bGVucy1sZW5zdWI7aSsrKQogICAgewogICAgICAgIGludCBtYXRjaGVkID0gMDsKICAgICAgICBmb3IoaW50IGo9MDtqPGxlbnN1YjtqKyspCiAgICAgICAgewogICAgICAgICAgICBpZihzdWJbal0gPT0gc1tpK2pdKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBtYXRjaGVkKys7CiAgICAgICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgICAgfQogICAgICAgICAgICBlbHNlCiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICB9CiAgICAgICAgaWYobWF0Y2hlZCA9PSBsZW5zdWIpCiAgICAgICAgewogICAgICAgICAgICBwb3MucHVzaF9iYWNrKGkpOwogICAgICAgIH0KICAgIH0KICAgIHJldHVybiBwb3M7Cn0KCnN0cmluZyBEZWxldGUoc3RyaW5nIHMsIHN0cmluZyBzdWIpCnsKICAgIGludCBsZW5zID0gTGVuZ3RoKHMpOwogICAgaW50IGxlbnN1YiA9IExlbmd0aChzdWIpOwogICAgdmVjdG9yIDxpbnQ+IHBvczsKICAgIHBvcyA9IFN1YlN0cmluZ0ZpbmQocyxzdWIpOwogICAgc3RyaW5nIHJlcyA9ICIiOwogICAgaW50IGtvdG90b21vID0gMDsKICAgIGZvcihpbnQgaT0wO2k8bGVucztpKyspCiAgICB7CiAgICAgICAgaWYoa290b3RvbW8gPiBwb3Muc2l6ZSgpIHx8IGkgIT0gcG9zW2tvdG90b21vXSkKICAgICAgICB7CiAgICAgICAgICAgIHJlcyA9IHJlcyArIHNbaV07CiAgICAgICAgfQogICAgICAgIGVsc2UKICAgICAgICB7CiAgICAgICAgICAgIGkrPSAobGVuc3ViLTEpOwogICAgICAgICAgICBrb3RvdG9tbysrOwogICAgICAgIH0KICAgIH0KICAgIHJldHVybiByZXM7Cn0KCnN0cmluZyBJbnNlcnRBdFBvcyhzdHJpbmcgcywgaW50IHBvcywgc3RyaW5nIHN1YikKewogICAgc3RyaW5nIHJlcyA9ICIiOwogICAgaW50IGxlbnMgPSBMZW5ndGgocyk7CiAgICBpbnQgbGVuc3ViID0gTGVuZ3RoKHN1Yik7CiAgICBmb3IoaW50IGk9MDtpPHBvcztpKyspCiAgICB7CiAgICAgICAgcmVzID0gcmVzICsgc1tpXTsKICAgIH0KICAgIHJlcyA9IHJlcyArIHN1YjsKICAgIGZvcihpbnQgaT1wb3M7aTxsZW5zO2krKykKICAgIHsKICAgICAgICByZXMgPSByZXMgKyBzW2ldOwogICAgfQogICAgcmV0dXJuIHJlczsKfQoKc3RyaW5nIFJlcGxhY2Uoc3RyaW5nIHMsIHN0cmluZyBzdWIxLCBzdHJpbmcgc3ViMikKewogICAgaW50IGxlbnMgPSBMZW5ndGgocyk7CiAgICBpbnQgbGVuc3ViMSA9IExlbmd0aChzdWIxKTsKICAgIGludCBsZW5zdWIyID0gTGVuZ3RoKHN1YjIpOwoKICAgIHZlY3RvciA8aW50PiBwb3M7CiAgICBwb3MgPSBTdWJTdHJpbmdGaW5kKHMsc3ViMSk7CiAgICBzdHJpbmcgcmVzOwogICAgcmVzID0gRGVsZXRlKHMsc3ViMSk7CiAgICBmb3IoaW50IGk9MDtpPHBvcy5zaXplKCk7aSsrKQogICAgewogICAgICAgIHJlcyA9IEluc2VydEF0UG9zKHJlcyxwb3NbaV0rKGkqKGxlbnN1YjItbGVuc3ViMSkpLHN1YjIpOwogICAgfQogICAgcmV0dXJuIHJlczsKfQoKaW50IG1haW4oKQp7CiAgICAvL21lbXNldChrb3RoYXksMTAwLC0xKTsKICAgIHZlY3RvciA8aW50PiBrb3RoYXk7CiAgICBzdHJpbmcgcyxzdWIxLHN1YjI7CiAgICBpbnQgcG9zOwogICAgY2luPj5zPj5zdWIxPj5zdWIyOwogICAgc3RyaW5nIHJlcyA9IFJlcGxhY2UocyxzdWIxLHN1YjIpOwogICAgY291dDw8cmVzOwogICAgcmV0dXJuIDA7Cn0=