#include <bits/stdc++.h>
using namespace std;
const int base0 = 233;
const int base1 = 2333;
const int base2 = 23333;
const int md0 = 666623333;
const int md1 = 1000109107;
const int md2 = 1004535809;
inline void add(int &x, int y, int md) {
x += y;
if (x >= md) {
x -= md;
}
}
inline void sub(int &x, int y, int md) {
x -= y;
if (x < 0) {
x += md;
}
}
inline int mul(int x, int y, int md) {
return (long long)x * y % md;
}
inline int power(int x, int y, int md) {
int result = 1;
for (; y; y >>= 1, x = mul(x, x, md)) {
if (y & 1) {
result = mul(result, x, md);
}
}
return result;
}
int main() {
#ifdef wxh010910
freopen("input.txt", "r", stdin);
#endif
char c = getchar();
while (!isdigit(c)) {
c = getchar();
}
while (isdigit(c)) {
c = getchar();
}
while (!isalpha(c)) {
c = getchar();
}
int hash0 = 0, coef0 = 1, rev_hash0 = 0;
int hash1 = 0, coef1 = 1, rev_hash1 = 0;
while (isalpha(c)) {
hash0 = mul(hash0, base0, md0);
add(hash0, c, md0);
hash1 = mul(hash1, base1, md1);
add(hash1, c, md1);
add(rev_hash0, mul(coef0, c, md0), md0);
add(rev_hash1, mul(coef1, c, md1), md1);
coef0 = mul(coef0, base0, md0);
coef1 = mul(coef1, base1, md1);
c = getchar();
}
puts(hash0 == rev_hash0 && hash1 == rev_hash1 ? "TAK" : "NIE");
return 0;
}
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 | #include <bits/stdc++.h> using namespace std; const int base0 = 233; const int base1 = 2333; const int base2 = 23333; const int md0 = 666623333; const int md1 = 1000109107; const int md2 = 1004535809; inline void add(int &x, int y, int md) { x += y; if (x >= md) { x -= md; } } inline void sub(int &x, int y, int md) { x -= y; if (x < 0) { x += md; } } inline int mul(int x, int y, int md) { return (long long)x * y % md; } inline int power(int x, int y, int md) { int result = 1; for (; y; y >>= 1, x = mul(x, x, md)) { if (y & 1) { result = mul(result, x, md); } } return result; } int main() { #ifdef wxh010910 freopen("input.txt", "r", stdin); #endif char c = getchar(); while (!isdigit(c)) { c = getchar(); } while (isdigit(c)) { c = getchar(); } while (!isalpha(c)) { c = getchar(); } int hash0 = 0, coef0 = 1, rev_hash0 = 0; int hash1 = 0, coef1 = 1, rev_hash1 = 0; while (isalpha(c)) { hash0 = mul(hash0, base0, md0); add(hash0, c, md0); hash1 = mul(hash1, base1, md1); add(hash1, c, md1); add(rev_hash0, mul(coef0, c, md0), md0); add(rev_hash1, mul(coef1, c, md1), md1); coef0 = mul(coef0, base0, md0); coef1 = mul(coef1, base1, md1); c = getchar(); } puts(hash0 == rev_hash0 && hash1 == rev_hash1 ? "TAK" : "NIE"); return 0; } |
English