n=int(eval(input()))



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



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

    t=str(i)

    c[int(t[0])][int(t[-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()))

cnt=[[0 for i in range(10)] for j in range(10)]



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

  s=str(i)

  head=int(s[0])

  tail=int(s[-1])

  cnt[head][tail]+=1



ans=0

for h in range(0,10):

  for t in range(0,10):

    ans+=cnt[h][t]*cnt[t][h]

print(ans)
n = int(eval(input()))
c = [[0] * 10 for i in range(10)]
for i in range(1, n + 1):
    t = str(i)
    c[int(t[0])][int(t[-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()))
cnt = [[0 for i in range(10)] for j in range(10)]
for i in range(1, n + 1):
    s = str(i)
    head = int(s[0])
    tail = int(s[-1])
    cnt[head][tail] += 1
ans = 0
for h in range(0, 10):
    for t in range(0, 10):
        ans += cnt[h][t] * cnt[t][h]
print(ans)

-c = [[0] * 10 for i in range(10)] +cnt = [[0 for i in range(10)] for j in range(10)] -    t = str(i) -    c[int(t[0])][int(t[-1])] += 1 +    s = str(i) +    head = int(s[0]) +    tail = int(s[-1]) +    cnt[head][tail] += 1 -for i in range(10): -    for j in range(10): -        ans += c[i][j] * c[j][i] +for h in range(0, 10): +    for t in range(0, 10): +        ans += cnt[h][t] * cnt[t][h]