#define _USE_MATH_DEFINES/////////////////////////////////////////////////////
#include <bits/stdc++.h>//////////////////////////////////////////////////////
#ifdef LOC////////////////////////////////////////////////////////////////////
#include "debuglib.h"/////////////////////////////////////////////////////////
#else/////////////////////////////////////////////////////////////////////////
#define deb(...)//////////////////////////////////////////////////////////////
#define DBP(...)//////////////////////////////////////////////////////////////
#endif////////////////////////////////////////////////////////////////////////
#define x first///////////////////////////////////////////////////////////////
#define y second//////////////////////////////////////////////////////////////
#define mp make_pair//////////////////////////////////////////////////////////
#define pb push_back//////////////////////////////////////////////////////////
#define sz(x)int((x).size())//////////////////////////////////////////////////
#define each(a,x)for(auto&a:(x))//////////////////////////////////////////////
#define all(x)(x).begin(),(x).end()///////////////////////////////////////////
#define rep(i,b,e)for(int i=(b);i<(e);i++)////////////////////////////////////
using namespace std;using namespace rel_ops;using ll=int64_t;using Pii=pair///
<int,int>;using ull=uint64_t;using Vi=vector<int>;void run();int main(){cin.//
sync_with_stdio(0);cin.tie(0);cout<<fixed<<setprecision(20);run();return 0;}//
//--------------------------------------------------------------------------//
constexpr int N_MODS = 3;
constexpr ull MODS[N_MODS] = { 2146496003, 2146496057, 2146496071 };
constexpr ull BASE = 29;
struct Hash {
ull v[N_MODS] = {};
Hash() {}
Hash(ull val) {
rep(i, 0, N_MODS) v[i] = val % MODS[i];
}
Hash& operator+=(const Hash& r) {
rep(i, 0, N_MODS) {
v[i] += r.v[i];
if (v[i] >= MODS[i]) v[i] -= MODS[i];
}
return *this;
}
Hash& operator*=(const Hash& r) {
rep(i, 0, N_MODS) v[i] = (v[i] * r.v[i]) % MODS[i];
return *this;
}
bool operator==(const Hash& r) {
rep(i, 0, N_MODS) if (v[i] != r.v[i]) return false;
return true;
}
};
void run() {
while (getchar_unlocked() != '\n') {}
Hash baseMult = BASE, curMult = 1;
Hash forward = 0, backward = 0;
while (true) {
int chr = getchar_unlocked();
if (chr < 'a' || chr > 'z') break;
Hash cur = chr-'a';
backward *= baseMult;
backward += cur;
cur *= curMult;
forward += cur;
curMult *= baseMult;
}
bool ans = (forward == backward);
cout << (ans ? "TAK" : "NIE") << endl;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | #define _USE_MATH_DEFINES///////////////////////////////////////////////////// #include <bits/stdc++.h>////////////////////////////////////////////////////// #ifdef LOC//////////////////////////////////////////////////////////////////// #include "debuglib.h"///////////////////////////////////////////////////////// #else///////////////////////////////////////////////////////////////////////// #define deb(...)////////////////////////////////////////////////////////////// #define DBP(...)////////////////////////////////////////////////////////////// #endif//////////////////////////////////////////////////////////////////////// #define x first/////////////////////////////////////////////////////////////// #define y second////////////////////////////////////////////////////////////// #define mp make_pair////////////////////////////////////////////////////////// #define pb push_back////////////////////////////////////////////////////////// #define sz(x)int((x).size())////////////////////////////////////////////////// #define each(a,x)for(auto&a:(x))////////////////////////////////////////////// #define all(x)(x).begin(),(x).end()/////////////////////////////////////////// #define rep(i,b,e)for(int i=(b);i<(e);i++)//////////////////////////////////// using namespace std;using namespace rel_ops;using ll=int64_t;using Pii=pair/// <int,int>;using ull=uint64_t;using Vi=vector<int>;void run();int main(){cin.// sync_with_stdio(0);cin.tie(0);cout<<fixed<<setprecision(20);run();return 0;}// //--------------------------------------------------------------------------// constexpr int N_MODS = 3; constexpr ull MODS[N_MODS] = { 2146496003, 2146496057, 2146496071 }; constexpr ull BASE = 29; struct Hash { ull v[N_MODS] = {}; Hash() {} Hash(ull val) { rep(i, 0, N_MODS) v[i] = val % MODS[i]; } Hash& operator+=(const Hash& r) { rep(i, 0, N_MODS) { v[i] += r.v[i]; if (v[i] >= MODS[i]) v[i] -= MODS[i]; } return *this; } Hash& operator*=(const Hash& r) { rep(i, 0, N_MODS) v[i] = (v[i] * r.v[i]) % MODS[i]; return *this; } bool operator==(const Hash& r) { rep(i, 0, N_MODS) if (v[i] != r.v[i]) return false; return true; } }; void run() { while (getchar_unlocked() != '\n') {} Hash baseMult = BASE, curMult = 1; Hash forward = 0, backward = 0; while (true) { int chr = getchar_unlocked(); if (chr < 'a' || chr > 'z') break; Hash cur = chr-'a'; backward *= baseMult; backward += cur; cur *= curMult; forward += cur; curMult *= baseMult; } bool ans = (forward == backward); cout << (ans ? "TAK" : "NIE") << endl; } |
English