Buggy python submission (verdict: Time Limit Exceeded):
#coding=utf-8
from itertools import combinations
from collections import Counter

def solve(n, ss):
    filtered_ss = list(filter(lambda x: x in "MARCH", ss))

    gc = Counter(filtered_ss)
    if len(gc) < 3:
        return 0

    ans = 0
    for permutation in combinations("MARCH", 3):
        ans += (gc[permutation[0]] * gc[permutation[1]] * gc[permutation[2]])

    return ans

def main():
    n = int(input())
    ss = []
    for x in range(n):
        ss = ss + [input()[0]]
    print(solve(n, ss))

if __name__ == '__main__':
    main()


Fixed submission:
#coding=utf-8
from itertools import combinations
from collections import Counter

def solve(n, gc):
    #filtered_ss = list(filter(lambda x: x in "MARCH", ss))

    #gc = Counter(filtered_ss)
    if len(gc) < 3:
        return 0

    ans = 0
    for permutation in combinations("MARCH", 3):
        ans += (gc[permutation[0]] * gc[permutation[1]] * gc[permutation[2]])

    return ans

def main():
    n = int(input())
    gc = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}
    for _ in range(n):
        x = input()[0]
        if x in "MARCH":
            gc[x] += 1
    print(solve(n, gc))

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#coding=utf-8
from itertools import combinations
from collections import Counter

def solve(n, ss):
    filtered_ss = list(filter(lambda x: x in "MARCH", map(lambda x:x[0], ss)))

    gc = Counter(filtered_ss)
    if len(gc) < 3:
        return 0

    ans = 0
    for permutation in combinations("MARCH", 3):
        if permutation[0] in gc.keys() and permutation[1] in gc.keys() and permutation[2] in gc.keys():
            tmp = (gc[permutation[0]] * gc[permutation[1]] * gc[permutation[2]])
            ans = ans + tmp

    return ans

def main():
    n = int(input())
    ss = []
    for x in range(n):
        ss = ss + [input()]
    print(solve(n, ss))

if __name__ == '__main__':
    main()


Fixed submission:
#coding=utf-8
from itertools import combinations
from collections import Counter

def solve(n, gc):
    #filtered_ss = list(filter(lambda x: x in "MARCH", ss))

    #gc = Counter(filtered_ss)
    if len(gc) < 3:
        return 0

    ans = 0
    for permutation in combinations("MARCH", 3):
        ans += (gc[permutation[0]] * gc[permutation[1]] * gc[permutation[2]])

    return ans

def main():
    n = int(input())
    gc = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}
    for _ in range(n):
        x = input()[0]
        if x in "MARCH":
            gc[x] += 1
    print(solve(n, gc))

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#coding=utf-8
import itertools

#[a] -> {a: Int} 
def group_count(l):
    group = list(set(l))
    dic = {}
    for x in group:
        dic[x] = l.count(x)
    return dic

def solve(n, ss):
    filtered_ss = list(filter(lambda x: x in "MARCH", map(lambda x:x[0], ss)))

    gc = group_count(filtered_ss)
    if len(gc) < 3:
        return 0

    ans = 0
    for permutation in itertools.combinations("MARCH", 3):
        if permutation[0] in gc.keys() and permutation[1] in gc.keys() and permutation[2] in gc.keys():
            tmp = (gc[permutation[0]] * gc[permutation[1]] * gc[permutation[2]])
            ans = ans + tmp

    return ans

def main():
    n = int(input())
    ss = []
    for x in range(n):
        ss = ss + [input()]
    print(solve(n, ss))

if __name__ == '__main__':
    main()


Fixed submission:
#coding=utf-8
from itertools import combinations
from collections import Counter

def solve(n, gc):
    #filtered_ss = list(filter(lambda x: x in "MARCH", ss))

    #gc = Counter(filtered_ss)
    if len(gc) < 3:
        return 0

    ans = 0
    for permutation in combinations("MARCH", 3):
        ans += (gc[permutation[0]] * gc[permutation[1]] * gc[permutation[2]])

    return ans

def main():
    n = int(input())
    gc = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}
    for _ in range(n):
        x = input()[0]
        if x in "MARCH":
            gc[x] += 1
    print(solve(n, gc))

if __name__ == '__main__':
    main()