#include <bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define fst first #define snd second #define int4 int32_t #define LL long long #define int LL #define FOR(i,a,b) for(int(i)=(a)-(int)((a)>(b));(i)!=(b)-(int)((a)>(b));(i)+=((a)<(b))?1:-1) #define REP(b) FOR(i, 0, b) #define REP1(b) FOR(i, 1, (b)+1) #define REV(b) FOR(i, b, 0) #define REV1(b) FOR(i, (b)+1, 1) #define ITER(i, b) for (auto (i) : (b)) #define ALL(x) (x).begin(), (x).end() #define sz(x) ((int)(x).size()) #define VI vector<int> #define PII pair<int,int> #define LD long double template<class C> void minu(C& a4, C b4) { a4 = min(a4, b4); } template<class C> void maxu(C& a4, C b4) { a4 = max(a4, b4); } template<class TH> void _dbg(const char *sdbg, TH h) { while(*sdbg==' ') sdbg++; if(*sdbg!='\"' && *sdbg!='\'')cerr<<" "<<sdbg<<"="<<h<<"\n"; else cerr<<" "<<h<<"\n"; } template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) { while(*sdbg==' ') sdbg++; if(*sdbg!='\"' && *sdbg!='\'') { cerr<<" "; while(*sdbg!=',')cerr<<*sdbg++; cerr<<"="<<h<<","; _dbg(sdbg+1, a...); } else { while(*sdbg!=',') sdbg++; cerr<<" "<<h<<","; _dbg(sdbg+1, a...); } } template<class T> ostream &operator<<(ostream &os, vector<T> V) { os<<"[";for(auto vv:V)os<<vv<<",";return os<<"]"; } template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) { return os << "(" << P.fst << "," << P.snd << ")"; } int XXXX_XXXX_XXXX; #ifdef LOCAL #define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__) #define scanf(...) (XXXX_XXXX_XXXX=scanf(__VA_ARGS__)) #else #define debug(...) (__VA_ARGS__) #define cerr if(0)cout #endif int mld=1e9; char a; void gcu() { a=getchar_unlocked(); } int32_t main() { while(a<'0' || a>'9') gcu(); while(a>='0' && a<='9') gcu(); int poc[3]{0, 0, 0}; int kon[3]{0, 0, 0}; int mod[3]{mld+7, mld+9, mld+696969}; int wyk[3]{26, 29, 31}; int pot[3]{1, 1, 1}; while(a<'a' || a>'z') gcu(); while(a>='a' && a<='z') { int war=a-'a'; for(int i=0; i<3; i++) { poc[i]=(poc[i]*wyk[i]+war)%mod[i]; kon[i]=(kon[i]+pot[i]*war)%mod[i]; pot[i]=(pot[i]*wyk[i])%mod[i]; } gcu(); } bool git=1; for(int i=0; i<3; i++) if(poc[i]!=kon[i]) git=0; if(git) { printf("TAK\n"); } else { printf("NIE\n"); } }
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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | #include <bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define fst first #define snd second #define int4 int32_t #define LL long long #define int LL #define FOR(i,a,b) for(int(i)=(a)-(int)((a)>(b));(i)!=(b)-(int)((a)>(b));(i)+=((a)<(b))?1:-1) #define REP(b) FOR(i, 0, b) #define REP1(b) FOR(i, 1, (b)+1) #define REV(b) FOR(i, b, 0) #define REV1(b) FOR(i, (b)+1, 1) #define ITER(i, b) for (auto (i) : (b)) #define ALL(x) (x).begin(), (x).end() #define sz(x) ((int)(x).size()) #define VI vector<int> #define PII pair<int,int> #define LD long double template<class C> void minu(C& a4, C b4) { a4 = min(a4, b4); } template<class C> void maxu(C& a4, C b4) { a4 = max(a4, b4); } template<class TH> void _dbg(const char *sdbg, TH h) { while(*sdbg==' ') sdbg++; if(*sdbg!='\"' && *sdbg!='\'')cerr<<" "<<sdbg<<"="<<h<<"\n"; else cerr<<" "<<h<<"\n"; } template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) { while(*sdbg==' ') sdbg++; if(*sdbg!='\"' && *sdbg!='\'') { cerr<<" "; while(*sdbg!=',')cerr<<*sdbg++; cerr<<"="<<h<<","; _dbg(sdbg+1, a...); } else { while(*sdbg!=',') sdbg++; cerr<<" "<<h<<","; _dbg(sdbg+1, a...); } } template<class T> ostream &operator<<(ostream &os, vector<T> V) { os<<"[";for(auto vv:V)os<<vv<<",";return os<<"]"; } template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) { return os << "(" << P.fst << "," << P.snd << ")"; } int XXXX_XXXX_XXXX; #ifdef LOCAL #define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__) #define scanf(...) (XXXX_XXXX_XXXX=scanf(__VA_ARGS__)) #else #define debug(...) (__VA_ARGS__) #define cerr if(0)cout #endif int mld=1e9; char a; void gcu() { a=getchar_unlocked(); } int32_t main() { while(a<'0' || a>'9') gcu(); while(a>='0' && a<='9') gcu(); int poc[3]{0, 0, 0}; int kon[3]{0, 0, 0}; int mod[3]{mld+7, mld+9, mld+696969}; int wyk[3]{26, 29, 31}; int pot[3]{1, 1, 1}; while(a<'a' || a>'z') gcu(); while(a>='a' && a<='z') { int war=a-'a'; for(int i=0; i<3; i++) { poc[i]=(poc[i]*wyk[i]+war)%mod[i]; kon[i]=(kon[i]+pot[i]*war)%mod[i]; pot[i]=(pot[i]*wyk[i])%mod[i]; } gcu(); } bool git=1; for(int i=0; i<3; i++) if(poc[i]!=kon[i]) git=0; if(git) { printf("TAK\n"); } else { printf("NIE\n"); } } |