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):
MAP_MAX = 10

N = int(input())


data_list = [[0 for i in range(MAP_MAX)] for j in range(MAP_MAX)]


def get_fN_eN(num):
    
    tmp_N = num
    while(tmp_N >= 10):
        tmp_N = tmp_N // 10
    f_N = tmp_N
    
    e_N = num % 10

    return [f_N, e_N]


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

    
    get_f_e = get_fN_eN(i)
    
    
    data_list[get_f_e[0]][get_f_e[1]] += 1



sum_val = 0
for i in range(1, MAP_MAX):
    for j in range(1, MAP_MAX):
        sum_val += data_list[i][j] * data_list[j][i]

print(sum_val)

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

D={}
for i in range(1,N+1):
    I=str(i)
    if (I[-1],I[0]) not in D:
        D[(I[-1],I[0])]=1
    else:
        D[(I[-1],I[0])]+=1

ans=0
for j in range(1,N+1):
    J=str(j)
    if (J[0],J[-1]) in D:
        ans+=D[(J[0],J[-1])]
print(ans)

Solution (Python):


import sys
sys.setrecursionlimit(300000)

def solve(N: int):
    counts = [[0] * 10 for _ in range(10)]
    for i in range(10, N + 1):
        b = i % 10
        while i >= 10:
            i //= 10
        counts[i][b] += 1
    ret = 0
    for i in range(1, min(N + 1, 10)):
        ret += 1
        if counts[i][i] > 0:
            ret += counts[i][i] * 2
    for i in range(1, 10):
        for j in range(1, 10):
            ret += counts[i][j] * counts[j][i]
    print(ret)
    return

def solve_(N: int):
    def is_valid(n, a, b):
        if n % 10 != b:
            return False
        while n >= 10:
            n //= 10
        if n % 10 == a:
            return True
        return False
    ret = 0
    for i in range(1, 10):
        for x in range(1, N + 1):
            if is_valid(x, i, i):
                print(x, i, i)
                ret += 1
    print(' -------- ')
    for i in range(1, 10):
        for j in range(1, 10):
            for x in range(10, N + 1):
                if is_valid(x, i, j):
                    print(x, i, j)
                    ret += 1
    print(ret)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    solve(N)

if __name__ == '__main__':
    main()

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

def f(a,b):
    ret = 0
    a,b = min(a,b),max(a,b)
    l = len(str(N))
    if a==b:
        if l==1:
            if a<=N: return 1
            else: return 0
        ret = 1
        for d in range(l-1):
            for i in range(10**d):
                A = a*(10**(d+1)+1) + i*10
                if A<=N: ret += 1
                else: break
            else:
                continue
            break
        ret **= 2
    else:
        Acnt = 0
        Bcnt = 0
        for d in range(l-1):
            for i in range(10**d):
                A = a*(10**(d+1)) + b + i*10
                B = b*(10**(d+1)) + a + i*10
                if B<=N: Bcnt += 1
                if A<=N: Acnt += 1
                else: break
            else:
                continue
            break
        ret = Acnt * Bcnt    
    return ret

ans = 0
for a in range(1,10):
    for b in range(1,10):
        ans += f(a,b)
print(ans)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n = I()
    c = collections.defaultdict(int)
    for i in range(1,n+1):
        s = str(i)
        c[s[0]+s[-1]] += 1

    r = 0
    for k,v in c.items():
        for l,u in c.items():
            if k > l or k[0] != l[1] or k[1] != l[0]:
                continue
            if k == l:
                r += v * u
            else:
                r += v * u * 2

    return r


print(main())

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

D = {}
for i in range(1,N+1):
  I = str(i)
  if (I[-1],I[0]) not in D:
    D[(I[-1],I[0])] = 1
  else:
    D[(I[-1],I[0])] += 1

ans = 0
for j in range(1,N+1):
  J = str(j)
  if (J[0],J[-1]) in D:
    ans += D[(J[0], J[-1])]    
print(ans)

Solution (Python):
import math
import sys

A  = int(input())

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


def count(n):
    for x in range(1,n+1):
        xj = x % 10 
        s = x; 
        while True:
            if s < 10:
                xi = s
                C[xi][xj] = C[xi][xj] + 1
                break
            s = s// 10 


count(A)

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

print(ans)

Solution (Python):

n=int(input())

def first_num(x):
    l=x
    while int(x/10)>0:
        x=int(x/10)
        l=x
    return l

kiroku=dict()
for i in range(1,n+1):
    first=first_num(i)
    last=i%10
    
    if (first,last) in kiroku:
        kiroku[first,last]+=1
    else:
        kiroku[first,last]=1

ans=0
for key in kiroku.keys():
    f,l=key
    if (l,f) in kiroku:
        kumi=kiroku[f,l]*kiroku[l,f]
        ans+=kumi
print(ans)

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

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

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

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

for j in range(1, n+1):
    ss = str(j)
    ans += numbers[int(ss[-1])][int(ss[0])]

print(ans)

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

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

    ans = 0
    for A in range(1, N+1):
        ss = str(A)
        ans += numss[int(ss[0])][int(ss[-1])]

    print(ans)

solve()

Solution (Python):
def get_lmb(N):
    while (N >= 10):
        N = int(N/10)
    return N

def get_rmb(N):
    return N%10

def find_all():
    from collections import defaultdict
    dic = defaultdict(int)
    N = int(input())
    for i in range(1, N+1):
        lmb, rmb = get_lmb(i), get_rmb(i)
        dic[(lmb, rmb)] += 1
    
    count = 0
    for i in range(1, 10):
        for j in range(1, 10):
            count += dic[(i, j)] * dic[(j, i)]
    
    
    return count

print(find_all())

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())
t = [[0] * 10 for _ in range(10)]
for i in range(1, N + 1):
    s = str(i)
    t[int(s[0])][int(s[-1])] += 1
result = 0
for i in range(1, 10):
    for j in range(1, 10):
        result += t[i][j] * t[j][i]
print(result)

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

Solution (Python):
N = int(input())
mat = list()
for i in range(10):
    mat.append([0] * 10)

for i in range(N):
    A = int(str(i + 1)[0])
    B = int(str(i + 1)[-1])
    mat[A][B] += 1
ans = 0
for i in range(10):
    for j in range(10):
        ans += mat[i][j] * mat[j][i]
print(ans)

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

Solution (Python):
N = int(input())
mat = list()
for i in range(10):
    mat.append([0] * 10)

for i in range(N):
    A = int(str(i + 1)[0])
    B = int(str(i + 1)[-1])
    mat[A][B] += 1
ans = 0
for i in range(N):
    A = int(str(i + 1)[0])
    B = int(str(i + 1)[-1])
    ans += mat[B][A]
print(ans)

Solution (Python):
N=int(input())
c=[[0 for z in range(10)] for z in range(10)] 
for i in range(1,10):
  for j in range(1,10):
    for k in range(1,N+1):
      k=str(k)
      if k[0]==str(i) and k[-1]==str(j):
        c[i][j]=c[i][j]+1
S=0
for i in range(1,10):
  for j in range(1,10):
    S=S+c[i][j]*c[j][i]
print(S)

Solution (Python):
import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
import sys
from collections import deque, defaultdict, Counter; from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20; INF = float("INF"); ans = 0; tmp = 0; cnt = 0; ansli = []; tmpli = []; candili = []; stillset = set()
eps = 1.0 / 10 ** 10; mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]; ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]; ddn9 = ddn + [(0, 0)]
"""for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""
def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def ws(): return sys.stdin.readline().split()
def i(): return int(sys.stdin.readline())
def s(): return input()
def s_list(): return list(input())
def hi(n): return [i() for _ in range(n)]
def hs(n): return [s() for _ in range(n)]
def mi(n): return [wi() for _ in range(n)]
def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[0]] for _ in range(n)]
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]
def grid(n): return [s_list() for _ in range(n)]

n = i()
nx = str(n)[0]
ny = str(n)[-1]
digit = len(str(n))
is_full = [1, 11, 111, 1111, 11111]

for i in range(1, n + 1):
    x = str(i)[0]
    y = str(i)[-1]
    if y == "0":  
        continue

    if x == y:  
        ans += 1

    if y < nx:  
        if digit - 2 < 0:  
            continue
        ans += is_full[digit - 2]
    elif y == nx:
        if digit - 3 >= 0:
            ans += is_full[digit - 3]
        for num, k in enumerate(list(str(n))[1: -1], 1):  
            ans += int(k) * 10 ** (digit - 2 - num)

        if digit >= 2 and x <= ny:  
            ans += 1
    else:  
        if digit - 3 < 0:  
            continue
        ans += is_full[digit - 3]

print(ans)

Solution (Python):
import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
import sys
from collections import deque, defaultdict, Counter; from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20; INF = float("INF"); ans = 0; tmp = 0; cnt = 0; ansli = []; tmpli = []; candili = []; stillset = set()
eps = 1.0 / 10 ** 10; mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]; ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]; ddn9 = ddn + [(0, 0)]
"""for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""
def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def ws(): return sys.stdin.readline().split()
def i(): return int(sys.stdin.readline())
def s(): return input()
def s_list(): return list(input())
def hi(n): return [i() for _ in range(n)]
def hs(n): return [s() for _ in range(n)]
def mi(n): return [wi() for _ in range(n)]
def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[0]] for _ in range(n)]
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]
def grid(n): return [s_list() for _ in range(n)]

n = i()
nx = str(n)[0]
ny = str(n)[-1]
digit = len(str(n))
is_full = [1, 11, 111, 1111, 11111]

for i in range(1, n + 1):
    x = str(i)[0]
    y = str(i)[-1]
    if y == "0":  
        continue

    if x == y:  
        ans += 1

    if y < nx:  
        if digit - 2 < 0:  
            continue
        ans += is_full[digit - 2]
    elif y == nx:
        if digit - 3 >= 0:
            ans += is_full[digit - 3]
        for num, k in enumerate(list(str(n))[1: -1], 1):  
            ans += int(k) * 10 ** (digit - 2 - num)

        if digit >= 2 and x <= ny:  
            ans += 1
    else:  
        if digit - 3 < 0:  
            continue
        ans += is_full[digit - 3]

print(ans)

Solution (Python):
import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
import sys
from collections import deque, defaultdict, Counter; from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20; INF = float("INF"); ans = 0; tmp = 0; cnt = 0; ansli = []; tmpli = []; candili = []; stillset = set()
eps = 1.0 / 10 ** 10; mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]; ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]; ddn9 = ddn + [(0, 0)]
"""for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""
def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def ws(): return sys.stdin.readline().split()
def i(): return int(sys.stdin.readline())
def s(): return input()
def s_list(): return list(input())
def hi(n): return [i() for _ in range(n)]
def hs(n): return [s() for _ in range(n)]
def mi(n): return [wi() for _ in range(n)]
def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[0]] for _ in range(n)]
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]
def grid(n): return [s_list() for _ in range(n)]

n = i()
nx = str(n)[0]
ny = str(n)[-1]
digit = len(str(n))
is_full = [1, 11, 111, 1111, 11111]

for i in range(1, n + 1):
    x = str(i)[0]
    y = str(i)[-1]
    if y == "0":
        continue
    
    if x == y:
        ans += 1
        if y < nx:
            if digit - 2 < 0:
                continue
            ans += is_full[digit - 2]
        elif y == nx:
            if digit - 3 >= 0:
                ans += is_full[digit - 3]
            for num, k in enumerate(list(str(n))[1: -1], 1):
                ans += int(k) * 10 ** (digit - 2 - num)

            if digit == 2:
                if int(x + y) <= n:
                    ans += 1
            if digit >= 3 and x <= ny:
                ans += 1

        else:
            if digit - 3 < 0:
                continue
            ans += is_full[digit - 3]
    else:
        if y < nx:
            if digit - 2 < 0:
                continue
            ans += is_full[digit - 2]
        elif y == nx:
            if digit - 3 >= 0:
                ans += is_full[digit - 3]
            for num, k in enumerate(list(str(n))[1: -1], 1):
                ans += int(k) * 10 ** (digit - 2 - num)
            if digit == 2:
                if int(x + y) <= n:
                    ans += 1
            if digit >= 3 and x <= ny:
                ans += 1
        else:
            if digit - 3 < 0:
                continue
            ans += is_full[digit - 3]

print(ans)

Solution (Python):
n = int(input())
ab = [0] * 100
for i in range(1, n + 1):
    s = str(i)
    front = s[0]
    back = s[-1]
    ab[int(front + back)] += 1

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

print(ans)

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

ans=0
Dic={}
for i in range(1,n+1):
    s=str(i)
    d=(s[0],s[-1])
    if d in Dic.keys():
        Dic[d]+=1
    else:
        Dic[d]=1

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

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

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

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

print(count)

Solution (Python):
n=int(input())
ans=0
dic={}
for i in range(1,n+1):
    s=str(i)
    d=(s[0],s[-1])
    if d not in dic.keys():
        dic[d] = 1
    else:
        dic[d] += 1
 
for a in dic.keys():
    b = (a[1],a[0])
    if b in dic.keys():
        ans += dic[a]*dic[(a[1],a[0])]
 
print(ans)

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



keta = len(str(N))
answer = 0

k = 1
for i in range(1,N+1):
    k = 1
    if i % 10 == 0:
        continue
    
    if str(i)[0] == str(i)[-1]:
        answer += 1
    
    if int(str(i)[-1]+str(i)[0]) <= N:
        answer += 1
    k =3
    
    if k <= keta:
        flag = 10
        while k < keta:
            answer += flag
            k += 1
            flag *= 10
        
        if str(i)[-1] < str(N)[0]:
            answer += flag
        elif str(i)[-1] == str(N)[0]:
            
            kake = ''
            for j in range(1,keta-1):
                kake += str(N)[j]
            
            if str(i)[0] <= str(N)[-1]:
                answer += (int(kake)+1)
            else:
                answer += max((int(kake)),0)
print(answer)

Solution (Python):

from collections import defaultdict

N = int(input())
dic = defaultdict(int)

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

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

Solution (Python):
import numpy as np
n = int(input())
ary = np.zeros((10, 10))
for i in range(n):
  ary[int(str(i + 1)[0]) - 1][int(str(i + 1)[-1]) - 1] += 1
print(np.sum(ary * ary.T).astype(np.int32))

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

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

ans = 0

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

print(ans)

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

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

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

print(ans)

Solution (Python):

"""
Created on Sun Jan 19 21:23:54 2020

@author: over-
"""
def check(N):
    c=0
    for i in range(1,N+1):
        if str(i)[-1] !=0:
            for j in range(1,N+1):
                if str(i)[0]==str(j)[-1] and str(i)[-1]==str(j)[0]: c+=1
                  
    return c

N=input()
L=len(N)

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

    
    if y!=0:
        d=0
        if x==y: 
            d+=1
        if L==2:
            if int(N)>=int('{}{}'.format(y,x)):
                d+=1
        if L==3:
            d+=1
            if int(N)>=int('{}9{}'.format(y,x)):
                d+=10
            elif int(N)>=int('{}0{}'.format(y,x)):
                d+=int(N[1:-1])
                if int(N)>=int('{}{}{}'.format(y,N[1:-1],x)):
                    d+=1
        if L==4:
            d+=1+10
            if int(N)>=int('{}99{}'.format(y,x)):
                d+=100
            elif int(N)>int('{}00{}'.format(y,x)):
                d+=int(N[1:-1])
                if int(N)>=int('{}{}{}'.format(y,N[1:-1],x)):
                    d+=1
        if L==5:
            d+=1+10+100
            if int(N)>=int('{}999{}'.format(y,x)):
                d+=1000
            elif int(N)>=int('{}000{}'.format(y,x)):
                d+=int(N[1:-1])
                if int(N)>=int('{}{}{}'.format(y,N[1:-1],x)):
                    d+=1
        if L==6:
            d+=1+10+100+1000
            if int(N)>=int('{}9999{}'.format(y,x)):
                d+=10000
            elif int(N)>=int('{}0000{}'.format(y,x)):
                d+=int(N[1:-1])
                if int(N)>=int('{}{}{}'.format(y,N[1:-1],x)):
                    d+=1
        
        c+=d
        

print(c)

Solution (Python):
n = int(input())
d = {}

for a in range(1, n+1):
    a = str(a)
    f, l = a[0], a[-1]
    if '0' in [f, l]:
        continue
    if (f, l) in d:
        d[(f, l)] += 1
    else:
        d[(f, l)] = 1

ans = 0
for b in range(1, n+1):
    b = str(b)
    f, l = b[-1], b[0]
    if (f, l) in d:
        ans += d[(f, l)]
print(ans)

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

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

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

print(ans)

Solution (Python):


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

for i in range(1,N+1):
    s = str(i)
    lis[int(s[0])][int(s[-1])] += 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
tmp = int("0"+str(N)[1:-1])
NR = int(str(N)[-1])
for i in range(1,N+1):
    L = int(str(i)[0])
    R = int(str(i)[-1])
    if R == 0:
        continue
    if L == R:
        ans += 1
    for j in range(1,6):
        mini = (R*10**j) +L
        maxi = ((R+1)*10**j) +L-10
        if N < mini:
            break
        if maxi <= N:
            ans += 10**(j-1)
            continue
        
        if L <= NR:
            ans += tmp+1
        else:
            ans += tmp
        break
print(ans)

Solution (Python):
n=int(input())
check=[[0]*9 for i in range(9)]
for i in range(1,n+1):
    s=str(i)
    s1=int(s[0])-1
    s2=int(s[-1])-1
    if s2==-1:continue
    check[s1][s2]+=1
cnt=0
for i in range(9):
    for j in range(9):
        cnt+=check[i][j]*check[j][i]
print(cnt)

Solution (Python):

import sys
def comp_begin_end(a):
    if int(str(n)[0]) >= int(str(n)[-1]): return 1
    else:   return 0

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n = int(readline())


c = [[0]*10 for _ in range(10)] 
for k in range(1,n+1):
    i = int(str(k)[0]) 
    j =  int(str(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)
"""
ans = 0
for i in range(1,n+1):
    if comp_begin_end(i): ans += 1
    if 10 <= n < 100:
        if int(str(n)[0]) == int(str(n)[-1]): ans += 1
    if 100 <= n < 1000:
        ans += 1
        if int(str(n)[0]) == int(str(n)[-1]): ans += 1
    if 1000 <= n < 100000:
        ans += 11
        if int(str(n)[0]) == int(str(n)[-1]): ans += 1
    if 10000 <= n:
        ans += 111
        if int(str(n)[0]) == int(str(n)[-1]): ans += 1
print(ans)"""

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

Solution (Python):
def sigma2(n,i,j):
    if i==j and n<i:
        ncnt= 0
    elif i==j and i<=n:
        ncnt=1
    else:
        ncnt=0    

    if i*10+j<=n:
        ncnt=ncnt+1
        
    mcnt=-1
    nn=0
    for kt in range(1,6,1):
       for kt2 in range(10**kt):
           mcnt=mcnt+1
           nn=i*10**(kt+1)+kt2*10+j
           if nn>n:
               break
       if nn>n:
           break
               
    return mcnt+ncnt                


n=int(input())
ncnt=0
for k in range(1,10,1):
    for m in range(1,10,1):
        s1=sigma2(n,k,m)
        s2=sigma2(n,m,k)
        ncnt=ncnt+s1*s2


print(ncnt)

Solution (Python):
N = int(input())
l = [[0] * 10 for i in range(10)]
ans = 0
for i in range(1, N+1):
  if str(i)[-1] == "0":
    continue
  else:
    l[int(str(i)[0])][int(str(i)[-1])] += 1
for i in range(10):
  for j in range(10):
    ans += l[i][j] * l[j][i]
print(ans)

Solution (Python):

import sys
import math
INF = float("inf")


def solve(N: int):
    table = [[0]*10 for _ in range(10)]

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

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


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    solve(N)


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
r = range(1, min(9, n) + 1)
a = [None]
for i in r:
  a.append([None])
  for j in r:
    a[i].append(i == j)
    k = 1
    while 10 * k * i + j <= n:
      a[i][j] += min(k, (n - j) // 10 - k * i + 1)
      k *= 10
print(sum(a[i][j] * a[j][i] for i in r for j in r))

Solution (Python):
n = int(input())
r = range(1, min(9, n) + 1)
a = [None] + [[None] * 10 for _ in r]
for i in r:
  for j in r:
    a[i][j] = i == j
    k = 1
    while 10 * k * i + j <= n:
      a[i][j] += min(k, (n - j) // 10 - k * i + 1)
      k *= 10
print(sum(a[i][j] * a[j][i] for i in r for j in r))

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

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

ans = 0
for i, j in list(d):
    c = d[(i,j)]
    f = d[(j,i)]
    ans += int(d[(i,j)]) * int(d[(j,i)])
print(ans)

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

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

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

print(ans)

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

n = 100
a = 0

while N > n:
    a += n//100
    n *= 10

n //= 10

x = [[a]*9 for _ in range(9)]

b = N // n
for i in range(b-1):
    for j in range(9):
        x[i][j] += n//10

for i in range(N%n+1):
    c = i % 10
    if c != 0:
        x[b-1][c-1] += 1

for i in range(min(9, N)):
    x[i][i] += 1

cnt = 0

for i in range(9):
    for j in range(9):
        cnt += x[i][j] * x[j][i]

print(cnt)

Solution (Python):
import copy
from collections import defaultdict

n = int(input())

count = defaultdict(int)


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

copied_count = copy.deepcopy(count)
ans = 0
for (h, t), v in count.items():
    ans += v * copied_count[(t, h)]

print(ans)

Solution (Python):
n=int(input())
a=[[0]*10 for i in range(10)]
for i in range(1,n+1):
    a[int(str(i)[0])][i%10]+=1
ans=0
for x in range(1,10):
    ans+=a[x][x]**2
    for y in range(x+1,10):
        ans+=a[y][x]*a[x][y]*2
print(ans)

Solution (Python):
n=int(input())
a=[[0]*10 for i in range(10)]
for i in range(1,n+1):
    a[int(str(i)[0])][i%10]+=1
def N(x,y): 
    return a[x][y]

ans=0
for x in range(1,10):
    ans+=N(x,x)*N(x,x)
    for y in range(x+1,10):
        ans+=N(x,y)*N(y,x)*2
print(ans)

Solution (Python):
from functools import lru_cache

@lru_cache(maxsize=10**6)
def N(x,y,n): 
    r=0
    for i in range(1,n+1):
        if str(i)[0]==str(x) and str(i)[-1]==str(y):
            r+=1
    return r

ans=0
n=int(input())
for x in range(1,10):
    ans+=N(x,x,n)*N(x,x,n)
    for y in range(x+1,10):
        ans+=N(x,y,n)*N(y,x,n)*2
        
print(ans)

Solution (Python):
def N(x,y,n): 
    r=0
    for i in range(1,n+1):
        if str(i)[0]==str(x) and str(i)[-1]==str(y):
            r+=1
    return r

ans=0
n=int(input())
for x in range(1,10):
    ans+=N(x,x,n)*N(x,x,n)
    for y in range(x+1,10):
        ans+=N(x,y,n)*N(y,x,n)*2
        
print(ans)

Solution (Python):



from collections import defaultdict

def main():
  count = defaultdict(lambda :defaultdict(int))
  n = int(input())
  for i in range(1, n+1):
    count[int(str(i)[0])][int(str(i)[-1])] += 1

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

if __name__=='__main__':
  main()

Solution (Python):
def main3(N):
    lst = list()
    for i in range(1, 10):
        lst.append([0]*9)

    for n in range(1, N+1):
        head = int(str(n)[0])
        tail = int(str(n)[-1])
        
        if tail != 0:
            lst[head-1][tail-1] += 1
        
    
    
    
    count = 0
    for i in range(0, len(lst)):
        for j in range(0, len(lst[i])):
            count += lst[i][j] * lst[j][i]

    print(count)

N = int(input())
main3(N)

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

k = {i: 0 for i in range(1, 100) if str(i)[-1] != '0'}

for i in range(1, N+1):
    if i < 10:
        k[i] += 1
        zoro = int(str(i)*2)
        if zoro <= N:
            k[zoro] += 1
    else:
        _i = str(i)
        first = int(_i[0])
        last  = int(_i[-1])
        if last != 0:
            handstand = int(str(last)+str(first))
            if first == last:
                k[first] += 1
                k[int(str(first)*2)] += 1
            elif handstand <= N:
                k[handstand] += 1

ans = 0
for i in range(1, N+1):
    _i = str(i)
    first = int(_i[0])
    last  = int(_i[-1])
    if i < 10:
        ans += k[i]
    elif last != 0:
        ans += k[int(str(first)+str(last))]

print(ans)

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

memo = [[0] * 10 for _ in range(10)]
for i in range(1, N + 1):
    S = str(i)
    a, b = int(S[0]), int(S[-1])
    memo[a][b] += 1

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

print(ans)

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

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



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

print(result)