Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

def main1(N):
    lst = list()
    count = 0
    for i in range(1, N+1):
        for j in range(i, N+1):
            ahead = int(str(i)[0])
            atail = i % 10
            bhead = int(str(j)[0])
            btail = j % 10
            if ahead == btail and atail == bhead:
                count += (1 if i == j else 2)
    print(count)

def main2(N):
    #9*9の表
    lst = list()
    for i in range(1,10):
        lst.append([0]*9)

    for n in range(1, N+1):
        for i in range(1,10):
            for j in range(1,10):
                head = str(n)[0]
                tail = str(n)[-1]
                if i == int(head) and j == int(tail):
                    lst[i-1][j-1] += 1
    
    count = 0
    for i in range(0, len(lst)):
        for j in range(0, len(lst[i])):
            count += lst[i][j] * lst[j][i]

    print(count)

main2(N)


Fixed submission:
def main3(N):
    lst = list()
    for i in range(1, 10):
        lst.append([0]*9)

    for n in range(1, N+1):
        head = int(str(n)[0])
        tail = int(str(n)[-1])
        #末尾が0はNG
        if tail != 0:
            lst[head-1][tail-1] += 1
        
    #for i in range(0, len(lst)):
    #    print(lst[i])
    
    count = 0
    for i in range(0, len(lst)):
        for j in range(0, len(lst[i])):
            count += lst[i][j] * lst[j][i]

    print(count)

N = int(input())
main3(N)

Buggy python submission (verdict: Runtime Error):
def main2(N):
    #9*9の表
    lst = list()
    for i in range(1,10):
        lst.append([0]*9)

    for n in range(1, N+1):
        for i in range(1,10):
            for j in range(1,10):
                head = str(n)[0]
                tail = str(n)[-1]
                if i == int(head) and j == int(tail):
                    lst[i-1][j-1] += 1
    
    count = 0
    for i in range(0, len(lst)):
        for j in range(0, len(lst[i])):
            count += lst[i][j] * lst[j][i]

    print(count)

main2(N)

Fixed submission:
def main3(N):
    lst = list()
    for i in range(1, 10):
        lst.append([0]*9)

    for n in range(1, N+1):
        head = int(str(n)[0])
        tail = int(str(n)[-1])
        #末尾が0はNG
        if tail != 0:
            lst[head-1][tail-1] += 1
        
    #for i in range(0, len(lst)):
    #    print(lst[i])
    
    count = 0
    for i in range(0, len(lst)):
        for j in range(0, len(lst[i])):
            count += lst[i][j] * lst[j][i]

    print(count)

N = int(input())
main3(N)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

lst = list()
count = 0
for i in range(1, N+1):
    for j in range(i, N+1):
        ahead = int(str(i)[0])
        atail = i % 10
        bhead = int(str(j)[0])
        btail = j % 10
        if ahead == btail and atail == bhead:
            count += (1 if i == j else 2)
print(count)


Fixed submission:
def main3(N):
    lst = list()
    for i in range(1, 10):
        lst.append([0]*9)

    for n in range(1, N+1):
        head = int(str(n)[0])
        tail = int(str(n)[-1])
        #末尾が0はNG
        if tail != 0:
            lst[head-1][tail-1] += 1
        
    #for i in range(0, len(lst)):
    #    print(lst[i])
    
    count = 0
    for i in range(0, len(lst)):
        for j in range(0, len(lst[i])):
            count += lst[i][j] * lst[j][i]

    print(count)

N = int(input())
main3(N)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

lst = list()
count = 0
for i in range(1, N+1):
    for j in range(1, N+1):
        ahead = int(str(i)[0])
        atail = i % 10
        bhead = int(str(j)[0])
        btail = j % 10
        if ahead == btail and atail == bhead:
            count += 1
print(count)


Fixed submission:
def main3(N):
    lst = list()
    for i in range(1, 10):
        lst.append([0]*9)

    for n in range(1, N+1):
        head = int(str(n)[0])
        tail = int(str(n)[-1])
        #末尾が0はNG
        if tail != 0:
            lst[head-1][tail-1] += 1
        
    #for i in range(0, len(lst)):
    #    print(lst[i])
    
    count = 0
    for i in range(0, len(lst)):
        for j in range(0, len(lst[i])):
            count += lst[i][j] * lst[j][i]

    print(count)

N = int(input())
main3(N)