Buggy python submission (verdict: Time Limit Exceeded):
import sys;input=sys.stdin.readline
N, = map(int, input().split())
S = []
for _ in range(N):
    s = input().strip()
    S.append(s)
S.sort(key=lambda x:len(x))
D = dict()
dd = set()
R = 0
for s in S:
    l = len(s)
    d = [0]*26
    for c in dd:
        d[c] += 1
    mm = 0
    xs = []
    for i in range(l-1, -1, -1):
        cc = ord(s[i]) - 97
        xs.append(s[i])
        R += d[cc]
        d[cc] = 0
        tmp = "".join(xs)
        if tmp in D:
            for c in D[tmp]:
                d[c] += 1
        if i == 0:
            f = cc
        if i == 1:
            nn = tmp
        mm += 1
    if l != 1:
        if nn not in D:
            D[nn] = set()
        D[nn].add(f)
    else:
        dd.add(f)
print(R)


Fixed submission:
import sys;input=sys.stdin.readline
N, = map(int, input().split())
MOD=67280421310721
S = []
for _ in range(N):
    s = input().strip()
    S.append(s)
S.sort(key=lambda x:len(x))
D = dict()
dd = set()
R = 0
for s in S:
    l = len(s)
    d = [0]*26
    for c in dd:
        d[c] += 1
    tmp=0
    for i in range(l-1, -1, -1):
        ee = ord(s[i]) - 97
        tmp = 100*tmp+(ee+1)
        tmp %= MOD
        R += d[ee]
        d[ee] = 0
        if tmp in D:
            for c in D[tmp]:
                d[c] += 1
        if i == 1:
            nn = tmp
    if l != 1:
        if nn not in D:
            D[nn] = set()
        D[nn].add(ee)
    else:
        dd.add(ee)
print(R)

Buggy python submission (verdict: Time Limit Exceeded):
import sys;input=sys.stdin.readline
N, = map(int, input().split())
S = []
for _ in range(N):
    s = input().strip()
    S.append(s)
S.sort(key=lambda x:len(x))
D = dict()
dd = set()
R = 0
for s in S:
    l = len(s)
    d = [0]*26
    for c in dd:
        d[c] += 1
    mm = 0
    for i in range(l-1, -1, -1):
        cc = ord(s[i]) - 97
        R += d[cc]
        d[cc] = 0
        if s[i:] in D:
            for c in D[s[i:]]:
                d[c] += 1
        if i == 0:
            f = cc
        mm += 1
    if l != 1:
        if s[1:] not in D:
            D[s[1:]] = set()
        D[s[1:]].add(f)
    else:
        dd.add(f)
print(R)


Fixed submission:
import sys;input=sys.stdin.readline
N, = map(int, input().split())
MOD=67280421310721
S = []
for _ in range(N):
    s = input().strip()
    S.append(s)
S.sort(key=lambda x:len(x))
D = dict()
dd = set()
R = 0
for s in S:
    l = len(s)
    d = [0]*26
    for c in dd:
        d[c] += 1
    tmp=0
    for i in range(l-1, -1, -1):
        ee = ord(s[i]) - 97
        tmp = 100*tmp+(ee+1)
        tmp %= MOD
        R += d[ee]
        d[ee] = 0
        if tmp in D:
            for c in D[tmp]:
                d[c] += 1
        if i == 1:
            nn = tmp
    if l != 1:
        if nn not in D:
            D[nn] = set()
        D[nn].add(ee)
    else:
        dd.add(ee)
print(R)

Buggy python submission (verdict: Time Limit Exceeded):
import sys;input=sys.stdin.readline
from collections import defaultdict
N, = map(int, input().split())
S = []
for _ in range(N):
    s = input().strip()
    S.append(s)
S.sort(key=lambda x:len(x))
D = defaultdict(set)
R = 0
for s in S:
    l = len(s)
    d = defaultdict(int)
    for c in D[""]:
        d[c] += 1
    for i in range(l-1, -1, -1):
        R += d[s[i]]
        d[s[i]] = 0
        for c in D[s[i:]]:
            d[c] += 1
    D[s[1:]].add(s[0])
print(R)


Fixed submission:
import sys;input=sys.stdin.readline
N, = map(int, input().split())
MOD=67280421310721
S = []
for _ in range(N):
    s = input().strip()
    S.append(s)
S.sort(key=lambda x:len(x))
D = dict()
dd = set()
R = 0
for s in S:
    l = len(s)
    d = [0]*26
    for c in dd:
        d[c] += 1
    tmp=0
    for i in range(l-1, -1, -1):
        ee = ord(s[i]) - 97
        tmp = 100*tmp+(ee+1)
        tmp %= MOD
        R += d[ee]
        d[ee] = 0
        if tmp in D:
            for c in D[tmp]:
                d[c] += 1
        if i == 1:
            nn = tmp
    if l != 1:
        if nn not in D:
            D[nn] = set()
        D[nn].add(ee)
    else:
        dd.add(ee)
print(R)