Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
ans = 0
k = [0] * n
a = [0] * n
for i in range(n):
    k[i], a[i] = int(input()), [int(j) for j in input().split()]
    
for match in range(1, m):
    for l in range(n):
        if match in a[i]:
            ans += 1

print(ans)

Fixed submission:
import sys
input = sys.stdin.readline

n, m = map(int, input().split())
ka = []
ans = 0
for i in range(n):
    ka_memo = list(map(int, input().split()))
    ka.append(ka_memo[1:])

for i in range(1, m + 1):
    flg = True
    for j in range(n):
        if i not in ka[j]:
            flg = False
            break
    if flg:
        ans += 1
print(ans)

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
ans = 0
k = [0] * n
a = [0] * n
for i in range(n):
    k[i] = int(input())
    a[i] = [int(input()) for j in range(k[i])]
    
for match in range(1, m):
    for l in range(n):
        if match in a[i]:
            ans += 1

print(ans)

Fixed submission:
import sys
input = sys.stdin.readline

n, m = map(int, input().split())
ka = []
ans = 0
for i in range(n):
    ka_memo = list(map(int, input().split()))
    ka.append(ka_memo[1:])

for i in range(1, m + 1):
    flg = True
    for j in range(n):
        if i not in ka[j]:
            flg = False
            break
    if flg:
        ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, m = map(int, readline().split())
a = list(map(int, readline().split()))
memo = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [''] * (n + 1)
for aa in a:
    if aa <= n:
        if dp[memo[aa]] < str(aa):
            dp[memo[aa]] = str(aa)
for i in range(n):
    if dp[i] == '':
        continue
    for aa in a:
        if i + memo[aa] <= n:
            v = str(aa) + dp[i]
            if len(dp[i + memo[aa]]) < len(v):
                dp[i + memo[aa]] = v
            else:
                dp[i + memo[aa]] = max(dp[i + memo[aa]], v)
print(dp[-1])


Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, m = map(int, readline().split())
a = list(map(int, readline().split()))
memo = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [''] * (n + 1)
for aa in a:
    if memo[aa] <= n:
        dp[memo[aa]] = max(dp[memo[aa]], str(aa))
for i in range(n):
    if dp[i] == '':
        continue
    for aa in a:
        if i + memo[aa] <= n:
            v = str(aa) + dp[i]
            if len(dp[i + memo[aa]]) < len(v):
                dp[i + memo[aa]] = v
            else:
                dp[i + memo[aa]] = max(dp[i + memo[aa]], v)
print(dp[-1])

Buggy python submission (verdict: Runtime Error):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, m = map(int, readline().split())
a = list(map(int, readline().split()))
memo = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [0] * (n + 1)
for aa in a:
    dp[memo[aa]] = max(dp[memo[aa]], aa)
for i in range(n):
    if dp[i] == 0:
        continue
    for aa in a:
        if i + memo[aa] <= n:
            v = int(str(aa) + str(dp[i]))
            if dp[i + memo[aa]] < v:
                dp[i + memo[aa]] = v
print(dp[-1])


Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, m = map(int, readline().split())
a = list(map(int, readline().split()))
memo = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [''] * (n + 1)
for aa in a:
    if memo[aa] <= n:
        dp[memo[aa]] = max(dp[memo[aa]], str(aa))
for i in range(n):
    if dp[i] == '':
        continue
    for aa in a:
        if i + memo[aa] <= n:
            v = str(aa) + dp[i]
            if len(dp[i + memo[aa]]) < len(v):
                dp[i + memo[aa]] = v
            else:
                dp[i + memo[aa]] = max(dp[i + memo[aa]], v)
print(dp[-1])
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
cheak = [0]*m
for i in range(m):
    cheak[m] = abs[x[m+1]-x[m]]
cheak.sort()
for j in range(n-1):
    cheak.pop(m-j)
ans = sum(cheak)
print(ans)

Fixed submission:
n, m = map(int, input().split())
x = list(map(int, input().split()))

if n >= m:
    ans = 0
else:
    x.sort()
    cheak = [0]*(m-1)
    
    for i in range(m-1):
        cheak[i] = abs(x[i+1]-x[i])
    cheak.sort(reverse=True)
    
    for j in range(n-1):
        cheak.pop(0)
    
    ans = sum(cheak)
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, k、*a = map(int, read().split())
v = 0
ans = 0
for i in range(40, -1, -1):
    cnt = 0
    for aa in a:
        if aa >> i & 1:
            cnt += 1
    if n - cnt > cnt and v + 1 << i <= k:
        v += 1 << i
        ans += (n - cnt) * 1 << i
    else:
        ans += cnt * 1 << i
print(ans)


Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, k, *a = map(int, read().split())
v = 0
ans = 0
for i in range(40, -1, -1):
    cnt = 0
    for aa in a:
        if (aa >> i) & 1:
            cnt += 1
    if n - cnt > cnt and v + (1 << i) <= k:
        v += 1 << i
        ans += (n - cnt) * (1 << i)
    else:
        ans += cnt * (1 << i)
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

n, W = map(int, input().split())
dp = [[0 for i in range(W + 1)] for j in range(n + 1)]
wv = [[int(x) for x in input().split()] for _ in range(n)]

for i in range(n):
    for j in range(W + 1):
        if j - wv[i][0] >= 0:
            dp[i + 1][j] = max(dp[i][j - wv[i][0]] + wv[i][1], dp[i + 1][j])
        dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])

print(max(dp[-1]))


Fixed submission:
import sys
input = sys.stdin.readline

n = int(input())
h = list(map(int, input().split()))
cnt = 0
dp = [0]*n
dp[1] = abs(h[1]-h[0])
for i in range(2, n):
    i_1 = dp[i-1] + abs(h[i]-h[i-1])
    i_2 = dp[i-2] + abs(h[i]-h[i-2])
    if i_1 > i_2:
        dp[i] = i_2
    else:
        dp[i] = i_1
print(dp[n-1])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [0] * n
dp_memo = [10 ** 4] * k

for i in range(1, n):
    for j in range(min(k, i)):
        dp_memo[j] = abs(h[i] - h[i - j - 1]) + dp[i - j -1]
    dp[i] = min(dp_memo)
    dp_memo = [10 ** 4] * k

print(dp[n - 1])


Fixed submission:
import sys
input = sys.stdin.readline

n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [0] * n
dp_memo = [10 ** 4] * k

for i in range(1, n):
    for j in range(min(k, i)):
        dp_memo[j] = abs(h[i] - h[i - j - 1]) + dp[i - j - 1]
    dp[i] = min(dp_memo)
    dp_memo = [10 ** 4] * k

print(dp[n - 1])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

n, W = map(int, input().split())
dp = [[0 for i in range(W + 1)] for j in range(n + 1)]
wv = [[int(x) for x in input().split()] for _ in range(n)]

for i in range(n):
    for j in range(W + 1):
        if j - wv[i][0] >= 0:
            dp[i + 1][j] = max(dp[i][j - wv[i][0]] + wv[i][1], dp[i + 1][j])
        dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])
print(max(dp[-1]))


Fixed submission:
import sys
input = sys.stdin.readline

n, W = map(int, input().split())
dp = [[0 for i in range(W + 1)] for j in range(n + 1)]
wv = [[int(x) for x in input().split()] for _ in range(n)]

for i in range(n):
    for j in range(W + 1):
        if j - wv[i][0] >= 0:
            dp[i + 1][j] = max(dp[i][j - wv[i][0]] + wv[i][1], dp[i + 1][j])
        dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])
print(max(dp[-1]))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

n, W = map(int, input().split())
wv = []
dp = [[0] * (W + 1)]
for i in range(n):
    w, v = map(int, input().split())
    wv.append([w, v])
    dp.append([0] * (W + 1))

for i in range(n):
    for j in range(W + 1):
        if j - wv[i][0] >= 0:
            dp[i + 1][j] = max(dp[i][j - wv[i][0]] + wv[i][1], dp[i + 1][j])
        dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])
print(max(dp[-1]))


Fixed submission:
import sys
input = sys.stdin.readline

n, W = map(int, input().split())
dp = [[0 for i in range(W + 1)] for j in range(n + 1)]
wv = [[int(x) for x in input().split()] for _ in range(n)]

for i in range(n):
    for j in range(W + 1):
        if j - wv[i][0] >= 0:
            dp[i + 1][j] = max(dp[i][j - wv[i][0]] + wv[i][1], dp[i + 1][j])
        dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])
print(max(dp[-1]))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

s = readline().rstrip().decode()
t = readline().rstrip().decode()
s_size = len(s)
t_size = len(t)
dp = [[0] * (t_size + 1) for _ in range(s_size + 1)]
ans = ''
for i in range(s_size):
    for j in range(t_size):
        if s[i] == t[j]:
            if dp[i + 1][j + 1] < dp[i][j] + 1:
                dp[i + 1][j + 1] = dp[i][j] + 1
        dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i + 1][j], dp[i][j + 1])
while s_size > 0 and t_size > 0:
    if dp[s_size][t_size] == dp[s_size - 1][t_size]:
        s_size -= 1
    elif dp[s_size][t_size] == dp[s_size][t_size - 1]:
        t_size -= 1
    else:
        ans = s[s_size - 1] + ans
        s_size -= 1
        t_size -= 1
print(ans)


Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

s = readline().rstrip().decode()
t = readline().rstrip().decode()
s_size = len(s)
t_size = len(t)
dp = [[0] * (t_size + 1) for _ in range(s_size + 1)]
ans = ''
for i in range(s_size):
    for j in range(t_size):
        if s[i] == t[j]:
            if dp[i + 1][j + 1] < dp[i][j] + 1:
                dp[i + 1][j + 1] = dp[i][j] + 1
        dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i + 1][j], dp[i][j + 1])
while s_size > 0 and t_size > 0:
    if dp[s_size][t_size] == dp[s_size - 1][t_size]:
        s_size -= 1
    elif dp[s_size][t_size] == dp[s_size][t_size - 1]:
        t_size -= 1
    else:
        ans = s[s_size - 1] + ans
        s_size -= 1
        t_size -= 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
ans = 0

for i in range(2*10**5):
    ss = s.count('BW')
    if ss == 0:
        break
    ans += ss
    s = s.replace('BW', 'WB')
print(ans)

Fixed submission:
s = input()
ans = 0
ss = s.count('B')
sss = len(s)
index = -1
sum_s = 0

for i in range(ss):
    index = s.find('B', index+1)
    ans += sss-index-1
    sum_s += i
    
ans -= sum_s
print(ans)
Buggy python submission (verdict: Runtime Error):
s = input()
ans_set = []

for i in range(len(s)):
    x = abs(int(s[i:i+3])-753)
    ans_set[i] = x
ans = min(ans_set)
print(ans)

Fixed submission:
s = input()
ans_set = [0] * len(s)

for i in range(len(s)):
    x = abs(int(s[i:i+3])-753)
    ans_set[i] = x
ans = min(ans_set)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)


def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True


n, m = map(int, readline().split())
if is_prime(m) and n != 1:
    print(1)
    exit()
for i in range(m // n, 0, -1):
    if m % i == 0:
        print(i)
        exit()


Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)


def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True


n, m = map(int, readline().split())
if is_prime(m):
    if n == 1:
        print(m)
    else:
        print(1)
    exit()
for i in range(m // n, 0, -1):
    if m % i == 0:
        print(i)
        exit()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, m = map(int, readline().split())
for i in range(m // n, 0, -1):
    if m % i == 0:
        print(i)
        exit()


Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)


def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True


n, m = map(int, readline().split())
if is_prime(m):
    if n == 1:
        print(m)
    else:
        print(1)
    exit()
for i in range(m // n, 0, -1):
    if m % i == 0:
        print(i)
        exit()
Buggy python submission (verdict: Runtime Error):
a,b,c = map(int, input().split())

if (a>b) and (a>c):
    ans = 10*a+b+c
elif = (b>a) and (b>c):
    ans = 10*b+a+c
else:
    ans = 10*c+a+b
print(ans)

Fixed submission:
a, b, c = map(int, input().split())

A = 10*a+b+c
B = 10*b+a+c
C = 10*c+a+b
print(max(A, B, C))
Buggy python submission (verdict: Runtime Error):
import sys
import bisect
input = sys.stdin.readline

n, k = map(int, input().split())
x = list(map(int, input().split()))
start = bisect.bisect_left(x, 0)
for i in range(start):
    x[i] = abs(x[i])
ans = [0] * (n - start)
if start == 0:
    print(x[k - 1])
    exit()
elif start == n - 1:
    print(x[k - start + 1])
    exit()
else:
    for i in range(n - start):
        ans[i] = min(x[i] * 2 + x[i + start], x[i] + x[i + start] * 2)
print(min(ans))


Fixed submission:
import sys
input = sys.stdin.readline

n, k = map(int, input().split())
x = list(map(int, input().split()))
ans = float('inf')

for l in range(n - k + 1):
    r = l + k - 1
    ans = min(ans, min(abs(x[l]), abs(x[r])) + x[r] - x[l])
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
n = int(input())

if n%7 != 0 and n%4 != 0 and n%11 != 0:
    for a in range(25):
        for b in range(14):
            if n%(7*b + 4*a) == 0:
                print('No')
                sys.exit()
else:
    print('No')
    sys.exit()
print('Yes')

Fixed submission:
import sys
n = int(input())

if n%7 != 0 and n%4 != 0 and n%11 != 0:
    for a in range(1, 25):
        for b in range(1, 14):
            if n%(7*b + 4*a) == 0:
                print('Yes')
                sys.exit()
else:
    print('Yes')
    sys.exit()
print('No')
Buggy python submission (verdict: Runtime Error):
import sys
import itertools
input = sys.stdin.readline

d, g = map(int, input().split())
pc = []
ans = []
bit = list(itertools.product([0, 1], repeat=d))
cnt_v = 0
cnt = 0

for i in range(d):
    p, c = map(int, input().split())
    pc.append([p, c])

for i in range(2 ** d):
    for j in range(d):
        if bit[i][j] == 1:
            p = pc[j][0]
            c = pc[j][1]
            p_index = j + 1
            cnt_v += p * 100 * p_index + c
            cnt += p

    for j in range(d):
        cnt_check = cnt_v
        if bit[i][j] == 0:
            p = pc[j][0]
            p_index = j + 1

            for k in range(p):
                if cnt_check >= g:
                    cnt += k
                    ans.append(cnt)
                    cnt -= k
                    break

                cnt_check += 100 * p_index
    cnt = 0
    cnt_v = 0

print(min(ans))


Fixed submission:
import sys
import itertools
input = sys.stdin.readline

d, g = map(int, input().split())
pc = []
ans = []
bit = list(itertools.product([0, 1], repeat=d))
cnt_v = 0
cnt = 0

for i in range(d):
    p, c = map(int, input().split())
    pc.append([p, c])

for i in range(2 ** d):
    for j in range(d):
        if bit[i][j] == 1:
            p = pc[j][0]
            c = pc[j][1]
            p_index = j + 1
            cnt_v += p * 100 * p_index + c
            cnt += p

    if cnt_v >= g:
        ans.append(cnt)

    else:
        for j in range(d):
            cnt_check = cnt_v
            if bit[i][j] == 0:
                p = pc[j][0]
                p_index = j + 1

                for k in range(p):
                    if cnt_check >= g:
                        cnt += k
                        ans.append(cnt)
                        cnt -= k
                        break

                    cnt_check += 100 * p_index
    cnt = 0
    cnt_v = 0

print(min(ans))
Buggy python submission (verdict: Runtime Error):
a_1, a_2, a_3 = map(int, input().split())
a = [a_1, a_2, a_3]

ad = sorted(a, reverse=True)
ans = (ad[0]-ad[1] + (ad[1]-ad[2])
print(ans)

Fixed submission:
a_1, a_2, a_3 = map(int, input().split())

maxs = max(a_1, a_2, a_3)
mins = min(a_1, a_2, a_3)
ans = maxs-mins
print(ans)
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())
c = [0]
for i in range(1, 999):
    c.append(c[i-1]+i)
    if c[i-1]-a > 0:
        ans = c[i-1]-a
        break
print(ans)


Fixed submission:
a, b = map(int, input().split())
c = [0]
for i in range(1, 1000):
    c.append(c[i-1]+i)
    if c[i-1]-a > 0:
        ans = c[i-1]-a
        if a+ans == c[i-1] and b+ans == c[i]:
            break
        else:
            ans = 0
print(ans)

Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())
c = [0]
for i in range(1, 999):
    c.append(c[i-1]+i)
    if c[i-1]-a >= 0:
        ans = c[i-1]-a
        break
print(ans)


Fixed submission:
a, b = map(int, input().split())
c = [0]
for i in range(1, 1000):
    c.append(c[i-1]+i)
    if c[i-1]-a > 0:
        ans = c[i-1]-a
        if a+ans == c[i-1] and b+ans == c[i]:
            break
        else:
            ans = 0
print(ans)
Buggy python submission (verdict: Runtime Error):
a, b, c, d = map(int, input().split())

if (min(abs(a-b)) <= d and min(abs(b-c)) <= d) or min(abs(a-c)) <= d:
    ans = 'Yes'
else:
    ans = 'No'
print(ans)

Fixed submission:
a, b, c, d = map(int, input().split())

if (abs(a-b) <= d and abs(b-c) <= d) or abs(a-c) <= d:
    ans = 'Yes'
else:
    ans = 'No'
print(ans)

Buggy python submission (verdict: Runtime Error):
a, b, c, d = map(int, input().split())

if min(abs(a-b, a-c, b-c)) <= d:
    ans = 'Yes'
else:
    ans = 'No'
print(ans)

Fixed submission:
a, b, c, d = map(int, input().split())

if (abs(a-b) <= d and abs(b-c) <= d) or abs(a-c) <= d:
    ans = 'Yes'
else:
    ans = 'No'
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import accumulate
import sys
input = sys.stdin.readline

n = int(input())
ans = [1]
a = list(map(int, input().split()))
for i in range(n):
    ans += list(accumulate(a[i:]))
print(ans.count(0))

Fixed submission:
import sys
import itertools
from collections import Counter
input = sys.stdin.readline

n = int(input())
a = list(map(int, input().split()))
cumsum = itertools.accumulate([0] + a)
counter = Counter(cumsum)
ans = 0

for value in counter.values():
    ans += value * (value - 1) // 2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# sys.stdin.readline()
import sys
input = sys.stdin.readline

from itertools import accumulate
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(n):
    ans += list(accumulate(a[i:])).count(0)
print(ans)

Fixed submission:
import sys
import itertools
from collections import Counter
input = sys.stdin.readline

n = int(input())
a = list(map(int, input().split()))
cumsum = itertools.accumulate([0] + a)
counter = Counter(cumsum)
ans = 0

for value in counter.values():
    ans += value * (value - 1) // 2

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from copy import deepcopy

n = int(readline())
x = list(map(int, readline().split()))
memo = sorted(x)
for xx in x:
    dx = deepcopy(memo)
    dx.remove(xx)
    if n % 2 == 0:
        print(dx[(n - 1) // 2])
    else:
        print((dx[(n - 1) // 2] + dx[(n - 1) // 2 - 1]) / 2)


Fixed submission:
import sys
input = sys.stdin.readline

n = int(input())
x = list(map(int, input().split()))
sort_x = sorted(x)
check = sort_x[n//2]
for i in range(n):
    if check <= x[i]:
        ans = sort_x[n//2-1]
    else:
        ans = check
    print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from collections import Counter
from scipy.special import comb

n = int(readline())
s = [input()[0] for i in range(n)]
memo = list(Counter(s).items())
check = ['M', 'A', 'R', 'C', 'H']
cnt = 0
ans = 0
for x, y in memo:
    if x in check:
        ans += y
        if y > 1:
            cnt += n - y
print(comb(ans, 3, exact=True) - cnt)


Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from collections import Counter
import itertools

n = int(readline())
s = [input()[0] for i in range(n)]
counter = Counter(s)
ans = 0
for i, j, k in itertools.combinations('MARCH', 3):
    ans += counter[i] * counter[j] * counter[k]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

h, w = map(int, readline().split())
s = [input() for i in range(h)]
q = [(0, 0)]
g = (h - 1, w - 1)
test = [(0, 1), (0, -1), (1, 0), (-1, 0)]
inf = float('inf')
dist = [[inf] * w for _ in range(h)]
dist[0][0] = 0
cnt = 0
while 1:
    qq = []
    cnt += 1
    for y, x in q:
        for dy, dx in test:
            yy, xx = y + dy, x + dx
            if xx < 0 or yy < 0 or xx > w - 1 or yy > h - 1:
                continue
            if s[yy][xx] == '#' or dist[yy][xx] != inf:
                continue
            dist[yy][xx] = cnt
            qq.append((yy, xx))
    q = qq
    if g in q:
        break
    if q:
        continue
    else:
        print(-1)
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            cnt += 1
print(h * w - cnt - 1)


Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

h, w = map(int, readline().split())
s = [input() for i in range(h)]
q = [(0, 0)]
g = (h - 1, w - 1)
test = [(0, 1), (0, -1), (1, 0), (-1, 0)]
inf = float('inf')
dist = [[inf] * w for _ in range(h)]
dist[0][0] = 0
cnt = 0
while 1:
    qq = []
    cnt += 1
    for y, x in q:
        for dy, dx in test:
            yy, xx = y + dy, x + dx
            if xx < 0 or yy < 0 or xx > w - 1 or yy > h - 1:
                continue
            if s[yy][xx] == '#' or dist[yy][xx] != inf:
                continue
            dist[yy][xx] = cnt
            qq.append((yy, xx))
    q = qq
    if g in q:
        break
    if q:
        continue
    else:
        print(-1)
        exit()
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            cnt += 1
print(h * w - cnt - 1)