N = int(eval(input()))



c = [[0]*10 for _ in range(10)]

for n in range(1,N+1):

    s = str(n)

    c[int(s[0])][int(s[-1])] += 1



ans = 0

for i in range(10):

    for j in range(10):

        ans += c[i][j] * c[j][i]

print(ans)
N = int(eval(input()))



dp = [[0]*10 for _ in range(10)]



for n in range(1,N+1):

    s = str(n)

    dp[int(s[0])][int(s[-1])] += 1



ans = 0

for i in range(10):

    for j in range(10):

        ans += dp[i][j] * dp[j][i]

print(ans)
N = int(eval(input()))
c = [[0] * 10 for _ in range(10)]
for n in range(1, N + 1):
    s = str(n)
    c[int(s[0])][int(s[-1])] += 1
ans = 0
for i in range(10):
    for j in range(10):
        ans += c[i][j] * c[j][i]
print(ans)

N = int(eval(input()))
dp = [[0] * 10 for _ in range(10)]
for n in range(1, N + 1):
    s = str(n)
    dp[int(s[0])][int(s[-1])] += 1
ans = 0
for i in range(10):
    for j in range(10):
        ans += dp[i][j] * dp[j][i]
print(ans)

-c = [[0] * 10 for _ in range(10)] +dp = [[0] * 10 for _ in range(10)] -    c[int(s[0])][int(s[-1])] += 1 +    dp[int(s[0])][int(s[-1])] += 1 -        ans += c[i][j] * c[j][i] +        ans += dp[i][j] * dp[j][i]