Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.

[Image]

Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.

Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.

Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.


-----Input-----

The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.

Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.


-----Output-----

Output a single integer — the number of ways to choose three cards that form a set.


-----Examples-----
Input
3 3
SET
ETS
TSE

Output
1
Input
3 4
SETE
ETSE
TSES

Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES

Output
2


-----Note-----

In the third example test, these two triples of cards are sets:  "SETT", "TEST", "EEET"  "TEST", "ESTE", "STES"

Difficulty: MEDIUM
Tags: Data structures

Implementation

Complete search
Skill types: Data structures

Complete search

Starter code:

Solutions:
import sys

def fastio():
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()

def debug(*var, sep=' ', end='\n'):
	print(*var, file=sys.stderr, end=end, sep=sep)
INF = 10 ** 20
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br
(n, k) = I()
a = []
for i in range(n):
	a.append(input())
d = Counter(a)
ans = 0
for i in range(n):
	for j in range(i + 1, n):
		possible = ''
		for x in range(k):
			if a[i][x] == a[j][x]:
				possible += a[i][x]
			else:
				ok = a[i][x] + a[j][x]
				if ok in ['SE', 'ES']:
					possible += 'T'
				elif ok in ['ET', 'TE']:
					possible += 'S'
				else:
					possible += 'E'
		ans += d[possible]
print(ans // 3)


import sys, math
input = sys.stdin.readline
(n, k) = map(int, input().split())
cards = set()
card_list = list()
for i in range(n):
	card = input().strip()
	cards.add(card)
	card_list.append(card)
int_char = {1: 'S', 2: 'E', 3: 'T'}
char_int = {'S': 1, 'E': 2, 'T': 3}
xor = 1 ^ 2 ^ 3
ans = 0
for i in range(n):
	for j in range(i + 1, n):
		card = ['' for _ in range(k)]
		for a in range(k):
			if card_list[i][a] != card_list[j][a]:
				x = char_int[card_list[i][a]]
				y = char_int[card_list[j][a]]
				card[a] = int_char[x ^ y]
			else:
				card[a] = card_list[i][a]
		card_str = ''.join(card)
		if card_str in cards:
			ans += 1
print(int(ans / 3))


n = int(input().split()[0])
s = {input() for _ in [0] * n}
a = [['SET'.index(x) for x in y] for y in s]
print(sum((''.join(('SET '[(3 - x - y, x)[x == y]] for (x, y) in zip(a[i], a[j]))) in s for i in range(n) for j in range(i))) // 3)


import sys
from itertools import combinations
input = sys.stdin.readline
h = {'S': 1, 'E': 2, 'T': 3}
(n, k) = map(int, input().split())
strings = set([tuple(map(h.get, input().rstrip())) for _ in range(0, n)])
ans = 0
for (a, b) in combinations(strings, 2):
	c = []
	for i in range(0, k):
		if a[i] == b[i]:
			c.append(a[i])
		else:
			c.append(6 - a[i] - b[i])
	if tuple(c) in strings:
		ans += 1
print(ans // 3)


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def li():
	return list(mi())

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def binarySearch(arr, l, r, x):
	if r >= l:
		mid = l + (r - l) // 2
		if arr[mid] == x:
			return True
		elif arr[mid] > x:
			return binarySearch(arr, l, mid - 1, x)
		else:
			return binarySearch(arr, mid + 1, r, x)
	else:
		return False

def main():
	for i in range(1):
		l = []
		(n, k1) = mi()
		for i in range(n):
			s = si()
			l.append(s)
		l.sort()
		c = 0
		for i in range(n):
			for j in range(i + 1, n):
				ans = ''
				for k in range(k1):
					if l[i][k] == l[j][k]:
						ans += l[i][k]
					else:
						a = ['S', 'E', 'T']
						a.remove(l[i][k])
						a.remove(l[j][k])
						ans += a[0]
				if binarySearch(l, j + 1, n - 1, ans):
					c += 1
		print(c)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


(n, m) = map(int, input().split())
cards = {}
cardsL = []
ans = {}
for i in range(n):
	card = input()
	cards[card] = i
	cardsL.append(card)

def getCard3(A, B, m):
	card3 = ''
	for i in range(m):
		if A[i] == B[i]:
			card3 += A[i]
		elif A[i] != 'T' and B[i] != 'T':
			card3 += 'T'
		elif A[i] != 'E' and B[i] != 'E':
			card3 += 'E'
		elif A[i] != 'S' and B[i] != 'S':
			card3 += 'S'
	return card3
res = 0
for i in range(n - 1):
	for j in range(i + 1, n - 1):
		CardT = getCard3(cardsL[i], cardsL[j], m)
		temp = cards.get(CardT, 0)
		if temp > j:
			res += 1
print(res)


def match(a, b):
	c = ''
	for i in range(len(a)):
		if a[i] == b[i]:
			c += a[i]
		elif a[i] + b[i] == 'SE' or a[i] + b[i] == 'ES':
			c += 'T'
		elif a[i] + b[i] == 'ST' or a[i] + b[i] == 'TS':
			c += 'E'
		else:
			c += 'S'
	return c
(n, k) = map(int, input().split())
s = [input() for i in range(n)]
st = set()
for i in range(n):
	st.add(s[i])
cnt = 0
for i in range(n):
	for j in range(i + 1, n):
		m = match(s[i], s[j])
		cnt += m in st
print(cnt // 3)


def create():
	s = ''
	for i in range(k):
		if x[i] == y[i]:
			s += x[i]
		else:
			s += chr(236 - ord(x[i]) - ord(y[i]))
	return s
l = input().split()
n = int(l[0])
k = int(l[1])
hashi = dict()
count = 0
l = []
for i in range(n):
	s = input()
	hashi[s] = i
	l.append(s)
for i in range(n):
	for j in range(i + 1, n):
		x = l[i]
		y = l[j]
		z = create()
		if z in hashi and hashi[z] > j:
			count += 1
print(count)


(n, k) = input().split(' ')
n = int(n)
k = int(k)
cards = dict()
orderLatter = {'S': 1, 'E': 2, 'T': 3}
for i in range(n):
	card = input()
	card = tuple((orderLatter[card[i]] for i in range(k)))
	cards[card] = i

def getThirdNumber(a, b):
	if a == b:
		return a
	return 6 - a - b

def getThird(c1, c2):
	return tuple((getThirdNumber(c1[i], c2[i]) for i in range(k)))
sum = 0
for c1 in cards.keys():
	for c2 in cards.keys():
		if cards[c1] >= cards[c2]:
			continue
		c3 = getThird(c1, c2)
		if c3 in cards.keys() and cards[c3] > cards[c2]:
			sum += 1
print(sum)


import array
card_set = dict()
n = 0
c_length = 0

def compare(first, second):
	global c_length
	third_card = ''
	for i in range(c_length):
		if first[i] == second[i]:
			third_card += first[i]
		else:
			if (first[i] == 'S' or second[i] == 'S') and (first[i] == 'E' or second[i] == 'E'):
				third_card += 'T'
			if (first[i] == 'S' or second[i] == 'S') and (first[i] == 'T' or second[i] == 'T'):
				third_card += 'E'
			if (first[i] == 'T' or second[i] == 'T') and (first[i] == 'E' or second[i] == 'E'):
				third_card += 'S'
	return third_card

def main():
	global n
	global c_length
	a = input()
	arr = list(map(int, a.split()))
	n = arr[0]
	c_length = arr[1]
	for i in range(n):
		card = input()
		card_set[card] = 0
	i = 0
	for key in card_set:
		card_set[key] = i
		i = i + 1
	result_count = 0
	for (first_card, index1) in card_set.items():
		for (second_card, index2) in card_set.items():
			if index2 <= index1:
				continue
			third_card = compare(first_card, second_card)
			if third_card in card_set and card_set[third_card] > index2:
				result_count += 1
	print(result_count)
main()


(n, k) = map(int, input().split())
deck = []
for _ in range(n):
	deck.append(input())
ans = 0
deck.sort()

def thirdChar(a, b):
	if a == b:
		return a
	if a == 'S' and b == 'T' or (a == 'T' and b == 'S'):
		return 'E'
	if a == 'S' and b == 'E' or (a == 'E' and b == 'S'):
		return 'T'
	if a == 'E' and b == 'T' or (a == 'T' and b == 'E'):
		return 'S'

def findThird(c1, c2):
	l = []
	for i in range(k):
		l.append(thirdChar(c1[i], c2[i]))
	return ''.join(l)

def binarySearch(sortedList, elem):
	l = 0
	r = len(sortedList) - 1
	while l <= r:
		m = (l + r) // 2
		if elem == sortedList[m]:
			return m
		if elem > sortedList[m]:
			l = m + 1
		else:
			r = m - 1
	return -1
for (i, c1) in enumerate(deck):
	for c2 in deck[i + 1:]:
		c3 = findThird(c1, c2)
		if c3 > c2 and binarySearch(deck, c3) != -1:
			ans += 1
print(ans)


(n, k) = map(int, input().split(' '))
cards_set = set()
cards_l = []
for _ in range(n):
	card = str(input())
	cards_set.add(card)
	cards_l.append(card)
dict = {'S': 0, 'E': 1, 'T': 2}
my_list = ['S', 'E', 'T']
ans = 0
for i in range(n):
	for j in range(i + 1, n):
		s = str()
		for c in range(k):
			if cards_l[i][c] != cards_l[j][c]:
				s = s + my_list[3 - dict[cards_l[i][c]] - dict[cards_l[j][c]]]
			else:
				s = s + cards_l[i][c]
		if s in cards_set:
			ans += 1
print(ans // 3)


n = int(input().split()[0])
s = set()
r = 0
for _ in [0] * n:
	t = input()
	for x in s:
		r += ''.join((chr((66 ^ ord(u)) * (u != v) ^ ord(v)) for (u, v) in zip(x, t))) in s
	s |= {t}
print(r // 2)


a = input().split()
n = int(a[0])
k = int(a[1])
l = []
t = 0
for i in range(n):
	a = input()
	l.append(a)
X = set(l)
for i in range(0, n - 1):
	for j in range(i + 1, n):
		r = ''
		for u in range(k):
			if l[i][u] == l[j][u]:
				r = r + l[i][u]
			else:
				r = r + chr(ord('S') + ord('T') + ord('E') - ord(l[i][u]) - ord(l[j][u]))
		if r in X:
			t += 1
print(int(t / 3))


import sys
input = lambda : sys.stdin.readline().rstrip()
(n, k) = map(int, input().split())
a = []
for i in range(n):
	s = input()
	a.append(s)
st = set(a)
st2 = {'SE': 'T', 'ES': 'T', 'ST': 'E', 'TS': 'E', 'ET': 'S', 'TE': 'S'}
ans = 0
for i in range(n):
	for j in range(i + 1, n):
		need = ''
		for p in range(k):
			if a[i][p] == a[j][p]:
				need += a[i][p]
			elif a[i][p] != a[j][p]:
				need += st2[a[i][p] + a[j][p]]
		if need in st:
			ans += 1
print(ans // 3)


(n, k) = map(int, input().split())
(cards, res, lock_cards) = ([], 0, set())
for _ in range(n):
	cards.append(input())
cards2 = set(cards)
for i in range(0, n - 1):
	a = cards[i]
	for j in range(i + 1, n):
		b = cards[j]
		example = ''
		for z in range(k):
			if a[z] != b[z]:
				letters = ['S', 'E', 'T']
				letters.remove(a[z])
				letters.remove(b[z])
				example += letters[0]
			else:
				example += a[z]
		if example in cards2:
			res += 1
print(res // 3)


(n, k) = list(map(int, input().split()))
words = []
was = dict()
for i in range(n):
	a = input()
	words.append(a)
	was[a] = i
ans = 0
for i in range(n):
	for i1 in range(i + 1, n):
		s = ''
		for j in range(k):
			a = ['S', 'E', 'T']
			if words[i][j] == words[i1][j]:
				s += words[i][j]
			elif words[i][j] == 'S' and words[i1][j] == 'T':
				s += 'E'
			elif words[i][j] == 'S' and words[i1][j] == 'E':
				s += 'T'
			elif words[i][j] == 'E' and words[i1][j] == 'T':
				s += 'S'
			elif words[i][j] == 'E' and words[i1][j] == 'S':
				s += 'T'
			elif words[i][j] == 'T' and words[i1][j] == 'E':
				s += 'S'
			elif words[i][j] == 'T' and words[i1][j] == 'S':
				s += 'E'
		if s in was:
			if was[s] > i1:
				ans += 1
print(ans)


def solve():
	(n, k) = map(int, input().split())
	d = set()
	a = [None] * n
	tr = {'S': 0, 'E': 1, 'T': 2}
	r = 0
	for i in range(n):
		z = 0
		for c in input():
			z = z * 4 + tr[c]
		a[i] = z
	d = set(a)
	for i in range(n):
		for j in range(i):
			(ii, jj) = (a[i], a[j])
			t = ii ^ jj
			tt = t >> 1 & 6148914691236517205 | t & 6148914691236517205
			ff = (ii | jj) ^ (tt | tt << 1)
			r += ff in d
	print(r // 3)
solve()


def count_hyperset(cards, n, k):
	ans = 0
	in_cards = dict()
	pairs = set()
	for i in range(len(cards)):
		in_cards[cards[i]] = i
	lookFor = [''] * k
	for i in range(len(cards) - 2):
		for j in range(i + 1, len(cards) - 1):
			if (i, j) in pairs:
				continue
			for u in range(k):
				if cards[i][u] == cards[j][u]:
					lookFor[u] = cards[i][u]
					continue
				if cards[i][u] == 'S':
					lookFor[u] = 'T' if cards[j][u] == 'E' else 'E'
				elif cards[i][u] == 'E':
					lookFor[u] = 'T' if cards[j][u] == 'S' else 'S'
				else:
					lookFor[u] = 'E' if cards[j][u] == 'S' else 'S'
			look_str = ''.join(lookFor)
			res = in_cards.get(look_str, -1)
			if res == -1:
				continue
			ans += 1
			pairs.add((i, j))
			pairs.add((i, res))
			pairs.add((j, res))
	return ans
inp = input().split()
n = int(inp[0])
k = int(inp[1])
cards = [''] * n
for i in range(n):
	cards[i] = input()
ans = count_hyperset(cards, n, k)
print(ans)


(n, k) = list(map(int, input().split()))
data = set()
mapping = {'S': 0, 'E': 1, 'T': 2}
for _ in range(n):
	data.add(tuple(map(mapping.get, input())))

def find(x, y):
	res = []
	for i in range(k):
		res.append((3 - (x[i] + y[i]) % 3) % 3)
	return tuple(res)
res = 0
for x in data:
	for y in data:
		if x != y:
			z = find(x, y)
			if z in data:
				res += 1
print(res // 6)


from sys import stdin, stdout
(n, m) = list(map(int, stdin.readline().split()))
l = []
for i in range(n):
	l.append(input())
out = 0
d = {}
for i in l:
	d[i] = 1
l = list(d.keys())
n = len(l)
for i in range(n - 1):
	a = l[i]
	for j in range(i + 1, n):
		b = l[j]
		nw = ''
		for k in range(m):
			if a[k] == b[k]:
				nw += a[k]
			else:
				v = a[k] + b[k]
				if v == 'ST' or v == 'TS':
					nw += 'E'
				elif v == 'SE' or v == 'ES':
					nw += 'T'
				elif v == 'ET' or v == 'TE':
					nw += 'S'
		if d.get(nw, 0):
			out += 1
stdout.write(str(out // 3))


class Trie:

	def __init__(self, N):
		self.N = N
		self.tree = [[-1, -1, -1, 0]]

	def add(self, s):
		tree = self.tree
		cur = 0
		for i in range(self.N):
			if tree[cur][s[i]] == -1:
				tree.append([-1, -1, -1, 0])
				tree[cur][s[i]] = len(tree) - 1
			cur = tree[cur][s[i]]
		tree[cur][3] += 1

	def count(self, s):
		tree = self.tree
		cur = 0
		for i in range(self.N):
			if tree[cur][s[i]] == -1:
				return 0
			cur = tree[cur][s[i]]
		return tree[cur][3]

def match(a, b):
	return [a[i] if a[i] == b[i] else 3 - a[i] - b[i] for i in range(len(a))]

def change(s):
	return [0 if s[i] == 'S' else 1 if s[i] == 'E' else 2 for i in range(len(s))]
(n, k) = map(int, input().split())
s = [change(input()) for i in range(n)]
trie = Trie(k)
for i in range(n):
	trie.add(s[i])
cnt = 0
for i in range(n):
	for j in range(i + 1, n):
		m = match(s[i], s[j])
		cnt += trie.count(m) - (s[i] == m) - (s[j] == m)
print(cnt // 3)


(n, k) = map(int, input().split())
st = {}
s = []
ans = 0
for i in range(n):
	kk = input()
	s.append(kk)
	if kk in st:
		st[kk] += 1
	else:
		st[kk] = 1
for i in range(n):
	st[s[i]] -= 1
	for j in range(i + 1, n):
		temp = ''
		for ii in range(k):
			if s[i][ii] == s[j][ii]:
				temp += s[i][ii]
			elif s[i][ii] == 'S' and s[j][ii] == 'T':
				temp += 'E'
			elif s[i][ii] == 'S' and s[j][ii] == 'E':
				temp += 'T'
			elif s[i][ii] == 'E' and s[j][ii] == 'T':
				temp += 'S'
			elif s[i][ii] == 'T' and s[j][ii] == 'S':
				temp += 'E'
			elif s[i][ii] == 'E' and s[j][ii] == 'S':
				temp += 'T'
			elif s[i][ii] == 'T' and s[j][ii] == 'E':
				temp += 'S'
		if temp in st:
			if st[temp] > 0:
				ans += 1
print(ans // 2)


def gen(a, b):
	gener = ''
	for i in range(k):
		if a[i] == b[i]:
			gener += a[i]
		elif 'S' not in (a[i], b[i]):
			gener += 'S'
		elif 'E' not in (a[i], b[i]):
			gener += 'E'
		else:
			gener += 'T'
	return gener
(n, k) = list(map(int, input().split()))
cards = []
diff = set()
for i in range(n):
	s = input()
	cards.append(s)
	diff.add(s)
ans = 0
was = set()
for i in range(n):
	for j in range(i + 1, n):
		aaa = gen(cards[i], cards[j])
		if aaa in diff and max(cards[i], cards[j], aaa) + min(cards[i], cards[j], aaa) not in was:
			ans += 1
			was.add(max(cards[i], cards[j], aaa) + min(cards[i], cards[j], aaa))
print(ans)


import io
import os
from collections import Counter, defaultdict, deque
import sys
sys.setrecursionlimit(10 ** 5)

def choose3(n):
	return n * (n - 1) * (n - 2) // 6

def solve(N, K, A):
	freq = Counter(A)
	ans = 0
	for v in freq.values():
		if v >= 3:
			ans += choose3(v)
	keys = sorted(freq.keys())
	for i in range(len(keys)):
		for j in range(i + 1, len(keys)):
			x = keys[i]
			y = keys[j]
			if x == y:
				continue
			target = []
			for k in range(K):
				if x[k] == y[k]:
					target.append(x[k])
				else:
					for c in 'SET':
						if c != x[k] and c != y[k]:
							target.append(c)
							break
			z = ''.join(target)
			if x < y < z:
				if z in freq:
					ans += freq[x] * freq[y] * freq[z]
	return ans
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
(N, K) = [int(x) for x in input().split()]
A = [input().decode().rstrip() for i in range(N)]
ans = solve(N, K, A)
print(ans)


(x, y) = map(int, input().split())
mp = {}
s = []
for n in range(x):
	j = input()
	if j not in mp:
		mp[j] = 1
	else:
		mp[j] += 1
	s.append(j)
res = 0

def ret(a, b):
	st = 'SET'
	for n in st:
		if n != a and n != b:
			return n
for n in range(x):
	for k in range(n + 1, x):
		st = ''
		for v in range(y):
			if s[n][v] == s[k][v]:
				st += s[n][v]
			else:
				st += ret(s[n][v], s[k][v])
		if st in mp:
			res += 1
		if s[n] == s[k]:
			res -= 2
print(res // 3)


from sys import stdin, stdout
import math
from bisect import bisect_left, bisect_right
input = lambda : stdin.readline().strip()
print = lambda s: stdout.write(s)
(n, k) = map(int, input().split())
ls = []
for i in range(n):
	ls.append(input())
d = {}
for i in ls:
	try:
		d[i] += 1
	except:
		d[i] = 1
cnt = 0
for i in range(n):
	for j in range(i + 1, n):
		s1 = ls[i]
		s2 = ls[j]
		ans = ''
		for index in range(k):
			if s1[index] == s2[index]:
				ans += s1[index]
			elif s1[index] in ['S', 'E'] and s2[index] in ['S', 'E']:
				ans += 'T'
			elif s1[index] in ['S', 'T'] and s2[index] in ['S', 'T']:
				ans += 'E'
			elif s1[index] in ['T', 'E'] and s2[index] in ['T', 'E']:
				ans += 'S'
		try:
			d[ans] += 0
			cnt += d[ans]
		except:
			pass
print(str(cnt // 3) + '\n')


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ans = ['SET', 'EST', 'TES', 'ETS', 'TSE', 'STE']
for _ in range(1):
	(n, k) = map(int, input().split())
	d = dict()
	ls = []
	for i in range(n):
		s = input()
		ls.append(s)
		d[s] = i
	cnt = 0
	for i in range(n):
		for j in range(i + 1, n):
			s1 = ''
			for f in range(k):
				if ls[i][f] == ls[j][f]:
					s1 += ls[i][f]
				else:
					for p in range(6):
						if ls[i][f] == ans[p][0] and ls[j][f] == ans[p][1]:
							s1 += ans[p][2]
							break
			m = d.get(s1)
			if m is not None and m > j:
				cnt += 1
	sys.stdout.write(str(cnt))


import sys
input = sys.stdin.readline
(n, k) = map(int, input().split())
cards = []
for _ in range(n):
	c = input().rstrip()
	cards.append(c)
check = set(cards)

def thirdCard(c1, c2, k):
	c3 = []
	for (p1, p2) in zip(c1, c2):
		if p1 == p2:
			c3.append(p1)
		else:
			if p1 != 'S' and p2 != 'S':
				p3 = 'S'
			elif p1 != 'E' and p2 != 'E':
				p3 = 'E'
			else:
				p3 = 'T'
			c3.append(p3)
	return ''.join(c3)
ctr = 0
for i in range(n):
	for j in range(i + 1, n):
		card3 = thirdCard(cards[i], cards[j], k)
		if card3 in check:
			ctr += 1
print(ctr // 3)


(n, k) = [int(i) for i in input().split()]
a = []
d = {}
for i in range(n):
	s = input()
	a.append(s)
	d[s] = i
c = 0
for i in range(n - 2):
	for j in range(i + 1, n - 1):
		e = []
		for ka in range(k):
			if a[i][ka] == a[j][ka]:
				e.append(a[i][ka])
			elif a[i][ka] != 'S' and a[j][ka] != 'S':
				e.append('S')
			elif a[i][ka] != 'E' and a[j][ka] != 'E':
				e.append('E')
			elif a[i][ka] != 'T' and a[j][ka] != 'T':
				e.append('T')
		s = ''.join(e)
		ind = d.get(s, -1)
		if ind > j:
			c += 1
print(c)


import sys
input = sys.stdin.readline
from collections import Counter
(N, K) = map(int, input().split())
Ss = [input().rstrip() for _ in range(N)]
D = Counter(Ss)
ans = 0
for v in D.values():
	ans += v * (v - 1) * (v - 2) // 6
p = 0
for i in range(N - 1):
	S1 = Ss[i]
	for j in range(i + 1, N):
		S2 = Ss[j]
		remain_S = ''
		for k in range(K):
			if S1[k] == S2[k]:
				remain_S += S1[k]
			else:
				for s in 'TES':
					if s != S1[k] and s != S2[k]:
						remain_S += s
						break
		if remain_S in D and remain_S != S1:
			p += D[remain_S]
ans += p // 3
print(ans)


import sys
from collections import defaultdict

def third(a, b):
	s = ''
	for i in range(len(a)):
		if a[i] == b[i]:
			s = s + a[i]
		else:
			if a[i] == 'S':
				if b[i] == 'E':
					s = s + 'T'
				else:
					s = s + 'E'
			if a[i] == 'E':
				if b[i] == 'S':
					s = s + 'T'
				else:
					s = s + 'S'
			if a[i] == 'T':
				if b[i] == 'S':
					s = s + 'E'
				else:
					s = s + 'S'
	return s
dic = defaultdict(lambda : -1)
(n, k) = map(int, sys.stdin.readline().split())
(l, ans) = ([], 0)
for _ in range(n):
	s = sys.stdin.readline()[:-1]
	dic[s] = _
	l.append(s)
vis = defaultdict(int)
for i in range(n):
	for j in range(i + 1, n):
		s = third(l[i], l[j])
		if dic[s] != -1:
			b = [i, j, dic[s]]
			b.sort()
			if vis[tuple(b)] == 0:
				ans += 1
				vis[tuple(b)] = 1
print(ans)


(n, kk) = list(map(int, input().split()))
cards = ['S', 'E', 'T']
cs = []
res = 0
rec = set()
for i in range(n):
	c = input()
	cs.append(c)
	rec.add(c)
for i in range(len(cs) - 1):
	for j in range(i + 1, len(cs)):
		new = ''
		for k in range(kk):
			if cs[i][k] == cs[j][k]:
				new += cs[i][k]
			else:
				for t in cards:
					if t != cs[i][k] and t != cs[j][k]:
						new += t
		if new in rec:
			res += 1
print(res // 3)


import sys
I = sys.stdin.readline
n = int(I().split()[0])
s = set()
r = 0
for _ in [0] * n:
	t = I()
	for x in s:
		r += ''.join((chr((66 ^ ord(u)) * (u != v) ^ ord(v)) for (u, v) in zip(x, t))) in s
	s |= {t}
print(r // 2)


(n, f) = map(int, input().split())
l = []
for i in range(n):
	t = input()
	l.append(t)
d = set(l)
count = 0
for i in range(n):
	for j in range(i + 1, n):
		temp = ''
		for k in range(f):
			if l[i][k] == l[j][k]:
				temp = temp + l[i][k]
			else:
				add = ['S', 'E', 'T']
				add.remove(l[i][k])
				add.remove(l[j][k])
				temp = temp + add[0]
		if temp in d:
			count = count + 1
print(count // 3)


(N, K) = map(int, input().split())
X = set([int(input().replace('S', '0000100').replace('E', '0001000').replace('T', '0010000'), 2) for _ in range(N)])
m = int('0011100' * K, 2)
ans = 0
while X:
	x = X.pop()
	for y in X:
		if m - (x | y) ^ ((x & y) >> 2) * 31 & m in X:
			ans += 1
print(ans // 2)


from sys import stdin, stdout
from math import gcd, sqrt, factorial
from collections import deque, defaultdict
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
L = lambda : list(R())
P = lambda x: stdout.write(x)
lcm = lambda x, y: x * y // gcd(x, y)
hg = lambda x, y: (y + x - 1) // x * x
pw = lambda x: 0 if x == 1 else 1 + pw(x // 2)
chk = lambda x: chk(x // 2) if not x % 2 else True if x == 1 else False
sm = lambda x: (x ** 2 + x) // 2
N = 10 ** 9 + 7
(n, k) = R()
a = [[0 if j == 'S' else 1 if j == 'T' else 2 for j in S()] for i in range(n)]
p = [3 ** i for i in range(k)]
d = defaultdict(int)
for i in range(n):
	c = 0
	for j in range(k):
		c += a[i][j] * p[j]
	d[c] = 1
ans = 0
for i in range(n - 1):
	for j in range(i + 1, n):
		c = 0
		for el in range(k):
			c += (3 - a[i][el] - a[j][el]) % 3 * p[el]
		ans += d[c]
print(ans // 3)


def gcd(a, b):
	return math.gcd(a, b)

def lcm(a, b):
	return a * b // math.gcd(a, b)

def ncr(n, r):
	return math.comb(n, r)

def npr(n, r):
	return math.factorial(n) // math.factorial(n - r)

def decimal_to_binary(n):
	return bin(n).replace('0b', '')

def binary_to_decimal(s):
	return int(s, 2)
import sys, os.path
import math
from collections import defaultdict, deque
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
S = lambda : list(map(str, input()))

def main():
	(n, k) = I()
	s1 = []
	for i in range(n):
		s = str(input())[:-1]
		s1.append(s)
	from collections import defaultdict
	mem1 = defaultdict(int)
	for i in range(len(s1)):
		mem1[s1[i]] += 1
	ans1 = set()
	s1 = list(set(s1))
	ans = 0
	final = 0
	for i in range(len(s1)):
		for j in range(i + 1, len(s1)):
			if s1[i] == s1[j]:
				continue
			count = 0
			req = ''
			for k1 in range(k):
				if s1[i][k1] == s1[j][k1]:
					count += 1
					req += s1[i][k1]
				elif s1[i][k1] == 'S' and s1[j][k1] == 'E' or (s1[i][k1] == 'E' and s1[j][k1] == 'S'):
					req += 'T'
				elif s1[i][k1] == 'S' and s1[j][k1] == 'T' or (s1[i][k1] == 'T' and s1[j][k1] == 'S'):
					req += 'E'
				elif s1[i][k1] == 'E' and s1[j][k1] == 'T' or (s1[i][k1] == 'T' and s1[j][k1] == 'E'):
					req += 'S'
				elif s1[i][k1] == 'E' and s1[j][k1] == 'E':
					req += 'E'
				elif s1[i][k1] == 'S' and s1[j][k1] == 'S':
					req += 'S'
				elif s1[i][k1] == 'T' and s1[j][k1] == 'T':
					req += 'T'
			if req in mem1:
				ans += mem1[req]
				ans1.add(tuple(sorted([s1[i], s1[j], req])))
	for i in mem1:
		if mem1[i] >= 3:
			ans1.add(tuple(sorted([s1[i], s1[j], req])))
	print(len(ans1))
main()


from math import ceil
from math import factorial
from collections import *
from operator import itemgetter
ii = lambda : int(input())
iia = lambda : list(map(int, input().split()))
isa = lambda : list(input().split())
(n, k) = iia()
s = [0] * n
ss = [0] * k
ee = [0] * k
tt = [0] * k
for i in range(n):
	s[i] = input()
	for j in range(k):
		if s[i][j] == 'S':
			ss[j] += 1
		elif s[i][j] == 'E':
			ee[j] += 1
		else:
			tt[j] += 1
s1 = [0] * n
c = 0
d = defaultdict(lambda : 0)
for i in range(n):
	d[s[i]] += 1
x = ''
for ii in range(n):
	for jj in range(ii + 1, n):
		for i in range(k):
			if s[ii][i] != 'T' and s[jj][i] != 'T' and (s[jj][i] != s[ii][i]):
				x += 'T'
			elif s[ii][i] != 'S' and s[jj][i] != 'S' and (s[jj][i] != s[ii][i]):
				x += 'S'
			elif s[ii][i] != 'E' and s[jj][i] != 'E' and (s[jj][i] != s[ii][i]):
				x += 'E'
			elif s[ii][i] == 'S' and s[jj][i] == 'S':
				x += 'S'
			elif s[ii][i] == 'E' and s[jj][i] == 'E':
				x += 'E'
			elif s[ii][i] == 'T' and s[jj][i] == 'T':
				x += 'T'
		c += d[x]
		x = ''
print(c // 3)


from sys import stdin

def solve():
	map = {'e': 0, 's': 1, 't': 2}

	def get_bits(letters):
		evens = 0
		odds = 0
		for d in (map[e] for e in letters):
			evens = evens << 1 | 1 & d
			odds = odds << 1 | 1 & d >> 1
		return (odds, evens)
	(n, k) = [int(i) for i in stdin.readline().strip().split()]
	cards = [get_bits(stdin.readline().strip().lower()) for _ in range(n)]
	pairs = ((cards[i], cards[j]) for i in range(n) for j in range(i + 1, n))
	cards_set = set(cards)
	counter = 0

	def inc():
		nonlocal counter
		counter += 1
	thirds = ((~x[1] & x[0] & ~y[1] & y[0] | ~x[1] & ~x[0] & y[1] & ~y[0] | ~y[1] & y[0] & ~x[1] & x[0] | ~y[1] & ~y[0] & x[1] & ~x[0], x[1] & ~x[0] & y[1] & ~y[0] | ~x[1] & ~x[0] & ~y[1] & y[0] | y[1] & ~y[0] & x[1] & ~x[0] | ~y[1] & ~y[0] & ~x[1] & x[0]) for (x, y) in pairs)
	tuple((inc() for t in thirds if t in cards_set))
	print(counter // 3)
solve()


(n, m) = (int(x) for x in input().strip().split())
arr = []
d = set()
for i in range(n):
	t = input()
	d.add(t)
	arr.append(t)
cnt = 0
for i in range(n - 1):
	for j in range(i + 1, n):
		s = ''
		for k in range(m):
			if arr[i][k] == arr[j][k]:
				s += arr[i][k]
			else:
				s += chr(ord('S') + ord('E') + ord('T') - ord(arr[i][k]) - ord(arr[j][k]))
		try:
			if s in d:
				cnt += 1
		except:
			continue
print(cnt // 3)


str_input = input().split()
n = int(str_input[0])
k = int(str_input[1])
card = [input() for i in range(n)]
features = {}
for c in card:
	kv = features
	for i in range(k):
		if c[i] not in kv:
			kv[c[i]] = {}
		kv = kv[c[i]]

def solve(f1, f2, f3):
	ret = 0
	if f1 is f2 is f3:
		if f1 == {}:
			return 0
		if len(f1) == 3:
			ret += solve(f1['S'], f1['E'], f1['T'])
		for f in ['S', 'E', 'T']:
			if f in f1:
				ret += solve(f1[f], f1[f], f1[f])
	else:
		if f1 == {} and f2 == {} and (f3 == {}):
			return 1
		if 'S' in f1 and 'S' in f2 and ('S' in f3):
			ret += solve(f1['S'], f2['S'], f3['S'])
		if 'E' in f1 and 'E' in f2 and ('E' in f3):
			ret += solve(f1['E'], f2['E'], f3['E'])
		if 'T' in f1 and 'T' in f2 and ('T' in f3):
			ret += solve(f1['T'], f2['T'], f3['T'])
		if 'S' in f1 and 'E' in f2 and ('T' in f3):
			ret += solve(f1['S'], f2['E'], f3['T'])
		if 'S' in f1 and 'T' in f2 and ('E' in f3):
			ret += solve(f1['S'], f2['T'], f3['E'])
		if 'E' in f1 and 'S' in f2 and ('T' in f3):
			ret += solve(f1['E'], f2['S'], f3['T'])
		if 'E' in f1 and 'T' in f2 and ('S' in f3):
			ret += solve(f1['E'], f2['T'], f3['S'])
		if 'T' in f1 and 'S' in f2 and ('E' in f3):
			ret += solve(f1['T'], f2['S'], f3['E'])
		if 'T' in f1 and 'E' in f2 and ('S' in f3):
			ret += solve(f1['T'], f2['E'], f3['S'])
	return ret
print(solve(features, features, features))


def f():
	(n, k) = [int(s) for s in input().split()]
	if n <= 2:
		return 0
	cards = set()
	nums = {'S': 0, 'T': 1, 'E': 2}
	for i in range(n):
		cards.add(tuple((nums[char] for char in input())))

	def predict(a, b):
		c = [None] * k
		for i in range(k):
			c[i] = (3 - a[i] - b[i]) % 3
		return tuple(c)
	ans = 0
	for i in range(n - 2):
		a = cards.pop()
		for b in cards:
			if predict(a, b) in cards:
				ans += 1
	ans //= 2
	return ans
print(f())


(n, k) = map(int, input().split())
dic = {}
lis = []
for i in range(n):
	s = input()
	if s in dic:
		dic[s] += 1
	else:
		dic[s] = 1
	lis.append(s)
ans = 0
sum = ord('T') + ord('S') + ord('E')
for i in range(n):
	for j in range(i + 1, n):
		tmp = ''
		for l in range(k):
			if lis[i][l] == lis[j][l]:
				tmp += lis[i][l]
			else:
				tmp += chr(sum - ord(lis[i][l]) - ord(lis[j][l]))
		if tmp in dic:
			ans += dic[tmp]
print(int(ans / 3))


(n, k) = map(int, input().split())
ar = []
dic = {'SS': 'S', 'TT': 'T', 'EE': 'E', 'SE': 'T', 'ES': 'T', 'ST': 'E', 'TS': 'E', 'TE': 'S', 'ET': 'S'}
for i in range(n):
	ar.append(input())
arse = set(ar)
count = 0
for i in range(n):
	for j in range(i + 1, n):
		st = ''
		for kk in range(k):
			st += dic[str(ar[i][kk]) + str(ar[j][kk])]
		if st in arse:
			count += 1
print(count // 3)


(n, k) = map(int, input().split())
(a, d) = ([], dict())
for _ in range(n):
	a.append(input())
	d[a[-1]] = True
ans = 0
for i in range(n):
	for j in range(i + 1, n):
		t = ''
		for x in range(k):
			if a[i][x] == a[j][x]:
				t += a[i][x]
			elif a[i][x] == 'S' and a[j][x] == 'E' or (a[i][x] == 'E' and a[j][x] == 'S'):
				t += 'T'
			elif a[i][x] == 'S' and a[j][x] == 'T' or (a[i][x] == 'T' and a[j][x] == 'S'):
				t += 'E'
			else:
				t += 'S'
		if d.get(t) != None:
			ans += 1
print(ans // 3)


cards = set()
(n, k) = (int(i) for i in input().split())
for i in range(n):
	cards.add(input())
res = 0
for first in cards:
	for second in cards:
		third = []
		for i in range(k):
			if first[i] == second[i]:
				third.append(first[i])
			else:
				third.append(chr(ord('S') + ord('E') + ord('T') - ord(first[i]) - ord(second[i])))
		if ''.join(third) in cards:
			res += 1
res -= n
res //= 6
print(res)


from sys import stdin, stdout
input = stdin.readline

def conv2(l1, l2):
	if l1 == l2:
		return l1
	if l1 == 'S':
		if l2 == 'E':
			return 'T'
		return 'E'
	if l1 == 'E':
		if l2 == 'S':
			return 'T'
		return 'S'
	if l1 == 'T':
		if l2 == 'E':
			return 'S'
		return 'E'
(n, k) = map(int, input().split())
sets = [''] * n
g = {}
tot = 0
for i in range(n):
	sets[i] = input().rstrip()
	if g.get(sets[i], 0) > 0:
		tot += g[sets[i]]
	for j in range(0, i):
		string = ''.join([conv2(sets[i][m], sets[j][m]) for m in range(k)])
		g[string] = g.get(string, 0) + 1
stdout.write(str(tot))


(n, k) = map(int, input().split())
(cards, res, lock_cards) = ([], 0, set())
for _ in range(n):
	cards.append(input())
cards2 = set(cards)
for i in range(0, n - 1):
	a = cards[i]
	for j in range(i + 1, n):
		b = cards[j]
		example = ''
		for z in range(k):
			if a[z] == b[z]:
				example += a[z]
			else:
				example += chr(236 - ord(a[z]) - ord(b[z]))
		if example in cards2:
			res += 1
print(res // 3)


(n, k) = list(map(int, input().split()))
a = [input() for i in range(n)]
b = set(a)
E = ord('S') + ord('E') + ord('T')
d = 0
for i in range(n - 1):
	for j in range(i + 1, n):
		c = ''
		for l in range(k):
			if a[i][l] == a[j][l]:
				c = c + a[i][l]
			else:
				c = c + chr(E - ord(a[i][l]) - ord(a[j][l]))
		if c in b:
			d = d + 1
print(d // 3)


import sys

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7
(N, K) = MAP()
A = [input() for i in range(N)]
S = set(A)
D1 = {'S': 1, 'E': 2, 'T': 3}
D2 = {1: 'S', 2: 'E', 3: 'T'}
cnt = 0
for (i, a1) in enumerate(A):
	for j in range(i + 1, N):
		a2 = A[j]
		a3 = ''
		for (k1, k2) in zip(a1, a2):
			if k1 == k2:
				a3 += k1
			else:
				key = 6 - D1[k1] - D1[k2]
				a3 += D2[key]
		if a3 in S:
			cnt += 1
print(cnt // 3)


nd = {}
nd['S'] = 1
nd['E'] = 2
nd['T'] = 3
nl = ' SET'

def revs(s, t):
	if s == t:
		return s
	else:
		return nl[6 - nd[s] - nd[t]]
(n, k) = map(int, input().split())
dic = {}
c = []
for i in range(n):
	C = input()
	dic[C] = i
	c.append(C)
ans = 0
for i in range(n):
	for j in range(i):
		if i == j:
			continue
		nstr = ''
		for p in range(k):
			nstr += revs(c[i][p], c[j][p])
		if nstr in dic and dic[nstr] > i:
			ans += 1
print(ans)


import os
from io import BytesIO, IOBase
import sys
from collections import defaultdict, deque, Counter
from bisect import *
from math import sqrt, pi, ceil, log, inf, gcd, floor
from itertools import permutations
from copy import deepcopy
from heapq import *

def lcm(a, b):
	return a * b // gcd(a, b)

def solve(a):
	b = 'SET'
	for i in b:
		if i not in a:
			return i

def main():
	(n, k) = map(int, input().split())
	b = []
	a = set()
	for i in range(n):
		b.append(input().rstrip())
		a.add(b[-1])
	ans = 0
	for i in range(n):
		for j in range(i + 1, n):
			z = []
			for l in range(k):
				if b[i][l] == b[j][l]:
					z.append(b[i][l])
				else:
					z.append(solve(b[i][l] + b[j][l]))
			if ''.join(z) in a:
				ans += 1
	print(ans // 3)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


(n, k) = map(int, input().split())
d = {}
a = []
import sys
input = sys.stdin.readline
for i in range(n):
	s = input().rstrip()
	a.append(s)
dd = set(a)
for i in range(n):
	u = ''.join(a[i])
	if u in d:
		continue
	d[u] = [0 for x in range(n)]
	d[u][i] = 1
	for j in range(i + 1, n):
		if a[i] == a[j]:
			d[u][j] = d[u][j - 1] + 1
		else:
			d[u][j] = d[u][j - 1]
c = 0
for i in range(n):
	for j in range(i + 1, n):
		z = ''
		l = ['S', 'E', 'T']
		for p in range(k):
			if a[i][p] == a[j][p]:
				z += a[i][p]
			else:
				for y in l:
					if a[i][p] != y and a[j][p] != y:
						z += y
						break
		if z in dd:
			c += d[z][n - 1] - d[z][j]
print(c)


mp = {}
e = [1]
S = ord('S') + ord('T') + ord('E')
(n, k) = map(int, input().split())
ans = 0
for i in range(1, n + 1):
	e.append(input())
	if e[i] in mp:
		mp[e[i]] += 1
	else:
		mp[e[i]] = 1
for i in range(1, n + 1):
	for j in range(i + 1, n + 1):
		if i == j:
			continue
		T = ''
		for x in range(k):
			if e[i][x] == e[j][x]:
				T += e[i][x]
			else:
				T += chr(S - ord(e[i][x]) - ord(e[j][x]))
		if T in mp:
			ans += mp[T]
		else:
			ans += 0
print(int(ans / 3))


def fastio():
	import sys
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()
(n, k) = map(int, input().split())
a = []
for i in range(n):
	s = input()
	a.append(s)
st = set(a)
st2 = {'SE': 'T', 'ES': 'T', 'ST': 'E', 'TS': 'E', 'ET': 'S', 'TE': 'S'}
ans = 0
for i in range(n):
	for j in range(i + 1, n):
		need = ''
		for p in range(k):
			if a[i][p] == a[j][p]:
				need += a[i][p]
			elif a[i][p] != a[j][p]:
				need += st2[a[i][p] + a[j][p]]
		if need in st:
			ans += 1
print(ans // 3)


from collections import Counter
(n, k) = list(map(int, input().split()))
a = list()
for i in range(0, n):
	q = input()
	a.append(q)
c = Counter(a)
ans = 0
for i in range(0, n - 1):
	for j in range(i + 1, n):
		s1 = a[i]
		s2 = a[j]
		q = 'SET'
		s = ''
		for p in range(0, k):
			if s1[p] != s2[p]:
				l = [0] * 3
				if s1[p] == 'S' or s2[p] == 'S':
					l[0] = 1
				if s1[p] == 'E' or s2[p] == 'E':
					l[1] = 1
				if s1[p] == 'T' or s2[p] == 'T':
					l[2] = 1
				for u in range(0, 3):
					if l[u] == 0:
						s = s + q[u]
			else:
				s = s + s1[p]
		ans = ans + c[s]
print(ans // 3)


from collections import *
from sys import stdin
from itertools import combinations

def solve():
	(mem2, ans, chars) = (Counter(a), 0, ord('S') + ord('E') + ord('T'))
	for (key1, key2) in mem.keys():
		third = ''
		for i in range(k):
			if key1[i] == key2[i]:
				third += key1[i]
			else:
				third += chr(chars - (ord(key1[i]) + ord(key2[i])))
		if mem2[third]:
			ans += 1
	return ans // 3
(n, k) = map(int, input().split())
a = [input() for i in range(n)]
com = deque(combinations(a, 2))
mem = Counter(com)
print(solve())


import math
import sys

def listIntInput():
	return list(map(int, input().split(' ')))

def listStrInput():
	return input().split(' ')

def main():
	answer = 0
	(n, k) = listIntInput()
	cards = []
	three = set(['S', 'E', 'T'])
	good_cards = []
	for _ in range(n):
		cards.append(input())
		pass
	for i in range(n):
		for j in range(i + 1, n):
			good_card = ''
			for letter in range(k):
				if cards[i][letter] == cards[j][letter]:
					good_card += cards[i][letter]
				elif 'S' in [cards[i][letter], cards[j][letter]]:
					if 'E' in [cards[i][letter], cards[j][letter]]:
						good_card += 'T'
					else:
						good_card += 'E'
				else:
					good_card += 'S'
			good_cards.append(good_card)
	appearances = dict()
	for card in cards:
		if appearances.get(card, None) == None:
			appearances[card] = 1
		else:
			appearances[card] += 1
	for gc in good_cards:
		answer += appearances.get(gc, 0)
	print(answer // 3)
main()


(x, y) = map(int, input().split())
dic = {}
st = []
for n in range(x):
	s = input()
	if s not in dic:
		dic[s] = 1
	else:
		dic[s] += 1
	st.append(s)

def f(x, y):
	s = 'SET'
	for n in s:
		if n != x and n != y:
			return n
res = 0
for n in range(x):
	for k in range(n + 1, x):
		t = ''
		for p in range(y):
			if st[n][p] == st[k][p]:
				t += st[n][p]
			else:
				t += f(st[n][p], st[k][p])
		if t in dic:
			res += dic[t]
		if st[n] == st[k]:
			res -= 2
print(res // 3)


import math
(n, k) = map(int, input().split())
m = {}
r = []
answer = 0
for i in range(n):
	e = str(input())
	r.append(e)
	if e in m:
		m[e] += 1
	else:
		m[e] = 1
for i in range(n - 1):
	for j in range(i + 1, n):
		q1 = r[i]
		q2 = r[j]
		ok = True
		y = ''
		for h in range(k):
			if q1[h] == q2[h]:
				y += q1[h]
			else:
				ok = False
				rt = q1[h] + q2[h]
				if rt in ['SE', 'ES']:
					y += 'T'
				elif rt in ['ST', 'TS']:
					y += 'E'
				else:
					y += 'S'
		if ok:
			answer += m[y] - 2
		elif y in m:
			answer += m[y]
print(answer // 3)


n = int(input().split()[0])
s = set()
r = 0
for _ in [0] * n:
	t = (*map(ord, input()),)
	for x in s:
		r += (*((u ^ v or u ^ 66) ^ 66 for (u, v) in zip(x, t)),) in s
	s |= {t}
print(r // 2)


def calc(a, b):
	if a == 'S':
		if b == 'E':
			return 'T'
		elif b == 'S':
			return 'S'
		else:
			return 'E'
	elif a == 'E':
		if b == 'E':
			return 'E'
		elif b == 'S':
			return 'T'
		else:
			return 'S'
	elif b == 'E':
		return 'S'
	elif b == 'S':
		return 'E'
	else:
		return 'T'
(n, k) = map(int, input().split())
d = {}
l = []
done = {}
for i in range(n):
	a = input()
	d[a] = 1
	l.append(a)
if n <= 2:
	print(0)
	exit()
ans = 0
for i in range(n):
	for j in range(i + 1, n):
		reqd = ''
		for m in range(k):
			reqd += calc(l[i][m], l[j][m])
		if reqd in d:
			if (l[i], l[j], reqd) not in done and (l[i], reqd, l[j]) not in done and ((l[j], l[i], reqd) not in done) and ((l[j], reqd, l[i]) not in done) and ((reqd, l[j], l[i]) not in done) and ((reqd, l[i], l[j]) not in done):
				done[l[i], l[j], reqd] = 1
				ans += 1
print(ans)


n = int(input().split()[0])
s = set()
r = 0
for _ in [0] * n:
	t = (*map('SET'.find, input()),)
	for x in s:
		r += (*((u != v) * (3 ^ u) ^ v for (u, v) in zip(x, t)),) in s
	s |= {t}
print(r // 2)


import sys
input = sys.stdin.readline
import bisect
from collections import defaultdict as dd
(n, k) = map(int, input().split())
d = dd(list)
l = []
for _ in range(n):
	s = input()
	d[s] = 1
	l.append(s)
res = 0
for i in range(n):
	for j in range(i + 1, n):
		s1 = l[i]
		s2 = l[j]
		s3 = ''
		for ii in range(k):
			if s1[ii] == s2[ii]:
				s3 += s1[ii]
			else:
				for jj in ['S', 'E', 'T']:
					if jj != s1[ii] and jj != s2[ii]:
						break
				s3 += jj
		s3 += '\n'
		if d[s3]:
			res += 1
print(res // 3)


import itertools

def go():
	(n, k) = map(int, input().split())
	s = [input() for _ in range(n)]
	dic = {'S': 1, 'E': 2, 'T': 3}
	s2 = [[dic[let] for let in ss] for ss in s]
	ts = {s[i]: i for i in range(n)}
	dif = {}
	alp = 'SET'
	for (aa, bb, cc) in itertools.permutations(alp):
		dif[dic[aa] * dic[bb]] = cc
	for aa in alp:
		dif[dic[aa] * dic[aa]] = aa
	done = [-1] * n
	donep = [-1] * (n * n)
	answer = 0
	for i in range(n - 2):
		a = s2[i]
		for j in range(i + 1, n - 1):
			if done[j] == i or donep[i * n + j] == 1:
				continue
			b = s2[j]
			c = ''.join((dif[a[kk] * b[kk]] for kk in range(k)))
			if c in ts:
				l = ts[c]
				if l > j:
					answer += 1
					done[l] = i
					donep[j * n + l] = 1
	print(answer)
go()


import sys
input = sys.stdin.readline
(n, k) = list(map(int, input().split()))
arr = []
for i in range(n):
	word = input().strip()
	arr.append(word)
d = {}
for i in arr:
	if i not in d:
		d[i] = 0
ans = 0
for x in range(n):
	for y in range(x + 1, n):
		s = ''
		for z in range(k):
			if arr[x][z] == arr[y][z]:
				s += arr[x][z]
			else:
				temp = arr[x][z] + arr[y][z]
				if 'S' not in temp:
					s += 'S'
				elif 'E' not in temp:
					s += 'E'
				elif 'T' not in temp:
					s += 'T'
		if s in d:
			ans += 1
print(ans // 3)


from collections import defaultdict
(n, k) = map(int, input().split())
Ss = []
s_ind = defaultdict(int)
for i in range(n):
	s = input()
	Ss.append(s)
	s_ind[s] = i

def mkstr(s, t):
	ret = ''
	for (s_, t_) in zip(s, t):
		if s_ == t_:
			ret += s_
		else:
			if s_ != 'S' and t_ != 'S':
				ret += 'S'
			if s_ != 'T' and t_ != 'T':
				ret += 'T'
			if s_ != 'E' and t_ != 'E':
				ret += 'E'
	return ret
cnt = 0
for i in range(n):
	for j in range(i + 1, n):
		s = Ss[i]
		t = Ss[j]
		q = mkstr(s, t)
		if s_ind[q] > j:
			cnt += 1
print(cnt)


(n, k) = map(int, input().split())
a = []
arr = []
for i in range(n):
	st = input()
	a.append(st)
for i in range(n):
	arr.append(set())
	for j in range(i, n):
		arr[i].add(a[j])
count = 0
for i in range(n):
	for j in range(i + 1, n):
		tmp = ''
		for t in range(k):
			if a[i][t] == a[j][t]:
				tmp += a[i][t]
			elif a[i][t] != 'T' and a[j][t] != 'T':
				tmp += 'T'
			elif a[i][t] != 'E' and a[j][t] != 'E':
				tmp += 'E'
			elif a[i][t] != 'S' and a[j][t] != 'S':
				tmp += 'S'
		if tmp in arr[j]:
			count += 1
print(count)


(n, k) = map(int, input().split())
array = [input() for i in range(n)]
set_array = set(array)
for el in array:
	new = ''
	for x in el:
		new += x
		set_array.add(new)
count = 0

def is_vzm(x, y):
	if x == y:
		return x
	for el in ['S', 'E', 'T']:
		if el != x and el != y:
			return el
visited = set()
for i in range(n):
	for j in range(i + 1, n):
		if (array[i], array[j]) in visited or (array[j], array[i]) in visited:
			continue
		vzm = ''
		for m in range(k):
			vzm += is_vzm(array[i][m], array[j][m])
			if vzm not in set_array:
				break
		if vzm in set_array:
			visited.add((array[j], vzm))
			visited.add((vzm, array[j]))
			visited.add((array[i], vzm))
			count += 1
print(count)


(n, o) = map(int, input().split())
b = []
ans = 0
brodi = set()
visto = []
for i in range(n):
	b.append(input())
	brodi.add(b[i])
	visto.append(True)
for j in range(n):
	for k in range(j + 1, n):
		a = ''
		for z in range(o):
			padrao = ['S', 'E', 'T']
			if b[j][z] == b[k][z]:
				a += b[j][z]
			else:
				for sla in padrao:
					if sla != b[j][z] and sla != b[k][z]:
						a += sla
						break
		if a in brodi:
			ans += 1
print(ans // 3)


import sys
from collections import defaultdict

def solution(cards, n, k):
	res = 0
	counts = defaultdict(int)
	for i in range(0, n):
		for j in range(i + 1, n):
			cur = ''
			for x in range(k):
				if cards[i][x] == cards[j][x]:
					cur += cards[i][x]
				else:
					if cards[i][x] != 'S' and cards[j][x] != 'S':
						cur += 'S'
					if cards[i][x] != 'E' and cards[j][x] != 'E':
						cur += 'E'
					if cards[i][x] != 'T' and cards[j][x] != 'T':
						cur += 'T'
			if counts[cur]:
				res += 1
		counts[cards[i]] += 1
	print(res)
for line in sys.stdin:
	(n, k) = [int(x) for x in line.split()]
	break
cards = []
for line in sys.stdin:
	cards.append(line[:-1])
solution(cards, n, k)


from collections import defaultdict as dc
(n, k) = map(int, input().split())
d = dc(int)
b = []
for i in range(n):
	c = input()
	d[c] += 1
	b.append(c)
ans = 0
for i in range(n):
	for j in range(i + 1, n):
		s = ['']
		for l in range(k):
			y = []
			if b[i][l] == b[j][l]:
				for x in s:
					e = x + b[i][l]
					y.append(e)
			elif b[i][l] == 'S' and b[j][l] == 'E' or (b[i][l] == 'E' and b[j][l] == 'S'):
				for x in s:
					e = x + 'T'
					y.append(e)
			elif b[i][l] == 'S' and b[j][l] == 'T' or (b[i][l] == 'T' and b[j][l] == 'S'):
				for x in s:
					e = x + 'E'
					y.append(e)
			elif b[i][l] == 'T' and b[j][l] == 'E' or (b[i][l] == 'E' and b[j][l] == 'T'):
				for x in s:
					e = x + 'S'
					y.append(e)
			s = y[:]
		for l in s:
			ans += d.get(l, 0)
print(ans // 3)


import sys

def input():
	return sys.stdin.readline().strip()
(n, k) = [int(x) for x in input().split()]
V = [input() for x in range(n)]
M = set(V)
z = ord('S') + ord('E') + ord('T')
cc = 0
for i in range(n):
	for j in range(i + 1, n):
		s = ''
		for l in range(k):
			if V[i][l] == V[j][l]:
				s += V[i][l]
			else:
				s += chr(z - ord(V[i][l]) - ord(V[j][l]))
		if s in M:
			cc += 1
print(cc // 3)


import sys
input = sys.stdin.readline
(n, k) = map(int, input().split())
S = [input().strip() for i in range(n)]
SET = set(S)
ANS = 0
for i in range(n - 1):
	for j in range(i + 1, n):
		rest = []
		for l in range(k):
			if S[i][l] == S[j][l]:
				rest += S[i][l]
			else:
				rest += chr(236 - ord(S[i][l]) - ord(S[j][l]))
		if ''.join(rest) in SET:
			ANS += 1
print(ANS // 3)


def other(s1, s2):
	s3 = ''
	for i in range(k):
		if s1[i] == s2[i]:
			s3 += s1[i]
		else:
			l = ['S', 'E', 'T']
			l.remove(s1[i])
			l.remove(s2[i])
			s3 += l[0]
	return s3
(n, k) = [int(zax) for zax in input().split()]
dic = {}
strings = []
for i in range(n):
	s = input()
	strings.append(s)
	dic[s] = True
count = 0
for i in range(n - 1):
	for j in range(i + 1, n):
		s3 = other(strings[i], strings[j])
		if s3 in dic:
			count += 1
print(count // 3)


def strneed(s1, s2, n):
	setstr = ['S', 'E', 'T']
	sn = ''
	for i in range(n):
		if s1[i] == s2[i]:
			sn += s1[i]
		else:
			for j in setstr:
				if j != s1[i] and j != s2[i]:
					sn += j
					break
	return sn

def found(s, arr, l, r):
	while l <= r:
		mid = l + (r - l) // 2
		if l == r:
			if arr[mid] == s:
				return True
			else:
				return False
		if arr[mid] == s:
			return True
		elif arr[mid] < s:
			l = mid + 1
		else:
			r = mid - 1
	return False
(n, kn) = map(int, input().split(' '))
arr = []
for i in range(n):
	s = input()
	arr.append(s)
arr.sort()
cnt = 0
for i in range(n - 2):
	for j in range(i + 1, n):
		s = strneed(arr[i], arr[j], kn)
		if s < arr[j]:
			continue
		if found(s, arr, j + 1, n - 1):
			cnt += 1
print(cnt)


def get(ch1, ch2):
	if ch1 == 'S' and ch2 == 'T' or (ch1 == 'T' and ch2 == 'S'):
		return 'E'
	if ch1 == 'S' and ch2 == 'E' or (ch1 == 'E' and ch2 == 'S'):
		return 'T'
	if ch1 == 'E' and ch2 == 'T' or (ch1 == 'T' and ch2 == 'E'):
		return 'S'
(n, k) = map(int, input().split())
tot = 0
pre = dict()
st = []
for i in range(0, n):
	s = input()
	st.append(s)
	if pre.get(s) == None:
		pre[s] = 0
	pre[s] += 1
for i in range(n):
	for j in range(i + 1, n):
		kk = ''
		for m in range(0, k):
			if st[i][m] == st[j][m]:
				kk += st[i][m]
			else:
				kk += get(st[i][m], st[j][m])
		if pre.get(kk) != None:
			tot += pre[kk]
print(tot // 3)


(n, k) = [int(j) for j in input().split()]
se = set()
l = []
for i in range(n):
	s = input()
	se.add(s)
	l.append(s)
ans = 0
for i in range(len(l) - 1):
	for j in range(i + 1, len(l)):
		l1 = [l[i][p] + l[j][p] for p in range(k)]
		k1 = ''
		for w in l1:
			if w[0] == w[1]:
				k1 += w[0]
			elif w == 'ES':
				k1 += 'T'
			elif w == 'ET':
				k1 += 'S'
			elif w == 'SE':
				k1 += 'T'
			elif w == 'TE':
				k1 += 'S'
			elif w == 'ST':
				k1 += 'E'
			else:
				k1 += 'E'
		if k1 in se:
			ans += 1
print(ans // 3)


(N, K) = map(int, input().split())
X = [int(input().replace('S', '0000100').replace('E', '0001000').replace('T', '0010000'), 2) for _ in range(N)]
D = {x: 1 for x in X}
m = int('0011100' * K, 2)
ans = 0
for i in range(N):
	for j in range(i + 1, N):
		if m - (X[i] | X[j]) ^ ((X[i] & X[j]) >> 2) * 31 & m in D:
			ans += 1
print(ans // 3)


import collections
(n, k) = list(map(int, input().split()))
a = [input() for i in range(n)]
c = set(a)
b = set()
for i in range(n):
	for j in range(i + 1, n):
		third = ''
		for (c1, c2) in zip(a[i], a[j]):
			if c1 == c2:
				third += c1
			elif c1 != 'S' and c2 != 'S':
				third += 'S'
			elif c1 != 'E' and c2 != 'E':
				third += 'E'
			else:
				third += 'T'
		if third in c:
			b.add(frozenset([a[i], a[j], third]))
print(len(b))


INF = 10 ** 10

def main():
	(n, k) = get_list()
	cards = defaultdict(int)
	for _ in range(n):
		cards[input()] += 1
	keys = list(cards.keys())
	st = ['S', 'E', 'T']
	res = 0
	for (i, card1) in enumerate(keys):
		for j in range(i + 1, len(keys)):
			rm = []
			card2 = keys[j]
			for l in range(k):
				if card1[l] == card2[l]:
					rm.append(card1[l])
				else:
					s2 = [card1[l], card2[l]]
					for er in st:
						if er not in s2:
							rm.append(er)
							break
			rm = ''.join(rm)
			if rm in cards:
				res += cards[card1] * cards[card2] * cards[rm]
	print(res // 3)
import sys
from collections import defaultdict, Counter
from bisect import bisect_left, bisect_right
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
out = []
get_int = lambda : int(input())
get_list = lambda : list(map(int, input().split()))
main()


import sys
from math import factorial as fact
from collections import defaultdict
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
S = lambda : list(map(str, input()))

def solve(a, b):
	ans = ''
	for i in range(k):
		if a[i] == b[i]:
			ans += a[i]
		elif a[i] != 'T' and b[i] != 'T':
			ans += 'T'
		elif a[i] != 'S' and b[i] != 'S':
			ans += 'S'
		else:
			ans += 'E'
	return ans
(n, k) = I()
if n <= 2:
	for i in range(n):
		s = S()[:-1]
	print(0)
else:
	b = []
	mem1 = defaultdict(int)
	for i in range(n):
		s = S()[:-1]
		b.append(s)
		mem1[''.join(s)] = 1
	count = 0
	for i in range(n):
		for j in range(i + 1, n):
			if solve(b[i], b[j]) in mem1:
				count += 1
	print(int(count / 3))


from sys import stdin
(n, k) = map(int, input().split())
deck = set()
for _ in range(n):
	deck.add(stdin.readline().strip())
ans = 0

def thirdChar(a, b):
	if a == b:
		return a
	if a == 'S' and b == 'T' or (a == 'T' and b == 'S'):
		return 'E'
	if a == 'S' and b == 'E' or (a == 'E' and b == 'S'):
		return 'T'
	if a == 'E' and b == 'T' or (a == 'T' and b == 'E'):
		return 'S'

def findThird(c1, c2):
	l = []
	for i in range(k):
		l.append(thirdChar(c1[i], c2[i]))
	return ''.join(l)
for c1 in deck:
	for c2 in deck:
		if c2 > c1:
			c3 = findThird(c1, c2)
			if c3 > c2 and c3 in deck:
				ans += 1
print(ans)


ltr_xor = ord('S') ^ ord('E') ^ ord('T')

def get_matching_card(c1: str, c2: str) -> str:
	c3 = []
	n = len(c1)
	for i in range(n):
		if c1[i] == c2[i]:
			c3.append(c1[i])
		else:
			c3.append(chr(ltr_xor ^ ord(c1[i]) ^ ord(c2[i])))
	return ''.join(c3)
(n, k) = map(int, input().split(' '))
cards = []
card_set = set()
ways = 0
for i in range(n):
	nc = input()
	cards.append(nc)
	card_set.add(nc)
for i in range(n - 1):
	for j in range(i + 1, n):
		if get_matching_card(cards[i], cards[j]) in card_set:
			ways += 1
print(int(ways / 3))


import sys
from collections import Counter
input = sys.stdin.readline

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7
(N, K) = MAP()
A = [input().rstrip() for i in range(N)]
C = Counter(A)
ordsm = ord('S') + ord('E') + ord('T')
cnt = 0
for (i, a1) in enumerate(A):
	for j in range(i + 1, N):
		a2 = A[j]
		a3 = ''
		for (k1, k2) in zip(a1, a2):
			if k1 == k2:
				a3 += k1
			else:
				key = ordsm - ord(k1) - ord(k2)
				a3 += chr(key)
		if a3 in C:
			cnt += 1
print(cnt // 3)


from collections import defaultdict

def getletter(a, b):
	if a == b:
		return a
	str = 'SET'
	for i in str:
		if i != a and i != b:
			return i
(n, k) = map(int, input().split())
z = []
d = defaultdict(int)
for i in range(n):
	s = input()
	d[s] += 1
	z.append(s)
count = 0
for i in range(n):
	for j in range(i + 1, n):
		astr = ''
		for num in range(k):
			astr += getletter(z[i][num], z[j][num])
		count += d[astr]
print(count // 3)


import sys

def solve():
	(n, k) = map(int, sys.stdin.readline().split())
	a = [None] * n
	tr = {'S': 0, 'E': 1, 'T': 2}
	for i in range(n):
		z = 0
		for c in sys.stdin.readline().strip():
			z = z * 4 + tr[c]
		a[i] = z
	d = frozenset(a)
	r = 0
	for i in range(n):
		for j in range(i):
			(ii, jj) = (a[i], a[j])
			t = ii ^ jj
			tt = t >> 1 & 6148914691236517205 | t & 6148914691236517205
			ff = (ii | jj) ^ (tt | tt << 1)
			r += ff in d
	print(r // 3)
solve()


import sys
input = sys.stdin.readline
(n, k) = [int(item) for item in input().split()]
cards = []
cnt = dict()
for _ in range(n):
	c = input().rstrip()
	if c not in cnt:
		cnt[c] = 1
	else:
		cnt[c] += 1
ans = 0
keys = list(cnt.keys())
key_num = len(keys)
ord_sum = ord('S') + ord('E') + ord('T')
for (i, key1) in enumerate(keys):
	for j in range(i + 1, key_num):
		key2 = keys[j]
		key3 = ''
		for (k1, k2) in zip(key1, key2):
			if k1 == k2:
				key3 += k1
			else:
				key3 += chr(ord_sum - ord(k1) - ord(k2))
		if key3 in cnt:
			ans += cnt[key1] * cnt[key2] * cnt[key3]
print(ans // 3)


(n, k) = map(int, input().split())
cards = set()
clist = []
for i in range(n):
	s = input()
	cards.add(s)
	clist.append(s)

def ex(a, b):
	for i in 'SET':
		if i not in (a, b):
			return i
ans = 0
for a in range(len(clist)):
	for b in range(a + 1, len(clist)):
		(c1, c2) = (clist[a], clist[b])
		complement = []
		for i in range(k):
			if c1[i] == c2[i]:
				complement.append(c1[i])
			else:
				complement.append(ex(c1[i], c2[i]))
		if ''.join(complement) in cards:
			ans += 1
print(ans // 3)


def solve(a):
	b = 'SET'
	for i in b:
		if i not in a:
			return i
(n, k) = map(int, input().split())
b = []
a = set()
for i in range(n):
	b.append(input().rstrip())
	a.add(b[-1])
ans = 0
for i in range(n):
	for j in range(i + 1, n):
		z = []
		for l in range(k):
			if b[i][l] == b[j][l]:
				z.append(b[i][l])
			else:
				z.append(solve(b[i][l] + b[j][l]))
		if ''.join(z) in a:
			ans += 1
print(ans // 3)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
(n, k) = map(int, input().split())
l = []
ans = 0
for i in range(n):
	l.append(input())
s = set(l)
r = ord('E') + ord('S') + ord('T')
for i in range(n):
	for j in range(i + 1, n):
		f = ''
		for h in range(k):
			if l[i][h] != l[j][h]:
				f += chr(r - ord(l[i][h]) - ord(l[j][h]))
			elif l[i][h] == l[j][h]:
				f += l[i][h]
		if f in s:
			ans += 1
print(ans // 3)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
from math import gcd
INF = 10 ** 18
MOD = 10 ** 9 + 7

def lcm(a, b):
	return a * b // gcd(a, b)

def ncr(a, b):
	if a < b:
		return 0
(n, k) = Ri()
lis = []
for i in range(n):
	lis.append(ri())
dic = {}
ans = 0
for i in range(n):
	for j in range(i + 1, n):
		fir = lis[i]
		sec = lis[j]
		toget = []
		for l in range(k):
			if fir[l] == sec[l]:
				toget.append(fir[l])
			elif fir[l] == 'E' and sec[l] == 'S':
				toget.append('T')
			elif fir[l] == 'S' and sec[l] == 'E':
				toget.append('T')
			elif fir[l] == 'T' and sec[l] == 'S':
				toget.append('E')
			elif fir[l] == 'S' and sec[l] == 'T':
				toget.append('E')
			elif fir[l] == 'T' and sec[l] == 'E':
				toget.append('S')
			elif fir[l] == 'E' and sec[l] == 'T':
				toget.append('S')
		toget = ''.join(toget)
		if toget in dic:
			ans += dic[toget]
	dic[lis[i]] = dic.get(lis[i], 0) + 1
print(ans)


(n, k) = tuple(map(int, input().strip().split()))
(cartas, buscadas, sets) = (set(), {}, 0)
for i in range(n - 1):
	carta1 = input()
	if carta1 in buscadas:
		sets += buscadas[carta1]
	for carta2 in cartas:
		buscada = ''
		for let in range(k):
			c1 = carta1[let]
			c2 = carta2[let]
			if c1 == c2:
				buscada += c1
			elif c1 == 'S' and c2 == 'E' or (c1 == 'E' and c2 == 'S'):
				buscada += 'T'
			elif c1 == 'S' and c2 == 'T' or (c1 == 'T' and c2 == 'S'):
				buscada += 'E'
			else:
				buscada += 'S'
		if buscada in buscadas:
			buscadas[buscada] += 1
		else:
			buscadas[buscada] = 1
	cartas.add(carta1)
cartafinal = input()
if cartafinal in buscadas:
	sets += buscadas[cartafinal]
print(sets)


import sys
import math
input = sys.stdin.readline
(n, k) = map(int, input().split())
l = list()
dc = dict()
for i in range(n):
	temp = list()
	s = input()
	for j in range(k):
		temp.append(s[j])
	temp1 = ''
	for j in range(k):
		temp1 += temp[j]
	l.append(temp1)
	if temp1 not in dc.keys():
		dc[temp1] = 1
	else:
		dc[temp1] += 1
ans = 0
for i in range(len(l)):
	flag = 0
	for j in range(i + 1, len(l)):
		s = ''
		for x in range(k):
			if l[i][x] == l[j][x]:
				s += l[i][x]
			elif l[i][x] != 'T' and l[j][x] != 'T':
				s += 'T'
			elif l[i][x] != 'E' and l[j][x] != 'E':
				s += 'E'
			elif l[i][x] != 'S' and l[j][x] != 'S':
				s += 'S'
		if s in dc.keys():
			ans += 1
print(ans // 3)


(n, k) = map(int, input().split())
string = []
strtmp = {}
result = 0
for i in range(n):
	tmp = input()
	string.append(tmp)
	strtmp[tmp] = i
if n >= 3:
	x = 0
	while x < n - 1:
		y = x + 1
		while y < n:
			temp = ''
			for i in range(k):
				if string[x][i] == string[y][i]:
					temp += string[x][i]
				else:
					temp += chr(236 - (ord(string[x][i]) + ord(string[y][i])))
			if strtmp.get(temp) and strtmp[temp] > x and (strtmp[temp] > y):
				result += 1
			y += 1
		x += 1
print(result)


from sys import stdin, stdout
import gc
gc.disable()
import array

def get(first, second):
	if first == second:
		return first
	elif first == 'S' and second == 'T' or (first == 'T' and second == 'S'):
		return 'E'
	elif first == 'E' and second == 'T' or (first == 'T' and second == 'E'):
		return 'S'
	elif first == 'S' and second == 'E' or (first == 'E' and second == 'S'):
		return 'T'
(n, k) = list(map(int, stdin.readline().split()))
all = set()
arr = []
for _ in range(n):
	temp = stdin.readline().strip()
	all.add(temp)
	arr.append(temp)
count = 0
for i in range(n):
	for j in range(i + 1, n):
		first = arr[i]
		second = arr[j]
		aux = []
		for _ in range(k):
			aux.append(get(first[_], second[_]))
		aux = ''.join(aux)
		if aux in all:
			count += 1
print(count // 3)


def greaterthan(ar, target, end):
	start = 0
	ans = -1
	while start <= end:
		mid = (start + end) // 2
		if ar[mid] <= target:
			start = mid + 1
		else:
			ans = mid
			end = mid - 1
	return ans

def binarySearch(arr, l, r, x):
	while l <= r:
		mid = (l + r) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] < x:
			l = mid + 1
		else:
			r = mid - 1
	return -1
(n, k) = map(int, input().split())
s = []
for i in range(n):
	s.append(input())
s.sort()
count = 0
for i in range(n - 1):
	for j in range(i + 1, n):
		s1 = s[i]
		s2 = s[j]
		ans = ''
		for ii in range(k):
			if s1[ii] == s2[ii]:
				ans += s1[ii]
			elif s1[ii] == 'S':
				if s2[ii] == 'E':
					ans += 'T'
				elif s2[ii] == 'T':
					ans += 'E'
			elif s1[ii] == 'E':
				if s2[ii] == 'S':
					ans += 'T'
				elif s2[ii] == 'T':
					ans += 'S'
			elif s1[ii] == 'T':
				if s2[ii] == 'S':
					ans += 'E'
				elif s2[ii] == 'E':
					ans += 'S'
		ind = binarySearch(s[j + 1:], 0, len(s[j + 1:]) - 1, ans)
		if ind != -1:
			count += 1
print(count)


from collections import defaultdict as dc
from collections import deque as dq
import bisect
import sys
import math
mod = 10 ** 9 + 7

def bs(a, x):
	i = bisect_left(a, x)
	if i != len(a):
		return i
	else:
		return len(a)

def binarysearchforsolvingeqautions(a, i, l, r):
	while 1:
		mid = (l + r) / 2
		(p, q) = force(a, mid, i)
		if abs(p - q) < 1e-13:
			return mid
		elif p > q:
			l = mid
		else:
			r = mid

def bs(a, b):
	l = a
	r = b + 1
	x = b
	ans = 0
	while l < r:
		mid = (l + r) // 2
		if x | mid > ans:
			ans = x | mid
			l = mid + 1
		else:
			r = mid
	return ans

def digit(n):
	a = []
	while n > 0:
		a.append(n % 10)
		n = n // 10
	return a

def inp():
	p = int(input())
	return p

def line():
	p = list(map(int, input().split()))
	return p

def ans(a, b):
	if a == b:
		return a
	p = ['S', 'E', 'T']
	for i in range(3):
		if a != p[i] and b != p[i]:
			z = p[i]
	return z
(n, k) = line()
p = []
q = dc(int)
for i in range(n):
	s = str(input())
	p.append(s)
	q[s] = i + 1
c = 0
abd = dc(int)
for i in range(n):
	for j in range(i + 1, n):
		x = p[i]
		y = p[j]
		s = ''
		for z in range(k):
			if x[z] == y[z]:
				s = s + x[z]
			else:
				s = s + chr(236 - (ord(x[z]) + ord(y[z])))
		kl = q[s]
		if kl != 0 and kl != i + 1 and (kl != j + 1) and (i != j):
			lst = (kl, i + 1, j + 1)
			lst = tuple(sorted(lst))
			if abd[lst] == 0:
				abd[lst] = 1
				c += 1
print(c)


(n, k) = map(int, input().split())
p = 0
a = []
s = {}
for i in range(n):
	t = str(input())
	a.append(t)
	s[t] = i
for i in range(n - 1):
	for j in range(i + 1, n):
		r = ''
		for q in range(k):
			if a[i][q] == a[j][q]:
				r = r + a[i][q]
			else:
				for m in 'SET':
					if m != a[i][q] and m != a[j][q]:
						r = r + m
		if s.get(r) and s[r] > i and (s[r] > j):
			p += 1
print(p)


from collections import Counter
(n, k) = map(int, input().split())
arr = []
cnt = Counter()
for i in range(n):
	s = input()
	arr.append(s)
	cnt[s] += 1
arr = list(arr)
res = 0
for i in range(n):
	cnt[arr[i]] = 0
	cnt2 = cnt.copy()
	for j in range(i + 1, n):
		needed = [''] * k
		for l in range(k):
			if arr[i][l] == arr[j][l]:
				needed[l] = arr[i][l]
			elif arr[i][l] != 'S' and arr[j][l] != 'S':
				needed[l] = 'S'
			elif arr[i][l] != 'E' and arr[j][l] != 'E':
				needed[l] = 'E'
			else:
				needed[l] = 'T'
		needed = ''.join(needed)
		res += cnt2[needed]
		cnt2[arr[j]] = 0
print(res)


import sys
input = sys.stdin.readline

def getInt():
	return int(input())

def getVars():
	return map(int, input().split())

def getList():
	return list(map(int, input().split()))

def getStr():
	return input().strip()
(n, k) = getVars()
res = 0
s = []
for i in range(n):
	s.append(getStr())
d = {}
for i in range(n):
	srez = ''
	for j in range(k):
		srez += s[i][j]
		if srez not in d:
			d[srez] = []
		d[srez].append(i)
for i in range(n - 2):
	for j in range(i + 1, n - 1):
		ss = ''
		for p in range(k):
			if s[i][p] == s[j][p]:
				ss += s[i][p]
			else:
				if s[i][p] == 'S' and s[j][p] == 'E':
					ss += 'T'
				if s[i][p] == 'S' and s[j][p] == 'T':
					ss += 'E'
				if s[i][p] == 'E' and s[j][p] == 'S':
					ss += 'T'
				if s[i][p] == 'E' and s[j][p] == 'T':
					ss += 'S'
				if s[i][p] == 'T' and s[j][p] == 'S':
					ss += 'E'
				if s[i][p] == 'T' and s[j][p] == 'E':
					ss += 'S'
			if ss not in d:
				break
		if len(ss) == k and ss in d:
			for p in d[ss]:
				if p > i and p > j:
					res += 1
print(res)


from sys import stdin

def get1(a, b):
	if a == b:
		return a
	if a == 'S':
		if b == 'E':
			return 'T'
		return 'E'
	if a == 'E':
		if b == 'S':
			return 'T'
		return 'S'
	if b == 'S':
		return 'E'
	return 'S'

def get(a, b):
	return ''.join(map(lambda x: get1(*x), zip(a, b)))

def solve():
	(n, k) = map(int, stdin.readline().split())
	ans = 0
	a = list(map(str.strip, stdin.readlines()))
	b = set(a)
	for i in range(n):
		for j in range(i + 1, n):
			if get(a[i], a[j]) in b:
				ans += 1
	print(ans // 3)
for _ in range(1):
	solve()


from __future__ import print_function
from collections import Counter, OrderedDict
from itertools import permutations as perm
from fractions import Fraction
from collections import deque
from sys import stdin
from bisect import *
from heapq import *
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
mod = int(1000000000.0) + 7
inf = float('inf')

def getChar(x, y):
	if x == y:
		return x
	for ch in 'SET':
		if ch not in (x, y):
			return ch
(n, k) = gil()
a = []
for _ in range(n):
	a.append(g())
b = Counter(a)
ans = 0
for i in range(n):
	for j in range(i + 1, n):
		c = [getChar(a[i][l], a[j][l]) for l in range(k)]
		if ''.join(c) in b:
			ans += 1
print(ans // 3)


(n, k) = map(int, input().split())
(res, pool) = (0, set())
for _ in range(n):
	a = bytes((ord(c) + 1 & 3 for c in input()))
	for b in pool:
		res += bytes((((0, 2, 1), (2, 1, 0), (1, 0, 2))[u][v] for (u, v) in zip(a, b))) in pool
	pool.add(a)
print(res // 2)


(n, k) = [int(x) for x in input().strip().split()]
V = []
for i in range(n):
	V.append(input().strip())
M = set(V)
Z = ['S', 'E', 'T']
cc = 0
for i in range(n):
	for j in range(i + 1, n):
		s = ''
		for l in range(k):
			if V[i][l] == V[j][l]:
				s += V[i][l]
			else:
				for c in Z:
					if V[i][l] != c and V[j][l] != c:
						s += c
		if s in M:
			cc += 1
print(cc // 3)


(n, k2) = map(int, input().split())
l = set()
for i in range(n):
	e = input()
	l.add(e)
r = set(l)
l = list(l)
an = 0
for j in range(n - 1):
	for k in range(j + 1, n):
		we = [0] * k2
		ty = 0
		while ty < k2:
			if l[j][ty] == l[k][ty]:
				we[ty] = l[j][ty]
			else:
				if l[j][ty] != 'E' and l[k][ty] != 'E':
					we[ty] = 'E'
				if l[j][ty] != 'T' and l[k][ty] != 'T':
					we[ty] = 'T'
				if l[j][ty] != 'S' and l[k][ty] != 'S':
					we[ty] = 'S'
			ty += 1
		we = ''.join(we)
		if we in r:
			an += 1
print(an // 3)


from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, groupby
import sys
import bisect
import string
import math
import time
import random

def S_():
	return input()

def LS():
	return [i for i in input().split()]

def I():
	return int(input())

def MI():
	return map(int, input().split())

def LI():
	return [int(i) for i in input().split()]

def LI_():
	return [int(i) - 1 for i in input().split()]

def StoI():
	return [ord(i) - 97 for i in input()]

def ItoS(nn):
	return chr(nn + 97)

def LtoS(ls):
	return ''.join([chr(i + 97) for i in ls])

def GI(V, E, Directed=False, index=0):
	org_inp = []
	g = [[] for i in range(n)]
	for i in range(E):
		inp = LI()
		org_inp.append(inp)
		if index == 0:
			inp[0] -= 1
			inp[1] -= 1
		if len(inp) == 2:
			(a, b) = inp
			g[a].append(b)
			if not Directed:
				g[b].append(a)
		elif len(inp) == 3:
			(a, b, c) = inp
			aa = (inp[0], inp[2])
			bb = (inp[1], inp[2])
			g[a].append(bb)
			if not Directed:
				g[b].append(aa)
	return (g, org_inp)

def bit_combination(k, n=2):
	rt = []
	for tb in range(n ** k):
		s = [tb // n ** bt % n for bt in range(k)]
		rt += [s]
	return rt

def show(*inp, end='\n'):
	if show_flg:
		print(*inp, end=end)
YN = ['Yes', 'No']
mo = 10 ** 9 + 7
inf = float('inf')
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
input = lambda : sys.stdin.readline().rstrip()

def ran_input():
	import random
	n = random.randint(4, 16)
	(rmin, rmax) = (1, 10)
	a = [random.randint(rmin, rmax) for _ in range(n)]
	return (n, a)
show_flg = False
show_flg = True
ans = 0
(n, k) = LI()
s = [0] * n
dc = dict(zip('SET', [0, 1, 2]))
trd = {}
st = set()
for i in range(n):
	t = input()
	s[i] = [dc[t[j]] for j in range(k)]
	t = 0
	for j in range(k):
		t |= s[i][j] << 2 * j
	st.add(t)
for i in range(n):
	for j in range(i + 1, n):
		u = 0
		for f in range(k):
			if s[i][f] != s[j][f]:
				u |= (1 << 2 * f) * (3 - s[i][f] - s[j][f])
			else:
				u |= (1 << 2 * f) * s[i][f]
		if u in st:
			ans += 1
print(ans // 3)


(n, k) = map(int, input().split())
a = []
for i in range(n):
	a.append(input())
st = set(a)
ct = 0
for i in range(n):
	for j in range(i + 1, n):
		s = ''
		for l in range(k):
			if a[i][l] == a[j][l]:
				s += a[i][l]
			elif a[i][l] == 'S' and a[j][l] == 'E' or (a[i][l] == 'E' and a[j][l] == 'S'):
				s += 'T'
			elif a[i][l] == 'S' and a[j][l] == 'T' or (a[i][l] == 'T' and a[j][l] == 'S'):
				s += 'E'
			elif a[i][l] == 'E' and a[j][l] == 'T' or (a[i][l] == 'T' and a[j][l] == 'E'):
				s += 'S'
		if s in st:
			ct += 1
print(ct // 3)


from sys import *
from math import *
from bisect import *
(n, l) = map(int, stdin.readline().split())
s = []
for i in range(n):
	a = input()
	s.append(a)
x = set(s)
ans = 0
for i in range(n - 1):
	for j in range(i + 1, n):
		z = ''
		for k in range(l):
			if s[i][k] == s[j][k]:
				z += s[i][k]
			else:
				if (s[i][k] == 'S' or s[j][k] == 'S') and (s[j][k] == 'T' or s[i][k] == 'T'):
					z += 'E'
				if (s[i][k] == 'S' or s[j][k] == 'S') and (s[j][k] == 'E' or s[i][k] == 'E'):
					z += 'T'
				if (s[i][k] == 'T' or s[j][k] == 'T') and (s[j][k] == 'E' or s[i][k] == 'E'):
					z += 'S'
		if z in x:
			ans += 1
print(ans // 3)


rev = {'ST': 'E', 'TS': 'E', 'SE': 'T', 'ES': 'T', 'TE': 'S', 'ET': 'S'}
ans = 0
(n, k) = map(int, input().split())
a = []
s = {}
for i in range(n):
	temp = input()
	a.append(temp)
	s[temp] = 1
for i in range(n):
	for j in range(i + 1, n):
		tf = ''
		for l in range(k):
			if a[i][l] == a[j][l]:
				tf += a[i][l]
			else:
				tf += rev[a[i][l] + a[j][l]]
		ans += int(bool(s.get(tf)))
print(ans // 3)


def solution():
	(n, k) = map(int, input().split())
	S = [input().strip() for i in range(n)]
	SET = set(S)
	p = 0
	for i in range(n - 1):
		for j in range(i + 1, n):
			c = []
			for l in range(k):
				if S[i][l] == S[j][l]:
					c += S[i][l]
				else:
					c += chr(236 - ord(S[i][l]) - ord(S[j][l]))
			if ''.join(c) in SET:
				p += 1
	print(p // 3)
solution()


import sys
input = sys.stdin.readline
(a, b) = map(int, input().split())
l = [input().strip() for i in range(a)]
c = 0
sey = set(l)
for i in range(a):
	for j in range(i + 1, a):
		s = ''
		for k in range(b):
			if l[i][k] == l[j][k]:
				s = s + l[i][k]
			else:
				s = s + chr(236 - ord(l[i][k]) - ord(l[j][k]))
		if s in sey:
			c = c + 1
print(c // 3)


from sys import stdout, stdin
ans = ['SET', 'EST', 'TES', 'ETS', 'TSE', 'STE']
for _ in range(1):
	(n, k) = map(int, stdin.readline().split())
	d = dict()
	ls = []
	for i in range(n):
		s = stdin.readline()
		ls.append(s)
		d[s] = i
	cnt = 0
	for i in range(n):
		for j in range(i + 1, n):
			s1 = ''
			for f in range(k):
				if ls[i][f] == ls[j][f]:
					s1 += ls[i][f]
				else:
					for p in range(6):
						if ls[i][f] == ans[p][0] and ls[j][f] == ans[p][1]:
							s1 += ans[p][2]
							break
			s1 += '\n'
			m = d.get(s1)
			if m is not None and m > j:
				cnt += 1
	stdout.write(str(cnt))


import os
import heapq
import sys, threading
import math
import operator
from collections import defaultdict, deque
from io import BytesIO, IOBase
sys.setrecursionlimit(10 ** 5)

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

def inpt():
	return [int(k) for k in input().split()]

def get(a, b):
	if a == b:
		return a
	if a == 'S' and b == 'T' or (a == 'T' and b == 'S'):
		return 'E'
	elif a == 'S' and b == 'E' or (a == 'E' and b == 'S'):
		return 'T'
	else:
		return 'S'

def main():
	(n, k) = inpt()
	ar = []
	for _ in range(n):
		ar.append(input())
	st = set(ar)
	ans = set()
	for i in range(n):
		for j in range(i + 1, n):
			temp = ''
			for p in range(k):
				temp += get(ar[i][p], ar[j][p])
			if temp in st:
				ans.add(tuple(sorted([ar[i], ar[j], temp])))
	print(len(ans))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


(n, kk) = map(int, input().split(' '))
l = []
for i in range(n):
	l.append(input())
l.sort()
l2 = set(l)

def f(l, e):
	if len(l) == 1:
		if l[0] == e:
			return True
		else:
			return False
	elif l[len(l) // 2] < e:
		return f(l[len(l) // 2:], e)
	elif l[len(l) // 2] == e:
		return True
	else:
		return f(l[:len(l) // 2], e)
o = 0
for i in range(len(l) - 1):
	for j in range(i + 1, len(l)):
		s = ''
		for k in range(kk):
			if l[i][k] == l[j][k]:
				s += l[i][k]
			elif 'S' not in [l[i][k], l[j][k]]:
				s += 'S'
			elif 'E' not in [l[i][k], l[j][k]]:
				s += 'E'
			elif 'T' not in [l[i][k], l[j][k]]:
				s += 'T'
		if s in l2:
			o += 1
print(o // 3)


def ne(a, b):
	if a == b:
		return a
	elif a == 'S' and b == 'E':
		return 'T'
	elif a == 'S' and b == 'T':
		return 'E'
	elif a == 'E' and b == 'T':
		return 'S'
	elif a == 'E' and b == 'S':
		return 'T'
	elif a == 'T' and b == 'S':
		return 'E'
	elif a == 'T' and b == 'E':
		return 'S'

def find_other(s1, s2, n):
	temp = ''
	for i in range(n):
		temp += ne(s1[i], s2[i])
	return temp
(a, b) = map(int, input().split())
s = []
for _ in range(a):
	s.append(input())
con = 0
s = set(s)
while len(s) > 2:
	st1 = s.pop()
	set2 = set()
	while len(s) >= 1:
		st2 = s.pop()
		temp2 = find_other(st1, st2, b)
		if temp2 in s:
			con += 1
			s.discard(temp2)
			set2.add(temp2)
		set2.add(st2)
	s = set2
print(con)


import sys
(n, k) = [int(x) for x in sys.stdin.readline().split(' ')]
cards = []
for _ in range(n):
	cards.append(sys.stdin.readline().rstrip())
cardset = set(cards)
asd = set(['S', 'E', 'T'])
ss = 0
for (i, ci) in enumerate(cards):
	for (j, cj) in enumerate(cards):
		if ci == cj:
			break
		com = ''
		for item in range(k):
			if ci[item] == cj[item]:
				com += ci[item]
			else:
				if ci[item] != 'S' and cj[item] != 'S':
					com += 'S'
				elif ci[item] != 'E' and cj[item] != 'E':
					com += 'E'
				if ci[item] != 'T' and cj[item] != 'T':
					com += 'T'
		if com in cardset:
			ss += 1
print(ss // 3)


def calc(a, b):
	ans = ''
	for i in range(k):
		if a[i] == b[i]:
			ans += a[i]
		elif a[i] != 'T' and b[i] != 'T':
			ans += 'T'
		elif a[i] != 'S' and b[i] != 'S':
			ans += 'S'
		else:
			ans += 'E'
	return ans
(n, k) = map(int, input().split())
d = {}
a = []
for i in range(n):
	s = input()
	a.append(s)
	d[s] = 1
count = 0
for i in range(n):
	for j in range(i + 1, n):
		if calc(a[i], a[j]) in d:
			count += 1
print(count // 3)


import copy
import sys
from collections import Counter
(n, k) = map(int, input().split())
mat = []
for i in range(n):
	mat.append(input())
res = 0
sett = set(mat)
n = len(mat)
dic = {}
tot = ord('S') + ord('T') + ord('E')
for i in range(n):
	x = mat[i]
	for j in range(i + 1, n):
		y = mat[j]
		tmp = []
		for m in range(k):
			if x[m] != y[m]:
				tmp.append(chr(tot - ord(x[m]) - ord(y[m])))
			else:
				tmp.append(x[m])
		st = ''.join(tmp)
		if st in sett:
			res += 1
print(res // 3)


(n, k) = [int(i) for i in input().split()]
d = {}
a = []
for i in range(n):
	x = input()
	if x not in d:
		d[x] = 0
	d[x] += 1
	a.append(x)
c = 0
for i in range(n):
	for j in range(i + 1, n):
		b = ''
		for i1 in range(k):
			if a[i][i1] == a[j][i1]:
				b = b + a[i][i1]
			else:
				ty = [0, 0, 0]
				if a[i][i1] == 'S' or a[j][i1] == 'S':
					ty[0] = 1
				if a[i][i1] == 'E' or a[j][i1] == 'E':
					ty[1] = 1
				if a[i][i1] == 'T' or a[j][i1] == 'T':
					ty[2] = 1
				if ty[0] == 0:
					b = b + 'S'
				elif ty[1] == 0:
					b = b + 'E'
				elif ty[2] == 0:
					b = b + 'T'
		if b in d:
			if a[i] == a[j]:
				if d[b] > 2:
					c += 1
			else:
				c += 1
print(int(c / 3))


import sys
import math
from collections import defaultdict, Counter
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
(n, k) = map(int, input().split())
l = []
s1 = set()
for i in range(n):
	s = input()
	l.append(s)
	s1.add(s)
ans = 0
for i in range(n - 2):
	for j in range(i + 1, n):
		s2 = ''
		for kk in range(k):
			if l[i][kk] == l[j][kk]:
				s2 += l[i][kk]
			elif l[i][kk] == 'T' and l[j][kk] == 'E' or (l[i][kk] == 'E' and l[j][kk] == 'T'):
				s2 += 'S'
			elif l[i][kk] == 'T' and l[j][kk] == 'S' or (l[i][kk] == 'S' and l[j][kk] == 'T'):
				s2 += 'E'
			elif l[i][kk] == 'S' and l[j][kk] == 'E' or (l[i][kk] == 'E' and l[j][kk] == 'S'):
				s2 += 'T'
		if s2 in s1:
			ans += 1
	s1.remove(l[i])
print(ans // 2)


import sys

def main():
	s = list()
	(n, k) = (int(e) for e in sys.stdin.readline().strip().split())
	q = set()
	for i in range(n):
		s.append(sys.stdin.readline().strip())
		q.add(s[i])
	m = ord('S') + ord('E') + ord('T')
	r = 0
	for i in range(n):
		for j in range(i + 1, n):
			t = list()
			b = 1
			for e in range(k):
				if s[i][e] == s[j][e]:
					t.append(s[i][e])
				else:
					t.append(chr(m - ord(s[i][e]) - ord(s[j][e])))
			if ''.join(t) in q:
				r += 1
	print(r // 3)
main()


def get_third(k, a, b):
	c = ''
	for i in range(k):
		if a[i] == b[i]:
			c += a[i]
		else:
			if a[i] != 'S' and b[i] != 'S':
				c += 'S'
			if a[i] != 'E' and b[i] != 'E':
				c += 'E'
			if a[i] != 'T' and b[i] != 'T':
				c += 'T'
	return c
(n, k) = list(map(int, input().split()))
cards = list()
for i in range(n):
	cards.append(input())
card_set = {cards[i]: i for i in range(n)}
count_valid = 0
for p in range(n - 2):
	for q in range(p + 1, n - 1):
		c = get_third(k, cards[p], cards[q])
		if c in card_set.keys() and card_set[c] > q:
			count_valid += 1
print(count_valid)


import sys
ip = lambda : sys.stdin.readline().rstrip()
(n, k) = map(int, ip().split())
a = []
s = set()
for _ in range(n):
	a.append(ip())
	s.add(a[-1])
ans = 0
for i in range(n):
	for j in range(i + 1, n):
		(s1, s2) = (a[i], a[j])
		s3 = ''
		for K in range(k):
			if s1[K] == s2[K]:
				s3 += s1[K]
			else:
				(v1, v2) = (s1[K], s2[K])
				if v1 == 'S' and v2 == 'E' or (v1 == 'E' and v2 == 'S'):
					s3 += 'T'
				elif v1 == 'S' and v2 == 'T' or (v1 == 'T' and v2 == 'S'):
					s3 += 'E'
				elif v1 == 'T' and v2 == 'E' or (v1 == 'E' and v2 == 'T'):
					s3 += 'S'
		if s3 in s:
			ans += 1
print(ans // 3)


from sys import stdin, stdout
(n, m) = list(map(int, stdin.readline().split()))
l = []
for i in range(n):
	l.append(input())
out = 0
d = {}
for i in l:
	d[i] = 1
l = list(d.keys())
n = len(l)
for i in range(n - 1):
	a = l[i]
	for j in range(i + 1, n):
		b = l[j]
		nw = ''
		for k in range(m):
			if a[k] == b[k]:
				nw += a[k]
			else:
				v = a[k] + b[k]
				if 'E' not in v:
					nw += 'E'
				elif 'T' not in v:
					nw += 'T'
				elif 'S' not in v:
					nw += 'S'
		if d.get(nw, 0):
			out += 1
stdout.write(str(out // 3))


(n, q) = [int(x) for x in input().split()]
arr = []
for _ in range(n):
	s = input()
	arr.append(s)
arr.sort()
import bisect
cnt = 0
for i in range(n - 2):
	for j in range(i + 1, n - 1):
		check = 0
		st = ''
		while check < q:
			if arr[i][check] == arr[j][check]:
				st += arr[i][check]
			elif arr[i][check] != arr[j][check] and arr[i][check] != 'S' and (arr[j][check] != 'S'):
				st += 'S'
			elif arr[i][check] != arr[j][check] and arr[i][check] != 'E' and (arr[j][check] != 'E'):
				st += 'E'
			elif arr[i][check] != arr[j][check] and arr[i][check] != 'T' and (arr[j][check] != 'T'):
				st += 'T'
			check += 1
		ind = bisect.bisect_left(arr, st)
		if ind < n and arr[ind] == st and (ind > j):
			cnt += 1
print(cnt)


import sys

def input():
	return sys.stdin.readline().strip()
(n, k) = [int(x) for x in input().split()]
V = [input() for x in range(n)]
M = set(V)
Z = ['S', 'E', 'T']
cc = 0
for i in range(n):
	for j in range(i + 1, n):
		s = ''
		for l in range(k):
			if V[i][l] == V[j][l]:
				s += V[i][l]
			else:
				for c in Z:
					if V[i][l] != c and V[j][l] != c:
						s += c
		if s in M:
			cc += 1
print(cc // 3)


(N, K) = list(map(int, input().split()))
C = []
S = set()
for i in range(N):
	C.append(input().strip())
	S.add(C[-1])
ans = 0
for i in range(N):
	for j in range(i + 1, N):
		aux = ''
		for k in range(K):
			if C[i][k] == C[j][k]:
				aux += C[i][k]
			if C[i][k] == 'S' and C[j][k] == 'E' or (C[i][k] == 'E' and C[j][k] == 'S'):
				aux += 'T'
			if C[i][k] == 'S' and C[j][k] == 'T' or (C[i][k] == 'T' and C[j][k] == 'S'):
				aux += 'E'
			if C[i][k] == 'T' and C[j][k] == 'E' or (C[i][k] == 'E' and C[j][k] == 'T'):
				aux += 'S'
		if aux in S:
			ans += 1
print(ans // 3)


(n, k) = list(map(int, input().split()))
cards = set()
L = []
x = ord('S') + ord('E') + ord('T')
total = 0
for i in range(n):
	s = input()
	cards.add(s)
	L.append(s)
for i in range(n):
	for j in range(n):
		if i == j:
			continue
		opposite = []
		for l in range(k):
			if L[i][l] == L[j][l]:
				opposite.append(L[i][l])
			else:
				opposite.append(chr(x - ord(L[i][l]) - ord(L[j][l])))
		if ''.join(opposite) in cards:
			total += 1
print(total // 6)


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
from collections import defaultdict
from itertools import permutations
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from itertools import combinations as cb
h = {'S': 1, 'E': 2, 'T': 3}
(n, k) = map(int, input().split())
S = set((tuple(map(h.get, input().rstrip())) for _ in range(n)))
ans = 0
for (a, b) in cb(S, 2):
	c = []
	for i in range(k):
		if a[i] == b[i]:
			c.append(a[i])
		else:
			t = 6 - a[i] - b[i]
			c.append(t)
	if tuple(c) in S:
		ans += 1
print(ans // 3)


(n, m) = list(map(int, input().split()))
l = []
for i in range(n):
	l.append(input())
out = 0
d = {}
for i in l:
	d[i] = 1
for i in range(n - 1):
	a = l[i]
	for j in range(i + 1, n):
		b = l[j]
		nw = ''
		for k in range(m):
			if a[k] == b[k]:
				nw += a[k]
			elif a[k] + b[k] == 'ST' or a[k] + b[k] == 'TS':
				nw += 'E'
			elif a[k] + b[k] == 'SE' or a[k] + b[k] == 'ES':
				nw += 'T'
			elif a[k] + b[k] == 'ET' or a[k] + b[k] == 'TE':
				nw += 'S'
		if d.get(nw, 0):
			out += 1
print(out // 3)


from sys import stdin
(n, k) = map(int, stdin.readline().split())
a = [stdin.readline().strip() for _ in range(n)]
d = {}
res = 0
S = ord('S') + ord('E') + ord('T')
for i in range(n):
	if a[i] in d.keys():
		d[a[i]] += 1
	else:
		d[a[i]] = 1
for i in range(n):
	for j in range(i + 1, n):
		if i == j:
			continue
		t = ''
		for p in range(k):
			if a[i][p] == a[j][p]:
				t += a[i][p]
			else:
				t += chr(S - ord(a[i][p]) - ord(a[j][p]))
		if t in d.keys():
			res += d[t]
print(int(res / 3))


import sys
import math
input = sys.stdin.readline
from functools import cmp_to_key
import bisect

def pi():
	return int(input())

def pl():
	return int(input(), 16)

def ti():
	return list(map(int, input().split()))

def ts():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
f = []

def factMod(n, m):
	global f
	f = [1 for i in range(n + 1)]
	f[0] = 1
	for i in range(1, n + 1):
		f[i] = f[i - 1] * i % m

def fact(n):
	global f
	f = [1 for i in range(n)]
	for i in range(1, n):
		f[i] = f[i - 1] * i

def fast_mod_exp(a, b, m):
	res = 1
	while b > 0:
		if b & 1:
			res = res * a % m
		a = a * a % m
		b = b >> 1
	return res

def inverseMod(n, m):
	return fast_mod_exp(n, m - 2, m)

def ncrMod(n, r, m):
	if r == 0:
		return 1
	if n < r:
		return 0
	return f[n] * inverseMod(f[n - r], m) % m * inverseMod(f[r], m) % m

def ncr(n, r):
	if r == 0:
		return 1
	if n < r:
		return 0
	return f[n] / (f[r] * f[n - r])

def nc2(n):
	return n * (n - 1) / 2

def main():
	B()

def B():
	[n, k] = ti()
	mp = {}
	a = [[0 for j in range(k)] for i in range(n)]
	for i in range(n):
		s = input()
		s = s[0:len(s) - 1]
		for j in range(k):
			if s[j] == 'S':
				a[i][j] = 1
			if s[j] == 'E':
				a[i][j] = 2
			if s[j] == 'T':
				a[i][j] = 4
		if s not in mp:
			mp[s] = 1
		else:
			mp[s] += 1
	ans = 0
	for i in range(n):
		for j in range(i + 1, n):
			req = ''
			for p in range(k):
				sum = a[i][p] + a[j][p]
				if sum == 2:
					req += 'S'
				elif sum == 4:
					req += 'E'
				elif sum == 8:
					req += 'T'
				elif sum == 3:
					req += 'T'
				elif sum == 5:
					req += 'E'
				elif sum == 6:
					req += 'S'
			if req not in mp:
				continue
			ans += mp[req]
	print(int(ans / 3))
main()


def main():
	(n, k) = map(int, input().split())
	(res, bbb) = (0, set())
	for _ in range(n):
		aa = bytes((ord(c) - 3 & 3 for c in input()))
		for bb in bbb:
			res += bytes((((0, 2, 1), (2, 1, 0), (1, 0, 2))[a][b] for (a, b) in zip(aa, bb))) in bbb
		bbb.add(aa)
	print(res // 2)
main()


[n, k] = [int(x) for x in input().split()]
cards = []
nums = {}
for i in range(n):
	s = input()
	cards.append([1 if x == 'S' else 2 if x == 'E' else 3 if x == 'T' else 'Z' for x in s])
	t = ''
	for a in cards[-1]:
		t += str(a)
	nums[int(t)] = i

def gen(i, j):
	a = cards[i]
	b = cards[j]
	t = ''
	for k in range(len(a)):
		if a[k] == b[k]:
			t += str(a[k])
		elif a[k] + b[k] == 3:
			t += '3'
		elif a[k] + b[k] == 4:
			t += '2'
		elif a[k] + b[k] == 5:
			t += '1'
	return int(t)
count = 0
for i in range(n):
	for j in range(i + 1, n):
		if gen(i, j) in nums and nums[gen(i, j)] > j:
			count += 1
print(count)


from collections import defaultdict
(n, k) = map(int, input().split())
a = []
import sys
input = sys.stdin.readline
for i in range(n):
	s = input().rstrip()
	a.append(s)
d = set(a)
c = 0
for i in range(n):
	for j in range(i + 1, n):
		z = ''
		l = ['S', 'E', 'T']
		for p in range(k):
			if a[i][p] == a[j][p]:
				z += a[i][p]
			else:
				for y in l:
					if y != a[i][p] and y != a[j][p]:
						z += y
		if z in d:
			c += 1
print(c // 3)


def main():
	(n, k) = map(int, input().split())
	t = str.maketrans({'S': '0000100', 'E': '0001000', 'T': '0010000'})
	xx = {int(input().translate(t), 2) for _ in range(n)}
	m = int('0011100' * k, 2)
	res = 0
	while xx:
		x = xx.pop()
		res += sum((m - (x | y) ^ ((x & y) >> 2) * 31 & m in xx for y in xx))
	print(res // 2)
main()


(n, k) = map(int, input().split())
c = []
for _ in range(n):
	c += [input()]
st = set(c)
ans = 0
for i1 in range(n):
	for j1 in range(i1 + 1, n):
		(i, j) = (c[i1], c[j1])
		t = ''
		for e in range(k):
			if i[e] == j[e]:
				t += i[e]
			if i[e] == 'S' and j[e] == 'E' or (i[e] == 'E' and j[e] == 'S'):
				t += 'T'
			if i[e] == 'E' and j[e] == 'T' or (i[e] == 'T' and j[e] == 'E'):
				t += 'S'
			if i[e] == 'S' and j[e] == 'T' or (i[e] == 'T' and j[e] == 'S'):
				t += 'E'
		if t in st:
			ans += 1
print(ans // 3)


import gc
gc.disable()
(n, k) = map(int, input().split())
deck = set()
for _ in range(n):
	deck.add(input())
ans = 0

def thirdChar(a, b):
	if a == b:
		return a
	if a == 'S' and b == 'T' or (a == 'T' and b == 'S'):
		return 'E'
	if a == 'S' and b == 'E' or (a == 'E' and b == 'S'):
		return 'T'
	if a == 'E' and b == 'T' or (a == 'T' and b == 'E'):
		return 'S'

def findThird(c1, c2):
	l = []
	for i in range(k):
		l.append(thirdChar(c1[i], c2[i]))
	return ''.join(l)
for c1 in deck:
	for c2 in deck:
		if c2 > c1:
			c3 = findThird(c1, c2)
			if c3 > c2 and c3 in deck:
				ans += 1
print(ans)


import itertools
import sys
from bisect import bisect
input = sys.stdin.readline

def madguy(alpha1, alpha2):
	out = []
	for g in range(len(alpha1)):
		if alpha1[g] == alpha2[g]:
			out.append(alpha1[g])
		else:
			out.append(3 - alpha1[g] - alpha2[g])
	return out
(n, k) = map(int, input().split())
cards = []
dic = {'S': 0, 'E': 1, 'T': 2}
s = set()
for _ in range(n):
	x = input().strip()
	cards.append([dic[i] for i in x])
	s.add(tuple([dic[i] for i in x]))
all = 0
for x in itertools.combinations(cards, 2):
	aaa = madguy(x[0], x[1])
	if tuple(aaa) in s:
		all += 1
print(all // 3)


(n, k) = map(int, input().split())
s = [input() for i in range(n)]
a = set(s)
s.sort()
cnt = 0
for i in range(n):
	for j in range(i + 1, n):
		cur = ''
		for h in range(k):
			if s[i][h] == s[j][h]:
				cur += s[i][h]
			elif s[i][h] == 'E' and s[j][h] == 'T':
				cur += 'S'
			elif s[i][h] == 'S' and s[j][h] == 'T':
				cur += 'E'
			elif s[i][h] == 'E' and s[j][h] == 'S':
				cur += 'T'
			elif s[i][h] == 'T' and s[j][h] == 'S':
				cur += 'E'
			elif s[i][h] == 'T' and s[j][h] == 'E':
				cur += 'S'
			elif s[i][h] == 'S' and s[j][h] == 'E':
				cur += 'T'
		if cur in a:
			cnt += 1
print(cnt // 3)


(n, k) = map(int, input().split())
S = [input().strip() for i in range(n)]
SET = set(S)
ANS = 0
for i in range(n - 1):
	for j in range(i + 1, n):
		rest = ''
		for l in range(k):
			if S[i][l] == S[j][l]:
				rest += S[i][l]
			else:
				rest += chr(236 - ord(S[i][l]) - ord(S[j][l]))
		if rest in SET:
			ANS += 1
print(ANS // 3)


import os
import sys
from io import BytesIO, IOBase
import heapq as h
from bisect import bisect_left
from types import GeneratorType
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import time
start_time = time.time()
import collections as col
import math, string
from functools import reduce

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())
MOD = 10 ** 9 + 7

def solve():
	(N, K) = getInts()
	S = set()
	T = list()
	for n in range(N):
		z = getStr()
		X = []
		for el in z:
			if el == 'S':
				X.append(0)
			elif el == 'T':
				X.append(1)
			else:
				X.append(2)
		S.add(''.join(map(str, X)))
		T.append(X)
	ans = 0
	for i in range(N):
		for j in range(i + 1, N):
			tmp = []
			for k in range(K):
				X1 = T[i][k]
				X2 = T[j][k]
				if X1 == X2:
					tmp.append(X1)
				else:
					tmp.append(3 - X1 - X2)
			if ''.join(map(str, tmp)) in S:
				ans += 1
	return ans // 3
print(solve())


(n, k) = [int(s) for s in input().split()]
l = [input().strip() for i in range(n)]
s = set(l)
comp = {'ST': 'E', 'TS': 'E', 'SE': 'T', 'ES': 'T', 'ET': 'S', 'TE': 'S'}
ans = 0
for i in range(n - 1):
	for j in range(i + 1, n):
		s1 = ''
		for w in range(k):
			if l[i][w] == l[j][w]:
				s1 += l[i][w]
			else:
				s1 += comp[l[i][w] + l[j][w]]
		if s1 in s:
			ans += 1
print(ans // 3)


ans = 0
V = []
M = {}
(n, k) = map(int, input().split())
for i in range(n):
	str = input()
	M[str] = 1
	V.append(str)
for i in range(n - 1):
	str1 = V[i]
	for j in range(i + 1, n):
		str2 = V[j]
		str = ''
		for K in range(k):
			if str1[K] == str2[K]:
				str += str1[K]
			elif str1[K] is not 'S' and str2[K] is not 'S':
				str += 'S'
			elif str1[K] is not 'E' and str2[K] is not 'E':
				str += 'E'
			else:
				str += 'T'
		if M.get(str) is not None:
			ans += 1
print(ans // 3)


(n, k) = map(int, input().split())
cards = set((input() for _ in range(n)))
lc = list(cards)
ans = 0
for i in range(n):
	for j in range(i):
		thrd = ''
		for t in range(k):
			if lc[i][t] == lc[j][t]:
				thrd += lc[i][t]
			else:
				for ch in ['S', 'E', 'T']:
					if ch != lc[i][t] and ch != lc[j][t]:
						thrd += ch
		if thrd in cards:
			ans += 1
ans //= 3
print(ans)


(n, k) = map(int, input().split())
cards = []
sum = ord('S') + ord('E') + ord('T')
for _ in range(n):
	cards.append(input())
cards_set = set(cards)
cnt = 0
for i in range(n - 1):
	for j in range(i + 1, n):
		ans = []
		for x in range(k):
			if cards[i][x] == cards[j][x]:
				ans.append(cards[i][x])
			else:
				ans.append(chr(sum - ord(cards[i][x]) - ord(cards[j][x])))
		if ''.join(ans) in cards_set:
			cnt += 1
print(cnt // 3)


def main():
	(N, K) = list(map(int, input().split()))
	S = [input() for _ in range(N)]
	(count, strs) = (0, [])
	for i in range(N):
		for j in range(i + 1, N):
			s = ''
			for k in range(K):
				if S[i][k] == S[j][k]:
					s += S[i][k]
				else:
					add = ['S', 'E', 'T']
					add.remove(S[i][k])
					add.remove(S[j][k])
					s += add[0]
			strs.append(s)
	S = set(S)
	for s in strs:
		if s in S:
			count += 1
	print(count // 3)
main()


(n, K) = map(int, input().split())
count = 0
card = []
cards_set = {}
for _ in range(n):
	s = input()
	card.append(s)
	cards_set[s] = _
for i in range(n - 2):
	for j in range(i + 1, n - 1):
		third = ''
		for l in range(K):
			if card[i][l] == card[j][l]:
				third += card[i][l]
			else:
				for letter in ['S', 'E', 'T']:
					if letter not in [card[i][l], card[j][l]]:
						break
				third += letter
		if third in cards_set and cards_set[third] > j:
			count += 1
if n < 3:
	print(0)
else:
	print(count)


import sys
import math
import heapq
import bisect
import re
from collections import deque
sys.setrecursionlimit(1000000000)

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def finput():
	return float(input())

def tinput():
	return input().split()

def rinput():
	return map(int, tinput())

def rlinput():
	return list(input())

def modst(w, s):
	res = 1
	while s:
		if s % 2:
			res *= w
		w *= w
		s //= 2
	return res

def error(n):
	return 'YES'

def main():
	(n, k) = rinput()
	s = []
	for i in range(n):
		s.append(input())
	res = 0
	q = dict()
	for i in s:
		q[i] = 0
	for i in range(n):
		for j in range(i + 1, n):
			t = ['0'] * k
			for o in range(k):
				if s[i][o] == s[j][o]:
					t[o] = s[i][o]
				else:
					if s[i][o] != 'S' and s[j][o] != 'S':
						t[o] = 'S'
					if s[i][o] != 'E' and s[j][o] != 'E':
						t[o] = 'E'
					if s[i][o] != 'T' and s[j][o] != 'T':
						t[o] = 'T'
			q[s[i]] -= 1
			q[s[j]] -= 1
			st = ''.join(t)
			if st in q:
				res += q[st]
			q[s[i]] += 1
			q[s[j]] += 1
		q[s[i]] += 1
	print(res)
for qwerty in range(1):
	main()


def go(s1, s2):
	ans = ''
	p = 'SET'
	for i in range(len(s1)):
		if s1[i] == s2[i]:
			ans += s1[i]
		elif p[0] != s1[i] and p[0] != s2[i]:
			ans += p[0]
		elif p[1] != s1[i] and p[1] != s2[i]:
			ans += p[1]
		elif p[2] != s1[i] and p[2] != s2[i]:
			ans += p[2]
	return ans
(n, k) = [int(i) for i in input().split()]
se = set()
if n < 3:
	print(0)
	exit(0)
for i in range(n):
	s = input()
	se.add(s)
ans = 0
a = list(se)
st = set()
for i in range(len(a)):
	for j in range(i + 1, len(a)):
		if (a[i], a[j]) in st or (a[j], a[i]) in st:
			continue
		chel = go(a[i], a[j])
		if chel in se:
			ans += 1
			st.add((a[j], chel))
			st.add((a[i], chel))
print(ans)


from sys import stdin

def solve():
	map = {'e': 0, 's': 1, 't': 2}

	def get_bits(letters):
		evens = 0
		odds = 0
		for d in (map[e] for e in letters):
			evens = evens << 1 | 1 & d
			odds = odds << 1 | 1 & d >> 1
		return (odds, evens)
	(n, k) = [int(i) for i in stdin.readline().strip().split()]
	cards = [get_bits(stdin.readline().strip().lower()) for _ in range(n)]
	pairs = ((cards[i], cards[j]) for i in range(n) for j in range(i + 1, n))
	cards_set = set(cards)
	counter = 0
	for (x, y) in pairs:
		a = x[0]
		A = x[1]
		b = y[0]
		B = y[1]
		c = A & ~a & B & ~b | ~A & ~a & ~B & b | B & ~b & A & ~a | ~B & ~b & ~A & a
		C = ~A & a & ~B & b | ~A & ~a & B & ~b | ~B & b & ~A & a | ~B & ~b & A & ~a
		if (C, c) in cards_set:
			counter += 1
	print(counter // 3)
solve()


from collections import defaultdict
(N, M) = map(int, input().split())
xs = []
di = defaultdict(int)
for _ in range(N):
	x = 0
	for (i, c) in enumerate(input().strip()):
		x += ((4 if c == 'E' else 1) if c != 'S' else 2) << 7 * i + 2
	xs.append(x)
	di[x] += 1
m = 0
for i in range(M):
	m += 7 << 2 << 7 * i
r = 0
for (i, a) in enumerate(xs):
	for j in range(i + 1, N):
		b = xs[j]
		c = (a & b) << 1 | (a & b) << 2 | (a & b) >> 1 | (a & b) >> 2
		r += di[(~(a ^ b) ^ c) & m]
print(r // 3)


def main():
	(n, k) = map(int, input().split())
	cards = []
	for i in range(n):
		cards.append(input().strip())
	cards_set = set(cards)
	ways = 0
	for i in range(n):
		for j in range(i + 1, n):
			s = ''
			for z in range(k):
				if cards[i][z] == cards[j][z]:
					s += cards[i][z]
				else:
					for c in 'SET':
						if c != cards[i][z] and c != cards[j][z]:
							s += c
							break
			if s in cards_set:
				ways += 1
	ways //= 3
	print(ways)
main()


n = int(input().split()[0])
s = {input() for _ in [0] * n}
a = [[ord(x) for x in y] for y in s]
print(sum((''.join((chr((66 ^ x ^ y, x)[x == y]) for (x, y) in zip(a[i], a[j]))) in s for i in range(n) for j in range(i))) // 3)


from math import *
(n, k) = map(int, input().split())

def cons(a, b):
	c = [''] * k
	for i in range(k):
		if a[i] != b[i]:
			if a[i] == 'S' and b[i] == 'E' or (b[i] == 'S' and a[i] == 'E'):
				c[i] = 'T'
			elif a[i] == 'S' and b[i] == 'T' or (b[i] == 'S' and a[i] == 'T'):
				c[i] = 'E'
			else:
				c[i] = 'S'
		else:
			c[i] = a[i]
	return c
ind = {}
li = []
for i in range(n):
	t = input()
	li.append(t)
	ind[t] = i
ans = 0
for i in range(n):
	for j in range(i + 1, n):
		temp = ''.join(cons(li[i], li[j]))
		if temp in ind and ind[temp] > i:
			ans += 1
print(ans // 2)


def binarySearch(arr, l, r, x):
	if r >= l:
		mid = l + (r - l) // 2
		if arr[mid] == x:
			return True
		elif arr[mid] > x:
			return binarySearch(arr, l, mid - 1, x)
		else:
			return binarySearch(arr, mid + 1, r, x)
	else:
		return False
(n, k) = map(int, input().split())
ls = []
for i in range(n):
	s = input()
	ls.append(s)
ls.sort()
count = 0
for i in range(n - 2):
	for j in range(i + 1, n - 1):
		s = ''
		for x in range(k):
			if ls[i][x] == ls[j][x]:
				s += ls[i][x]
			else:
				a = ['S', 'E', 'T']
				a.remove(ls[i][x])
				a.remove(ls[j][x])
				s += a[0]
		if binarySearch(ls, j + 1, n - 1, s):
			count += 1
print(count)


def f(x, y):
	if x == y:
		return x
	if x == 'T' and y == 'E' or (x == 'E' and y == 'T'):
		return 'S'
	if x == 'S' and y == 'T' or (x == 'T' and y == 'S'):
		return 'E'
	if x == 'S' and y == 'E' or (x == 'E' and y == 'S'):
		return 'T'
(n, k) = [int(x) for x in input().split()]
s = []
for i in range(n):
	s.append(input())
ans = 0
m = {}
for i in range(n - 1, -1, -1):
	for j in range(i):
		cur = ''
		for l in range(k):
			cur += f(s[i][l], s[j][l])
		if cur in m:
			ans += m[cur]
	if s[i] in m:
		m[s[i]] += 1
	else:
		m[s[i]] = 1
print(ans)


from itertools import combinations
import sys
input = lambda : sys.stdin.readline().rstrip()
(n, k) = map(int, input().split())
li = []
for _ in range(n):
	li.append(input())
se = set(li)
ans = 0
for (x, y) in combinations(li, 2):
	tmp = []
	for i in range(k):
		if x[i] == y[i]:
			tmp.append(x[i])
		elif x[i] != 'S' and y[i] != 'S':
			tmp.append('S')
		elif x[i] != 'E' and y[i] != 'E':
			tmp.append('E')
		else:
			tmp.append('T')
	tmp = ''.join(tmp)
	if tmp in se:
		ans += 1
print(ans // 3)


def main():
	from sys import stdin, stdout
	xorred = ord('s') ^ ord('e') ^ ord('t')

	def _third(c, d):
		return c if c == d else chr(ord(c) ^ ord(d) ^ xorred)

	def third(s, t):
		return ''.join((_third(c, d) for (c, d) in zip(s, t)))
	(n, k) = map(int, stdin.readline().split())
	inp = set()
	ans = 0
	for _ in range(n):
		inp1 = stdin.readline().rstrip('\n').lower()
		for inp2 in inp:
			if third(inp1, inp2) in inp:
				ans += 1
		inp.add(inp1)
	stdout.write(f'{ans // 2}')
main()


(n, m) = map(int, input().split())
l = []
s = set()
for i in range(n):
	l.append(input())
	s.add(l[i])
l1 = set()
s1 = set()
ans = 0
for i in range(n):
	for j in range(i + 1, n):
		st = ''
		for k in range(m):
			li = ['S', 'E', 'T']
			if l[i][k] == l[j][k]:
				st += l[i][k]
			else:
				li.remove(l[i][k])
				li.remove(l[j][k])
				st += li[0]
		p = [l[i], l[j], st]
		p.sort()
		p = tuple(p)
		if p not in l1 and st in s:
			ans += 1
			l1.add(p)
print(ans)


def third(a, b):
	if a == b:
		return a
	elif a == 'S' or b == 'S':
		if a == 'E' or b == 'E':
			return 'T'
		else:
			return 'E'
	else:
		return 'S'
(n, k) = map(int, input().split())
arr = [None] * n
count = 0
for i in range(n):
	str = input()
	arr[i] = str
st = set(arr)
for i in range(n - 1):
	for j in range(i + 1, n):
		third_st = ''
		for q in range(k):
			third_st += third(arr[i][q], arr[j][q])
		if third_st in st:
			count += 1
print(count // 3)


import sys
import math
import heapq
import collections

def inputnum():
	return int(input())

def inputnums():
	return map(int, input().split())

def inputlist():
	return list(map(int, input().split()))

def inputstring():
	return [x for x in input()]

def inputstringnum():
	return [ord(x) - ord('a') for x in input()]

def inputmatrixchar(rows):
	arr2d = [[j for j in input().strip()] for i in range(rows)]
	return arr2d

def inputmatrixint(rows):
	arr2d = []
	for _ in range(rows):
		arr2d.append([int(i) for i in input().split()])
	return arr2d

def conv2(l1, l2):
	if l1 == l2:
		return l1
	if l1 == 'S':
		if l2 == 'E':
			return 'T'
		return 'E'
	if l1 == 'E':
		if l2 == 'S':
			return 'T'
		return 'S'
	if l1 == 'T':
		if l2 == 'E':
			return 'S'
		return 'E'
(n, k) = inputnums()
sets = [''] * n
g = {}
ans = 0
for i in range(n):
	sets[i] = input()
	if g.get(sets[i], 0) != 0:
		ans += g[sets[i]]
	for j in range(0, i):
		string = ''.join([conv2(sets[i][m], sets[j][m]) for m in range(k)])
		g[string] = g.get(string, 0) + 1
print(ans)


(n, k) = map(int, input().split(' '))
g = []
for z in range(n):
	c = input()[:k]
	h = []
	for (i, f) in enumerate(c):
		if f == 'S':
			l = 0
		elif f == 'E':
			l = 1
		else:
			l = 2
		h.append(l)
	g.append(tuple(h))
t = set(g)
p = 0
for i in range(len(g)):
	a = g[i]
	for j in range(i + 1, len(g)):
		b = g[j]
		n = []
		for z in range(k):
			if a[z] == b[z]:
				n.append(a[z])
				continue
			else:
				n.append(3 - a[z] - b[z])
		if tuple(n) in t:
			p += 1
print(p // 3)


import sys
reader = (line.rstrip() for line in sys.stdin)
input = reader.__next__
(n, k) = map(int, input().split())
cards = [input() for _ in range(n)]
check = set(cards)
ordSum = ord('S') + ord('E') + ord('T')
ctr = 0
for i in range(n):
	for j in range(i + 1, n):
		card1 = cards[i]
		card2 = cards[j]
		card3 = ''
		for x in range(k):
			c1 = card1[x]
			c2 = card2[x]
			if c1 == c2:
				card3 += c1
			else:
				c3 = chr(ordSum - ord(c1) - ord(c2))
				card3 += c3
		if card3 in check:
			ctr += 1
print(ctr // 3)


from itertools import combinations
(n, k) = map(int, input().split())
cards = [None for i in range(n)]
for i in range(n):
	cards[i] = input()
ans = 0
card_set = set(cards)
combos = combinations(cards, 2)
for i in range(n):
	for j in range(i + 1, n):
		req_ans = ''
		for l in range(k):
			if cards[i][l] == cards[j][l]:
				req_ans += cards[i][l]
			elif cards[i][l] == 'S' and cards[j][l] == 'E' or (cards[i][l] == 'E' and cards[j][l] == 'S'):
				req_ans += 'T'
			elif cards[i][l] == 'S' and cards[j][l] == 'T' or (cards[i][l] == 'T' and cards[j][l] == 'S'):
				req_ans += 'E'
			else:
				req_ans += 'S'
		if req_ans in card_set:
			ans += 1
print(ans // 3)


(n, k) = [int(x) for x in input().split()]
l = []
for i in range(n):
	l.append(input())
st = set(l)
total = ord('S') + ord('E') + ord('T')
ans = 0
for i in range(n - 1):
	for j in range(i + 1, n):
		c = ''
		for z in range(k):
			if l[i][z] == l[j][z]:
				c = c + l[i][z]
			else:
				c = c + chr(total - ord(l[i][z]) - ord(l[j][z]))
		if c in st:
			ans += 1
print(ans // 3)


from collections import defaultdict

def get(x, y):
	a = ['S', 'E', 'T']
	a.remove(x)
	a.remove(y)
	return a[0]

def solve():
	(n, x) = [int(f) for f in input().split()]
	a = []
	d = defaultdict(int)
	for i in range(n):
		s = input()
		a += [s]
		d[s] += 1
	ans = 0
	for i in range(n - 1):
		for j in range(i + 1, n):
			s = ''
			for k in range(x):
				if a[i][k] == a[j][k]:
					s += str(a[j][k])
				else:
					s += get(a[i][k], a[j][k])
			ans += d[s]
	print(ans // 3)
for _ in range(1):
	solve()


import sys, itertools
(N, K) = [int(i) for i in sys.stdin.readline().strip().split(' ')]
S = set()
for _ in range(N):
	S.add(sys.stdin.readline().strip())
ans = 0
for c in itertools.combinations(S, 2):
	NS = ''
	for (a, b) in zip(c[0], c[1]):
		if a == b:
			NS += a
		elif a == 'S':
			if b == 'E':
				NS += 'T'
			else:
				NS += 'E'
		elif a == 'E':
			if b == 'S':
				NS += 'T'
			else:
				NS += 'S'
		elif a == 'T':
			if b == 'S':
				NS += 'E'
			else:
				NS += 'S'
	if NS in S:
		ans += 1
print(ans // 3)


(n, k) = map(int, input().split())
dic = {}
x = []
for i in range(n):
	s = input()
	dic[s] = i
	x.append(s)
ans = 0
for i in range(n):
	for j in range(i + 1, n):
		hyp = ''
		for l in range(k):
			if x[i][l] == x[j][l]:
				hyp += x[j][l]
			elif x[i][l] == 'S' and x[j][l] == 'T' or (x[i][l] == 'T' and x[j][l] == 'S'):
				hyp += 'E'
			elif x[i][l] == 'S' and x[j][l] == 'E' or (x[i][l] == 'E' and x[j][l] == 'S'):
				hyp += 'T'
			elif x[i][l] == 'E' and x[j][l] == 'T' or (x[i][l] == 'T' and x[j][l] == 'E'):
				hyp += 'S'
		if hyp in dic and dic[hyp] > j:
			ans += 1
print(ans)


I = lambda : list(map(int, input().split()))
(n, m) = I()
l = []
d = {}
for i in range(n):
	x = input()
	l.append(x)
	d[x] = 1
x = 0
v = [0] * n
for i in range(n):
	if v[i]:
		continue
	for j in range(i + 1, n):
		if v[j]:
			continue
		p = ''
		for r in range(m):
			if l[i][r] == l[j][r]:
				p += l[i][r]
			else:
				k = l[i][r] + l[j][r]
				if k in ['SE', 'ES']:
					p += 'T'
				elif k in ['ET', 'TE']:
					p += 'S'
				else:
					p += 'E'
		x += d.get(p, 0)
print(x // 3)


(n, k) = map(int, input().split())
l = []
for i in range(n):
	l.append(input())
ans = 0
for i in range(n):
	s = set()
	for jj in range(i + 1, n):
		s.add(l[jj])
	for j in range(i + 1, n):
		to_find = ''
		for kk in range(k):
			if l[i][kk] == l[j][kk]:
				to_find += l[i][kk]
			else:
				for ss in ['S', 'E', 'T']:
					if ss not in l[i][kk] and ss not in l[j][kk]:
						to_find += ss
						break
		s.remove(l[j])
		if to_find in s:
			ans += 1
print(ans)


from collections import Counter
from collections import defaultdict
import math
import random
import heapq as hq
from math import sqrt
import sys

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def tinput():
	return input().split()

def rinput():
	return map(int, tinput())

def rlinput():
	return list(rinput())
mod = int(1000000000.0) + 7
(n, k) = rinput()
a = []
d = {}
for i in range(n):
	s = input()
	a.append(s)
	d[s] = 1
ans = 0
for i in range(n - 1):
	s1 = a[i]
	for j in range(i + 1, n):
		s2 = a[j]
		want = ''
		for l in range(k):
			if s1[l] == s2[l]:
				want += s1[l]
			elif s1[l] is not 'S' and s2[l] is not 'S':
				want += 'S'
			elif s1[l] is not 'E' and s2[l] is not 'E':
				want += 'E'
			else:
				want += 'T'
		if want in d:
			ans += 1
print(ans // 3)


(n, f) = map(int, input().split())
a = []
for _ in range(n):
	s = input()
	a.append(s)
count = 0
strs = []
for i in range(n):
	for j in range(i + 1, n):
		s = ''
		for k in range(f):
			if a[i][k] == a[j][k]:
				s += a[i][k]
			else:
				add = ['S', 'E', 'T']
				add.remove(a[i][k])
				add.remove(a[j][k])
				s += add[0]
		strs.append(s)
a = set(a)
for s in strs:
	if s in a:
		count += 1
print(count // 3)


def binarySearch(arr, x):
	l = 0
	r = len(arr) - 1
	while l <= r:
		mid = (l + r) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] < x:
			l = mid + 1
		else:
			r = mid - 1
	return -1
(n, k) = map(int, input().split())
s = []
for i in range(n):
	ss = input()
	s.append(ss)
s.sort()
count = 0
i = 0
while i < n - 1:
	for j in range(i + 1, n):
		s1 = s[i]
		s2 = s[j]
		ans = ''
		for ii in range(k):
			if s1[ii] == s2[ii]:
				ans += s1[ii]
			elif s1[ii] == 'S' and s2[ii] == 'E':
				ans += 'T'
			elif s1[ii] == 'S' and s2[ii] == 'T':
				ans += 'E'
			elif s1[ii] == 'E' and s2[ii] == 'S':
				ans += 'T'
			elif s1[ii] == 'E' and s2[ii] == 'T':
				ans += 'S'
			elif s1[ii] == 'T' and s2[ii] == 'S':
				ans += 'E'
			elif s1[ii] == 'T' and s2[ii] == 'E':
				ans += 'S'
		index = binarySearch(s[j + 1:], ans)
		if index != -1:
			count += 1
	i += 1
print(count)


import sys
import heapq
import math
input = sys.stdin.readline
print = sys.stdout.write
from collections import deque
from collections import defaultdict
from collections import Counter
I = lambda : list(map(int, input().split(' ')))
(n, k) = I()
lst = [input() for i in range(n)]
cnt = 0
ss = set()
lst.sort()

def binSearch(start, end, lst, ele):
	left = start
	right = end
	while left <= right:
		mid = (left + right) // 2
		if lst[mid] == ele:
			return 1
		elif lst[mid] < ele:
			left = mid + 1
		else:
			right = mid - 1
	return 0
for i in range(n - 1):
	for j in range(i + 1, n - 1):
		c = []
		for (f1, f2) in zip(lst[i], lst[j]):
			if f1 == f2:
				c.append(f1)
			else:
				xx = f1 + f2
				if xx == 'ST' or xx == 'TS':
					a = 'E'
				elif xx == 'SE' or xx == 'ES':
					a = 'T'
				elif xx == 'TE' or xx == 'ET':
					a = 'S'
				c.append(a)
		cur = ''.join(c)
		cnt += binSearch(j + 1, n - 1, lst, cur)
print(str(cnt))


(n, k) = map(int, input().split())
st = set()
cards = []
for i in range(n):
	card = input()
	st.add(card)
	cards.append(card)
ans = 0
for i in range(n):
	for j in range(i + 1, n):
		last_card = ''
		for t in range(k):
			if cards[i][t] == cards[j][t]:
				last_card += cards[i][t]
			else:
				for ch in ['S', 'T', 'E']:
					if cards[i][t] != ch and cards[j][t] != ch:
						last_card += ch
						break
		if last_card in st:
			ans += 1
	st.remove(cards[i])
print(ans // 2)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
(n, k) = map(int, input().split())
vals = [input() for s in range(n)]
dict1 = {}
outy = 0
for j in range(n - 1):
	setty = set(vals[j + 1:])
	for s in range(j + 1, n):
		setty.remove(vals[s])
		card1 = vals[j]
		card2 = vals[s]
		card3 = ''
		for b in range(k):
			if card1[b] == card2[b]:
				card3 += card1[b]
			else:
				sum1 = 0
				if card1[b] == 'S':
					sum1 += 1
				elif card1[b] == 'E':
					sum1 += 2
				else:
					sum1 += 3
				if card2[b] == 'S':
					sum1 += 1
				elif card2[b] == 'E':
					sum1 += 2
				else:
					sum1 += 3
				if 6 - sum1 == 1:
					card3 += 'S'
				elif 6 - sum1 == 2:
					card3 += 'E'
				else:
					card3 += 'T'
		if card3 in setty:
			outy += 1
print(outy)


(n, k) = input().split(' ')
n = int(n)
k = int(k)
arr = []
set1 = set()
count = 0
for i in range(n):
	arr.append(input())
	set1.add(arr[-1])
for i in range(n):
	for j in range(i + 1, n):
		cons_str = ''
		for u in range(k):
			if arr[i][u] != arr[j][u]:
				if arr[i][u] != 'S' and arr[j][u] != 'S':
					cons_str += 'S'
				elif arr[i][u] != 'E' and arr[j][u] != 'E':
					cons_str += 'E'
				elif arr[i][u] != 'T' and arr[j][u] != 'T':
					cons_str += 'T'
			else:
				cons_str += arr[i][u]
		if cons_str in set1:
			count += 1
print(count // 3)


(n, k) = [int(ele) for ele in input().split()]
lst = []
N = n
while N > 0:
	ele = input()
	lst.append(ele)
	N -= 1
setC = set(lst)
z = ord('S') + ord('T') + ord('E')
count = 0
for i in range(n):
	for j in range(i + 1, n):
		st = ''
		for ind in range(k):
			if lst[i][ind] == lst[j][ind]:
				st += lst[i][ind]
			else:
				a = lst[i][ind]
				b = lst[j][ind]
				st += chr(z - ord(a) - ord(b))
		if st in setC:
			count += 1
print(count // 3)


import sys
import atexit
import io
from collections import defaultdict, Counter
sys.setrecursionlimit(10 ** 9)
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER

@atexit.register
def write():
	sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())

def main():
	dct = {'S': 0, 'E': 1, 'T': 2}
	(n, k) = [int(i) for i in input().split()]
	c = [tuple([dct[i] for i in input()]) for s in range(n)]
	cs = set(c)
	ans = 0
	for i in range(n):
		s1 = c[i]
		for j in range(i + 1, n):
			s2 = c[j]
			li = [0 for kkk in range(k)]
			for kk in range(k):
				if s1[kk] == s2[kk]:
					li[kk] = s1[kk]
				else:
					li[kk] = 3 - s1[kk] - s2[kk]
			if tuple(li) in cs:
				ans += 1
	print(ans // 3)
main()


def binarySearch(words, low, high, key):
	if high < low:
		return -1
	mid = (low + high) // 2
	if words[mid] < key:
		return binarySearch(words, mid + 1, high, key)
	elif words[mid] > key:
		return binarySearch(words, low, mid - 1, key)
	else:
		return mid
a = input().split()
n = int(a[0])
k = int(a[1])
l = []
t = 0
for i in range(n):
	a = input()
	l.append(a)
l.sort()
for i in range(0, n - 1):
	for j in range(i + 1, n):
		r = ''
		for u in range(k):
			if l[i][u] == l[j][u]:
				r = r + l[i][u]
			else:
				r = r + chr(ord('S') + ord('T') + ord('E') - ord(l[i][u]) - ord(l[j][u]))
		if binarySearch(l, 0, n - 1, r) != -1:
			t += 1
print(int(t / 3))


import math
import sys
from collections import defaultdict, Counter, deque, OrderedDict
import bisect
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda : map(int, input().split())
alele = lambda : list(map(int, input().split()))

def list2d(a, b, c):
	return [[c] * b for i in range(a)]
from itertools import accumulate, groupby
import sys
mod = 1000000007
(n, k) = ilele()
l = [input() for i in range(n)]
if n <= 2:
	print(0)
else:
	s = list(set(l))
	mark = {i: 1 for i in s}
	comp = {'ST': 'E', 'TS': 'E', 'SE': 'T', 'ES': 'T', 'ET': 'S', 'TE': 'S'}
	ans = 0
	for i in range(n - 1):
		for j in range(i + 1, n):
			s1 = ''
			for w in range(k):
				if l[i][w] == l[j][w]:
					s1 += l[i][w]
				else:
					s1 += comp[l[i][w] + l[j][w]]
			ans += mark.get(s1, 0)
	print(ans // 3)


(n, k) = map(int, input().split())
cards = ['' for _ in range(n)]
for i in range(n):
	cards[i] = input()
seen_cards = {}
ans = 0
for f_i in range(n):
	first = cards[f_i]
	for s_i in range(f_i + 1, n):
		second = cards[s_i]
		want_card = ''
		for i in range(k):
			if first[i] == second[i]:
				want_card += second[i]
			elif 'S' != first[i] and 'S' != second[i]:
				want_card += 'S'
			elif 'E' != first[i] and 'E' != second[i]:
				want_card += 'E'
			elif 'T' != first[i] and 'T' != second[i]:
				want_card += 'T'
		if want_card in seen_cards:
			ans += seen_cards[want_card]
	if first in seen_cards:
		seen_cards[first] += 1
	else:
		seen_cards[first] = 1
print(ans)


from sys import stdin
inp = stdin.readline
(n, k) = map(int, inp().split())
ans = 0
cards = []
for i in range(n):
	cards.append(inp().strip())
total = ord('E') + ord('S') + ord('T')
cards_hash = set(cards)
for i in range(n):
	for j in range(i + 1, n):
		complement = ''
		for h in range(k):
			if cards[i][h] != cards[j][h]:
				complement += chr(total - ord(cards[i][h]) - ord(cards[j][h]))
			else:
				complement += cards[i][h]
		if complement in cards_hash:
			ans += 1
print(ans // 3)


import sys
input = sys.stdin.readline
(n, k) = map(int, input().split())
l = []
for i in range(k):
	o = []
	for j in range(3):
		o.append(0)
	l.append(o)
d = set()
da = []
for i in range(n):
	s = input()
	h = []
	for i in range(k):
		h.append(s[i])
	da.append(h)
	b = tuple(h)
	d.add(b)
i = 0
ans = 0
while i < n:
	j = i + 1
	while j < n:
		p = ['S'] * k
		c = k - 1
		while c > -1:
			if da[i][c] == da[j][c]:
				p[c] = da[i][c]
			else:
				q = {'S', 'E', 'T'}
				q.remove(da[i][c])
				q.remove(da[j][c])
				for r in q:
					p[c] = r
			c -= 1
		w = j + 1
		u = tuple(p)
		if u in d:
			ans += 1
		j = j + 1
	i = i + 1
sys.stdout.write(str(ans // 3) + '\n')


from collections import defaultdict as de
(n, k) = map(int, input().split())
s = [[0 if j == 'S' else 1 if j == 'E' else 2 for j in list(input())] for i in range(n)]
q = de(int)
p = [3 ** i for i in range(k)]
for i in range(n):
	c = 0
	for j in range(k):
		c += s[i][j] * p[j]
	q[c] = 1
an = 0
for i in range(n):
	for j in range(i + 1, n):
		c = 0
		for h in range(k):
			c += (3 - s[i][h] - s[j][h]) % 3 * p[h]
		an += q[c]
print(an // 3)


(n, m) = input().split()
(n, m) = (int(n), int(m))
d = {}
a = []
for i in range(n):
	s = input()
	d[s] = i
	a.append(s)
t = ''
ans = 0
for i in range(n):
	for j in range(n):
		if j > i:
			for k in range(m):
				if a[i][k] == 'T' and a[j][k] == 'T':
					t = t + 'T'
				if a[i][k] == 'E' and a[j][k] == 'E':
					t = t + 'E'
				if a[i][k] == 'S' and a[j][k] == 'S':
					t = t + 'S'
				if a[i][k] == 'S' and a[j][k] == 'E':
					t = t + 'T'
				if a[i][k] == 'S' and a[j][k] == 'T':
					t = t + 'E'
				if a[i][k] == 'T' and a[j][k] == 'E':
					t = t + 'S'
				if a[i][k] == 'T' and a[j][k] == 'S':
					t = t + 'E'
				if a[i][k] == 'E' and a[j][k] == 'T':
					t = t + 'S'
				if a[i][k] == 'E' and a[j][k] == 'S':
					t = t + 'T'
			if t in d:
				ans += 1
			t = ''
print(int(ans / 3))


(N, K) = map(int, input().split())
S = [input().replace('S', '0').replace('E', '1').replace('T', '2') for _ in range(N)]
X = [[int(a) for a in s] for s in S]
D = {int(s, 3): 1 for s in S}

def calc(a, b):
	re = 0
	for (s, t) in zip(a, b):
		re = re * 3 + (s + t) * 2 % 3
	return re
ans = 0
for i in range(N):
	for j in range(i + 1, N):
		if calc(X[i], X[j]) in D:
			ans += 1
print(ans // 3)


from operator import itemgetter
from collections import Counter
(n, k) = map(int, input().split())

def accept_string(s, ss):
	tmp = []
	for i in range(len(s)):
		if s[i] == ss[i]:
			tmp.append(s[i])
		else:
			for l in ['S', 'E', 'T']:
				if l != s[i] and l != ss[i]:
					tmp.append(l)
	return ''.join(tmp)

def solve(s_list):
	ans = 0
	for i in range(n):
		counter = Counter()
		for j in range(i + 1, n):
			ans += counter[s_list[j]]
			counter[accept_string(s_list[i], s_list[j])] += 1
	print(ans)
s_list = []
for i in range(n):
	s_list.append(input())
solve(s_list)


import sys
reader = (line.rstrip() for line in sys.stdin)
input = reader.__next__
(n, k) = map(int, input().split())
cards = [input() for _ in range(n)]
check = set(cards)
ordSum = ord('S') + ord('E') + ord('T')
ctr = 0
for i in range(n):
	for j in range(i + 1, n):
		thirdCard = []
		for (c1, c2) in zip(cards[i], cards[j]):
			if c1 == c2:
				thirdCard.append(c1)
			else:
				c3 = chr(ordSum - ord(c1) - ord(c2))
				thirdCard.append(c3)
		if ''.join(thirdCard) in check:
			ctr += 1
print(ctr // 3)


from collections import defaultdict, Counter
from bisect import bisect, bisect_left
from math import sqrt, gcd, ceil, factorial
from heapq import heapify, heappush, heappop
MOD = 10 ** 9 + 7
inf = float('inf')
ans_ = []

def nin():
	return int(input())

def ninf():
	return int(file.readline())

def st():
	return input().strip()

def stf():
	return file.readline().strip()

def read():
	return list(map(int, input().strip().split()))

def readf():
	return list(map(int, file.readline().strip().split()))
ans_ = []

def f(tup):
	(a, b) = tup
	if a == b:
		return a
	else:
		s = list('SET')
		s.remove(a)
		s.remove(b)
		return s[0]

def solve():
	(n, k) = read()
	arr = []
	freq = set()
	for i in range(n):
		t = st()
		arr.append(t)
		freq.add(t)
	ans = 0
	for i in range(n):
		for j in range(i + 1, n):
			(x, y) = (arr[i], arr[j])
			z = ''
			for l in range(k):
				if x[l] == y[l]:
					z += x[l]
				else:
					s = list('SET')
					s.remove(x[l])
					s.remove(y[l])
					z += s[0]
			ans += [0, 1][z in freq]
	print(ans // 3)
solve()
for i in ans_:
	print(i)


(n, k) = map(int, input().split())
d = {}
d1 = {}
for i in range(n):
	d[i] = input()
for i in range(n - 1, -1, -1):
	if d1.get(d[i], -1) == -1:
		d1[d[i]] = []
	d1[d[i]].append(i)
ans = 0
r = k
for i in range(n):
	for j in range(i + 1, n):
		s = ''
		cnt = 0
		for k in range(r):
			if d[i][k] == d[j][k]:
				s += d[i][k]
				cnt += 1
			elif abs(ord(d[i][k]) - ord(d[j][k])) == 14:
				s += 'T'
			elif abs(ord(d[i][k]) - ord(d[j][k])) == 15:
				s += 'S'
			else:
				s += 'E'
		if d1.get(s, -1) != -1:
			if cnt == r:
				d1[s].pop()
				d1[s].pop()
				if d1.get(s, -1) != -1:
					for i1 in d1[s]:
						if i1 < j:
							break
						else:
							ans += 1
			else:
				for i1 in d1[s]:
					if i1 <= j:
						break
					else:
						ans += 1
print(ans)


def get_complement(s, t):
	k = len(s)
	c = list()
	for i in range(k):
		if s[i] == t[i]:
			c.append(s[i])
		elif s[i] == 'S' and t[i] == 'E' or (s[i] == 'E' and t[i] == 'S'):
			c.append('T')
		elif s[i] == 'S' and t[i] == 'T' or (s[i] == 'T' and t[i] == 'S'):
			c.append('E')
		else:
			c.append('S')
	return ''.join(c)
(n, k) = map(int, input().split())
cards = list()
cards_set = set()
for _ in range(n):
	s = input()
	cards.append(s)
	cards_set.add(s)
counter = 0
for i in range(len(cards)):
	for j in range(i + 1, len(cards)):
		c = get_complement(cards[i], cards[j])
		if c in cards_set:
			counter += 1
print(counter // 3)


import sys

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7
(N, K) = MAP()
A = [input() for i in range(N)]
S = set(A)
ordsm = ord('S') + ord('E') + ord('T')
cnt = 0
for i in range(N):
	a1 = A[i]
	for j in range(i + 1, N):
		a2 = A[j]
		a3 = ''
		for k in range(K):
			if a1[k] == a2[k]:
				a3 += a1[k]
			else:
				key = ordsm - ord(a1[k]) - ord(a2[k])
				a3 += chr(key)
		if a3 in S:
			cnt += 1
print(cnt // 3)


from itertools import combinations
for _ in range(1):
	(n, k) = map(int, input().split())
	l = []
	d = dict()
	for i in range(n):
		l.append(input())
		d[l[-1]] = 0
	count = 0
	combs = list(combinations(l, 2))
	for i in combs:
		a = i[0]
		b = i[1]
		temp = ''
		for j in range(k):
			if a[j] == b[j]:
				temp += a[j]
			elif a[j] == 'S' and b[j] == 'E' or (a[j] == 'E' and b[j] == 'S'):
				temp += 'T'
			elif a[j] == 'S' and b[j] == 'T' or (a[j] == 'T' and b[j] == 'S'):
				temp += 'E'
			elif a[j] == 'T' and b[j] == 'E' or (a[j] == 'E' and b[j] == 'T'):
				temp += 'S'
		d[temp] = d.get(temp, 0) + 1
	for x in l:
		count += d[x]
	print(count // 3)


(n, k) = [int(x) for x in input().strip().split()]

def match(a, b):
	s = []
	for i in range(k):
		if a[i] == b[i]:
			s.append(a[i])
		elif a[i] == 'S':
			if b[i] == 'E':
				s.append('T')
			elif b[i] == 'T':
				s.append('E')
		elif a[i] == 'E':
			if b[i] == 'S':
				s.append('T')
			elif b[i] == 'T':
				s.append('S')
		elif a[i] == 'T':
			if b[i] == 'S':
				s.append('E')
			elif b[i] == 'E':
				s.append('S')
	return ''.join(s)
ans = 0
cards = set()
for i in range(n):
	cards.add(input())
seen = set()
for c in cards:
	seen.add(c)
	for c2 in cards:
		if c == c2 or c2 in seen:
			continue
		s = match(c, c2)
		if s in cards:
			ans += 1
print(int(ans / 3))


import bisect
(n, k) = map(int, input().split())
cards = []
d = [0] * n
razl = [0] * n
cards2 = set()
for _ in range(n):
	pl = input()
	cards.append(pl)
	cards2.add(pl)
ans = 0
for i in range(n):
	card1 = cards[i]
	for j in range(i + 1, n):
		card2 = cards[j]
		card3 = ''
		for m in range(k):
			if card1[m] == card2[m]:
				card3 += card1[m]
			else:
				a = ['S', 'E', 'T']
				if card1[m] in a:
					a.remove(card1[m])
				if card2[m] in a:
					a.remove(card2[m])
				card3 += a[0]
		if card3 in cards2:
			ans += 1
print(ans // 3)


from sys import stdin
input = stdin.readline
(n, k) = map(int, input().split())
arr = list((input() for _ in range(n)))
(res, cnt) = (0, {})
for s in arr:
	s = s[:-1]
	cnt[s] = cnt.get(s, 0) + 1
for i in range(n):
	for j in range(i + 1, n):
		curr = ''
		for c in range(k):
			if arr[i][c] == arr[j][c]:
				curr += arr[i][c]
			else:
				for t in 'SET':
					if t != arr[i][c] and t != arr[j][c]:
						curr += t
						break
		res += cnt.get(curr, 0)
print(res // 3)


(n, k) = map(int, input().split())
se = set()
ls = []
for i in range(n):
	s = input()
	se.add(s)
	ls.append(s)
anscnt = 0
for i in range(n - 1):
	s = ls[i]
	for j in range(i + 1, n):
		t = ls[j]
		ans = []
		for l in range(k):
			if s[l] == t[l]:
				ans.append(s[l])
			elif s[l] == 'S':
				if t[l] == 'E':
					ans.append('T')
				else:
					ans.append('E')
			elif s[l] == 'T':
				if t[l] == 'E':
					ans.append('S')
				else:
					ans.append('E')
			elif t[l] == 'T':
				ans.append('S')
			else:
				ans.append('T')
		x = ''.join(ans)
		if x in se:
			anscnt += 1
print(anscnt // 3)


from math import factorial
from collections import Counter
from heapq import heapify, heappop, heappush
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
mod = 1000000007
INF = float('inf')

def main():
	(n, kk) = list(RL())
	cards = ['S', 'E', 'T']
	cs = []
	res = 0
	rec = set()
	for i in range(n):
		c = input()
		cs.append(c)
		rec.add(c)
	for i in range(len(cs) - 1):
		for j in range(i + 1, len(cs)):
			new = ''
			for k in range(kk):
				if cs[i][k] == cs[j][k]:
					new += cs[i][k]
				else:
					for t in cards:
						if t != cs[i][k] and t != cs[j][k]:
							new += t
			if new in rec:
				res += 1
	print(res // 3)
main()


(n, k) = map(int, input().split())
s = []
dic = {}
for i in range(n):
	s.append(input().strip())
	dic[s[i]] = 1
ans = 0
visited = set()
for i in range(n):
	for j in range(i + 1, n):
		expec = ''
		for l in range(k):
			if s[i][l] != s[j][l]:
				v = [s[i][l], s[j][l]]
				if 'T' not in v:
					expec += 'T'
				elif 'S' not in v:
					expec += 'S'
				else:
					expec += 'E'
			else:
				expec += s[i][l]
		if expec in dic and tuple(sorted([s[i], s[j], expec])) not in visited:
			visited.add(tuple(sorted([s[i], s[j], expec])))
			ans += 1
print(ans)