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):
N = int(input())

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

for k in range(1, N+1):
    s = str(k)
    cnt[int(s[0])][int(s[-1])] += 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

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

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

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

Solution (Python):
n = int(input())
memo = [[0 for i in range(10)] for j in range(10)]
for i in range(1,n+1):
    i_first = int(str(i)[0])
    i_last = int(str(i)[-1])
    memo[i_first][i_last] += 1
ans = 0
for i in range(1,n+1):
    i_first = int(str(i)[0])
    i_last = int(str(i)[-1])
    ans += memo[i_last][i_first]
print(ans)

Solution (Python):
n=int(input())
A=[[0 for i in range(9)] for j in range(9)]
for i in range(1,n+1):
  if i%10!=0:
    num=str(i)
    A[int(num[0])-1][int(num[-1])-1] +=1

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

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

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

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


ans = 0
for s in range(1, 10):
    for e in range(1, 10):
        ans += c[s][e] * c[e][s]
    
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):
    i = [int(j) for j in list(str(i))]
    c[i[0]][i[-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):
from sys import stdin

n = int(stdin.readline().rstrip())

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

for k in range(1,n+1):
    atama = int(str(k)[0])
    ushiro = int(str(k)[-1])
    li[atama][ushiro] += 1

point = 0

for l in range(1,10):
    for m in range(1,10):
        point += li[l][m]*li[m][l]
print(point)

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

Solution (Python):
import numpy as  np

N=int(input())
key=np.zeros((10,10))

for i in range(1, N+1):
    s = str(i)
    key[int(s[0]), int(s[-1])]+=1
print(int(sum(sum((key*np.transpose(key))))))

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

cnt = [[0] * 10 for i 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 i in range(10):
    for j in range(10):
        ans += cnt[i][j] * cnt[j][i]

print(ans)

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

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

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

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

print(ans)

Solution (Python):
n=int(input())
d=[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":
    continue
  else:
    d[int(s[0])][int(s[-1])]+=1
for i in range(1,10):
  for j in range(1,10):
    ans+=d[i][j]*d[j][i]
print(ans)

Solution (Python):
n = input()
 
d = [ [0] * 10 for _ in range(10) ]
for i in range( 1, int( n ) + 1 ):
  k = str(i)
  d[ int( k[ 0 ])][ int( k[ -1 ])] += 1

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

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

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

for a in range(1, n + 1):
  s = str(a)
  t = int(s[0])
  b = int(s[-1])
  m[b][t] += 1

ans = 0
for a in range(1, n + 1):
  s = str(a)
  t = int(s[0])
  b = int(s[-1])
  ans += m[t][b]

print(ans)

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

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

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

ans = 0
ctable = [[-1 for _ in range(10)] for _ in range(10)]

def c(x, y):
    cnt = 0
    strx = str(x)
    stry = str(y)
    for i in range(1, N+1):
        stri = str(i)
        if stri[0] == strx and stri[-1] == stry:
            cnt += 1
    return cnt

for i in range(10):
    for j in range(10):
        ctable[i][j] = c(i, j)

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

print(ans)

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

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

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

for j in range(10):
    for k in range(10):
        count += c[j][k] * c[k][j]

print(count)

Solution (Python):
import itertools

n = int(input())

tl = [i for i in range(1, n+1) if i % 10 != 0]

"""
l = list(itertools.product(tl, tl))



ans = []
count = 0
for pair in l:
    a = str(pair[0])
    b = str(pair[1])
    if (a[0] == b[len(b)-1]) and (a[len(a)-1] == b[0]):
        count += 1
        

print(count)

"""

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

count = 0

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

print(count)

Solution (Python):
n = int(input())
cand = 0
memo = dict()
ans = 0
for i in range(1, n+1):
    s = str(i)[0]
    f = str(i)[-1]
    if s+f in memo:
        ans += memo[s+f]
    else:
        count = 0
        for j in range(1,n+1):
            q = str(j)[0]
            r = str(j)[-1]
            if q == f and r == s:
                count += 1
        ans += count
        memo[s+f] = count
print(ans)

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

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

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

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

print(cc)

Solution (Python):

import numpy as np
N=int(input()) 
num=0
count=0
allcount=0
diglen=len(str(N)) 

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

for i in range(N):
    num=str(i+1)
    b=int(num[len(num)-1])
    a=int(num[0])
    table[a][b]=table[a][b]+1

for i in range(10):
    for j in range(10):
        count=count+table[i][j]*table[j][i]
        
print(int(count))

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

for i in range(1, N+1):
    s = str(i)
    if s[-1] == '0': continue
    table[int(s[0])][int(s[-1])] += 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):
import sys
from pprint import pprint

def solve(n):
    c = [[0 for i in range(10)] for j in range(10)]
    for i in range(1, n+1):
        str_i = str(i)
        len_i = len(str_i)
        c[int(str_i[len_i-1])][int(str_i[0])] += 1
    ans = 0
    for i in range(10):
        for j in range(10):
            ans += c[i][j] * c[j][i]
        
    print(ans)

if __name__ == '__main__':
    n = int(sys.stdin.readline().strip())
    solve(n)

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

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

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

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    n = int(input())
    
    res = [[0] * 10 for _ in range(10)]
    for i in range(1, n+1):
        s = str(i)
        if s[-1] == '0':
            continue
        res[int(s[0])][int(s[-1])] += 1

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

if __name__ == '__main__':
    main()

Solution (Python):
import sys
input = sys.stdin.readline


def main():
    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)
        A[int(s[0])][int(s[-1])] += 1
    ans = 0

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


if __name__ == '__main__':
    main()

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

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

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

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

Solution (Python):
c={}
for i in range(1,10):
  for j in range(1,10):
    l=str(i)
    r=str(j)
    c[l+r]=0


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

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

for i in range(1,N+1):
    s = str(i)
    p = s[0]
    l = s[-1]
    p = int(p)
    l = int(l)
    if p != 0 and l != 0:
        c[p-1][l-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):
import numpy as np
N = int(input())
c = np.zeros((10, 10), dtype='int')

for k in range(1, N + 1):
    k = str(k)
    i, j = int(k[0]), int(k[-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)

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

Solution (Python):
import numpy as np
n = int(input())
a = 10
b = 0
x = np.zeros((10, 10, ))
for i in range(1,n+1):
  while (i // a != 0):
    a = a * 10
  c = (i * 10) // a
  d = i % 10
  x[c][d] += 1

for i in range(0,10):
  for j in range(0,10):
    b += int(x[i][j] * x[j][i])
print(b)

Solution (Python):
n = int(input())
num = [[0 for j in range(10)] for i in range(10)]
for i in range(1, n+1):
    X = str(i)
    num[int(X[0])][int(X[-1])] += 1

ans = 0
print(sum(num[i][j]*num[j][i] for i in range(10) for j in range(10)))

Solution (Python):
from collections import defaultdict

N = int(input())
cnt = defaultdict(int)

for i in range(1, N + 1):
    h = str(i)[0]
    f = str(i)[-1]
    if f == '0':
        continue
    cnt[(h, f)] += 1

ans = 0
dlst = list(cnt.items())
for i, v in dlst:
    ans += v * cnt[i[1], i[0]]

print(ans)

Solution (Python):
n = input()

d = [ [0] * 10 for _ in range(10) ]
for i in range( 1, int( n ) + 1 ):
  k = str(i)
  d[ int( k[ 0 ])][ int( k[ -1 ])] += 1

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

Solution (Python):
import numpy as np
N = int(input())

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

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

y = 0
for i in range(1,10):
    for j in range(1,10):
        y += TT[i,j]*TT[j,i]
print(int(y))

Solution (Python):
def solve():
    N = int(input())
    
    counter = [[0] * 10 for _ in range(10)]
    for i in range(1, N+1):
        s = str(i)
        counter[int(s[0])][int(s[-1])] += 1
    
    ans = 0
    for i in range(10):
        for j in range(10):
            ans += counter[i][j] * counter[j][i]
    print(ans)


if __name__ == '__main__':
    solve()

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

d = [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": continue
    d[int(s[0])][int(s[-1])] += 1

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

Solution (Python):
N = int(input())
K = len(str(N))
MS = int(str(N)[0])
ML = int(str(N)[-1])
res = 0

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

    if AL == 0:
        continue

    for k in range(1, K+1):
        if k == 1:
            if AS == AL and AS <= N:
                res += 1
            continue
        if k == 2:
            if int(str(AL) + str(AS)) <= N:
                res += 1
            continue
        if k < K:
            res += 10 ** (k - 2)
            continue
        if k == K:
            if AL > MS:
                continue
            if AL < MS:
                res += 10 ** (k - 2)
                continue
            if AL == MS:
                if AS <= ML:
                    res += (int(str(N)[1:])+9) // 10
                    continue
                else:
                    res += (int(str(N)[1:])) // 10
                    continue


print(res)

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

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

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

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

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

Solution (Python):

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

Solution (Python):



def solve(*args: str) -> str:
    n = int(args[0])

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

    for a in range(1, n+1):
        s = str(a)
        i, j = int(s[0]), int(s[-1])
        C[i][j] += 1

    for b in range(1, n+1):
        s = str(b)
        i, j = int(s[0]), int(s[-1])
        ret += C[j][i]

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

Solution (Python):
def main():
    N = int(input())
    c = [[0 for i in range(10)] for j in range(10)]
    for k in range(1, N+1):
        s = str(k)
        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)


if __name__ == '__main__':
    main()

Solution (Python):

N = int(input())
if N <= 9:
    print(N)
    exit()

tot_count = 0
for af in map(str, range(1, 10)):
    for bf in map(str, range(1, 10)):
        a_count = 0
        b_count = 0
        for a in map(str, range(1, N + 1)):
            if a[0] == af and a[-1] == bf:
                a_count += 1
        for b in map(str, range(1, N + 1)):
            if b[0] == bf and b[-1] == af:
                b_count += 1

        tot_count += a_count * b_count

print(tot_count)

Solution (Python):


import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
ans = 0

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

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

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

Solution (Python):
import itertools

n = int(input())
AB = [(int(s[0]), int(s[-1])) for s in map(str, range(1,n+1))]

def count(a, b):
    return sum([1 for ab in AB if ab[0] == a and ab[1] == b])

ans = 0
for pair in itertools.product(range(10), range(10)):
    a, b = pair
    c1 = count(a, b)
    c2 = count(b, a)
    ans += c1 * c2
print(ans)

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

C = [[ 0 for _ in range(10)] for _ in range(10)]
for i in range(N+1):
  si = str(i)
  s = int(si[0])
  e = int(si[-1])
  C[s][e] += 1
ans = 0
for i in range(1,10):
  for j in range(1,10):

    ans += (C[i][j] * C[j][i])
print(ans)

Solution (Python):
import sys

input = sys.stdin.readline


def main():
    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)
        A[int(s[0])][int(s[-1])] += 1

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

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
 
c = []
for i in range(10):
    c.append([0] * 10)
 
for i in range(N):
    s = str(i+1)
    i1 = int(s[0])
    i2 = int(s[-1])
    c[i1][i2] += 1
    
total = 0
for i in range(10):
    for j in range(10):
        total += c[i][j] * c[j][i]
        
print(total)

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

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

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

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

for i in range(N):
    s = str(i+1)
    i1 = int(s[0])
    i2 = int(s[-1])
    c[i1][i2] += 1
    
total = 0
for i in range(10):
    for j in range(10):
        total += c[i][j] * c[j][i]
        
print(total)

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

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

a = list(range(1, 10))
z = list(range(1, 10))

az = []
az_r = []
az0 = []
az1 = []
for i in a:
    for j in z:
        az.append(i*10+j)
        az_r.append(i+j*10)
        az0.append(0)
        az1.append(0)

for i in range(1, n+1):
    if i < 10:
        j = i*10+i
    else:
        j = i
    str1 = str(j)
    str_index = int(str1[0])*10 + int(str1[-1])
    str_index_r = int(str1[0]) + int(str1[-1])*10
    if int(str1[-1]) != 0 and int(str1[0]) != 0:
        az0[az.index(str_index)] += 1
        az1[az.index(str_index_r)] += 1

ans = 0
for i in range(len(az0)):
    if az0[i] >0 and az1[i] >0:
        ans += az0[i]*az1[i]

print(ans)

Solution (Python):
N = int(input())
ans = 0
for i in range(1, N+1):
    head, tail = str(i)[0], str(i)[-1]
    if tail == "0":
        continue
    if head == tail:
        ans += 1
    if int(tail + head) <= N:
        ans += 1
    if len(str(N))-2 >= 1 or head == tail:
        num = len(str(N))-2
        if int(tail) <= int(str(N)[0]) and num > 0:
            if int(tail + "9"*(len(str(N))-2) + head) <= N:
                j = int("9"*(len(str(N))-2))
            else:
                if int(tail + str(N)[1:-1] + head) <= N:
                    j = int(str(N)[1:-1])
                else:
                    j = int(str(N)[1:-1]) - 1
            ans += int(j) + 1
        if num > 1:
            ans += int((num - 1) * "1") * 10
    
                    
print(ans)

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

c = [[0 for _ in range(9)] for _ in range(9)]
for i in range(1, 10):
  for j in range(1, 10):
    cnt = 0
    for n in range(1, N + 1):
      if n // (10 ** (len(str(n)) - 1)) == i and n % 10 == j:
        cnt += 1
    c[i - 1][j - 1] = cnt

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())
len_N = len(str(N))
str_N = str(N)
N_a = int(str_N[0])
N_b = int(str_N[-1])
ans = 0
if len_N == 1:
    print(N)
    exit()
if len_N == 2:
    ans += 9
    for i in range(11, N+1):
        str_i = str(i)
        if str_i[1] == '0':
            continue
        i_tmp = int(str(i)[1] + str(i)[0])
        if i_tmp <= N:
            ans += 1
    tmp = N // 11
    ans += tmp * 2
    print(ans)
    exit()

for i in range(1, N+1):
    tmp = str(i)
    tmp_a = int(tmp[0])
    tmp_b = int(tmp[-1])
    if tmp_b == 0:
        continue
    if tmp_a == tmp_b:
        ans += 1
 
    if tmp_b > N_a:
        ans += int('1' * (len_N - 2))

    elif tmp_b == N_a and tmp_a <= N_b:
        ans += int('1' * (len_N - 2))
        naka = str_N[1:-1]
        if naka == "":
            continue
        ans += int(naka) + 1

    elif tmp_b == N_a and tmp_a > N_b:
        ans += int('1' * (len_N - 2))
        naka = str_N[1:-1]
        if naka == "":
            continue
        ans += int(naka)

    else:
        ans += int('1' * (len_N - 1))

print(ans)

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

for i in range(1, n + 1):
  s = str(i)
  if s[-1] == '0':
    continue
  d[int(s[0])][int(s[-1])] += 1

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

Solution (Python):
N=int(input())
A=[0]*101
count=0
for i in range(1,N+1):
    T = str(i)
    K = len(T) - 1
    if i<10:
        A[i*10+i]+=1
    else:
        X=i%10
        Y=i//(10**K)
        if X!=0:
            A[Y*10+X]+=1



for i in range(1,N+1):
    T = str(i)
    K = len(T) - 1
    if i<10:
        count+=A[i*10+i]
    else:
        X=i%10
        Y=i//(10**K)
        if X!=0:
            count+=A[X*10+Y]
print(count)

Solution (Python):
N = input()

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

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

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

print(ans)

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

digits = 1
base = 10
for i in range(0, 20):
    if n < 10 ** i:
        digits = i
        break

smallest_digit = n % 10
largest_digit = n // (10 ** (digits - 1)) % 10
mid_digit_pattern = (n - largest_digit * (10 ** (digits - 1))) // 10 + 1

def count_pattern(a, b, dig):
    if dig == 1 and a != b:
        return 0
    elif dig == 1:
        return 1
    elif dig == digits:
        if a > largest_digit:
            return 0
        elif a < largest_digit:
            return 10 ** (dig - 2)
        elif b <= smallest_digit:
            return mid_digit_pattern
        elif b > smallest_digit:
            return mid_digit_pattern - 1
        else:
            assert False, "Can't reach here"
    else:
        return 10 ** (dig - 2)

result = 0
if digits == 1:
    result = n
else:
    counts = {}
    for i in range(1, 10):
        for j in range(1, 10):
            state = (i, j)
            counts[state] = sum([count_pattern(i, j, d) for d in range(1, digits + 1)])

    for state in counts.keys():
        result += counts[state] * counts[tuple(reversed(state))]

print(result)

Solution (Python):
import sys
from math import log10, floor, ceil
from itertools import combinations, product
n = int(input())
n_start = int(str(n)[0])
n_last = int(str(n)[-1])
n_keta = floor(log10(n)) + 1
ans = 0
dic = {(i[0], i[1]) : 0 for i in product(range(10), repeat=2)}
for i in range(n+1):
    _i = str(i)
    dic[(int(_i[0]), int(_i[-1]))] += 1
dic[(0, 0)] = 0
for a, b in product(range(10), repeat=2):
    ans += dic[(a, b)] * dic[(b, a)]
print(ans)

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

c = [[0 for _ in range(10)] for _ in range(10)]
for k in range(1, n+1):
    s = str(k)
    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())
from collections import defaultdict
dic=defaultdict(int)

for i in range(1,N+1):
  n=str(i)
  dic[(int(n[0]),int(n[-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)

Solution (Python):
from functools import lru_cache

N = int(input())

@lru_cache(maxsize=None)
def c(i, j):
    return len([
        i
        for n in range(1, N + 1)
        if str(n)[0] == i
        if str(n)[-1] == j
    ])

def main():
    tmp = 0
    for i in "0123456789":
        for j in "0123456789":
            tmp += c(i, j) * c(j ,i)

    print(tmp)

main()

Solution (Python):
s = input().rstrip()
N = int(s)

ans = 0
i = 1
order = len(str(N))

params = {}

for i in range(1, N + 1):
    Akey = str(i)[-1] + str(i)[0] 
    if params.get(Akey) is not None:
        params[Akey] = params[Akey] + 1
    else:
        params[Akey] = 1

for i in range(1, N + 1):
    Bkey = str(i)[0] + str(i)[-1] 
    count = params.get(Bkey)
    if count is not None:
        ans =  ans + count;

print(ans)

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

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

for i in range(n+1):
    hn = int(str(i)[0])
    tn = i % 10
    cc[hn][tn] = cc[hn][tn]+1

    
c = 0

for h in range(1,10):
    for t in range(1, 10):
        c = c + (cc[h][t]*cc[t][h])

        
print(c)

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

print(count)

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

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

c = [[0]*10 for i in range(10)]
for n in range(1,N+1):
    n_str = str(n)
    n_last = len(n_str)-1
    c[int(n_str[0])][int(n_str[n_last])] += 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 sys
from collections import defaultdict

def main():
    n = int(sys.stdin.readline().strip())
    

    
    
    
    
    

    
    
    
    

    
    
    
    
    
    
    
    
    


    
    
    
    
    

    

    
    
    
    
    
    
    
    
    
    
    
    
    

    dic = {}
    for i in range(1, 10):
        dic[i] = {}
        for j in range(10):
            dic[i][j] = 0

    for i in range(1, n+1):
        tmp = i
        while tmp >= 10:
            tmp //= 10
        dic[tmp][i % 10] += 1

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


if __name__ == '__main__':
    main()

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

ans = 0

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

    if end != 0 :
        book[pre-1][end-1] += 1

for i in range(9) :
    for j in range(i, 9) :
        if i == j :
            ans += book[i][j] * book[j][i]
            
            continue
        if book[i][j] != 0 and book[j][i] != 0 :
            ans += book[i][j] * book[j][i] * 2
            




print(ans)

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

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

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

Solution (Python):

import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


N = read_a_int()
N_str = str(N)
n_keta = len(N_str)



from collections import defaultdict
container = defaultdict(lambda: 0)

for n in range(N + 1):
    if n % 10 == 0:
        continue
    n_str = str(n)
    container[(int(n_str[0]), int(n_str[-1]))] += 1

ans = 0
from itertools import product
for i, j in product(range(1, 10), range(1, 10)):
    ans += container[(i, j)] * container[(j, i)]

print(ans)

Solution (Python):

n = int(input())

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

for i in range(1,n+1):
    sn = str(i)
    for ci in range(10):
        for cj in range(10):
            if sn[0]==str(ci) and sn[-1]==str(cj):
                c[ci][cj] += 1

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

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

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

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

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

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N = int(read())

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

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

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

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

Solution (Python):
N= int(input())
lead_N = int(str(N)[0]) 
end_N = int(str(N)[-1])
ans = 0
for i in range(1, N + 1):
  lead = int(str(i)[0])
  end = int(str(i)[-1])
  
  if lead == end:
    ans += 1
  
  for j in range((len(str(N)) - 2) + 1):
    if end == 0 or (end > lead_N and j == (len(str(N)) - 2)):
      
      continue
    elif end == lead_N and j == (len(str(N)) - 2):
      
      
      if len(str(N)) >= 3:
        ans += int(str(N)[1:-1])
      if lead <= end_N:
        ans += 1
    else:
      
      ans += 10 ** j

print(ans)