Problem: There are N people. The name of the i-th person is S_i.  We would like to choose three people so that the following conditions are met:    * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`.   * There are no multiple people whose names begin with the same letter.  How many such ways are there to choose three people, disregarding order?  Note that the answer may not fit into a 32-bit integer type.

Submission attempts (in order):
n = int(input())
s = []
for i in range(n):
    s.append(input()[0])

def qwe(y):
    m = 0
    a = 0
    r = 0
    c = 0
    h = 0
    for i in y:
        if i == 'M':
            m += 1
        elif i == 'A':
            a += 1
        elif i == 'R':
            r += 1
        elif i == 'C':
            c += 1
        elif i == 'H':
            h += 1
        else:
            pass
    q = [m,a,r,c,h]
    return q

def qwer(arr):
    count = 0
    coun = 0
    for j in arr:
        if j == 0:
            count += 1
        else:
            coun += 1
    if count == 5:
        return 0
    else:
        if arr[0] == 0:
            arr[0] = 1
        if arr[1] == 0:
            arr[1] = 1
        if arr[2] == 0:
            arr[2] = 1
        if arr[3] == 0:
            arr[3] = 1
        if arr[4] == 0:
            arr[4] = 1
        if coun == 4:
            asd = arr[0]*arr[1]*arr[2]*arr[3]*arr[4]*4 - 1
            return asd
        if coun == 5:
            asd = arr[0]*arr[1]*arr[2]*arr[3]*arr[4]*10 - 4
            return asd
v = qwe(s)
print(qwer(v))


n = int(input())
s = []
for i in range(n):
    s.append(input()[0])

def qwe(y):
    m = 0
    a = 0
    r = 0
    c = 0
    h = 0
    for i in y:
        if i == 'M':
            m += 1
        elif i == 'A':
            a += 1
        elif i == 'R':
            r += 1
        elif i == 'C':
            c += 1
        elif i == 'H':
            h += 1
        else:
            pass
    q = [m,a,r,c,h]
    return q

def qwer(arr):
    count = 0
    coun = 0
    for j in range(len(arr)):
        if arr[j] == 0:
            count += 1
            arr.pop(j)
        else:
            coun += 1
    if count == 5:
        return 0
    if coun == 4:
        asd_1 = arr[0]*arr[1]*arr[2]
        asd_2 = arr[0]*arr[1]*arr[3]
        asd_3 = arr[0]*arr[2]*arr[3]
        asd_4 = arr[1]*arr[2]*arr[3]
        return (asd_1 + asd_2 + asd_3 + asd_4)
    if coun == 5:
        asf_1 = arr[0]*arr[1]*arr[2]
        asf_2 = arr[0]*arr[1]*arr[3]
        asf_3 = arr[0]*arr[1]*arr[4]
        asf_4 = arr[0]*arr[2]*arr[3]
        asf_5 = arr[0]*arr[2]*arr[4]
        asf_6 = arr[0]*arr[3]*arr[4]
        asf_7 = arr[1]*arr[2]*arr[3]
        asf_8 = arr[1]*arr[2]*arr[4]
        asf_9 = arr[1]*arr[3]*arr[4]
        asf_10 = arr[2]*arr[3]*arr[4]
        return (asf_1 + asf_2 + asf_3 + asf_4 + asf_5 + asf_6 + asf_7 + asf_8 + asf_9 + asf_10)
v = qwe(s)
print(qwer(v))


n = int(input())
s = []
for i in range(n):
    s.append(input()[0])

def qwe(y):
    m = 0
    a = 0
    r = 0
    c = 0
    h = 0
    for i in y:
        if i == 'M':
            m += 1
        elif i == 'A':
            a += 1
        elif i == 'R':
            r += 1
        elif i == 'C':
            c += 1
        elif i == 'H':
            h += 1
        else:
            pass
    q = [m,a,r,c,h]
    return q

def qwer(arr):
    count = 0
    for j in range(len(arr)):
        if arr[j] == 0:
            count += 1
            arr[j] = "D"
    arr.remove("D")
    if count == 5:
        return 0
    if count == 4:
        return 0
    if count == 3:
        return 0
    if count == 2:
        wer = arr[0] * arr[1] * arr[2]
        return wer
    if count == 1:
        asd_1 = arr[0]*arr[1]*arr[2]
        asd_2 = arr[0]*arr[1]*arr[3]
        asd_3 = arr[0]*arr[2]*arr[3]
        asd_4 = arr[1]*arr[2]*arr[3]
        asde = asd_1 + asd_2 + asd_3 + asd_4
        return asde
    if count == 0:
        asf_1 = arr[0]*arr[1]*arr[2]
        asf_2 = arr[0]*arr[1]*arr[3]
        asf_3 = arr[0]*arr[1]*arr[4]
        asf_4 = arr[0]*arr[2]*arr[3]
        asf_5 = arr[0]*arr[2]*arr[4]
        asf_6 = arr[0]*arr[3]*arr[4]
        asf_7 = arr[1]*arr[2]*arr[3]
        asf_8 = arr[1]*arr[2]*arr[4]
        asf_9 = arr[1]*arr[3]*arr[4]
        asf_10 = arr[2]*arr[3]*arr[4]
        asdf =  asf_1 + asf_2 + asf_3 + asf_4 + asf_5 + asf_6 + asf_7 + asf_8 + asf_9 + asf_10
        return asdf
v = qwe(s)
print(qwer(v))


n = int(input())
s = []
for i in range(n):
    s.append(input()[0])

def qwe(y):
    m = 0
    a = 0
    r = 0
    c = 0
    h = 0
    for i in y:
        if i == 'M':
            m += 1
        elif i == 'A':
            a += 1
        elif i == 'R':
            r += 1
        elif i == 'C':
            c += 1
        elif i == 'H':
            h += 1
        else:
            pass
    q = [m,a,r,c,h]
    return q

def qwer(arr):
    count = 0
    for j in range(len(arr)):
        if arr[j] == 0:
            count += 1
            arr.pop(j)
    if count == 5:
        return 0
    if count == 4:
        return 0
    if count == 3:
        return 0
    if count == 2:
        wer = arr[0] * arr[1] * arr[2]
        return wer
    if count == 1:
        asd_1 = arr[0]*arr[1]*arr[2]
        asd_2 = arr[0]*arr[1]*arr[3]
        asd_3 = arr[0]*arr[2]*arr[3]
        asd_4 = arr[1]*arr[2]*arr[3]
        asde = asd_1 + asd_2 + asd_3 + asd_4
        return asde
    if count == 0:
        asf_1 = arr[0]*arr[1]*arr[2]
        asf_2 = arr[0]*arr[1]*arr[3]
        asf_3 = arr[0]*arr[1]*arr[4]
        asf_4 = arr[0]*arr[2]*arr[3]
        asf_5 = arr[0]*arr[2]*arr[4]
        asf_6 = arr[0]*arr[3]*arr[4]
        asf_7 = arr[1]*arr[2]*arr[3]
        asf_8 = arr[1]*arr[2]*arr[4]
        asf_9 = arr[1]*arr[3]*arr[4]
        asf_10 = arr[2]*arr[3]*arr[4]
        asdf =  asf_1 + asf_2 + asf_3 + asf_4 + asf_5 + asf_6 + asf_7 + asf_8 + asf_9 + asf_10
        return asdf
v = qwe(s)
print(qwer(v))


n = int(input())
s = []
for i in range(n):
    s.append(input()[0])

def qwe(y):
    m = 0
    a = 0
    r = 0
    c = 0
    h = 0
    for i in y:
        if i == 'M':
            m += 1
        elif i == 'A':
            a += 1
        elif i == 'R':
            r += 1
        elif i == 'C':
            c += 1
        elif i == 'H':
            h += 1
        else:
            pass
    q = [m,a,r,c,h]
    return q

def qwer(arr):
    count = 0
    for j in range(len(arr)):
        if arr[j] == 0:
            count += 1
            arr[j] = "D"
    while "D" in arr:
        arr.remove("D")
    if count == 5:
        return 0
    if count == 4:
        return 0
    if count == 3:
        return 0
    if count == 2:
        wer = arr[0] * arr[1] * arr[2]
        return wer
    if count == 1:
        asd_1 = arr[0]*arr[1]*arr[2]
        asd_2 = arr[0]*arr[1]*arr[3]
        asd_3 = arr[0]*arr[2]*arr[3]
        asd_4 = arr[1]*arr[2]*arr[3]
        asde = asd_1 + asd_2 + asd_3 + asd_4
        return asde
    if count == 0:
        asf_1 = arr[0]*arr[1]*arr[2]
        asf_2 = arr[0]*arr[1]*arr[3]
        asf_3 = arr[0]*arr[1]*arr[4]
        asf_4 = arr[0]*arr[2]*arr[3]
        asf_5 = arr[0]*arr[2]*arr[4]
        asf_6 = arr[0]*arr[3]*arr[4]
        asf_7 = arr[1]*arr[2]*arr[3]
        asf_8 = arr[1]*arr[2]*arr[4]
        asf_9 = arr[1]*arr[3]*arr[4]
        asf_10 = arr[2]*arr[3]*arr[4]
        asdf =  asf_1 + asf_2 + asf_3 + asf_4 + asf_5 + asf_6 + asf_7 + asf_8 + asf_9 + asf_10
        return asdf
v = qwe(s)
print(qwer(v))


Verdicts: Wrong Answer

Runtime Error

Runtime Error

Runtime Error

Accepted