#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; using ll = long long; constexpr int mod[2] = {(int)1e9 + 7, (int)1e9 + 9}, p = 29; int h[2][2], x[2] = {1, 1}; void put_ans(string s) { for (char c : s) putc_unlocked(c, stdout); putc_unlocked('\n', stdout); } int main() { while (true) { char c = getc_unlocked(stdin); if ('a' <= c and c <= 'z') { for (int i = 0; i < 2; ++i) { h[i][0] = (((ll)h[i][0] * p) + (c - 'a' + 1)) % mod[i]; h[i][1] = (((ll)(c - 'a' + 1) * x[i]) + h[i][1]) % mod[i]; x[i] = ((ll)x[i] * p) % mod[i]; } } if (c == EOF) break; } put_ans((h[0][0] == h[0][1] and h[1][0] == h[1][1])? "TAK" : "NIE"); }
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 | #pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; using ll = long long; constexpr int mod[2] = {(int)1e9 + 7, (int)1e9 + 9}, p = 29; int h[2][2], x[2] = {1, 1}; void put_ans(string s) { for (char c : s) putc_unlocked(c, stdout); putc_unlocked('\n', stdout); } int main() { while (true) { char c = getc_unlocked(stdin); if ('a' <= c and c <= 'z') { for (int i = 0; i < 2; ++i) { h[i][0] = (((ll)h[i][0] * p) + (c - 'a' + 1)) % mod[i]; h[i][1] = (((ll)(c - 'a' + 1) * x[i]) + h[i][1]) % mod[i]; x[i] = ((ll)x[i] * p) % mod[i]; } } if (c == EOF) break; } put_ans((h[0][0] == h[0][1] and h[1][0] == h[1][1])? "TAK" : "NIE"); } |