N=int(eval(input()))



def cnt(i,j):

    ret=0

    si=str(i)

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

        if n%10!=j:

            continue

        if str(n)[0]!=si:

            continue

        ret+=1

    return ret



ans=0

for i in range(10):

    for j in range(10):

        ans+=cnt(i,j)*cnt(j,i)

print(ans)

S=eval(input())

N=int(S)

keta=len(S)

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

fa=0

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

    ns=str(A)

    tailA=int(ns[-1])

    if tailA==0: continue

    headA=int(ns[0])

    if ans[headA][tailA]==0:

        dp=[[[0]*2 for __ in range(2)] for _ in range(keta+1)]

        dp[0][0][1]=1

        for i in range(keta):

            x=int(S[i])

            for j in range(2):

                for k in range(2):

                    for n in range(10):

                        ni=i+1

                        nj=1 if j==1 or n>0 else 0

                        nk=1 if k==1 and n==x else 0

                        if k==1 and n>x: continue

                        if j==0 and nj==1 and n!=tailA: continue

                        if ni==keta and n!=headA: continue

                        dp[ni][nj][nk]+=dp[i][j][k]

        for k in range(2):

            ans[headA][tailA]+=dp[keta][1][k]

    fa+=ans[headA][tailA]

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


def cnt(i, j):
    ret = 0
    si = str(i)
    for n in range(1, N + 1):
        if n % 10 != j:
            continue
        if str(n)[0] != si:
            continue
        ret += 1
    return ret


ans = 0
for i in range(10):
    for j in range(10):
        ans += cnt(i, j) * cnt(j, i)
print(ans)

S = eval(input())
N = int(S)
keta = len(S)
ans = [[0] * 10 for _ in range(10)]
fa = 0
for A in range(1, N + 1):
    ns = str(A)
    tailA = int(ns[-1])
    if tailA == 0:
        continue
    headA = int(ns[0])
    if ans[headA][tailA] == 0:
        dp = [[[0] * 2 for __ in range(2)] for _ in range(keta + 1)]
        dp[0][0][1] = 1
        for i in range(keta):
            x = int(S[i])
            for j in range(2):
                for k in range(2):
                    for n in range(10):
                        ni = i + 1
                        nj = 1 if j == 1 or n > 0 else 0
                        nk = 1 if k == 1 and n == x else 0
                        if k == 1 and n > x:
                            continue
                        if j == 0 and nj == 1 and n != tailA:
                            continue
                        if ni == keta and n != headA:
                            continue
                        dp[ni][nj][nk] += dp[i][j][k]
        for k in range(2):
            ans[headA][tailA] += dp[keta][1][k]
    fa += ans[headA][tailA]
print(fa)

-N = int(eval(input())) - - -def cnt(i, j): -    ret = 0 -    si = str(i) -    for n in range(1, N + 1): -        if n % 10 != j: -            continue -        if str(n)[0] != si: -            continue -        ret += 1 -    return ret - - -ans = 0 -for i in range(10): -    for j in range(10): -        ans += cnt(i, j) * cnt(j, i) -print(ans) +S = eval(input()) +N = int(S) +keta = len(S) +ans = [[0] * 10 for _ in range(10)] +fa = 0 +for A in range(1, N + 1): +    ns = str(A) +    tailA = int(ns[-1]) +    if tailA == 0: +        continue +    headA = int(ns[0]) +    if ans[headA][tailA] == 0: +        dp = [[[0] * 2 for __ in range(2)] for _ in range(keta + 1)] +        dp[0][0][1] = 1 +        for i in range(keta): +            x = int(S[i]) +            for j in range(2): +                for k in range(2): +                    for n in range(10): +                        ni = i + 1 +                        nj = 1 if j == 1 or n > 0 else 0 +                        nk = 1 if k == 1 and n == x else 0 +                        if k == 1 and n > x: +                            continue +                        if j == 0 and nj == 1 and n != tailA: +                            continue +                        if ni == keta and n != headA: +                            continue +                        dp[ni][nj][nk] += dp[i][j][k] +        for k in range(2): +            ans[headA][tailA] += dp[keta][1][k] +    fa += ans[headA][tailA] +print(fa)