1 /**************************************************************
2 Problem: 3555
3 User: HansBug
4 Language: Pascal
5 Result: Accepted
6 Time:18504 ms
7 Memory:10764 kb
8 ****************************************************************/
9
10 const p=314159;q=951413;
11 type arr=array[0..50000,1..2] of int64;
12 var
13 i,j,k,l,m,n,t:longint;
14 ans,x,y:int64;ch:char;
15 ap:array[char] of longint;
16 ml,a,b:arr;
17 ss:ansistring;
18 st:array[0..50000] of ansistring;
19 procedure sort(l,r:longint;var a:arr);
20 var i,j:longint;x,y,z:int64;
21 begin
22 i:=l;j:=r;x:=a[(l+r) div 2,1];y:=a[(l+r) div 2,2];
23 repeat
24 while (a[i,1]<x) or ((a[i,1]=x) and (a[i,2]<y)) do inc(i);
25 while (a[j,1]>x) or ((a[j,1]=x) and (a[j,2]>y)) do dec(j);
26 if i<=j then
27 begin
28 z:=a[i,1];a[i,1]:=a[j,1];a[j,1]:=z;
29 z:=a[i,2];a[i,2]:=a[j,2];a[j,2]:=z;
30 inc(i);dec(j);
31 end;
32 until i>j;
33 if i<r then sort(i,r,a);
34 if l<j then sort(l,j,a);
35 end;
36 begin
37 readln(n,m,t);
38 fillchar(ap,sizeof(ap),0);
39 if t=64 then
40 begin
41 i:=0;
42 for ch:=‘A‘ to ‘Z‘ do
43 begin
44 inc(i);
45 ap[ch]:=i;
46 end;
47 for ch:=‘a‘ to ‘z‘ do
48 begin
49 inc(i);
50 ap[ch]:=i;
51 end;
52 for ch:=‘0‘ to ‘9‘ do
53 begin
54 inc(i);
55 ap[ch]:=i;
56 end;
57 inc(i);ap[‘_‘]:=i;
58 inc(i);ap[‘@‘]:=i;
59 end
60 else
61 begin
62 ap[‘0‘]:=1;
63 ap[‘1‘]:=2;
64 ap[‘2‘]:=3;
65 end;
66 ml[0,1]:=1;ml[0,2]:=1;
67 for i:=1 to 1000 do
68 begin
69 ml[i,1]:=(ml[i-1,1]*p) mod q;
70 ml[i,2]:=(ml[i-1,2]*q) mod p;
71 end;
72 for i:=1 to n do
73 begin
74 readln(ss);
75 x:=0;y:=0;st[i]:=ss;
76 for j:=1 to m do
77 begin
78 x:=(x+(ap[ss[j]]*ml[j,1]) mod q) mod q;
79 y:=(y+(ap[ss[j]]*ml[j,2]) mod p) mod p;
80 end;
81 a[i,1]:=x;a[i,2]:=y;
82 end;
83 ans:=0;
84 for i:=1 to m do
85 begin
86
87 for j:=1 to n do
88 begin
89 b[j,1]:=(a[j,1]-(ap[st[j][i]]*ml[i,1]) mod q+q) mod q;
90 b[j,2]:=(a[j,2]-(ap[st[j][i]]*ml[i,2]) mod p+p) mod p;
91 end;
92 sort(1,n,b);
93 b[n+1,1]:=-maxlongint;b[n+1,2]:=-maxlongint;
94 k:=1;l:=1;
95 for j:=2 to n+1 do
96 begin
97 if (b[j,1]<>b[k,1]) or (b[j,2]<>b[k,2]) then
98 begin
99 ans:=ans+(l*(l-1)) div 2;
100 k:=j;l:=1;
101 end
102 else inc(l);
103 end;
104 end;
105 writeln(ans);
106 readln;
107 end.