Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

n = int(input())
d = list(map(int, input().split()))
b = 1
ans = 1
if d[0] == 0 and d.count(0) == 1:
    for i in range(1, max(d)+1):
        dc = d.count(i)
        if dc == 0:
            print(0)
            exit()
        if dc == 1:
            ans *= b
        else:
            if b != 1:
                ans *= pow(b, dc, 998244353)
        b = dc
    print(ans % 998244353)
else:
    print(0)

### FIXED CODE ###

n = int(input())
d = list(map(int, input().split()))
b = 1
ans = 1
max = 0
dd=[0]*10**5
for i in d:
    dd[i]+=1
    if(max<i):
        max=i
if d[0] == 0 and d.count(0) == 1:
    for i in range(1, max+1):
        if dd[i] == 0:
            print(0)
            exit()
        if dd[i] == 1:
            ans *= b
        else:
            if b != 1:
                ans *= pow(b, dd[i], 998244353)
        b = dd[i]
    print(ans % 998244353)
else:
    print(0)
### BUGGY CODE ###

# n, m, l = map(int, input().split())

# list_n = list(map(int, input().split()))

# n = input()
# list = [input() for i in range(N)

# list = [[i for i in range(N)] for _ in range(M)]

import sys
input = sys.stdin.readline

N = int(input())
P = list(map(int, input().split()))

ans = 1
for i in range(1, N):
    if min(P[0:i+1]) >= P[i]:
        ans += 1

print(ans)


### FIXED CODE ###

# n, m, l = map(int, input().split())

# list_n = list(map(int, input().split()))

# n = input()
# list = [input() for i in range(N)

# list = [[i for i in range(N)] for _ in range(M)]

import sys
input = sys.stdin.readline

N = int(input())
P = list(map(int, input().split()))
Pmin = [2*10**5 for i in range(N)]
Pmin[0] = P[0]
for i in range(1, N):
    Pmin[i] = min(Pmin[i-1], P[i])

ans = 0
for i in range(N):
    if Pmin[i] >= P[i]:
        ans += 1

print(ans)
### BUGGY CODE ###

S = input().split()
N = int(S[0])
M = int(S[1])
A = list(map(int, input().split()))
B = list(map(int, input().split()))

A_MAX = max(A)
B_MAX = max(B)
MAX = A_MAX if (A_MAX > B_MAX) else B_MAX

mod = int(1e9 + 7)

A_F_cnt = 0
B_F_cnt = 0

result = 1

for i in range(MAX, 0, -1):
    in_A = (i in A)
    in_B = (i in B)
    if (in_A and in_B):
        A_F_cnt += 1
        B_F_cnt += 1
    elif (in_A):
        result *= B_F_cnt
        A_F_cnt += 1 
    elif (in_B):
        result *= A_F_cnt
        B_F_cnt += 1
    else:
        coef = ( ( A_F_cnt * B_F_cnt )%mod - (N*M - i) )
        if coef < 0:
            coef += mod
        result *= coef
        
    # print(in_A, in_B, A_F_cnt, B_F_cnt, result)

print(result % mod)

### FIXED CODE ###

S = input().split()
N = int(S[0])
M = int(S[1])
A = list(map(int, input().split()))
B = list(map(int, input().split()))

A_MAX = max(A)
B_MAX = max(B)
MAX = A_MAX if (A_MAX > B_MAX) else B_MAX

mod = int(1e9 + 7)

A_F_cnt = 0
B_F_cnt = 0

result = 1
sA = [ False for _ in range(MAX+1) ]
sB = [ False for _ in range(MAX+1) ]

for i in range(len(A)):
    sA[A[i]] = True
for i in range(len(B)):
    sB[B[i]] = True


for i in range(MAX, 0, -1):
    in_A = sA[i]
    in_B = sB[i]
    if (in_A and in_B):
        A_F_cnt += 1
        B_F_cnt += 1
    elif (in_A):
        result *= B_F_cnt
        result %= mod
        A_F_cnt += 1 
    elif (in_B):
        result *= A_F_cnt
        result %= mod
        B_F_cnt += 1
    else:
        coef = ( ( A_F_cnt * B_F_cnt )%mod - (N*M - i) )
        if coef < 0:
            coef += mod
        result *= coef
        result %= mod
        
    # print(in_A, in_B, A_F_cnt, B_F_cnt, result)

print(result % mod)
### BUGGY CODE ###

n=int(input())
if n%2==0:
    print(-1)
else:
    c=1
    k=7
    while 1:
        if k%n==0:
            break
        if c>n:
            c=-1
            break
        k=int(str(k)+'7')
        c+=1
        #print(k)
    print(c)

### FIXED CODE ###

n=int(input())
if n%2==0:
    print(-1)
else:
    c=1
    k=7
    while 1:
        if k%n==0:
            break
        if c>n:
            c=-1
            break
        k=(k%n)*10+7
        c+=1
        #print(k)
    print(c)
### BUGGY CODE ###

#!/usr/bin/env python
"""AtCoder Beginner Contest 167: C
https://atcoder.jp/contests/abc167/tasks/abc167_c
"""
import sys
import itertools

__author__ = 'bugttle <bugttle@gmail.com>'


def main():
    [N, M, X] = list(map(int, input().split()))

    l = []
    for n in range(N):
        l.append(list(map(int, input().split())))
    # print(l)

    cost = 0
    status = [0]*M
    for n in range(N):
        cost += l[n][0]
        for m in range(M):
            status[m] += l[n][m + 1]
    
    isJust = True
    for v in status:
        if v < X:
            print(-1)
            return
        if v != X:
            isJust = False
    if isJust:
        print(cost)
        return 


    
    min_cost = sys.maxsize
    for p in itertools.permutations(range(N)):
        # print(p)
        cost = 0
        status = [0]*M
        for n in p:
            cost += l[n][0]
            if min_cost < cost:
                break
            isCompleted = True
            for m in range(M):
                status[m] += l[n][m + 1]
                if status[m] < X:
                    isCompleted = False
            # print(status)
            if isCompleted:
                # print('fin')
                # print(cost)
                if cost < min_cost:
                    min_cost = cost
                break
    if min_cost == sys.maxsize:
        print(-1)
    else:
        print(min_cost)
            
                    

                # status[m] += l[n][m]
    # for n in range(N):
    #     for m in range(M):
    #         print([n, m])
    # cost = 0
    # status = [[0]*M]*N
    # for n in range(N):
    #     for m in range(M):
    #         print(l[n][m + 1])
    #         # status[n][m] = l[n][m + 1]
    # print(status)

    


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python
"""AtCoder Beginner Contest 167: C - Skill Up
https://atcoder.jp/contests/abc167/tasks/abc167_c
"""

N, M, X = 0, 0, 0
BOOKS = []


def calc_price(book_combinations):
    price = 0
    understandings = [0] * M
    for i in range(len(book_combinations)):
        if book_combinations[i]:
            price += BOOKS[i][0]
            for j in range(len(BOOKS[i][1:])):
                understandings[j] += BOOKS[i][j + 1]
    for u in understandings:
        if u < X:  # couldn't understand
            return -1
    return price


def main():
    global N, M, X, BOOKS
    N, M, X = list(map(int, input().split()))
    BOOKS = [list(map(int, input().split())) for i in range(N)]

    ans = float('inf')
    for i in range(1, 2 ** N):  # => 1: at least one book should be buy
        price = calc_price([(i >> j) & 1 for j in range(N)])
        if 0 < price and price < ans:
            ans = price
    if ans == float('inf'):
        ans = -1
    print(ans)


if __name__ == '__main__':
    main()
### BUGGY CODE ###

s=str(input())
s=list(s)
q=int(input())
t=0
for i in range(q):
  temp=str(input())
  temp=list(temp)
  if temp[0]=="1":
    t=t+1
  else:
    if t%2!=0:
      s.reverse()
    t=0
    if temp[2]=="1":
      s.insert(0,temp[4])
    else:
      s.append(temp[4])
if t%2!=0:
  s.reverse()
print("".join(s))

### FIXED CODE ###

s=str(input())
s=list(s)
q=int(input())
sb=[0]*(q+1)
sa=[0]*(q+1)
sbi=0
sai=0
ta=0
for i in range(q):
  temp=str(input())
  temp=list(temp)
  if temp[0]=="1":
    ta=ta+1
  else:
    if (temp[2]=="1" and ta%2==0) or (temp[2]=="2" and ta%2!=0):
      sb[sbi]=temp[4]
      sbi=sbi+1
    else:
      sa[sai]=temp[4]
      sai=sai+1
lsb=sb.index(0)
lsa=sa.index(0)
sb.reverse()
ans=sb[len(sb)-lsb:len(sb)]+s+sa[0:lsa]
if ta%2!=0:
  ans.reverse()
print("".join(ans))
### BUGGY CODE ###

n=input()
nums=list(map(int,input().split()))

ans = 1
for num in nums:
    ans = ans * num

if ans > 10**18:
    print(-1)
else:
    print(ans)


### FIXED CODE ###

n=input()
nums=list(map(int,input().split()))

if 0 in nums:
    print(0)
    exit()


ans = 1
over = 10**18

for num in nums:
    ans = ans * num

    if ans > over:
        print(-1)
        exit()

print(ans)
### BUGGY CODE ###

N, K = map(int, input().split())
lst = [int(x) for x in input().split()]
a = len(lst) - K + 1
n = 0
ret_lst = []
for i in range(a):
    m = sum(lst[i : i + K])
    if n < m:
        n = m
        ret_lst = lst[i : i + K]

ret = 0
for x in ret_lst:
    ret += sum(range(1, x + 1)) / x
print(ret)


### FIXED CODE ###

N, K = map(int, input().split())
lst = [int(x) for x in input().split()]
tmp = sum(lst[:K])
ret = tmp
for i in range(N - K):
    tmp -= lst[i]
    tmp += lst[i + K]
    ret = max(ret, tmp)
print((ret + K) / 2)
### BUGGY CODE ###

n,x,y=map(int,input().split())
dis=[0]*(n-1)
for i in range(1,n):
  for j in range(i+1,n+1):
    d=min(j-i,min(abs(j-x)+1+abs(i-y),abs(j-y)+1+abs(i-x)))
    dis[d-1]+=1
for i in dis:
  print(i)

### FIXED CODE ###

n,x,y=map(int,input().split())
dis=[0]*(n-1)
for i in range(1,n):
  for j in range(i+1,n+1):
    d=j-i
    if d>abs(j-x)+1+abs(i-y):
      d=abs(j-x)+1+abs(i-y)
    if d>abs(j-y)+1+abs(i-x):
      d=abs(j-y)+1+abs(i-x)
    dis[d-1]+=1
for i in dis:
  print(i)
### BUGGY CODE ###

N = int(input())
a = list(map(int, input().split()))

aa = [ai - i-1 for i,ai in enumerate(a)]

def tri_search(f:"f(x:float)->float", left, right, iter=100)->float:
    for _ in range(iter):
        ml = (left*2 + right) / 3
        mr = (left + right*2) / 3
        if f(ml) < f(mr):
            right = mr
        else:
            left = ml
    # print(left, right)
    return (right + left) / 2

def f(x):
    ret = 0
    x = round(x)
    for aai in aa:
        ret += abs(aai - x)
    return ret

b = tri_search(f, -10**9, 10**9)
print(f(b))


### FIXED CODE ###

N = int(input())
a = list(map(int, input().split()))

aa = [ai - i-1 for i,ai in enumerate(a)]

def tri_search(f:"f(x:float)->float", left, right, iter=100)->float:
    for _ in range(iter):
        ml = (left*2 + right) / 3
        mr = (left + right*2) / 3
        if f(ml) < f(mr):
            right = mr
        else:
            left = ml
    # print(left, right)
    return (right + left) / 2

def f(x):
    ret = 0
    x = int(x+0.5)
    for aai in aa:
        ret += abs(aai - x)
    return ret

b = tri_search(f, -10**9, 10**9)
print(min(f(b), f(b+1), f(b-1)))
### BUGGY CODE ###

N, K = map(int, input().split())
H = list(map(int, input().split()))

for _ in range(K):
    if len(H) == 0:
        break
    H.remove(max(H))

print(sum(H))

### FIXED CODE ###

from heapq import heapify, heappush, heappop
N, K = map(int, input().split())
H = list(map(int, input().split()))

H = [-h for h in H]
heapify(H)
for _ in range(K):
    if len(H) == 0:
        break
    heappop(H)

print(-sum(H))
### BUGGY CODE ###

K,S = map(int, input().split())

ans = 0
if K*3<S:
  print(0)
  exit()

for x in range(K, -1, -1):
  for y in range(K, -1, -1):
    for z in range(K, -1, -1):
      if x+y+z==S:
        ans+=1
      elif x+y+z<S:
        break

print(ans)

### FIXED CODE ###

K,S = map(int, input().split())

ans = 0
if K*3<S:
  print(0)
  exit()

for x in range(K, -1, -1):
  if x >S:
    continue
  for y in range(min(S-x, K), -1, -1):
    if x+y >S:
      continue
    for z in range(min(S-x-y, K), -1, -1):
      if x+y+z==S:
        ans+=1
      elif x+y+z<S:
        break

print(ans)
### BUGGY CODE ###

import sys
from itertools import combinations
input = sys.stdin.readline
n = int(input())
a = [int(x) for x in input().strip().split()]
b = [int(x) for x in input().strip().split()]

all_cards = []
for i, (aa, bb) in enumerate(zip(a, b)):
    all_cards.append((aa, bb, i))

def check(cards):
    pre = -1
    for c in cards:
        print(c)
        if c[0] >= pre:
            pre = c[0]
        else:
            return False
    else:
        return True

def cnt(l):
    ret = 0
    for i in range(len(l)-1):
        for j in range(i+1, len(l)):
            if l[i] > l[j]:
                ret += 1
    return ret

dic = {}
def dp(all_cards, l, p):
    i = len(l) + 1
    if len(l) == n:
        return cnt(l)
    ret = float('inf')
    for card in all_cards:
        if card[2] in l:
            continue
        if card[(i-(card[2]+1))%2] >= p:
            ret = min(ret, dp(all_cards - set(card), l+[card[2]], card[(i-(card[2]+1))%2]))
    dic[tuple(l)] = ret
    return ret

ans = dp(set(all_cards), [], -float('inf'))
if ans == float('inf'):
    ans = -1
print(ans)

### FIXED CODE ###

import sys
from itertools import combinations
input = sys.stdin.readline
n = int(input())
a = [int(x) for x in input().strip().split()]
b = [int(x) for x in input().strip().split()]

all_cards = []
for i, (aa, bb) in enumerate(zip(a, b)):
    if i % 2:
        aa, bb = bb, aa
    all_cards.append([aa, bb, i])

def cnt(l):
    ret = 0
    for i in range(len(l)-1):
        for j in range(i+1, len(l)):
            if l[i][1] > l[j][1]:
                ret += 1
    return ret

ans = float('inf')
for cards in combinations(all_cards, (n + 1)// 2):
    acards = []
    for card in cards:
        acards.append([card[0],card[2]])
    bcards = []
    for card in all_cards:
        if [card[0],card[2]] not in acards:
            bcards.append([card[1],card[2]])

    acards.sort()
    bcards.sort()
    abcards = []
    # print(acards, bcards)
    for i in range(len(bcards)):
        abcards.extend([acards[i], bcards[i]])
    else:
        if n % 2:
            abcards.append(acards[-1])
    # print(abcards)
    if abcards != sorted(abcards, key=lambda x: x[0]):
        continue
    ans = min(ans, cnt(abcards))

if ans == float('inf'):
    ans = -1
print(ans)
### BUGGY CODE ###

from itertools import permutations
import sys
INF = float('inf')
n, m, R = map(int, sys.stdin.readline().split())
r = list(map(int, input().split()))
dist = [[INF]*(n+1) for _ in range(n+1)]
for i in range(n+1):
    dist[i][i] = 0
for i in range(m):
    a, b, c = map(int, sys.stdin.readline().split())
    dist[a][b] = c
    dist[b][a] = c
    
for k in range(1, n+1):
    for i in range(1, n+1):
        for j in range(1, n+1):
            dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j])
# for d in dist: print(d)

ans = INF
for p in permutations(r):
    ans_ = 0
    for i in range(R-1):
        ans_ += dist[p[i]][p[i+1]]
    ans = min(ans, ans_)
print(ans)


### FIXED CODE ###

from itertools import permutations

INF = float('inf')
n, m, R = list(map(int, input().split()))
r = list(map(int, input().split()))
dist = [[INF]*(n+1) for _ in range(n+1)]
for i in range(1, n+1):
    dist[i][i] = 0
for i in range(m):
    a, b, c = map(int, input().split())
    dist[a][b] = c
    dist[b][a] = c

from scipy.sparse import csgraph
dist = csgraph.floyd_warshall(dist)
# for k in range(n):
#     for i in range(n):
#         for j in range(n):
#             dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j])
# for d in dist: print(d)

ans = INF
for p in permutations(r):
    ans_ = 0
    for i in range(R-1):
        ans_ += dist[p[i]][p[i+1]]
    ans = min(ans, ans_)
print(int(ans))
### BUGGY CODE ###

import math

def combinations_count(n, r):
    return (math.factorial(n) // (math.factorial(n - r) * math.factorial(r)))%(10**9+7)
    
div = 10**9+7
n,a,b = [int(i) for i in input().split()]
ans = 1
for i in range(n):
    ans = (2*ans)%div

print((ans-1- combinations_count(n,a) - combinations_count(n,b))%div)

### FIXED CODE ###

def combinations(n,k,mod):
    x,y = 1,1
    for i in range(k):
        x = (x*(n-i))%mod
        y = (y*(i+1))%mod
    return (x*pow(y,mod-2,mod))%mod
    

div = 10**9+7
n,a,b = map(int,input().split())

cn = pow(2,n,div)-1
ca = combinations(n,a,div)
cb = combinations(n,b,div)

print((cn-ca-cb)%div)
### BUGGY CODE ###

from collections import deque, Counter
N, X, Y = map(int, input().split())
G = [[0]*N for _ in range(N)]
for i in range(N-1):
    G[i][i+1] = 1
    G[i+1][i] = 1
G[X-1][Y-1] = 1
G[Y-1][X-1] = 1

def bfs():
    C = Counter([i+1 for i in range(N)])
    for i in range(N):
        color = ['W']*N
        D = [10**5]*N
        D[i] = 0
        color[i] = 'B'
        Q = deque([])
        Q.append(i)
        idx = 1
        while Q:
            q = Q.popleft()
            for j in range(N):
                if q == j:
                    continue
                if G[q][j] == 1 and color[j] != 'B':
                    color[j] = 'G'
                    D[j] = min(D[q]+1, D[j])
                    Q.append(j)
                color[q] = 'B'
        for d in D:
            C[d] += 1
    return C

C = bfs()

for k in range(1, N):
    ans = C[k]//2
    print(ans)

### FIXED CODE ###

N, X, Y = map(int, input().split())
ans = [0]*(N-1)
for i in range(1, N):
    for j in range(i+1, N+1):
        d = min(j-i, abs(X-i)+abs(j-Y)+1)
        ans[d-1] += 1

print(*ans, sep='\n')
### BUGGY CODE ###

num = input()
listt = input().split()

def hoge(fuga):
    new_list = []
    for i in fuga:
        if int(i) % 2 == 0:
            new_list.append(i)
        else:
            return False
    return new_list


count = 0
while True:
    listt = hoge(listt)
    if listt == False:
        break
    count += 1

print(count)


### FIXED CODE ###

num = input()
listt = input().split()

def hoge(fuga):
    new_list = []
    for i in fuga:
        if int(i) % 2 == 0:
            new_list.append(int(i)/2)
        else:
            return False
    return new_list


count = 0
while True:
    listt = hoge(listt)
    if listt == False:
        break
    count += 1

print(count)
### BUGGY CODE ###

# D - Even Relation

# ある頂点からの距離の偶奇が一致する点を同じ色で塗る

from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import dijkstra

N = int(input())

neighbor = [[0]*N for _ in range(N)]

for _ in range(N-1):
    u, v, w = map(int, input().split())
    neighbor[u-1][v-1] = w%2 + 2
    neighbor[v-1][u-1] = w%2 + 2

neighbor = csr_matrix(neighbor)
dist_from_0 = dijkstra(neighbor, indices = 0)

for i in range(N):
    print(0 if dist_from_0[i]%2 == 0 else 1)

### FIXED CODE ###

# D - Even Relation

# 木なのでノードAB間の辺を辿ればそれがAB間の最短経路となる
# 全ての｢辺｣についてループする

from collections import deque

N = int(input())

edge = [[] for _ in range(N)]

for _ in range(N-1):
    u, v, w = map(int, input().split())
    edge[u-1].append([v-1, w])
    edge[v-1].append([u-1, w])

color = [0] + [-1]*(N-1)
d = deque([0])

while d:
    current_point = d.pop()
    for current_edge in edge[current_point]:
        if color[current_edge[0]] == -1:
            color[current_edge[0]] = (color[current_point] + current_edge[1]) % 2
            d.append(current_edge[0])

for idx in range(N):
    print(color[idx])
### BUGGY CODE ###

from collections import deque
from copy import copy, deepcopy
from bisect import bisect_left, bisect_right
N = int(input())
A = list(map(int, input().split()))
edge = [[] for _ in range(N)]
for i in range(N-1):
    a,b = map(int, input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)


ans = [0]*N
visited = [False]*N
visited[0]=True
ans[0] = 1
vs = deque([0])
LISs = deque([[A[0]]])
while len(vs)>0:
    v = vs.popleft()
    LIS = LISs.popleft()
    for u in edge[v]:
        if visited[u]==False:
            visited[u] = True
            lis = copy(LIS)
            if A[u]>lis[-1]:
                lis.append(A[u])
            else:
                ind = bisect_left(lis,A[u])
                lis[ind] = A[u]
            ans[u] = len(lis)
            vs.append(u)
            LISs.append(lis)
print(*ans, sep='\n')

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**8)
from bisect import bisect_left, bisect_right
N = int(input())
A = list(map(int, input().split()))
edge = [[] for _ in range(N)]
for i in range(N-1):
    a,b = map(int, input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)

def dfs(v,LIS):
    if len(edge[v])==0:
        return
    for u in edge[v]:
        if visited[u]==False:
            visited[u]=True
            if A[u] > LIS[-1]:
                LIS.append(A[u])
                ans[u] = len(LIS)
                dfs(u,LIS)
                LIS.pop()
            else:
                ind = bisect_left(LIS,A[u])
                stack = LIS[ind]
                LIS[ind] = A[u]
                ans[u] = len(LIS)
                dfs(u,LIS)
                LIS[ind] = stack
    return

ans = [0]*N
visited = [False]*N
visited[0]=True
LIS = [A[0]]
ans[0] = 1
dfs(0,LIS)
print(*ans, sep='\n')
### BUGGY CODE ###

# C - Exception Handling
N = int(input())
A = [int(input()) for i in range(N)]

#print(A)
max1 = max(A)

for i in range(N):
    if A[i] == max1:
        tmp =A[i]
        A[i] = 0
        print(max(A))
        A[i] = tmp
    else:
        print(max1)

### FIXED CODE ###

# C - Exception Handling
N = int(input())
A = [int(input()) for i in range(N)]

#print(A)
max1 = sorted(A, reverse=True)
max2 = max1[0]

for i in range(N):
    if A[i] == max2:
        print(max1[1])

    else:
        print(max2)
### BUGGY CODE ###

# coding: utf-8
# Your code here!
import sys
import math
from collections import Counter
input = sys.stdin.readline

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

def C(n, r):
    return P(n, r)//math.factorial(r)

N = int(input())
arr = [input() for i in range(N)]
ini_arr = [j[0] for j in arr if j[0] == "M" or j[0] == "A" or j[0] == "R" or j[0] == "C" or j[0] == "H"]
dic = Counter(ini_arr)
key_num = len(dic)
val_num = sum(v for v in dic.values())
if key_num < 3:
    print(0)
else:
    total = C(len(ini_arr), 3)
    for i in dic.values():
        if i == 2:
            total -= C(val_num - i, 1)
        elif i >= 3:
            total -= C(i, 2) * C(val_num - i, 1)  + C(i, 3)
    print(total)

### FIXED CODE ###

# coding: utf-8
# Your code here!
import sys
input = sys.stdin.readline

n = int(input())
t = [0] * n
for i in range(n):
    t[i] =input()[0]
t2 = [t.count(i) for i in ["M","A","R","C","H"]]
ans = 0
for i in range(5):
    for j in range(5):
        if j == i:
            break
        for k in range(5):
            if k == j:
                break
            ans += t2[i] * t2[j] * t2[k]
print(ans)
### BUGGY CODE ###

from fractions import gcd
from functools import reduce
N = int(input())
a = list(map(int, input().split()))

list_ans = []

for i in range(N):
    remove_a = a.pop(0)
    #print("a is",a)
    ans = reduce(gcd, a)
    list_ans.append(ans)
    a.append(remove_a)
    #print("fix a is",a)

print(max(list_ans))

### FIXED CODE ###

from fractions import gcd

N = int(input())
A = list(map(int, input().split()))

L = [0]
R = [0]

for i in range(N):
    L.append(gcd(L[i], A[i]))  # 0, gcd(0,A[0]), gcd(0,A[0],A[1]) , ...
    R.append(gcd(R[i], A[N - i -1])) # 0 , gcd(0, A[N-1]), gcd(0, A[N-1], A[N-2]))..

R.reverse() # R is gcd(0,A[N-1]...A[0]), gcd(0,A[N-1]...A[1]),....
# pairs are 
#  L     :R
#  0    : (0,A[N-1],A[n-2], ... A[1])
#  A[0] : (0,A[N-1],A[n-2], ... A[2])
#  ...
#  A[0,1,..N-3] :(0,A[N-1]
#  A[0,1,..N-2] :(0)
print(max( (gcd(L[i], R[i+1]) for i in range(N))))
### BUGGY CODE ###

N, Q = input().split(' ')
N = int(N)
Q = int(Q)

S = input()
AC ='AC'

indices = []
for i in range(Q):
    l_i, r_i = input().split(' ')
    indices.append((int(l_i), int(r_i)))

for idx in indices:
    print(S[idx[0]-1:idx[1]].count(AC))

### FIXED CODE ###

N, Q = map(int, input().split())
S = input()
t = [0] * (N + 1)
for i in range(N):
    t[i+1] = t[i] + (1 if S[i:i+2] == 'AC' else 0)

for i in range(Q):
    l_i, r_i = map(int, input().split())
    print(t[r_i-1] - t[l_i-1])