def rank(c) :
mp = {'A' : 1, 'T' : 10, 'J' : 11, 'Q' : 12, 'K' : 13}
if c in mp :
return mp[c]
return ord(c) - ord('0')
cnt = [0] * 14
n = int(input())
tot = 0
while tot < n :
s = input().split()
for c in s :
cnt[rank(c)] += 1
tot += 1
dp = [0] * 16
dp[0] = 1
for c in range(1, 14) :
v = min(c, 10)
for t in range(cnt[c]) :
for j in range(15, v - 1, -1) :
dp[j] += dp[j - v]
ans = dp[15] * 2
for c in range(1, 14) :
ans += cnt[c] * (cnt[c] - 1)
l = 1
r = 1
while l < 14 :
if cnt[l] == 0 :
l += 1
continue
r = l
while r < 14 and cnt[r] > 0 :
r += 1
if r - l >= 3 :
prod = 1
for j in range(l, r) :
prod *= cnt[j]
ans += prod * (r - l)
l = r
print(ans)