Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N = int(input().strip())
    S = []
    D1 = {}
    D2 = {}
    for _ in range(N):
        in_s = input().strip()[0]
        if in_s in ['M','A','R','C','H']:
            S.append(in_s)  
    S.sort()
    count = 0
    for i in range(len(S)):
        D1 = {}
        D2 = {}
        D1[S[i]]=True
        for j in range(i+1, len(S)):
            D2 = {}
            if S[j] in D1: continue
            D2[S[j]]=True
            for k in range(j+1, len(S)):
                if S[k] in D2: continue
                count += 1
    return count
if __name__ == '__main__':
    print(main())

Fixed submission:
import math
def kumi(s, n):
    count = 1
    for x in range(s, s - n, -1):
        count *= x
    ret = count // math.factorial(n)
    return ret

def main():
    N = int(input().strip())
    S = []
    D = {}
    for _ in range(N):
        in_s = (input().strip())[0]
        if in_s in ['M','A','R','C','H']:
            S.append(in_s)
            D[in_s] = D.get(in_s, 0) + 1

    if not S or len(D.keys()) < 3:
        return 0

    
    # 組み合わせ数
    count = kumi(len(S), 3)
    # 重複削除
    for v in D.values():
        if v < 2:
            continue
        elif v == 2:
            count -= len(S) - v
        else:
            count -= kumi(v, 2) * (len(S) - v)
            count -= kumi(v, 3)
    return count

if __name__ == '__main__':
    print(main())

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
def main():
    N = int(input().strip())
    S = []
    for _ in range(N):
        in_s = (input().strip())[0]
        if in_s in ['M','A','R','C','H']:
            S.append(in_s)

    if not S:
        return 0

    pat = itertools.combinations(S, 3);
    
    count = 0
    for x in pat:
        if len(x) == len(set(x)):
            count += 1
    return count
    
if __name__ == '__main__':
    print(main())

Fixed submission:
import math
def kumi(s, n):
    count = 1
    for x in range(s, s - n, -1):
        count *= x
    ret = count // math.factorial(n)
    return ret

def main():
    N = int(input().strip())
    S = []
    D = {}
    for _ in range(N):
        in_s = (input().strip())[0]
        if in_s in ['M','A','R','C','H']:
            S.append(in_s)
            D[in_s] = D.get(in_s, 0) + 1

    if not S or len(D.keys()) < 3:
        return 0

    
    # 組み合わせ数
    count = kumi(len(S), 3)
    # 重複削除
    for v in D.values():
        if v < 2:
            continue
        elif v == 2:
            count -= len(S) - v
        else:
            count -= kumi(v, 2) * (len(S) - v)
            count -= kumi(v, 3)
    return count

if __name__ == '__main__':
    print(main())

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
def main():
    N = int(input().strip())
    S = [input().strip() for _ in range(N)]
    MARCH_S = [x[0] for x in S if x[0] in ['M','A','R','C','H']]
    if not MARCH_S:
        return 0

    pat = list(itertools.combinations(MARCH_S, 3));
    pat_len = len(pat)
    
    for x in ['M','A','R','C','H']:
        pat_len -= len([p for p in pat if p.count(x) > 1])

    return pat_len
    
if __name__ == '__main__':
    print(main())

Fixed submission:
import math
def kumi(s, n):
    count = 1
    for x in range(s, s - n, -1):
        count *= x
    ret = count // math.factorial(n)
    return ret

def main():
    N = int(input().strip())
    S = []
    D = {}
    for _ in range(N):
        in_s = (input().strip())[0]
        if in_s in ['M','A','R','C','H']:
            S.append(in_s)
            D[in_s] = D.get(in_s, 0) + 1

    if not S or len(D.keys()) < 3:
        return 0

    
    # 組み合わせ数
    count = kumi(len(S), 3)
    # 重複削除
    for v in D.values():
        if v < 2:
            continue
        elif v == 2:
            count -= len(S) - v
        else:
            count -= kumi(v, 2) * (len(S) - v)
            count -= kumi(v, 3)
    return count

if __name__ == '__main__':
    print(main())