#include <bits/stdc++.h>
using namespace std;
bool validCharacter(char c) {
return isalpha(c);
}
bool isP(const string& s) {
int lo = 0;
int hi = s.size() - 1;
while (lo < hi) {
while (!validCharacter(s[lo])) {
++lo;
}
while (!validCharacter(s[hi])) {
--hi;
}
if (tolower(s[lo]) != tolower(s[hi])) {
return false;
}
++lo;
--hi;
}
return true;
}
int main() {
string s = "tab a cat";
cout << isP(s) << endl;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKYm9vbCB2YWxpZENoYXJhY3RlcihjaGFyIGMpIHsKCXJldHVybiBpc2FscGhhKGMpOwp9Cgpib29sIGlzUChjb25zdCBzdHJpbmcmIHMpIHsKCWludCBsbyA9IDA7CiAgICBpbnQgaGkgPSBzLnNpemUoKSAtIDE7CiAgICB3aGlsZSAobG8gPCBoaSkgewogICAgICAgIHdoaWxlICghdmFsaWRDaGFyYWN0ZXIoc1tsb10pKSB7CiAgICAgICAgICAgICsrbG87CiAgICAgICAgfQogICAgICAgIHdoaWxlICghdmFsaWRDaGFyYWN0ZXIoc1toaV0pKSB7CiAgICAgICAgICAgIC0taGk7CiAgICAgICAgfQogICAgICAgIGlmICh0b2xvd2VyKHNbbG9dKSAhPSB0b2xvd2VyKHNbaGldKSkgewogICAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgfQogICAgICAgICsrbG87CiAgICAgICAgLS1oaTsKICAgIH0KICAgIHJldHVybiB0cnVlOwp9CgppbnQgbWFpbigpIHsKCXN0cmluZyBzID0gInRhYiBhIGNhdCI7Cgljb3V0IDw8IGlzUChzKSA8PCBlbmRsOwp9