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

ans = 0
ctable = [[-1 for _ in range(10)] for _ in range(10)]

def c(x, y):
    cnt = 0
    strx = str(x)
    stry = str(y)
    for i in range(1, N+1):
        stri = str(i)
        if stri[0] == strx and stri[-1] == stry:
            cnt += 1
    return cnt

for i in range(10):
    for j in range(10):
        ctable[i][j] = c(i, j)

for i in range(10):
    for j in range(10):
        ans += ctable[i][j] * ctable[j][i]

print(ans)


Fixed submission:
N = int(input())

cnt = 0
for i in range(1, N+1):
    first = str(i)[0]
    last = str(i)[-1]
    if first == last:
        cnt += 1
    if last != '0':
        if len(str(N)) == 2:
            if int(last+first) <= N:
                cnt += 1
        if len(str(N)) >= 3:
            for j in range(len(str(N))-2):
                cnt += 10**j
            middle = str(N)[1:-1]
            if last < str(N)[0]:
                cnt += 10**(len(str(N))-2)
            elif last == str(N)[0]:
                if first > str(N)[-1]:
                    cnt += int(middle)
                else:
                    cnt += int(middle) + 1

print(cnt)

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

ans = 0
ctable = [[-1 for _ in range(10)] for _ in range(10)]

def c(x, y):
    cnt = 0
    for i in range(1, N+1):
        if int(str(i)[0]) == x and int(str(i)[-1]) == y:
            cnt += 1
    return cnt

for i in range(10):
    for j in range(10):
        ctable[i][j] = c(i, j)

for i in range(10):
    for j in range(10):
        ans += ctable[i][j] * ctable[j][i]

print(ans)


Fixed submission:
N = int(input())

cnt = 0
for i in range(1, N+1):
    first = str(i)[0]
    last = str(i)[-1]
    if first == last:
        cnt += 1
    if last != '0':
        if len(str(N)) == 2:
            if int(last+first) <= N:
                cnt += 1
        if len(str(N)) >= 3:
            for j in range(len(str(N))-2):
                cnt += 10**j
            middle = str(N)[1:-1]
            if last < str(N)[0]:
                cnt += 10**(len(str(N))-2)
            elif last == str(N)[0]:
                if first > str(N)[-1]:
                    cnt += int(middle)
                else:
                    cnt += int(middle) + 1

print(cnt)

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

ans = 0

def c(x, y):
    cnt = 0
    for i in range(1, N+1):
        if int(str(i)[0]) == x and int(str(i)[-1]) == y:
            cnt += 1
    return cnt

for i in range(10):
    for j in range(10):
        ans += c(i, j) * c(j, i)

print(ans)


Fixed submission:
N = int(input())

cnt = 0
for i in range(1, N+1):
    first = str(i)[0]
    last = str(i)[-1]
    if first == last:
        cnt += 1
    if last != '0':
        if len(str(N)) == 2:
            if int(last+first) <= N:
                cnt += 1
        if len(str(N)) >= 3:
            for j in range(len(str(N))-2):
                cnt += 10**j
            middle = str(N)[1:-1]
            if last < str(N)[0]:
                cnt += 10**(len(str(N))-2)
            elif last == str(N)[0]:
                if first > str(N)[-1]:
                    cnt += int(middle)
                else:
                    cnt += int(middle) + 1

print(cnt)

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

ans = 0

def c(x, y):
    cnt = 0
    for i in range(1, N+1):
        if int(str(i)[0]) == x and int(str(i)[-1]) == y:
            cnt += 1
    return cnt

for i in range(10):
    for j in range(10):
        ans += c(i, j) * c(j, i)

print(ans)


Fixed submission:
N = int(input())

cnt = 0
for i in range(1, N+1):
    first = str(i)[0]
    last = str(i)[-1]
    if first == last:
        cnt += 1
    if last != '0':
        if len(str(N)) == 2:
            if int(last+first) <= N:
                cnt += 1
        if len(str(N)) >= 3:
            for j in range(len(str(N))-2):
                cnt += 10**j
            middle = str(N)[1:-1]
            if last < str(N)[0]:
                cnt += 10**(len(str(N))-2)
            elif last == str(N)[0]:
                if first > str(N)[-1]:
                    cnt += int(middle)
                else:
                    cnt += int(middle) + 1

print(cnt)