n = int(eval(input()))

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

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

  p = int(str(i)[0])

  q = int(str(i)[-1])

  c[p][q] += 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()))

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

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

  C[int(str(i)[0])][i % 10] += 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()))
c = [[0] * 10 for _ in range(10)]
for i in range(1, n + 1):
    p = int(str(i)[0])
    q = int(str(i)[-1])
    c[p][q] += 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()))
C = [[0] * 10 for _ in range(10)]
for i in range(1, n + 1):
    C[int(str(i)[0])][i % 10] += 1
ans = 0
for i in range(10):
    for j in range(10):
        ans += C[i][j] * C[j][i]
print(ans)

-c = [[0] * 10 for _ in range(10)] +C = [[0] * 10 for _ in range(10)] -    p = int(str(i)[0]) -    q = int(str(i)[-1]) -    c[p][q] += 1 +    C[int(str(i)[0])][i % 10] += 1 -        ans += c[i][j] * c[j][i] +        ans += C[i][j] * C[j][i]