1 /**************************************************************
2 Problem: 2938
3 User: Tunix
4 Language: C++
5 Result: Accepted
6 Time:68 ms
7 Memory:3528 kb
8 ****************************************************************/
9
10 //BZOJ 2938
11 #include<vector>
12 #include<cstdio>
13 #include<cstring>
14 #include<cstdlib>
15 #include<iostream>
16 #include<algorithm>
17 #define rep(i,n) for(int i=0;i<n;++i)
18 #define F(i,j,n) for(int i=j;i<=n;++i)
19 #define D(i,j,n) for(int i=j;i>=n;--i)
20 #define pb push_back
21 using namespace std;
22 inline int getint(){
23 int v=0,sign=1; char ch=getchar();
24 while(ch<‘0‘||ch>‘9‘){ if (ch==‘-‘) sign=-1; ch=getchar();}
25 while(ch>=‘0‘&&ch<=‘9‘){ v=v*10+ch-‘0‘; ch=getchar();}
26 return v*sign;
27 }
28 const int N=1e5+10,INF=~0u>>2;
29 typedef long long LL;
30 /******************tamplate*********************/
31 struct Trie{
32 int ch[2],fail;
33 bool sign;
34 }T[N];
35 char s1[N];
36 int cnt=1,Q[N];
37 void ins(){
38 scanf("%s",s1);
39 int x=1,y;
40 rep(i,strlen(s1)){
41 y=s1[i]-‘0‘;
42 if (!T[x].ch[y]) T[x].ch[y]=++cnt;
43 x=T[x].ch[y];
44 }
45 T[x].sign=1;
46 }
47 void make_fail(){
48 int l=0,r=-1;
49 Q[++r]=1;
50 while(l<=r){
51 int x=Q[l++],y,j;
52 T[x].sign|=T[T[x].fail].sign;
53 rep(i,2){
54 j=T[x].fail;
55 while(j && T[j].ch[i]==0) j=T[j].fail;
56 if (T[x].ch[i]){
57 y=T[x].ch[i];
58 T[y].fail=j ? T[j].ch[i] : 1;
59 Q[++r]=y;
60 }else T[x].ch[i]=j ? T[j].ch[i] : 1;
61 }
62 }
63 }
64 bool vis[N],in[N];
65 bool dfs(int x){
66 if (vis[x]) return 0;
67 bool ans=0;
68 if (T[x].sign) return 0;
69 vis[x]=in[x]=1;
70 rep(i,2){
71 if (in[T[x].ch[i]]) return 1;
72 if (!T[T[x].ch[i]].sign) ans|=dfs(T[x].ch[i]);
73 }
74 in[x]=0;
75 return ans;
76 }
77 int main(){
78 #ifndef ONLINE_JUDGE
79 freopen("2938.in","r",stdin);
80 freopen("2938.out","w",stdout);
81 #endif
82 int n=getint();
83 F(i,1,n) ins();
84 make_fail();
85 if (dfs(1)) puts("TAK");
86 else puts("NIE");
87 return 0;
88 }