Buggy python submission (verdict: Time Limit Exceeded):
import math                                                                                                                                                         
                                                                                                                                                                    
n = int(input())                                                                                                                                                    
                                                                                                                                                                    
def N(n, i, j):                                                                                                                                                     
    num = 0                                                                                                                                                         
    for x in range(1,n+1):                                                                                                                                          
        low = int(x%10)                                                                                                                                             
        high = int(x/(pow(10, int(math.log10(x)))))                                                                                                                 
        if((high == i)and(low == j)):                                                                                                                               
            num = num + 1                                                                                                                                           
    return num                                                                                                                                                      
                                                                                                                                                                    
s = 0                                                                                                                                                               
for i in range(1,10):                                                                                                                                               
    for j in range(1,10):                                                                                                                                           
        s = s + N(n, i, j)*N(n, j, i)                                                                                                                               
                                                                                                                                                                    
print(s)                                                                                                                                                            
                 

Fixed submission:
import math

n = int(input())

def N(n, i, j):
    num = 0
    for x in range(1,n+1):
        low = int(x%10)
        high = int(x/(pow(10, int(math.log10(x)))))
        if((high == i)and(low == j)):
            num = num + 1
    return num

s = 0
for i in range(1,10):
    s = s + pow(N(n, i, i), 2)

for i in range(2,10):
    for j in range(1,i):
        s = s + 2*N(n, i, j)*N(n, j, i)

print(s)

Buggy python submission (verdict: Time Limit Exceeded):
import math

n = int(input())

def N(n, i, j):
    num = 0
    for x in range(1,n+1):
        low = int(x%10)
        high = int(x/(pow(10, int(math.log10(x)))))
        if((high == i)and(low == j)):
            num = num + 1
    return num

s = 0
for i in range(1,10):
    for j in range(1,10):
        s = s + N(n, i, j)*N(n, j, i)

print(s)
        

    







Fixed submission:
import math

n = int(input())

def N(n, i, j):
    num = 0
    for x in range(1,n+1):
        low = int(x%10)
        high = int(x/(pow(10, int(math.log10(x)))))
        if((high == i)and(low == j)):
            num = num + 1
    return num

s = 0
for i in range(1,10):
    s = s + pow(N(n, i, i), 2)

for i in range(2,10):
    for j in range(1,i):
        s = s + 2*N(n, i, j)*N(n, j, i)

print(s)