n=int(eval(input()))

D={}

DD={}

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

   s=(str(i)[0],str(i)[-1])

   t=(str(i)[-1],str(i)[0])

   if s not in D:

      D[s]=1

   else:

      D[s]+=1

   if t not in DD:

      DD[t]=1

   else:

      DD[t]+=1

ans=0

for i in D:

   if i in DD:

      ans+=D[i]*DD[i]

print(ans)

      
n=int(eval(input()))

D={}

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

   s=(str(i)[0],str(i)[-1])

   if s in D:

      D[s]+=1

   else:

      D[s]=1



ans=0

for aj,bj in D:

   if (bj,aj) in D:

      ans+=D[(aj,bj)]*D[(bj,aj)]

print(ans)
n = int(eval(input()))
D = {}
DD = {}
for i in range(1, n + 1):
    s = (str(i)[0], str(i)[-1])
    t = (str(i)[-1], str(i)[0])
    if s not in D:
        D[s] = 1
    else:
        D[s] += 1
    if t not in DD:
        DD[t] = 1
    else:
        DD[t] += 1
ans = 0
for i in D:
    if i in DD:
        ans += D[i] * DD[i]
print(ans)

n = int(eval(input()))
D = {}
for i in range(1, n + 1):
    s = (str(i)[0], str(i)[-1])
    if s in D:
        D[s] += 1
    else:
        D[s] = 1
ans = 0
for aj, bj in D:
    if (bj, aj) in D:
        ans += D[(aj, bj)] * D[(bj, aj)]
print(ans)

-DD = {} -    t = (str(i)[-1], str(i)[0]) -    if s not in D: +    if s in D: +        D[s] += 1 +    else: -    else: -        D[s] += 1 -    if t not in DD: -        DD[t] = 1 -    else: -        DD[t] += 1 -for i in D: -    if i in DD: -        ans += D[i] * DD[i] +for aj, bj in D: +    if (bj, aj) in D: +        ans += D[(aj, bj)] * D[(bj, aj)]