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

n=int(eval(input()))

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

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

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

  c[a][b]+=1

ans=0

for i in range(1,10):

  for j in range(1,10):

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

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

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

for i in range(1,n+1):d[int(str(i)[0])][int(str(i)[-1])]+=1

ans=0

for i in range(1,10):

  for j in range(1,10):ans+=d[i][j]*d[j][i]

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

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

-c = [10 * [0] for _ in range(10)] +d = [10 * [0] for _ in range(10)] -    a = int(str(i)[0]) -    b = int(str(i)[-1]) -    c[a][b] += 1 +    d[int(str(i)[0])][int(str(i)[-1])] += 1 -        ans += c[i][j] * c[j][i] +        ans += d[i][j] * d[j][i]