#include <bits/stdc++.h>
#define int long long
using namespace std;
int n,h1,h2,pot,wyk,v,pot1,h3,h4;
char c;
const int mod=1000003871;
const int k=29;
const int mod1=1000053491;
const int k1=31;
inline void f(int &x)
{
register char c=0;
x=0;
while(c<33)c=getchar_unlocked();
do{
x=(x<<1)+(x<<3)+c-'0';
c=getchar_unlocked();
}
while(c>33);
}
main()
{
f(n);
pot=1;
pot1=1;
c=getchar_unlocked();
while(c>='a'&&c<='z')
{
v=c-'a'+1;
c=getchar_unlocked();
h1*=k;
h1+=v;
h1%=mod;
h2+=pot*v;
h2%=mod;
pot*=k;
pot%=mod;
h3*=k1;
h3+=v;
h3%=mod1;
h4+=pot1*v;
h4%=mod1;
pot1*=k1;
pot1%=mod1;
if(c<'a'||c>'z')break;
}
if(h1==h2&&h3==h4)cout<<"TAK";
else cout<<"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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | #include <bits/stdc++.h> #define int long long using namespace std; int n,h1,h2,pot,wyk,v,pot1,h3,h4; char c; const int mod=1000003871; const int k=29; const int mod1=1000053491; const int k1=31; inline void f(int &x) { register char c=0; x=0; while(c<33)c=getchar_unlocked(); do{ x=(x<<1)+(x<<3)+c-'0'; c=getchar_unlocked(); } while(c>33); } main() { f(n); pot=1; pot1=1; c=getchar_unlocked(); while(c>='a'&&c<='z') { v=c-'a'+1; c=getchar_unlocked(); h1*=k; h1+=v; h1%=mod; h2+=pot*v; h2%=mod; pot*=k; pot%=mod; h3*=k1; h3+=v; h3%=mod1; h4+=pot1*v; h4%=mod1; pot1*=k1; pot1%=mod1; if(c<'a'||c>'z')break; } if(h1==h2&&h3==h4)cout<<"TAK"; else cout<<"NIE"; } |
English