#include <bits/stdc++.h>
using namespace std;
int b[300010];
void kmpPreprocess(string P, int m)
{
int i = 0, j = -1;
b[0] = -1;
while (i < m)
{
while (j >= 0 && P[i] != P[j])
{
j = b[j];
}
i++;
j++;
b[i] = j;
}
}
int main()
{
string s,ss;
while(cin>>s)
{
int x=s.size();
ss=s;
reverse(s.begin(),s.end());
s=s+"~"+ss;
int m=s.size();
kmpPreprocess(s, m);
for(int i=b[m-1]+1;i<x;i++)
ss+=s[i];
cout<<ss<<endl;
}
return 0;
}
using namespace std;
int b[300010];
void kmpPreprocess(string P, int m)
{
int i = 0, j = -1;
b[0] = -1;
while (i < m)
{
while (j >= 0 && P[i] != P[j])
{
j = b[j];
}
i++;
j++;
b[i] = j;
}
}
int main()
{
string s,ss;
while(cin>>s)
{
int x=s.size();
ss=s;
reverse(s.begin(),s.end());
s=s+"~"+ss;
int m=s.size();
kmpPreprocess(s, m);
for(int i=b[m-1]+1;i<x;i++)
ss+=s[i];
cout<<ss<<endl;
}
return 0;
}
কোন মন্তব্য নেই:
একটি মন্তব্য পোস্ট করুন