Problem:
 Score : 400 points    Problem Statement  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 1 25      Sample Output 1 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) .       Sample Input 2 1      Sample Output 2 1       Sample Input 3 100      Sample Output 3 108       Sample Input 4 2020      Sample Output 4 40812       Sample Input 5 200000      Sample Output 5 400000008

Solution (Python):
import math

N = int(input())

dp = [[-1] * 10 for _ in range(10)]
temp = 0
total = 0

mae_usiro = [[-1] * 2 for _ in range(N+1)]
for i in range(1, N+1):
    mae = int(i / 10 ** int(math.log10(i)))
    usiro = i % 10
    mae_usiro[i] = [mae, usiro]

for i in range(1, N+1):
    mae, usiro = mae_usiro[i]
    if i > 100:
        total += dp[mae][usiro]
    elif dp[mae][usiro] != -1:
        total += dp[mae][usiro]
    else:
        count = 0
        for j in range(1, N+1):
            mae2, usiro2 = mae_usiro[j]
            if mae == usiro2 and usiro == mae2:
                count += 1
        dp[mae][usiro] = count
        total += count
    
print(total)

Solution (Python):
N = int(input())
d = dict()
ans = 0
for i in range(1, N + 1):
    if not (str(i)[0], str(i)[-1]) in d:
        d[(str(i)[0], str(i)[-1])] = 1
    else:
        d[(str(i)[0], str(i)[-1])] += 1
for j in d:
    if (j[-1], j[0]) in d:
        ans += d[j] * d[(j[-1], j[0])]
print(ans)

Solution (Python):
n = int(input())
d = {}
for i in range(1, n+1):
    s = str(i)
    t = (int(s[0]), int(s[-1]))
    if t in d:
        d[t] += 1
    else:
        d[t] = 1

ans = 0
for i, c in d.items():
    r = (i[1], i[0])
    if r in d:
        ans += d[r] * c

print(ans)

Solution (Python):
N = int(input())

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

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

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

print(ans)

Solution (Python):
N = int(input())
count = [0,1]
if N == 1:
  print(1)
  exit()
for i in range(2,N+1):
  digit = len(str(i))
  head = int(str(i)[0])
  tail = int(str(i)[-1])
  plus = 0
  if digit == 1:
    plus=1
  elif digit == 2:
    if head == tail:
      plus = 3
    elif head>tail and tail>0:
      plus = 2
  elif tail>0:
    for j in range(digit-2):
      plus += 10**j*2
    if head == tail:
      mid = str(i)[1:-1]
      while len(mid)>1 and mid[0]=='0':
        mid = mid[1:]
      mid = int(mid)
      plus += 2*mid+1
      plus += 2
    elif head > tail:
      plus += 10**(digit-2)*2
  count.append(count[-1]+plus)
print(count[N])

Solution (Python):
N=int(input())
d=dict()
ans=0
for i in range(1,N+1):
  if not (str(i)[0],str(i)[-1]) in d:    
    d[(str(i)[0],str(i)[-1])]=1
  else:
    d[(str(i)[0],str(i)[-1])]+=1
for j in d:
  if (j[-1],j[0]) in d:
    ans+=d[j]*d[(j[-1],j[0])]
print(ans)

Solution (Python):
n = int(input())

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

for i in range(n):
    num = str(i+1)
    st = int(num[0])
    en = int(num[-1])
    
    c[st][en] += 1


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


print(ans)

Solution (Python):
N = int(input())
count = [10*[0]for _ in range(10)]
ans = 0
for i in range(1,N+1):
  s = str(i)
  if s[0] == '0' or s[-1] == '0':
    pass
  else:
    count[int(s[0])][int(s[-1])] += 1
for j in range(1,10):
  for k in range(1,10):
    ans += count[j][k]*count[k][j]
print(ans)

Solution (Python):
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()
dp = [0]*max(101,(n+1))
for i in range(1,n+1):
    s = str(i)
    if s[0] == s[-1]:
        dp[int(s[0])] += 1
    elif s[-1] == "0":
        continue
    else:
        ima = int(s[0])*10 + int(s[-1])
        dp[ima] += 1
ans = 0
for i in range(1,min(100,n+1)):
    s = str(i)
    if s[0] == s[-1]:
        ans += dp[int(s[0])]**2
        dp[int(s[0])] = 0
    elif s[-1] == "0":
        continue
    else:
        ima = int(s[0])*10 + int(s[-1])
        ima2 = int(s[-1])*10 + int(s[0])
        ans += dp[ima] * dp[ima2] *2
        dp[ima] = 0
        dp[ima2] = 0
print(ans)

Solution (Python):
n = int(input())
a = [[0 for _ in range(10)] for _ in range(10)]
for i in range(1, n + 1):
    l = list(str(i))
    a[int(l[0])][int(l[len(l) - 1])] += 1
ans = 0
for i in range(10):
    for j in range(10):
        ans += a[i][j] * a[j][i]
print(ans)

Solution (Python):
n=int(input())
A=[0]*105
for i in range(1,n+1):
    x=str(i)
    A[int(x[0]+x[len(x)-1])]+=1
ans=0
for i in range(11,100):
    y=str(i)
    if '0' in y:
        continue
    ans+=A[i]*A[int(y[1]+y[0])]
print(ans)

Solution (Python):
import sys

input = sys.stdin.readline


def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def gcd(a, b):
    if a < b:
        d, (p, q) = gcd(b, a)
        return d, (q, p)
    if b == 0:
        return a, (1, 0)
    d, (q, p) = gcd(b, a % b)
    q -= a // b * p
    return d, (p, q)


def ch(x, y):
    a1, m1 = x
    a2, m2 = y
    d, (p, q) = gcd(m1, m2)
    if (a2 - a1) % d != 0:
        return (0, -1)

    m = m1 * m2 // d
    r = (a1 + m1 * (a2 - a1) // d * p) % m
    return (r, m)


def main():
    N = int(input())
    D = len(str(N))

    res = 0
    for n in range(1, N + 1):
        p, q = int(str(n)[0]), int(str(n)[-1])
        if q == 0:
            continue
        for k in range(1, D + 1):
            if k == 1:
                res += 1 if p == q else 0
                continue

            if k == D:
                t = int(str(N)[0])
                if t < q:
                    continue
                elif t == q:
                    res += ((N - t * 10 ** (D - 1)) - p) // 10 + 1
                    continue

            res += 10 ** (k - 2)
    print(res)


if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
c = [[0] * 10 for _ in range(10)]
for k in range(1, n+1):
    i = int(str(k)[0])
    j = k % 10
    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)

Solution (Python):

 
import math
import itertools
import sys
import copy

 







N = int(input())

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

ans = 0
for x in range(1, 10) :
  for y in range(1, 10) :
    ans += tbl[x][y] * tbl[y][x]

print (ans)

Solution (Python):
n = int(input())

def test():
    ans = 0
    for i in range(1, n+1):
        for j in range(1, n+1):
            a, b = str(i), str(j)
            if a[0] == b[-1] and a[-1] == b[0]:
                ans += 1
    print(ans)

c = [[0 for _ in range(9)] for _ in range(9)]
for  i in range(1, n+1):
    first_digit = str(i)[0]
    last_digit = str(i)[-1]
    if first_digit == '0' or last_digit == '0':
        continue
    c[int(first_digit)-1][int(last_digit)-1] += 1
ans = 0
for i in range(1,10):
    for j in range(1, 10):
        ans += c[i-1][j-1]* c[j-1][i-1]
print(ans)

Solution (Python):
N=int(input())
count = 0
c = [[0] * 10 for i in range(10)]
for num in range(N):
    s = str(num+1)
    start = int(s[0])
    end = int(s[len(s)-1])
    c[start][end] += 1

ans = 0

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

Solution (Python):
n=int(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)

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
ce = [[0] * 10 for i in range(10)]
for i in range(1,n+1):
    tmp = str(i)
    a = int(tmp[0]); b = int(tmp[-1])
    ce[a][b] += 1
res = 0
for i in range(10):
    for j in range(10):
        res += ce[i][j] * ce[j][i]
print(res)

Solution (Python):
n = int(input())

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

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

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



print(ans)

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

Solution (Python):
from collections import defaultdict
n = int(input())
counter = defaultdict(int)

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

ans = 0
for i in range(1, n+1):
    t = str(i)
    ans += counter[(t[-1], t[0])]
print(ans)

Solution (Python):
n = int(input())

ab = {}
for i in range(1, n+1):
    t = str(i)
    if (t[0], t[-1]) in ab:
        ab[(t[0], t[-1])] += 1
    else:
        ab[(t[0], t[-1])] = 1

ans = 0
for i in range(1, n+1):
    t = str(i)
    if (t[-1], t[0]) in ab:
        ans += ab[(t[-1], t[0])]
print(ans)

Solution (Python):
if __name__ == '__main__':
    n = int(input())

    total = 0
    data = [[0] * 9 for i in range(9)]
    for i in range(1, n + 1):
        str_num = str(i)
        top = str_num[0]
        bottom = str_num[-1]
        if bottom == '0':
            continue
        else:
            data[int(top) - 1][int(bottom) - 1] += 1

    for i in range(9):
        for j in range(9):
            total += (data[i][j] * data[j][i])

    print(total)

Solution (Python):
n = int(input())
key = [[0]*9 for i in range(9)]

ans = 0
for v in range(1, n+1):
  l = str(v)
  if v%10 == 0:
    continue
  k1, k2 = int(l[0]), int(l[-1])
  key[k1-1][k2-1] += 1
  ans += key[k2-1][k1-1]*2
  for i in range(len(l)):
    if l[i] != l[-1-i]:
      continue
    if i == len(l)-1:
      ans -= 1
print(ans)

Solution (Python):
import math
N = int(input())
max_l = len(str(N))
cnt = 0
for n in range(1, N+1):
    str_n = str(n)
    f_n, l_n = str_n[0], str_n[-1]
    if(f_n == '0' or l_n == '0'):
        continue
    if(f_n == l_n):
        cnt += 1
    i = 0
    while(int(l_n +'0'*i + f_n)<=N):
        cnt += min((N-int(l_n +'0'*i + f_n))//10 + 1, 10**i)
        i += 1

print(cnt)

Solution (Python):
def resolve():
    n = int(input())
    c = [[0] * 10 for i in range(10)]
    for i in range(n+1):
        b = i % 10
        for j in range(6):
            if i//(10**(j+1)) == 0:
                a = i//(10**j)
                break
        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)
resolve()

Solution (Python):
N = int(input())
count =[[0 for x in range(10)] for z in range(10)]
for x in range(1,N+1):
    F = str(x)[0]
    E = str(x)[-1] 
    count[int(F)][int(E)] +=1
ans = 0
for x in range(10):
    for y in range(10):
        ans += count[x][y] *count[y][x]
print(ans)

Solution (Python):
import numpy as np
import math

N = int(input())

c = np.zeros((10, 10), dtype=int)
d = np.zeros((10, 10), dtype=int)

for n in range(1, N+1):
    k = math.floor(math.log10(n)) + 1
    
    i = n// (10 ** (k-1))
    
    j = n%10
    
    c[i][j] += 1
    d[j][i] += 1

ans = np.sum(c*d)
print(ans)

Solution (Python):
n = int(input())
lis = [[0] * 10 for i in range(10)]
for i in range(1, n+1):
    val = list(str(i))
    lis[int(val[-1])][int(val[0])] += 1


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

print(ans)

Solution (Python):
N = int(input())
ans = 0

"""
def c_i_j(n, i, j):
    counter = 0
    for num in range(1, n + 1):
        if int(str(num)[0]) == i and int(str(num)[-1]) == j:
            counter += 1
    return counter

for i in range(1, 10):
    for j in range(1, 10):
        ans += c_i_j(N, i, j) * c_i_j(N, j, i)

print(ans)
"""
table = list([0] * 10 for i in range(10))

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

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

print(ans)

Solution (Python):

n=int(input())

c=[[0]*9 for _ in range(9)]
for i in range(1,n+1):
    stri = str(i)
    head = int(stri[0])
    tail = int(stri[-1])
    if tail!=0:
        c[head-1][tail-1]+=1

print( sum(c[i][j] * c[j][i] for i in range(9) for j in range(9)) )

Solution (Python):
n = int(input())
lis = [[0] * 10 for i in range(10)]
for i in range(1, n + 1):
    val = list(str(i))
    lis[int(val[-1])][int(val[0])] += 1

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

print(ans)

Solution (Python):
N = int(input())
def get_num(a,b,N):
    cnt = 0
    if(a == b and N >= a):
        cnt += 1
    if(a*10+b <= N):
        cnt += 1
    
    if(100<=N<1000):
        c = 100*a + b
        while(c <= N and c < 100*a + 90 + b + 1):
            cnt += 1
            c += 10
    elif(1000<=N<10000):
        c = 1000*a+b
        cnt += 10
        while(c <= N and c < 1000*a + 990 + b + 1):
            cnt += 1
            c += 10
    elif(10000<=N<100000):
        c = 10000*a + b
        cnt += 110
        while(c <= N and c < 10000*a + 9990 + b + 1):
            cnt += 1
            c += 10
    elif(100000<=N<=200000):
        c = 100000*a + b
        cnt += 1110
        while(c <= N and c < 100000*a + 99990 + b + 1):
            cnt += 1
            c += 10
    return cnt
sum = 0
for i in range(1,10):
    for j in range(1,10):
        sum += get_num(i,j,N)*get_num(j,i,N)
print(sum)

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

Solution (Python):
n = int(input())
ans = 0
a = [[[] for i in range(10)] for j in range(10)]
for i in range(1, n + 1):
    a[int(str(i)[0])][int(str(i)[-1])].append(i)

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

print(ans)

Solution (Python):
from collections import deque
import sys
input = sys.stdin.readline
import bisect as bi
from operator import mul
from functools import reduce
from math import factorial

def main():
    n = int(input())
    c = {(i,j): 0 for i in range(1,10) for j in range(1,10)}

    for i in range(1, n+1):
        s = str(i)
        if s[-1] == "0":
            continue
        h, t = map(int, (s[0], s[-1]))
        c[h, t] += 1

    print(sum(c[i,j] * c[j,i] for i in range(1,10) for j in range(1, 10)))


main()

Solution (Python):
n = int(input())
c = {i: {j: 0 for j in range(1, 10)} for i in range(1, 10)}
for i in range(1, n + 1):
    i = str(i)
    if i[-1] == "0":
        continue
    j, k = map(int, [i[0], i[-1]])
    c[j][k] += 1

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

print(result)

Solution (Python):
N = int(input())
count = [[0 for _ in range(9)] for _ in range(9)]
for i in range(1, N + 1):
    if str(i)[0] != "0" and str(i)[-1] != "0":
        count[int(str(i)[0]) - 1][int(str(i)[-1]) - 1] += 1
ans = 0
for i in range(0, 9):
    for k in range(0, 9):
        ans += count[i][k] * count[k][i]
print(ans)

Solution (Python):
def handstand2(n):
    c = 0
    c_list = [[0 for j in range(10)] for i in range(10)]

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

    for i, _ in enumerate(c_list):
        for j, c_i_j in enumerate(_):
            c += c_i_j*c_list[j][i]
    return c

n = int(input())

print(handstand2(n))

Solution (Python):
n = int(input())
dic = {i:0 for i in range(100)}
for i in range(1,n+1):
    num = str(i)
    dic[int(num[0])*10+int(num[-1])] += 1
count = 0
for i in range(1,10):
    count += dic[i*11]**2
    for j in range(i+1,10):
        count += dic[i*10+j]*dic[j*10+i]*2
print(count)

Solution (Python):
from collections import defaultdict

d = defaultdict(int)
N = int(input())

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

    a = n[0]
    b = n[-1]

    d[(a, b)] += 1


s = 0
for i in range(10):
    for j in range(10):

        s += d[(str(j), str(i))] * d[(str(i), str(j))]

print(s)

Solution (Python):
import math
N = int(input())

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

for i in range(N):
    i += 1
    top = int(str(i)[0])
    bottom = int(str(i)[-1])
    counter[top][bottom] += 1

c = 0
for i in range(10):
    for j in range(10):
        if i == j:
            t = counter[i][j]
            
            c += t**2
        else:
            c += counter[i][j] * counter[j][i]

print(c)

Solution (Python):
N = int(input())
C = [[0]*10 for _ in range(10)]
for i in range(1,N+1):
    C[int(str(i)[0])][int(str(i)[-1])] += 1
answer = 0
for i in range(10):
    for j in range(10):
        answer += C[i][j] * C[j][i]
print(answer)

Solution (Python):
N = input()
cnt = 0

for i in range(1, int(N)+1):
    
    if i % 10 == 0:
        continue
    
    if i % 10 < int(N[0]):
        for j in range(len(N)-1):
            cnt += 10 ** j
    
    elif i % 10 == int(N[0]):
        if len(N) >= 3:
            for j in range(len(N)-2):
                cnt += 10 ** j
            cnt += int(N[1:-1])+1
        
        if len(N) == 2:
            cnt += 1
        
        if int(str(i)[0]) > int(N[-1]):
            cnt -= 1
    
    else:
        for j in range(len(N)-2):
            cnt += 10 ** j
        
    if str(i)[0] == str(i)[-1]:
        cnt += 1
    
print(cnt)

Solution (Python):
n = int(input())

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

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

Solution (Python):
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30
from collections import defaultdict

def main():
    n = int(input().strip())
    d = defaultdict(int)
    for i in range(1, n+1):
        ds = str(i)
        d[(ds[0], ds[-1])] += 1
    ans = 0
    for i in range(1, 10):
        for j in range(1, 10):
            si = str(i)
            sj = str(j)
            ans += d[(si, sj)] * d[(sj, si)]
    print(ans)


if __name__ == '__main__':
    main()

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

Solution (Python):
from collections import defaultdict

N = int(input())

"""
A, Bの桁数でfor文を回して大爆死しました
単純にN以下の自然数で先頭の数がa, 末尾の数がbになる数の個数C[(a, b)]を洗い出しておけば
求める個数は
    ¥Sum_{0<=a, b<=9} C[(a, b)] * C[(b, a)]
"""

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

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

print(ans)

Solution (Python):
n = int(input())
ans = 0

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

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

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

Solution (Python):

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

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

print(ans)

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

Solution (Python):
n = int(input())

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

for i in range(1, n+1):
    a = int(str(i)[0])
    b = int(str(i)[-1])
    
    C[a][b] += 1
        
answer = sum([C[i][j]*C[j][i] for i in range(10) for j in range(10)])

print(answer)

Solution (Python):
N = int(input())
cnt_list = [[0 for _ in range(9)] for _ in range(9)]

for A in range(1, N+1):
    A_high = A//pow(10, len(str(A))-1)
    A_low = A%10
    if A_low != 0:
        cnt_list[A_high-1][A_low-1] += 1

cnt = 0
for i in range(9):
    for j in range(9):
        cnt += cnt_list[i][j] * cnt_list[j][i]
print(cnt)

Solution (Python):
N = int(input())
c = [[0]*10 for _ in range(10)]

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

print(sum([c[i][j]*c[j][i] for i in range(10) for j in range(10)]))

Solution (Python):
N = int(input())
C = [[0 for i in range(9)] for j in range(9)]


def top(n):
    while 10 <= n:
        n = n // 10
    return n


for n in range(N):
    c = n + 1
    i = c % 10
    j = top(c)
    if i and j:
        C[i - 1][j - 1] += 1

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

print(ans)

Solution (Python):
N=int(input())
s=[[0]*9 for i in range(9)]
for i in range(1,N+1):
    if i%10:
        t=str(i)
        s[int(t[0])-1][int(t[-1])-1]+=1
a=0
for i in range(9):
    for j in range(i):
        a+=s[i][j]*s[j][i]*2
    a+=s[i][i]**2
print(a)

Solution (Python):
n= int(input())

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

for i in range(1,n+1):
  a,b = int(str(i)[0]), i%10
  mat[a][b] += 1

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

print(ans)

Solution (Python):
n = int(input())
a = [[0]*9 for _ in range(9)]
for i in range(n):
    if str(i+1)[0] != '0' and str(i+1)[-1] != '0':
        a[int(str(i+1)[0])-1][int(str(i+1)[-1])-1] += 1
        
ans = 0
for i in range(9):
    for j in range(9):
        ans += a[i][j]*a[j][i]
        
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read 
input = sys.stdin.buffer.readline
def inputS(): return input().rstrip().decode()
readlines = sys.stdin.buffer.readlines 

from collections import defaultdict

N = int(input())

counter = defaultdict(int)

for i in map(str, range(1, N+1)):
  
  head = i[0]
  tail = i[-1]
  counter[(head, tail)] += 1

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

print(ans)

Solution (Python):
N = int(input())
c = [[0 for i in range(10)] for j in range(10)]
for i in range(1,N+1):
    top = int(str(i)[0])
    bot = int(str(i)[-1])
    c[top][bot]+=1

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

print(ans)

Solution (Python):
N = int(input())
N_str = list(str(N))
length = len(str(N))


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


def count(i, j):
    pass

for i in range(9):
    for j in range(9):
        c[i][j] = count(i, j)
'''

for i in range(1, N+1):
    s = str(i)
    if s[0] == "0" or s[-1] == "0":continue
    c[int(s[0])-1][int(s[-1])-1] += 1

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

print(ans)

Solution (Python):
n = int(input())
cnt = [ [0]*10 for _ in range(10)]

for i in range(1, n+1):
  strI = str(i)

  t = strI[0]
  b = strI[-1]
  cnt[int(t)][int(b)] += 1

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

print(ans)

Solution (Python):
N = int(input())
c = [[0]*9 for _ in range(9)]
count = 0
for i in range(1,N+1):
    li = i//10**(len(str(i))-1) 
    ri = i%10
    if ri == 0:
        continue
    c[li-1][ri-1] += 1

for i in range(9):
    for j in range(9):
        count += c[i][j]*c[j][i]

print(count)

Solution (Python):
def get_first_end(n):
    n = str(n)
    return (int(n[0]), int(n[-1]))


n = int(input())
ans = 0

ans_dict = {}
for i in range(1, n+1):
    p = get_first_end(i)
    if not(p in ans_dict):
        ans_dict[p] = 0
    ans_dict[p] += 1

for i in range(1, n+1):
    p = get_first_end(i)
    reverse = (p[1], p[0])
    if reverse in ans_dict:
        ans += ans_dict[reverse]
print(ans)

Solution (Python):

import sys,os
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    sN = input()
    N = int(sN)
    firts_digit = int(sN[0])
    last_digit = int(sN[-1])
    num_candidates = max(min(firts_digit,last_digit),firts_digit -1 )
    max_inter_digits = len(sN) - 2
    

    ans = 0
    
    max_inter_digits = len(sN) - 2
    intermediate = 0
    for _ in range(max_inter_digits):
        intermediate = intermediate*10+1
    
    if len(sN) == 1:
        print(N)
        return
    elif len(sN) == 2:
        ans = 9
        for i in range(1,10):
            tmp = i
            if i * 11 <= N:
                ans += 1
        for i in range(11,N+1):
            if i % 10 == 0:
                continue
            if i % 11 == 0:
                ans += 1
            if (i % 10) * 10 + i//10 <= N:
                ans += 1
            
        print(ans)
        return 

    first_N = int(sN[0])
    last_N = N % 10
    for i in range(1,N+1):

        
        if i%10 == 0:
            continue
        si = str(i)
        
        if si[0] != si[-1]:
            ans += intermediate
        else:
            ans += intermediate + 1
            
        
        first_B = i % 10
        last_B = int(si[0])
        
        



        
        if first_B <  first_N:
            ans += pow(10,max(len(sN)-2,0))
        elif first_B == first_N:
            
            sm = sN[1:-1]
            m = (N % pow(10,len(sN)-1)) // 10 + 1 
            
            if last_B <= last_N:
                ans += m
            else:
                ans += max(m-1,0)
            

            
            
    print(ans)
    '''


        N = 2500
        2012
        2
        22
        2?2
        2xy2 - 2492
            x: 0...4
            y: 0...9
            sm = 2492 = sN[:-2]+si[0]
            m = int(m)
            if m > N:
                sm = str(m-10)
            intermediate += (sm[1]+1)*....*(sm[-2]+1)
            

        N = 90000
        i = 65432
        26
        2?6
        2??6
        2???6 29996
            first_i = int(si[-1])
            first_N = int(N[0])
            if first_i <  first_N:
                intermediate = intermediate *10 +1
                ans += intermediate
            elif first_i == first_N:
                sm = sN[:-2]+si[0]
                tmp = 1
                for c in sm[1:-2]:
                    tmp*= c+1
                ans += tmp
            
                
                



        N = 30512
        i = 503
        i[-1] == N[0]
        35
        3?5
        3??5
        3???5 
        sm =  30505 = sN[0:-1] + str(i[0])
        intermediate += (s[1]+1)*...*(s[-2]+1)
        if m < N:
            m -=10
        '''

    

if __name__ == '__main__':
    main()

Solution (Python):
n=int(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)

Solution (Python):
d=dict()
n=int(input())
ans=0
special=0
for i in range(1,n+1):
  ii=str(i)
  if (ii[0],ii[-1]) in d.keys():
    d[(ii[0],ii[-1])]+=1
  else:
    d[(ii[0],ii[-1])]=1
  if (ii[-1],ii[0]) in d.keys():
    ans+=d[(ii[-1],ii[0])]
  if (ii[0]==ii[-1]):
    special+=1
  

print(2*(ans-special)+special)

Solution (Python):
n = int(input())
dp = [[0] * 10 for _ in range(10)]
ans = 0

for i in range(1, n+1):
    top = int(str(i)[0])
    end = int(str(i)[-1])
    ans += 2 * dp[end][top]
    if top == end:
        ans += 1
    dp[top][end] += 1

print(ans)

Solution (Python):
n=int(input())
cnt=[[0]*10 for _ in range(10)]

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

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

print(sum)

Solution (Python):
N = int(input())

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

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

ans = 0

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

print(ans)

Solution (Python):
import itertools


n = int(input())

XY = {xy:0 for xy in itertools.product("0123456789", repeat = 2)}
for i in range(1, n + 1):
    x, y = str(i)[0], str(i)[-1]
    XY[(x, y)] += 1

answer = 0
for a in range(1, n + 1):
    x, y = str(a)[0], str(a)[-1]
    answer += XY[(y, x)]

print(answer)

Solution (Python):
N = int(input())
ans = 0
for n in range(1,N+1):
    if n%10==0:continue
    s = str(n)
    if s[0]==s[-1]:ans+=1
    for i in range(10):
        a = int(s[-1]+"9"*i+s[0])
        b = int(s[-1]+"0"*i+s[0])
        if a<=N:ans+=pow(10,i)
        elif b<=N:
            ans+=(N-b)//10+1
        else:
            break
print(ans)

Solution (Python):
N = int(input())


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


for i in range(1,N+1):
    n = str(i)
    head = int(n[0])
    tail = int(n[-1])
    L[head][tail] += 1

ans = 0

for j in range(10):
    for k in range(10):
        ans += L[j][k] * L[k][j]

print(ans)

Solution (Python):
N = int(input())

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

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

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

print(ans)

Solution (Python):
n=int(input())
ans=0
if n<10:
    print(1)
    exit()
count=[[0]*10 for _ in range(10)]

for i in range(1,n+1):
    tmp=str(i)
    a=int(tmp[0])
    b=int(tmp[-1])
    count[a][b]+=1

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

print(ans)

Solution (Python):






import math
from functools import lru_cache





MOD = 10**9 +7
INF = float('inf')





kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret





N = int(input())

dic = [[0 for i in range(10)] for j in range(10)]
for i in range(1,N+1):
  top = int(str(i)[0])
  bottom = int(str(i)[-1])
  dic[top][bottom] += 1

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

print(ans)