Given is a positive integer N.

Find the number of pairs (A, B) of positive integers not greater than N that satisfy the following condition:
 - When A and B are written in base ten without leading zeros, the last digit of A is equal to the first digit of B, and the first digit of A is equal to the last digit of B.

-----Constraints-----
 - 1 \leq N \leq 2 \times 10^5
 - All values in input are integers.

-----Input-----
Input is given from Standard Input in the following format:
N

-----Output-----
Print the answer.

-----Sample Input-----
25

-----Sample Output-----
17

The following 17 pairs satisfy the condition: (1,1), (1,11), (2,2), (2,22), (3,3), (4,4), (5,5), (6,6), (7,7), (8,8), (9,9), (11,1), (11,11), (12,21), (21,12), (22,2), and (22,22).

Difficulty: interview

Starter code:

Solutions:
N = int(input())
keep = [[0 for i in range(10)] for j in range(10)]
ans = 0

for i in range(1, N + 1):
    first = int(str(i)[0])
    end = int(str(i)[-1])
    keep[first - 1][end - 1] += 1

for i in range(9):
    for j in range(9):
        ans += (keep[i][j] * keep[j][i])
print(ans)


def main():
    import sys
    from collections import defaultdict

    def input(): return sys.stdin.readline().rstrip()

    n = int(input())
    nd = defaultdict(int)
    for i in range(1, n+1):
        tmp = str(i)
        h, t  = int(tmp[0]), int(tmp[-1])
        nd[(h, t)] += 1
    
    ans = 0
    for i in range(1, 10):
        for j in range(1, 10):
            ans += nd[(i, j)]*nd[(j, i)]
    print(ans)



    
def __starting_point():
    main()
__starting_point()

N = int(input())
ans = 0
lst = [0]*100

for i in range(1, N+1):
    A = str(i)
    a, b = A[0], A[-1]

    if b == '0':
        pass

    else:
        lst[int(b+a)] += 1

for i in range(1, N+1):
    A = str(i)
    a, b = A[0], A[-1]
    c = int(a+b)
    ans += lst[c]

print(ans)

import sys
import collections
import bisect


def main():
    n = int(input())
    a = [str(i + 1)[0] + str(i + 1)[-1] for i in range(n)]
    b = [str(i + 1)[-1] + str(i + 1)[0] for i in range(n)]
    ac, bc = collections.Counter(a), collections.Counter(b)
    print((sum(ac[i] * bc[i] for i in list(ac.keys()))))


def __starting_point():
    main()

__starting_point()

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

N = int(input())
# cnt[i][j] := 先頭がi, 末尾がjで始まるような数
cnt = [[0] * 10 for i in range(10)]
for n in range(1, N + 1):
    cnt[int(str(n)[0])][int(str(n)[-1])] += 1

ans = 0
for i in range(10):
    for j in range(10):
        ans += cnt[i][j] * cnt[j][i]

print(ans)

n = int(input())
c = [[0] * 10 for _ in range(10)]
for i in range(1, n + 1):
    s = str(i)
    l = int(s[0])
    r = int(s[-1])
    c[l][r] += 1
ans = 0
for i in range(10):
    for j in range(10):
        ans += c[i][j] * c[j][i]

print(ans)

N = int(input())
ans = 0
lst = [0]*100

for i in range(1, N+1):
    A = str(i)
    a, b = A[0], A[-1]
    if a == b:
        lst[int(a)] += 1

    if b == '0':
        pass

    else:
        lst[int(b+a)] += 1

for i in range(1, N+1):
    A = str(i)
    a, b = A[0], A[-1]
    c = int(a+b)
    ans += lst[c]

print(ans)

N = int(input())
dp = 100*[0]
ans = 0

for n in range(N+1):
  s = str(n)
  dp[10*int(s[0])+int(s[-1])]+=1

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

print(ans)

N=int(input())
d={}
for i in range(1,10):
  for j in range(1,10):
    d[i*10+j]=0
for i in range(1,min(10,N+1)):
  d[i*10+i]=1
p,h,t,c=10,10,1,1
for i in range(11,N+1):
  if t==10:
    t=1
  else:
    d[h+t]+=1
    t+=1
  if p==c:
    h+=10
    c=0
  if h==100:
    h=10
    p*=10
  c+=1
ans=0
for i in range(1,9):
  for j in range(i+1,10):
    ans+=(d[i*10+j]*d[j*10+i])*2
for i in range(1,10):
  ans+=d[i*10+i]**2
print(ans)

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


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

def kazu(start_num,end_num):
    nonlocal memo
    if memo[start_num][end_num] > 0:
        #print('memo',start_num,end_num)
        return memo[start_num][end_num]
    else:
        ans = 0
        #1桁
        if start_num == end_num:
            if start_num <= n:
                #print(start_num)
                ans += 1
        #2桁
        if start_num * 10 + end_num <= n:
            #print(start_num * 10 + end_num)
            ans += 1
        #3桁
        for i in range(10):
            if start_num * 100 + i * 10 + end_num <= n:
                #print(start_num * 100 + end_num)
                ans += 1
            else:
                break
        #4桁
        for i in range(100):
            if start_num * 1000 + i * 10 + end_num <= n:
                #print(start_num * 1000 + end_num)
                ans += 1
            else:
                break
        #5桁
        for i in range(1000):
            if start_num * 10000 + i * 10 + end_num <= n:
                #print(start_num * 10000 + end_num)
                ans += 1
            else:
                break
        #6桁
        for i in range(10000):
            if start_num * 100000 + i * 10 + end_num <= n:
                #print(start_num * 10000 + end_num)
                ans += 1
            else:
                break
        memo[start_num][end_num] = ans
        #print(start_num,end_num,'---',ans)
        return ans

n = int(input())
str_n = str(n)
kotae = 0
#print(memo)
for a in range(1,n+1):
    if a%10!=0:
        str_a = str(a)
        #print('-----',a,'-----',int(str_a[-1]),int(str_a[0]))
        kotae += kazu(int(str_a[-1]),int(str_a[0]))
        #print(memo)
print(kotae)

N = int(input())
ans = 0
lst = [0]*100
 
for i in range(1, N+1):
    A = str(i)
    a, b = A[0], A[-1]
 
    if b == '0':
        pass
 
    else:
        lst[int(b+a)] += 1
 
for i in range(1, N+1):
    A = str(i)
    a, b = A[0], A[-1]
    c = int(a+b)
    ans += lst[c]
 
print(ans)

N=int(input())
c=[[0 for i in range(10)] for j in range(10)]

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

ans=0
for i in range(10):
  for j in range(10):
    ans+=c[i][j]*c[j][i]
print(ans)


import numpy as np
N = int(input())

cnt = np.zeros((10,10))

for x in map(str,range(0,N+1)):
    cnt[int(x[0]),int(x[-1])] += 1

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

print(int(ans))

N = int(input())

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

for i in range(1, N+1):
    top = int(str(i)[0])
    end = int(str(i)[-1])
    num[top][end] += 1

count = 0
for i in range(10):
    for j in range(10):
        count += num[i][j] * num[j][i]

print(count)

N = int(input())
A = [[0 for j in range(9)] for i in range(9)]
count = 0
for x in range(1, N+1):
  if x%10==0:
    continue
  if x >= 10**(count+1):
    count += 1
  i = x%10
  j = x//(10**count)
  A[i-1][j-1] += 1
ans = 0
for i in range(9):
  for j in range(i, 9):
    r = 2 if i!=j else 1
    ans += A[i][j]*A[j][i]*r
    
print(ans)
#for a in A:
#  print(a)


import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
ans = 0
n_ketasuu = len(str(n))
sta_max = int(str(n)[0])
end_max = int(str(n)[n_ketasuu-1])
for i in range(1,n+1):
    sta = int(str(i)[len(str(i))-1])
    end = int(str(i)[0])
    if sta == 0:
        continue
    #1桁
    if sta == end:
        ans +=1
    #2桁
    if n_ketasuu >= 2 and sta*10 + end <= n:
        ans += 1
    #3桁
    if n_ketasuu > 3 or (n_ketasuu == 3 and sta < sta_max):
        ans += 10
    elif n_ketasuu == 3 and sta == sta_max:
        ans += int(str(n)[1:n_ketasuu-1])
        if end <= end_max:
            ans += 1
    #4桁
    if n_ketasuu > 4 or (n_ketasuu == 4 and sta < sta_max):
        ans += 100
    elif n_ketasuu == 4 and sta == sta_max:
        ans += int(str(n)[1:n_ketasuu-1])
        if end <= end_max:
            ans += 1
    #5桁
    if n_ketasuu > 5 or (n_ketasuu == 5 and sta < sta_max):
        ans += 1000
    elif n_ketasuu == 5 and sta == sta_max:
        ans += int(str(n)[1:n_ketasuu-1])
        if end <= end_max:
            ans += 1
    #6桁
    if n_ketasuu > 6 or (n_ketasuu == 6 and sta < sta_max):
        ans += 10000
    elif n_ketasuu == 6 and sta == sta_max:
        ans += int(str(n)[1:n_ketasuu-1])
        if end <= end_max:
            ans += 1

print(ans)

n = int(input())
d = [[0] * 10 for _ in range(10)]
for i in range(1, n + 1):
    d[int(str(i)[0])][i % 10] += 1
ret = 0
for s in range(10):
    for e in range(10):
        ret += d[s][e] * d[e][s]
print(ret)


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

from collections import defaultdict
n = int(input())

counter = defaultdict(int)
for x in map(str, range(1, n+1)):
    head = x[0]
    tail = x[-1]
    counter[(head, tail)] += 1

ans = 0
items = list(counter.items())
for (head,tail), cnt in items:
    ans += cnt * counter[(tail,head)]
print(ans)

n=int(input())
l=[[0]*10 for i in range(10)]
for i in range(1,n+1):
    st=str(i)
    start=int(st[0])
    end=int(st[-1])
    l[start][end]+=1
ans=0
for i in range(10):
    for j in range(10):
        ans+=l[i][j]*l[j][i]
print(ans)


n = int(input())
a = [[0 for j in range(10)] for i in range(10)]

for i in range(1, n+1):
    if i >= 10**5:
        tmp1 = i//10**5
    elif i >= 10**4:
        tmp1 = i//10**4
    elif i >= 10**3:
        tmp1 = i//10**3
    elif i >= 10**2:
        tmp1 = i//10**2
    elif i >= 10:
        tmp1 = i//10
    else :
        tmp1 = i
    tmp2 = i % 10
    a[tmp1][tmp2] += 1

cnt = 0
for i in range(1, 10):
    for j in range(1, 10):
        cnt += a[i][j] * a[j][i]
print(cnt)



import sys
import collections
import bisect


def main():
    n = int(input())
    a = [str(i + 1)[0] + str(i + 1)[-1] for i in range(n)]
    b = [str(i + 1)[-1] + str(i + 1)[0] for i in range(n)]
    ac, bc = collections.Counter(a), collections.Counter(b)
    acKeys = list(ac.keys())
    bcKeys = list(bc.keys())
    cnt = 0
    for i in acKeys:
        cnt += ac[i] * bc[i]
    print(cnt)


def __starting_point():
    main()

__starting_point()

def N():
    return int(input())
def L():
    return list(map(int,input().split()))
def NL(n):
    return [list(map(int,input().split())) for i in range(n)]
mod = pow(10,9)+7

#import numpy as np
import sys
import math
import collections

n = N()
c = [[0]*10 for i in range(10)]
for i in range(1,n+1):
    h = int(str(i)[0])
    t = int(str(i)[-1])
    c[h][t] += 1
sum = 0
for i in range(1,10):
    for j in range(1,10):
        sum += c[i][j] * c[j][i]
print(sum)

from sys import setrecursionlimit, exit
setrecursionlimit(1000000000)

def main():
    n = int(input())
    ans = 0
    for i in range(1, n + 1):
        s = str(i)
        if s[-1] == '0':
            continue
        if s[0] == s[-1]:
            ans += 1
        if i < 10:
            continue
        if s[0] == s[-1]:
            ans += 2
        l = len(s)
        for i in range(2, l):
            ans += 10 ** (i - 2) * 2
        if s[0] < s[-1]:
            continue
        if s[0] > s[-1]:
            ans += 10 ** (l - 2) * 2
        elif l > 2:
            dp = int(s[1])
            for i in range(2, l - 1):
                dp *= 10
                dp += int(s[i])
            ans += dp * 2
    print(ans)

main()

N = int(input())
counter = [[0 for _ in range(10)] for _ in range(10)]
for k in range(1, N+1):
  counter[k%10][int(str(k)[0])] += 1
ans = 0
for k in range(1, 10):
  for j in range(1, 10):
    ans += counter[k][j]*counter[j][k]
print(ans)

from collections import defaultdict

N = int(input())

cnts = defaultdict(int)
for i in range(1, N + 1):
    if i % 10 == 0:
        continue
    digits = []
    while i > 0:
        i, r = divmod(i, 10)
        digits.append(r)
    digits = digits[::-1]
    cnts[(digits[0], digits[-1])] += 1

ans = 0
for (head, tail), c1 in list(cnts.items()):
    c2 = cnts.get((tail, head), 0)
    ans += c1 * c2
print(ans)


N=int(input())
m=0
x=[[0]*9 for i in range(9)]
for i in range(1,N+1):
    if i%10==0:
        continue
    b=int(str(i)[0])
    g=int(i%10)
    x[b-1][g-1]+=1
ans=0
for i in range(9):
    for j in range(9):
        ans+=x[i][j]*x[j][i]
        #print(i+1,j+1,x[i][j])
print(ans)

x=int(input())

dp=[[0 for n in range(10)] for n in range(10)]
dp1=dp.copy()

for n in range(x+1):
    v=str(n)
    p=int(v[0])
    q=int(v[-1])
    for a in range(10):
        for b in range(10):
            if a==p and b==q:
                dp[a][b]+=1

res=-1

for n in range(10):
    for k in range(10):
        res+=dp[n][k]*dp[k][n]

print(res)


n = int(input())
hist = [[0 for _ in range(10)] for _ in range(10)]
ans = 0
for i in range(1,n+1):
  top = int(str(i)[0])
  bot = int(str(i)[-1])
  hist[top][bot] += 1
  
for i in range(1,n+1):
  top = int(str(i)[0])
  bot = int(str(i)[-1])
  ans += hist[bot][top]
  
print(ans)

N = int(input())
num = [[0] * 10 for i in range(10)]
for i in range(1, N + 1):
    num[int(str(i)[0])][int(str(i)[-1])] += 1
    
ans = 0
for i in range(1, N + 1):
    ans += num[int(str(i)[-1])][int(str(i)[0])]
print(ans)

n = int(input())

li = [0]*100
for i in range(n+1):
    li[int(str(i)[0]+str(i)[-1])]+=1
ans = 0
for i in range(1,10):
    for j in range(1,10):
        ans += li[int(str(i)+str(j))] * li[int(str(j)+str(i))]

print(ans)


import sys
# import math
# import bisect
# import numpy as np
# from decimal import Decimal
# from numba import njit, i8, u1, b1 #JIT compiler
# from itertools import combinations, product
# from collections import Counter, deque, defaultdict

# sys.setrecursionlimit(10 ** 6)
MOD = 10 ** 9 + 7
INF = 10 ** 9
PI = 3.14159265358979323846

def read_str():      return sys.stdin.readline().strip()
def read_int():      return int(sys.stdin.readline().strip())
def read_ints():     return map(int, sys.stdin.readline().strip().split())
def read_ints2(x):   return map(lambda num: int(num) - x, sys.stdin.readline().strip().split())
def read_str_list(): return list(sys.stdin.readline().strip().split())
def read_int_list(): return list(map(int, sys.stdin.readline().strip().split()))
def GCD(a: int, b: int) -> int: return b if a%b==0 else GCD(b, a%b)
def LCM(a: int, b: int) -> int: return (a * b) // GCD(a, b)

def f(num):
    front = num
    back = num
    while front >= 10:
        front //= 10
    while back >= 10:
        back %= 10
    
    return front, back

def Main():
    n = read_int()
    cnt = [[0] * 10 for _ in range(10)]
    for x in range(1, n + 1):
        front, back = f(x)
        cnt[front][back] += 1
    
    ans = 0
    for x in range(10):
        for y in range(10):
            ans += cnt[x][y] * cnt[y][x]
    print(ans)

def __starting_point():
    Main()
__starting_point()

#!/usr/bin/env python3
def main():
    import numpy as np

    N = int(input())

    cnt = np.zeros((10, 10), dtype=np.int64)
    for n in [str(x) for x in range(1, N + 1)]:
        cnt[int(n[0])][int(n[-1])] += 1

    print(((cnt[:, :] * cnt.T[:, :]).sum()))


def __starting_point():
    main()

__starting_point()

n = int(input())
num = [[0] * 10 for i in range(10)]
for i in range(1,n+1):
    j = str(i)
    x = j[0]
    y = j[-1]
    if x != '0' and y != '0':
        num[int(x)][int(y)] += 1
ans = 0
for i in range(1,10):
    for j in range(1,10):
        ans += num[i][j] * num[j][i]
print(ans)

n = int(input())
cnt = [[0]*9 for _ in range(9)]
for i in range(1,n+1):
    s = str(i)
    if s[-1]!="0":
        cnt[int(s[0])-1][int(s[-1])-1] += 1
ans = 0
for i in range(9):
    for j in range(9):
        ans += cnt[i][j]*cnt[j][i]
print(ans)

N = int(input())
dp = [[0 for i in range(10)] for j in range(10)]
 
for i in range(1, N + 1):
    i = str(i)
    dp[int(i[0])][int(i[-1])] += 1
 
ans = 0
for i in range(1, 10):
    for j in range(1, 10):
        ans += dp[i][j] * dp[j][i]
print(ans)

N = int(input())
cnt = [[0] * 10 for i in range(10)]
for n in range(1, N + 1):
    cnt[int(str(n)[0])][int(str(n)[-1])] += 1

ans = 0
for i in range(10):
    for j in range(10):
        ans += cnt[i][j] * cnt[j][i]

print(ans)

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


N = int(input())

dp = [[0] * 9 for _ in range(9)]

for i in range(1, N+1):
  if i % 10:
    st = str(i)
    start = int(st[0])
    end = int(st[-1])
    dp[start-1][end-1] += 1

ans = 0

for i in range(9):
  for j in range(9):
    ans += dp[i][j] * dp[j][i]

print(ans)


N = int(input())
num = [[0] * 10 for i in range(10)]
for i in range(1, N + 1):
    num[int(str(i)[0])][int(str(i)[-1])] += 1
    
ans = 0

for i in range(10):
    for j in range(10):
        ans += num[i][j] * num[j][i]
print(ans)

import sys
readline = sys.stdin.readline

N = int(readline())

from collections import defaultdict
dic = defaultdict(int)

for i in range(1, N + 1):
  s = str(i)
  dic[(int(s[0]),int(s[-1]))] += 1
  
ans = 0
for i in range(1, 10):
  for j in range(1, 10):
    ans += dic[(i,j)] * dic[(j,i)]
    
print(ans)

n = int(input())
hist = [[0 for _ in range(10)] for _ in range(10)]
for i in range(1,n+1):
    top = int(str(i)[0])
    bot = int(str(i)[-1])
    hist[top][bot] += 1
    
ans = 0

for i in range(1,n+1):
    top = int(str(i)[0])
    bot = int(str(i)[-1])
    ans += hist[bot][top]

print(ans)

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

from collections import defaultdict
n = int(input())
d = defaultdict(int)
for i in range(1, n+1):
    if str(i)[-1] == '0':
        continue
    d[int(str(i)[0] + str(i)[-1])] += 1
ans = 0
for i in range(11, 100):
    ans += d[i] * d[int(str(i)[1] + str(i)[0])]
print(ans)

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

import numpy as np
N = int(input())
list_all =np.zeros((9,9))
num_list = [str(i) for i in range(1,N+1)]
overlap = [0 for i in range(9)]
for i in range(N):
    head = int(num_list[i][0])
    length = len(num_list[i])
    tail = int(num_list[i][length -1])
    if (head == 0) or (tail == 0):
        continue
    list_all[head-1,tail -1] += 1
sum1 = 0
for i in range(9):
    for j in range(i+1):
        if i ==j:
            sum1 += (list_all[i,j] * list_all[j,i])
        else:
            sum1 += (list_all[i,j] * list_all[j,i]) *2
print(int(sum1))

# 問題:文字の先頭が'i'で末尾が'j', 且つ文字の先頭が'j'で末尾が'i'のペアはいくつ？
# 'n'以下の全ての数について 先頭を'i', 末尾が'j'としたDBを作成

n = int(input())
# cnt[i][j] := 先頭が'i', 末尾が'j'の数
cnt = [[0] * 10 for _ in range(10)]

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

# 先頭が'i'で末尾が'j'の総数 [掛ける] 先頭が'j'で末尾が'i'の総数の総和が'ans'
ans = 0
for i in range(10):
    for j in range(10):
        ans += cnt[i][j] * cnt[j][i]

print(ans)

#!/usr/bin/env python3
import sys
from itertools import chain


def solve(N: int):
    m = [0] * 100
    for n in range(N + 1):
        s = str(n)
        h = int(s[0])
        l = int(s[-1])
        if l != 0:
            m[h * 10 + l] += 1

    answer = 0
    for h in range(1, 10):
        for l in range(1, 10):
            answer += m[h * 10 + l] * m[l * 10 + h]
    return answer


def main():
    N = int(input())
    answer = solve(N)
    print(answer)


def __starting_point():
    main()

__starting_point()

N = int(input())

ans = 0
for i in range(1, N+1):
    a = list(map(int, str(i)))
    x = a[0]
    y = a[-1]
    if x == y:
        ans += 1
    if y != 0:
        for j in (5, 4, 3, 2, 1):
            z = (y+1)*(10**j)
            if z <= N:
                ans += 10**(j-1)
            elif y*(10**j) + x <= N and N < z:
                s = N-y*(10**j)
                ans += int(s/10)
                if N%10 >= x:
                    ans += 1

print(ans)

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

N = int(input())

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

for i in range(1,N+1):
    x = i
    while x >= 10:
        x //= 10
    cnt[x][i%10] += 1

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

print(ans)

n = int(input())
lst = [[0 for i in range(9)] for j in range(9)]
for i in range(1, n + 1):
    s = str(i)
    if i % 10:
        lst[int(s[0]) - 1][i % 10 - 1] += 1
res = 0
for i in range(9):
    for j in range(9):
        res += lst[i][j] * lst[j][i]
print(res)

N = int(input())
results = {(str(i), str(j)): 0 for i in range(1, 10) for j in range(1, 10)}


for i in range(N+1):
    s = str(i)
    if (s[0], s[-1]) in results.keys():
        results[(s[0], s[-1])] += 1

cnt = 0
for i in range(1, 10):
    for j in range(1, 10):
        cnt += results[(str(i), str(j))] * results[(str(j), str(i))]

print(cnt)

N=int(input())
d={}
for i in range(1,10):
  for j in range(1,10):
    d[i*10+j]=0
for i in range(1,min(10,N+1)):
  d[i*10+i]=1
for i in range(11,N+1):
  i=str(i)
  h,t=int(i[0])*10,int(i[-1])
  if t!=0:
    d[h+t]+=1
ans=0
for i in range(1,9):
  for j in range(i+1,10):
    ans+=(d[i*10+j]*d[j*10+i])*2
for i in range(1,10):
  ans+=d[i*10+i]**2
print(ans)

n=int(input())

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

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

ans=0

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


n=int(input())
ans=[[0]*9 for _ in range(9)]
for i in range(1,n+1):
    s=str(i)
    if s[0]!="0" and s[-1]!="0":
        ans[int(s[0])-1][int(s[-1])-1]+=1
cnt=0
for i in range(1,10):
    for j in range(1,10):
        cnt+=ans[i-1][j-1]*ans[j-1][i-1]
print(cnt)


N = int(input())

count = [[0] * 10 for _ in range(10)]
for i in range(1, N + 1):
    s = str(i)
    head = int(s[0])
    tail = int(s[-1])
    count[head][tail] += 1

ans = 0
for a in range(1, N + 1):
    s = str(a)
    head = int(s[0])
    tail = int(s[-1])
    ans += count[tail][head]
print(ans)

N = int(input())

dp = [[0] * 9 for _ in range(9)]

for i in range(1, N+1):
  if i % 10:
    start = int(str(i)[0])
    end = int(str(i)[-1])
    dp[start-1][end-1] += 1

ans = 0

for i in range(9):
  for j in range(9):
    ans += dp[i][j] * dp[j][i]

print(ans)


import math

def main():
	N = int(input())
	c = [[0] * 10 for i in range(10)]
	for i in range(1, N + 1):
		digit = int(math.log10(i)) + 1
		c[i // (10 ** (digit - 1))][i % 10] += 1

	cnt = 0
	for i in range(10):
		for j in range(10):
			cnt += c[i][j] * c[j][i]

	print(cnt)



main()

def main():
    N = int(input())
    comb_count = [[0 for i in range(10)] for j in range(10)]
    res = 0

    for i in range(1, N + 1):
        s = str(i)
        max, min = int(s[0]), int(s[-1])
        comb_count[max][min] += 1

    for l in range(1, 10):
        for r in range(1, 10):
            res += comb_count[l][r] * comb_count[r][l]
        
    print(res)

def __starting_point():
    main()
__starting_point()

def solve():
    table = [[0] * 10 for _ in range(10)]
    for i in range(N + 1):
        s = list(map(int, str(i)))
        table[s[0]][s[-1]] += 1
    return sum(table[i][j] * table[j][i] for i in range(1, 10) for j in range(1, 10))


N = int(input())
print((solve()))


n = int(input())
t = [0] * 100
for i in range(11, 100):
  msb = i // 10
  lsb = i % 10
  if lsb == 0:
    continue
  for j in range(1, n+1):
    if j % 10 == lsb and int(str(j)[0]) == msb:
      t[i] += 1

ans = 0
for i in range(11, 100):
  msb = i // 10
  lsb = i % 10
  if lsb == 0:
    continue
  if msb == lsb:
    ans += t[i] ** 2
  else:
    ans += t[i] * t[lsb * 10 + msb]
print(ans)


import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
N = int(input())
Comlist = []
Ans = dict()
Answer = 0
for i in range(1,10):
    for j in range(1,10):
        M = i*10 + j
        Comlist.append(str(M))
        Ans[str(M)] = 0
for k in range(1,N+1):
    strk = str(k)
    if k < 10:
        Tar = strk + strk
        Ans[Tar] += 1
    else:
        Tar = strk[0] + strk[-1]
        if Tar in Ans:
            Ans[Tar] += 1
Answer = 0
for q in range(len(Comlist)):
    p = Comlist[q]
    pin = p[1] + p[0]
    Answer += Ans[p] * Ans[pin]
print(Answer)

n = int(input()) 

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

for i in range(n+1):
    a = int(str(i)[0])
    b = int(str(i)[-1])
    if a == 0 or b == 0:
        continue
    cnt[a][b] += 1

ans = 0
for i in range(n+1):
    a = int(str(i)[0])
    b = int(str(i)[-1])
    ans += cnt[b][a]
print(ans)

import sys
import collections
import bisect


def main():
    n = int(input())
    ac, bc = collections.Counter([str(i + 1)[0] + str(i + 1)[-1] for i in range(
        n)]), collections.Counter([str(i + 1)[-1] + str(i + 1)[0] for i in range(n)])
    print((sum(ac[i] * bc[i] for i in list(ac.keys()))))


def __starting_point():
    main()

__starting_point()

N = int(input())
M = [0] * 100
for i in range(1, N+1):
    i = str(i)
    l, r = int(i[0]), int(i[-1])
    M[l*10+r] += 1
ans = 0
for i, cnt in enumerate(M):
    l, r = divmod(i, 10)
    ans += cnt * M[r*10+l]
print(ans)


import sys
import math

# a != b のとき


def count(a, b, N):

    keta = len(str(N))

    cnt = 0

    # k == 1 なら a == b
    if a == b:
        cnt += 1 if a <= N else 0

    if keta == 1:
        return cnt

    # k == 2 なら ba のみ
    if keta == 2:
        cnt += 1 if b * 10 + a <= N else 0
        return cnt

    # k 桁より少ない数の場合 : 好きな数を間に挟む
    for k in range(2, keta):
        cnt += 10**(k - 2)

    # k 桁の数字の場合
    s = N // (10**(keta - 1))
    t = N % 10
    if b > s:
        return cnt
    elif b < s:
        cnt += 10**(keta - 2)
    else:
        tempN = (N - s * (10**(keta - 1)) - t) // 10
        # print(f"tempN {tempN}")
        cnt += (tempN + 1)  # tempN が 1 なら 0,1 を選べる
        if a > t:
            cnt -= 1

    return cnt


def count_aa(a, N):

    keta = len(str(N))

    cnt = 0

    # keta == 1
    if keta == 1:
        return 1 if a <= N[-1] else 0

    cnt += 1  # a

    # k == 2 なら aa のみ
    if keta == 2:
        return cnt + 1 if a <= N[-1] else 0

    # 3桁以上
    # k 桁より少ない数の場合
    for k in range(2, keta):
        cnt += 10**(k - 2)

    # k 桁の数字の場合
    s = N // (10**(keta - 1))
    t = N % 10
    if b > s:
        return cnt
    elif b < s:
        cnt += 10**(keta - 2)
    else:
        tempN = (N - s * (10**(keta - 1)) - t) // 10
        # print(f"tempN {tempN}")
        cnt += (tempN + 1)  # tempN が 1 なら 0,1 を選べる
        if a > t:
            cnt -= 1

    return cnt


N = int(input())

c = 0
for i in range(1,N+1):
    a = int(str(i)[0])
    b = i % 10
    # print(a,b)
    if b == 0:
        continue
    c += count(a,b,N)

print(c)

n = int(input())

graph = [[0] * 9 for i in range(9)]

for i in range(1, n + 1):
    if i % 10 != 0:
        i = str(i)
        sentou = int(i[0])
        matubi = int(i[-1])
        graph[sentou - 1][matubi - 1] += 1

import numpy as np

graph = np.array(graph)

print(np.trace(np.dot(graph, graph)))

N = int(input())
# cnt[i][j] := 先頭がi, 末尾がjで始まるような数
cnt = [[0] * 10 for i in range(10)]
for n in range(1, N + 1):
    cnt[int(str(n)[0])][int(str(n)[-1])] += 1

ans = 0
for i in range(10):
    for j in range(10):
        ans += cnt[i][j] * cnt[j][i]

print(ans)

n = int(input())
cnt = [[0] * 10 for i in range(10)]

#int(str(n)[i]) nのi桁目
for n in range(1, n+1):
  cnt[int(str(n)[0])][int(str(n)[-1])] += 1

ans = 0
for i in range(10):
  for j in range(10):
    ans += cnt[i][j]*cnt[j][i]

print(ans)


n=int(input())
l=[[0]*10 for i in range(10)]

for i in range(1,min(10,n+1),1):
    l[i][i]+=1

if len(str(n))>=2:
    for k in range(2,len(str(n)),1):
        for i in range(1,10,1):
            for j in range(1,10,1):
                l[i][j]+=10**(k-2)

    for i in range(1,int(str(n)[0]),1):
        for j in range(1, 10, 1):
            l[i][j] += 10**(len(str(n))-2)
    if len(str(n))>=3:
        for j in range(1, 10, 1):
            if j<=int(str(n)[-1]):
                l[int(str(n)[0])][j]+=int(str(n)[1:-1])+1
            else:
                l[int(str(n)[0])][j] += int(str(n)[1:-1])
    else:
        for j in range(1, 10, 1):
            if j<=int(str(n)[-1]):
                l[int(str(n)[0])][j]+=1

t=0
for i in range(1,10,1):
    for j in range(1,10,1):
        t+=l[i][j]*l[j][i]

print(t)

N = int(input())
ans = 0
lst = [0]*100

for i in range(1, N+1):
    A = str(i)
    a, b = A[0], A[-1]
    if a == b:
        lst[int(a)] += 1

    if b == '0':
        pass

    else:
        lst[int(b+a)] += 1

for i in range(1, N+1):
    A = str(i)
    a, b = A[0], A[-1]
    c = int(a+b)
    ans += lst[c]

print(ans)

N = int(input())
bucket = [[0] * 10 for _ in range(10)]

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

ans = 0
for i in range(10):
    for j in range(10):
        ans += bucket[i][j] * bucket[j][i]

print(ans)

N = int(input())

from collections import defaultdict
dic = defaultdict(int)

for i in range(1, N + 1):
  s = str(i)
  dic[(s[0], s[-1])] += 1

ans = 0
for key in dic.keys():
  a,b = key
  if (b,a) in dic:
    ans += dic[(a,b)] * dic[(b,a)]
  
print(ans)

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

N=int(input())

table=[[0]*9 for i in range(9)]

for i in range(1,N+1):
  if int(str(i)[len(str(i))-1])==0:
    continue
  table[int(str(i)[0])-1][int(str(i)[len(str(i))-1])-1]+=1

ans=0
for i in range(9):
  for j in range(i,9):
    if i==j:
      ans+=table[i][j]*table[j][i]
    else:
      ans+=table[i][j]*table[j][i]*2
print(ans)

##以下ググった（https://at274.hatenablog.com/entry/2020/01/24/060000）
n = int( input() )

cnt = [ [ 0 for i in range( 10 ) ] for j in range( 10 ) ]
# cnt[ i ][ j ] = 先頭がi，末尾がjである，n以下の整数の個数

for k in range( n + 1 ):
    head = int( str( k )[ 0 ] )
    foot = int( str( k )[ -1 ] )
    cnt[ head ][ foot ] += 1

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

print( ans )

n=int(input())
if n<=9:
    print(n)
    return
dp=[[0]*10 for _ in range(10)]
for k in range(1,n+1):
    s=str(k)
    dp[int(s[0])][int(s[-1])]+=1
ans=0
for i in range(10):
    for j in range(10):
        ans+=dp[i][j]*dp[j][i]
print(ans)

# import itertools
# import math
# from functools import reduce
# import sys
# sys.setrecursionlimit(500*500)
# import numpy as np
# import heapq
# from collections import deque

N = int(input())
# S = input()
# n, *a = map(int, open(0))
# N, M = map(int, input().split())
# A = list(map(int, input().split()))
# B = list(map(int, input().split()))
# tree = [[] for _ in range(N + 1)]
# B_C = [list(map(int,input().split())) for _ in range(M)]
# S = input()

# B_C = sorted(B_C, reverse=True, key=lambda x:x[1])
# all_cases = list(itertools.permutations(P))
# a = list(itertools.combinations_with_replacement(range(1, M + 1), N))
# itertools.product((0,1), repeat=n)

# A = np.array(A)
# cum_A = np.cumsum(A)
# cum_A = np.insert(cum_A, 0, 0)

# def dfs(tree, s):
#     for l in tree[s]:
#         if depth[l[0]] == -1:
#             depth[l[0]] = depth[s] + l[1]
#             dfs(tree, l[0])
# dfs(tree, 1)

# def factorization(n):
#     arr = []
#     temp = n
#     for i in range(2, int(-(-n**0.5//1))+1):
#         if temp%i==0:
#             cnt=0
#             while temp%i==0:
#                 cnt+=1
#                 temp //= i
#             arr.append([i, cnt])
#     if temp!=1:
#         arr.append([temp, 1])
#     if arr==[]:
#         arr.append([n, 1])
#     return arr

# def gcd_list(numbers):
#     return reduce(math.gcd, numbers)

# if gcd_list(A) > 1:
#     print("not coprime")
#     return

# 高速素因数分解準備
#MAXN = 10**6+10
#sieve = [i for i in range(MAXN+1)]
#p = 2
#while p*p <= MAXN:
#    if sieve[p] == p:
#        for q in range(2*p, MAXN+1, p):
#            if sieve[q] == q:
#                sieve[q] = p
#    p += 1

cnt = [[0] * 10 for i in range(10)]
for i in range(1, N + 1):
    cnt[int(str(i)[0])][int(str(i)[-1])] += 1

ans = 0
for i in range(10):
    for j in range(10):
        ans += cnt[i][j] * cnt[j][i]

print(ans)

from collections import defaultdict
N = int(input())

head_tail = defaultdict(int)
for i in range(1, N + 1):
    tail = i % 10
    head = int(str(i)[0])
    head_tail[(head, tail)] += 1

answer = 0
for i in range(1, N + 1):
    head = int(str(i)[0])
    tail = i % 10
    answer += head_tail[(tail, head)]
print(answer)

N = int(input())
l = [[0] * 10 for i in range(10)]

for i in range(1, N+1):
    s = len(str(i))
    if s == 1:
        l[i][i] += 1
    else:
        l[i//(10**(s-1))][i%10] += 1

ans = 0

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

#for i in range(10):
#    print(l[i])

print(ans)

n = int(input())

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

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

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

def kazu(start_num,end_num):
    nonlocal memo
    if memo[start_num][end_num] > 0:
        #print('memo',start_num,end_num)
        return memo[start_num][end_num]
    else:
        ans = 0
        #1桁
        if start_num == end_num:
            if start_num <= n:
                #print(start_num)
                ans += 1
        #2桁
        if start_num * 10 + end_num <= n:
            #print(start_num * 10 + end_num)
            ans += 1
        #3桁
        for i in range(10):
            if start_num * 100 + i * 10 + end_num <= n:
                #print(start_num * 100 + end_num)
                ans += 1
            else:
                break
        #4桁
        for i in range(100):
            if start_num * 1000 + i * 10 + end_num <= n:
                #print(start_num * 1000 + end_num)
                ans += 1
            else:
                break
        #5桁
        for i in range(1000):
            if start_num * 10000 + i * 10 + end_num <= n:
                #print(start_num * 10000 + end_num)
                ans += 1
            else:
                break
        #6桁
        for i in range(10000):
            if start_num * 100000 + i * 10 + end_num <= n:
                #print(start_num * 100000 + end_num)
                ans += 1
            else:
                break
        memo[start_num][end_num] = ans
        #print(start_num,end_num,'---',ans)
        return ans

n = int(input())
str_n = str(n)
kotae = 0
#print(memo)
for a in range(1,n+1):
    if a%10!=0:
        str_a = str(a)
        #print('-----',a,'-----',int(str_a[-1]),int(str_a[0]))
        kotae += kazu(int(str_a[-1]),int(str_a[0]))
        #print(memo)
print(kotae)

from collections import defaultdict
n = int(input())

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

ans = 0
for a in range(1, 10):
    for b in range(1, 10):
        ans += d[(a, b)] * d[(b, a)]
print(ans)

n = int(input())
a = [[0 for i in range(10)] for j in range(10)]
for i in range(1, n+1):
    s = str(i)
    if s[-1] != '0':
        a[int(s[0])][int(s[-1])] += 1
ans = 0
for i in range(1, 10):
    for j in range(1, 10):
        ans += a[i][j] * a[j][i]
print(ans)

N=int(input())
A=[str(i)for i in range(1,10)]
ans=0
for a in A:
    for b in A:
        countA=0
        if a==b and int(a)<=N:
            countA+=1
        for i in range(5):
            m=int(a+'0'*i+b)
            M=int(a+'9'*i+b)
            if m<=N:
                if M<=N:
                    countA+=10**i
                else:
                    while m<=N:
                        countA+=1
                        m+=10

        countB=0
        if b==a and int(b)<=N:
            countB+=1
        for i in range(5):
            m=int(b+'0'*i+a)
            M=int(b+'9'*i+a)
            if m<=N:
                if M<=N:
                    countB+=10**i
                else:
                    while m<=N:
                        countB+=1
                        m+=10

        ans+=countA*countB
print(ans)

N=int(input());a,b=divmod(N,10);h=lambda n:h(n//10)if n>9else n;print(a**2+8+sum((h(i)<=b)*(i%10==h(N))*(1+(a!=i//10))for i in range(1,N+1))if a else N)

#!/usr/bin/env python3
def main():
    import numpy as np

    N = int(input())

    cnt = np.zeros((10, 10), dtype=np.int64)
    for n in map(str, list(range(1, N + 1))):
        cnt[int(n[0])][int(n[-1])] += 1

    print((np.sum(cnt * cnt.T)))


def __starting_point():
    main()

__starting_point()

def main():
    n = int(input())
    dp = [[0 for i in range(10)] for i in range(10)]
    for i in range(1,n+1):
        h,t = int(str(i)[0]), int(str(i)[-1])
        dp[h][t] += 1
    ans = 0
    for i in range(10):
        for j in range(10):
            ans += dp[i][j] * dp[j][i]
    print(ans)

def __starting_point():
    main()

__starting_point()

N = int(input())

X = [[0 for _ in range(10)] for _ in range(10)]

for i in range(1, N+1):
    s = str(i)
    a, b = int(s[0]), int(s[-1])
    X[a][b] += 1

ans = 0
for a in range(10):
    for b in range(10):
        ans += X[a][b] * X[b][a]

print(ans)


N = int(input())

d = dict()
for i in range(1, N + 1):
    _0 = str(i)[0]
    _1 = str(i)[-1]
    if _1 == "0":
        continue
    s = _0 + _1
    if s in d:
        d[s] += 1
    else:
        d[s] = 1

res = 0
for i in range(1, N + 1):
    _0 = str(i)[0]
    _1 = str(i)[-1]
    if _1 == "0":
        continue
    s = _1 + _0
    if s in d:
        res += d[s]
    
print(res)


N=int(input())
l=[[0]*10 for i in range(10)]


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

ans=0
for i in range(10):
  for j in range(10):
    ans+=l[i][j]*l[j][i]
  
print(ans)


def solve():
    N = int(input())
    cnt = [[0]*10 for i in range(10)]
    for i in range(1, N+1):
        target_str = str(i)
        cnt[int(target_str[0])][int(target_str[-1])] += 1

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

def __starting_point():
    solve()
__starting_point()

N = int(input())

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

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

for i in range(1,N+1):
    ans += cnt[int(str(i)[-1])][int(str(i)[0])]

print(ans)